[clang] [NFC] Cleanup and sort hlsl_intrinsics.h (PR #72414)

2023-11-15 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 approved this pull request.


https://github.com/llvm/llvm-project/pull/72414
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

2024-03-13 Thread Joshua Batista via cfe-commits


@@ -8545,6 +8545,11 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
+def dxc_hlsl_version : Option<["/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+ Group,
+ Visibility<[DXCOption]>,
+ HelpText<"HLSL Version">,
+ NormalizedValues<["2016", "2017", "2018", "2021", 
"202x"]>;

bob80905 wrote:

Populating the help spew seems helpful! I can remove the marshalling part, but 
it seems helpful to leave the rest as is.

https://github.com/llvm/llvm-project/pull/83938
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

2024-03-13 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/83938

>From 7453ffdea39c624221c9696394bbd47be7eec662 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 13:42:02 -0800
Subject: [PATCH 01/10] first try

---
 clang/include/clang/Driver/Options.td | 4 
 clang/lib/Driver/ToolChains/HLSL.cpp  | 8 
 2 files changed, 12 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bef38738fde82e..6fe3dea1655b24 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,6 +8545,10 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
+def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+ Group,
+ Visibility<[DXCOption]>,
+ HelpText<"HLSL Version">;
 def dxc_validator_path_EQ : Joined<["--"], "dxv-path=">, Group,
   HelpText<"DXIL validator installation path">;
 def dxc_disable_validation : DXCFlag<"Vd">,
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index c6ad862b229420..0ffc15155e4db3 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,6 +226,14 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
+if (A->getOption().getID() == options::OPT_HLSL_Version) {
+  // Translate -HV into -std for llvm
+  DAL->AddSeparateArg(nullptr,
+  Opts.getOption(options::OPT_stdlibxx_isystem),
+  A->getValue());
+  A->claim();
+  continue;
+}
 DAL->append(A);
   }
 

>From 69953d737b842f2144ebe0519d810c57b5c031b9 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 17:11:37 -0800
Subject: [PATCH 02/10] add HV option, and translation test

---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 22 ++
 clang/test/Options/HV.hlsl| 13 +
 3 files changed, 32 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Options/HV.hlsl

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6fe3dea1655b24..c4caf232887b56 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,7 +8545,7 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
-def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+def dxc_hlsl_version : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"HLSL Version">;
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 0ffc15155e4db3..fe258919dedf3e 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,11 +226,25 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
-if (A->getOption().getID() == options::OPT_HLSL_Version) {
+if (A->getOption().getID() == options::OPT_dxc_hlsl_version) {
   // Translate -HV into -std for llvm
-  DAL->AddSeparateArg(nullptr,
-  Opts.getOption(options::OPT_stdlibxx_isystem),
-  A->getValue());
+  // depending on the value given, assign std to:
+  // c++14,c++17,c++20,c++latest,c11,c17
+  const char *value = A->getValue();
+  if (strcmp(value, "2016") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2016");
+  } else if (strcmp(value, "2017") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2017");
+  } else if (strcmp(value, "2018") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2018");
+  } else if (strcmp(value, "2021") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2021");
+  }
+
   A->claim();
   continue;
 }
diff --git a/clang/test/Options/HV.hlsl b/clang/test/Options/HV.hlsl
new file mode 100644
index 00..59158ff2f001ed
--- /dev/null
+++ b/clang/test/Options/HV.hlsl
@@ -0,0 +1,13 @@
+// RUN: %clang_dxc -T lib_6_4 -HV 2016 %s 2>&1 -###   | FileCheck 
-check-prefix=2016 %s
+// RUN: %clang_dxc -T lib_6_4 -HV 2017 %s 2>&1 -###   | FileCheck 
-c

[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

2024-03-13 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/83938

>From 7453ffdea39c624221c9696394bbd47be7eec662 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 13:42:02 -0800
Subject: [PATCH 01/11] first try

---
 clang/include/clang/Driver/Options.td | 4 
 clang/lib/Driver/ToolChains/HLSL.cpp  | 8 
 2 files changed, 12 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bef38738fde82e..6fe3dea1655b24 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,6 +8545,10 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
+def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+ Group,
+ Visibility<[DXCOption]>,
+ HelpText<"HLSL Version">;
 def dxc_validator_path_EQ : Joined<["--"], "dxv-path=">, Group,
   HelpText<"DXIL validator installation path">;
 def dxc_disable_validation : DXCFlag<"Vd">,
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index c6ad862b229420..0ffc15155e4db3 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,6 +226,14 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
+if (A->getOption().getID() == options::OPT_HLSL_Version) {
+  // Translate -HV into -std for llvm
+  DAL->AddSeparateArg(nullptr,
+  Opts.getOption(options::OPT_stdlibxx_isystem),
+  A->getValue());
+  A->claim();
+  continue;
+}
 DAL->append(A);
   }
 

>From 69953d737b842f2144ebe0519d810c57b5c031b9 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 17:11:37 -0800
Subject: [PATCH 02/11] add HV option, and translation test

---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 22 ++
 clang/test/Options/HV.hlsl| 13 +
 3 files changed, 32 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Options/HV.hlsl

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6fe3dea1655b24..c4caf232887b56 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,7 +8545,7 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
-def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+def dxc_hlsl_version : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"HLSL Version">;
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 0ffc15155e4db3..fe258919dedf3e 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,11 +226,25 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
-if (A->getOption().getID() == options::OPT_HLSL_Version) {
+if (A->getOption().getID() == options::OPT_dxc_hlsl_version) {
   // Translate -HV into -std for llvm
-  DAL->AddSeparateArg(nullptr,
-  Opts.getOption(options::OPT_stdlibxx_isystem),
-  A->getValue());
+  // depending on the value given, assign std to:
+  // c++14,c++17,c++20,c++latest,c11,c17
+  const char *value = A->getValue();
+  if (strcmp(value, "2016") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2016");
+  } else if (strcmp(value, "2017") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2017");
+  } else if (strcmp(value, "2018") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2018");
+  } else if (strcmp(value, "2021") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2021");
+  }
+
   A->claim();
   continue;
 }
diff --git a/clang/test/Options/HV.hlsl b/clang/test/Options/HV.hlsl
new file mode 100644
index 00..59158ff2f001ed
--- /dev/null
+++ b/clang/test/Options/HV.hlsl
@@ -0,0 +1,13 @@
+// RUN: %clang_dxc -T lib_6_4 -HV 2016 %s 2>&1 -###   | FileCheck 
-check-prefix=2016 %s
+// RUN: %clang_dxc -T lib_6_4 -HV 2017 %s 2>&1 -###   | FileCheck 
-c

[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

2024-03-13 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/83938

>From 7453ffdea39c624221c9696394bbd47be7eec662 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 13:42:02 -0800
Subject: [PATCH 01/12] first try

---
 clang/include/clang/Driver/Options.td | 4 
 clang/lib/Driver/ToolChains/HLSL.cpp  | 8 
 2 files changed, 12 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bef38738fde82e..6fe3dea1655b24 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,6 +8545,10 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
+def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+ Group,
+ Visibility<[DXCOption]>,
+ HelpText<"HLSL Version">;
 def dxc_validator_path_EQ : Joined<["--"], "dxv-path=">, Group,
   HelpText<"DXIL validator installation path">;
 def dxc_disable_validation : DXCFlag<"Vd">,
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index c6ad862b229420..0ffc15155e4db3 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,6 +226,14 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
+if (A->getOption().getID() == options::OPT_HLSL_Version) {
+  // Translate -HV into -std for llvm
+  DAL->AddSeparateArg(nullptr,
+  Opts.getOption(options::OPT_stdlibxx_isystem),
+  A->getValue());
+  A->claim();
+  continue;
+}
 DAL->append(A);
   }
 

>From 69953d737b842f2144ebe0519d810c57b5c031b9 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 17:11:37 -0800
Subject: [PATCH 02/12] add HV option, and translation test

---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 22 ++
 clang/test/Options/HV.hlsl| 13 +
 3 files changed, 32 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Options/HV.hlsl

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6fe3dea1655b24..c4caf232887b56 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,7 +8545,7 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
-def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+def dxc_hlsl_version : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"HLSL Version">;
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 0ffc15155e4db3..fe258919dedf3e 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,11 +226,25 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
-if (A->getOption().getID() == options::OPT_HLSL_Version) {
+if (A->getOption().getID() == options::OPT_dxc_hlsl_version) {
   // Translate -HV into -std for llvm
-  DAL->AddSeparateArg(nullptr,
-  Opts.getOption(options::OPT_stdlibxx_isystem),
-  A->getValue());
+  // depending on the value given, assign std to:
+  // c++14,c++17,c++20,c++latest,c11,c17
+  const char *value = A->getValue();
+  if (strcmp(value, "2016") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2016");
+  } else if (strcmp(value, "2017") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2017");
+  } else if (strcmp(value, "2018") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2018");
+  } else if (strcmp(value, "2021") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2021");
+  }
+
   A->claim();
   continue;
 }
diff --git a/clang/test/Options/HV.hlsl b/clang/test/Options/HV.hlsl
new file mode 100644
index 00..59158ff2f001ed
--- /dev/null
+++ b/clang/test/Options/HV.hlsl
@@ -0,0 +1,13 @@
+// RUN: %clang_dxc -T lib_6_4 -HV 2016 %s 2>&1 -###   | FileCheck 
-check-prefix=2016 %s
+// RUN: %clang_dxc -T lib_6_4 -HV 2017 %s 2>&1 -###   | FileCheck 
-c

[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

2024-03-13 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/83938

>From 7453ffdea39c624221c9696394bbd47be7eec662 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 13:42:02 -0800
Subject: [PATCH 01/13] first try

---
 clang/include/clang/Driver/Options.td | 4 
 clang/lib/Driver/ToolChains/HLSL.cpp  | 8 
 2 files changed, 12 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bef38738fde82e..6fe3dea1655b24 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,6 +8545,10 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
+def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+ Group,
+ Visibility<[DXCOption]>,
+ HelpText<"HLSL Version">;
 def dxc_validator_path_EQ : Joined<["--"], "dxv-path=">, Group,
   HelpText<"DXIL validator installation path">;
 def dxc_disable_validation : DXCFlag<"Vd">,
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index c6ad862b229420..0ffc15155e4db3 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,6 +226,14 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
+if (A->getOption().getID() == options::OPT_HLSL_Version) {
+  // Translate -HV into -std for llvm
+  DAL->AddSeparateArg(nullptr,
+  Opts.getOption(options::OPT_stdlibxx_isystem),
+  A->getValue());
+  A->claim();
+  continue;
+}
 DAL->append(A);
   }
 

>From 69953d737b842f2144ebe0519d810c57b5c031b9 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 17:11:37 -0800
Subject: [PATCH 02/13] add HV option, and translation test

---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 22 ++
 clang/test/Options/HV.hlsl| 13 +
 3 files changed, 32 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Options/HV.hlsl

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6fe3dea1655b24..c4caf232887b56 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,7 +8545,7 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
-def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+def dxc_hlsl_version : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"HLSL Version">;
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 0ffc15155e4db3..fe258919dedf3e 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,11 +226,25 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
-if (A->getOption().getID() == options::OPT_HLSL_Version) {
+if (A->getOption().getID() == options::OPT_dxc_hlsl_version) {
   // Translate -HV into -std for llvm
-  DAL->AddSeparateArg(nullptr,
-  Opts.getOption(options::OPT_stdlibxx_isystem),
-  A->getValue());
+  // depending on the value given, assign std to:
+  // c++14,c++17,c++20,c++latest,c11,c17
+  const char *value = A->getValue();
+  if (strcmp(value, "2016") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2016");
+  } else if (strcmp(value, "2017") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2017");
+  } else if (strcmp(value, "2018") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2018");
+  } else if (strcmp(value, "2021") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2021");
+  }
+
   A->claim();
   continue;
 }
diff --git a/clang/test/Options/HV.hlsl b/clang/test/Options/HV.hlsl
new file mode 100644
index 00..59158ff2f001ed
--- /dev/null
+++ b/clang/test/Options/HV.hlsl
@@ -0,0 +1,13 @@
+// RUN: %clang_dxc -T lib_6_4 -HV 2016 %s 2>&1 -###   | FileCheck 
-check-prefix=2016 %s
+// RUN: %clang_dxc -T lib_6_4 -HV 2017 %s 2>&1 -###   | FileCheck 
-c

[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

2024-03-13 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/83938

>From 7453ffdea39c624221c9696394bbd47be7eec662 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 13:42:02 -0800
Subject: [PATCH 01/14] first try

---
 clang/include/clang/Driver/Options.td | 4 
 clang/lib/Driver/ToolChains/HLSL.cpp  | 8 
 2 files changed, 12 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bef38738fde82e..6fe3dea1655b24 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,6 +8545,10 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
+def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+ Group,
+ Visibility<[DXCOption]>,
+ HelpText<"HLSL Version">;
 def dxc_validator_path_EQ : Joined<["--"], "dxv-path=">, Group,
   HelpText<"DXIL validator installation path">;
 def dxc_disable_validation : DXCFlag<"Vd">,
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index c6ad862b229420..0ffc15155e4db3 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,6 +226,14 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
+if (A->getOption().getID() == options::OPT_HLSL_Version) {
+  // Translate -HV into -std for llvm
+  DAL->AddSeparateArg(nullptr,
+  Opts.getOption(options::OPT_stdlibxx_isystem),
+  A->getValue());
+  A->claim();
+  continue;
+}
 DAL->append(A);
   }
 

>From 69953d737b842f2144ebe0519d810c57b5c031b9 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 17:11:37 -0800
Subject: [PATCH 02/14] add HV option, and translation test

---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 22 ++
 clang/test/Options/HV.hlsl| 13 +
 3 files changed, 32 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Options/HV.hlsl

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6fe3dea1655b24..c4caf232887b56 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,7 +8545,7 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
-def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+def dxc_hlsl_version : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"HLSL Version">;
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 0ffc15155e4db3..fe258919dedf3e 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,11 +226,25 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
-if (A->getOption().getID() == options::OPT_HLSL_Version) {
+if (A->getOption().getID() == options::OPT_dxc_hlsl_version) {
   // Translate -HV into -std for llvm
-  DAL->AddSeparateArg(nullptr,
-  Opts.getOption(options::OPT_stdlibxx_isystem),
-  A->getValue());
+  // depending on the value given, assign std to:
+  // c++14,c++17,c++20,c++latest,c11,c17
+  const char *value = A->getValue();
+  if (strcmp(value, "2016") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2016");
+  } else if (strcmp(value, "2017") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2017");
+  } else if (strcmp(value, "2018") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2018");
+  } else if (strcmp(value, "2021") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2021");
+  }
+
   A->claim();
   continue;
 }
diff --git a/clang/test/Options/HV.hlsl b/clang/test/Options/HV.hlsl
new file mode 100644
index 00..59158ff2f001ed
--- /dev/null
+++ b/clang/test/Options/HV.hlsl
@@ -0,0 +1,13 @@
+// RUN: %clang_dxc -T lib_6_4 -HV 2016 %s 2>&1 -###   | FileCheck 
-check-prefix=2016 %s
+// RUN: %clang_dxc -T lib_6_4 -HV 2017 %s 2>&1 -###   | FileCheck 
-c

[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

2024-03-13 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 closed 
https://github.com/llvm/llvm-project/pull/83938
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add diagnostic for enabling 16 bit types (PR #84537)

2024-03-14 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 closed 
https://github.com/llvm/llvm-project/pull/84537
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-14 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 created 
https://github.com/llvm/llvm-project/pull/85340

Previously, the clang compiler with the dxc driver would accept the 
-enable-16bit-types flag without checking to see if the required conditions are 
met for proper processing of the flag. 
Specifically, -enable-16bit-types requires a shader model of at least 6.2 and 
an HLSL version of at least 2021.
This PR adds a validation check for these other options having the required 
values, and emits an error if these constraints are not met. 
Fixes #57876

>From 3cdcfa4e63550b9677c8ffe2f33eab85899b2c45 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 14 Mar 2024 17:04:12 -0700
Subject: [PATCH] add test

---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 86 ---
 2 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e33a1f4c45b949..fae9132bd0a9c9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,7 +753,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types_option_invalid: Error<
+  "enable_16bit_types option only valid when target shader model [-T] is >= 
6.2 and Hlsl Version [-HV] is >= 2021">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 05aac9caa7fb29..bf8fc42a27816c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -66,15 +66,48 @@ bool isLegalShaderModel(Triple &T) {
   return false;
 }
 
-std::optional tryParseProfile(StringRef Profile) {
-  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+struct ShaderModel {
+  StringRef TargetKind;
+  unsigned Major;
+  unsigned Minor;
+  bool OfflineLibMinor = false;
+};
+
+std::optional GetShaderModelFromString(StringRef Profile) {
   SmallVector Parts;
   Profile.split(Parts, "_");
   if (Parts.size() != 3)
 return std::nullopt;
 
+  unsigned long long Major = 0;
+  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
+return std::nullopt;
+
+  unsigned long long Minor = 0;
+  bool isOfflineLibMinor = false;
+  if (Parts[0] == "lib" && Parts[2] == "x")
+isOfflineLibMinor = true;
+  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
+return std::nullopt;
+
+  ShaderModel ret;
+  ret.TargetKind = Parts[0];
+  ret.Major = Major;
+  ret.Minor = Minor;
+  ret.OfflineLibMinor = isOfflineLibMinor;
+
+  return ret;
+}
+
+std::optional tryParseProfile(StringRef Profile) {
+  std::optional SM = GetShaderModelFromString(Profile);
+  if (!SM.has_value()) {
+return std::nullopt;
+  }
+  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+
   Triple::EnvironmentType Kind =
-  StringSwitch(Parts[0])
+  StringSwitch(SM.value().TargetKind)
   .Case("ps", Triple::EnvironmentType::Pixel)
   .Case("vs", Triple::EnvironmentType::Vertex)
   .Case("gs", Triple::EnvironmentType::Geometry)
@@ -88,21 +121,11 @@ std::optional tryParseProfile(StringRef 
Profile) {
   if (Kind == Triple::EnvironmentType::UnknownEnvironment)
 return std::nullopt;
 
-  unsigned long long Major = 0;
-  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
-return std::nullopt;
-
-  unsigned long long Minor = 0;
-  if (Parts[2] == "x" && Kind == Triple::EnvironmentType::Library)
-Minor = OfflineLibMinor;
-  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
-return std::nullopt;
-
   // dxil-unknown-shadermodel-hull
   llvm::Triple T;
   T.setArch(Triple::ArchType::dxil);
   T.setOSName(Triple::getOSTypeName(Triple::OSType::ShaderModel).str() +
-  VersionTuple(Major, Minor).getAsString());
+  VersionTuple(SM.value().Major, SM.value().Minor).getAsString());
   T.setEnvironment(Kind);
   if (isLegalShaderModel(T))
 return T.getTriple();
@@ -258,6 +281,41 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_fnative_half_type)) {
+
+bool HVArgIsValid = true;
+bool TPArgIsValid = true;
+
+const StringRef HVArg =
+DAL->getLastArgValue(options::OPT_std_EQ, "hlsl2021");
+
+const StringRef TPArg =
+DAL->getLas

[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-14 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/85340

>From 3cdcfa4e63550b9677c8ffe2f33eab85899b2c45 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 14 Mar 2024 17:04:12 -0700
Subject: [PATCH 1/2] add test

---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 86 ---
 2 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e33a1f4c45b949..fae9132bd0a9c9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,7 +753,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types_option_invalid: Error<
+  "enable_16bit_types option only valid when target shader model [-T] is >= 
6.2 and Hlsl Version [-HV] is >= 2021">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 05aac9caa7fb29..bf8fc42a27816c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -66,15 +66,48 @@ bool isLegalShaderModel(Triple &T) {
   return false;
 }
 
-std::optional tryParseProfile(StringRef Profile) {
-  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+struct ShaderModel {
+  StringRef TargetKind;
+  unsigned Major;
+  unsigned Minor;
+  bool OfflineLibMinor = false;
+};
+
+std::optional GetShaderModelFromString(StringRef Profile) {
   SmallVector Parts;
   Profile.split(Parts, "_");
   if (Parts.size() != 3)
 return std::nullopt;
 
+  unsigned long long Major = 0;
+  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
+return std::nullopt;
+
+  unsigned long long Minor = 0;
+  bool isOfflineLibMinor = false;
+  if (Parts[0] == "lib" && Parts[2] == "x")
+isOfflineLibMinor = true;
+  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
+return std::nullopt;
+
+  ShaderModel ret;
+  ret.TargetKind = Parts[0];
+  ret.Major = Major;
+  ret.Minor = Minor;
+  ret.OfflineLibMinor = isOfflineLibMinor;
+
+  return ret;
+}
+
+std::optional tryParseProfile(StringRef Profile) {
+  std::optional SM = GetShaderModelFromString(Profile);
+  if (!SM.has_value()) {
+return std::nullopt;
+  }
+  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+
   Triple::EnvironmentType Kind =
-  StringSwitch(Parts[0])
+  StringSwitch(SM.value().TargetKind)
   .Case("ps", Triple::EnvironmentType::Pixel)
   .Case("vs", Triple::EnvironmentType::Vertex)
   .Case("gs", Triple::EnvironmentType::Geometry)
@@ -88,21 +121,11 @@ std::optional tryParseProfile(StringRef 
Profile) {
   if (Kind == Triple::EnvironmentType::UnknownEnvironment)
 return std::nullopt;
 
-  unsigned long long Major = 0;
-  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
-return std::nullopt;
-
-  unsigned long long Minor = 0;
-  if (Parts[2] == "x" && Kind == Triple::EnvironmentType::Library)
-Minor = OfflineLibMinor;
-  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
-return std::nullopt;
-
   // dxil-unknown-shadermodel-hull
   llvm::Triple T;
   T.setArch(Triple::ArchType::dxil);
   T.setOSName(Triple::getOSTypeName(Triple::OSType::ShaderModel).str() +
-  VersionTuple(Major, Minor).getAsString());
+  VersionTuple(SM.value().Major, SM.value().Minor).getAsString());
   T.setEnvironment(Kind);
   if (isLegalShaderModel(T))
 return T.getTriple();
@@ -258,6 +281,41 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_fnative_half_type)) {
+
+bool HVArgIsValid = true;
+bool TPArgIsValid = true;
+
+const StringRef HVArg =
+DAL->getLastArgValue(options::OPT_std_EQ, "hlsl2021");
+
+const StringRef TPArg =
+DAL->getLastArgValue(options::OPT_target_profile, "");
+std::optional parsedTargetProfile =
+GetShaderModelFromString(TPArg);
+
+unsigned long long HV_year;
+StringRef HV_year_str = HVArg.drop_front(4);
+if (HV_year_str != "202x") {
+  llvm::getAsUnsignedInteger(HV_year_str, 0, HV_year);
+  if (HV_year < 2021)
+HVArgIsValid = false;
+}
+
+if (!parsedTargetProfile.has_value())
+  return DAL;
+else {
+

[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-15 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/85340

>From 3cdcfa4e63550b9677c8ffe2f33eab85899b2c45 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 14 Mar 2024 17:04:12 -0700
Subject: [PATCH 1/3] add test

---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 86 ---
 2 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e33a1f4c45b949..fae9132bd0a9c9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,7 +753,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types_option_invalid: Error<
+  "enable_16bit_types option only valid when target shader model [-T] is >= 
6.2 and Hlsl Version [-HV] is >= 2021">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 05aac9caa7fb29..bf8fc42a27816c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -66,15 +66,48 @@ bool isLegalShaderModel(Triple &T) {
   return false;
 }
 
-std::optional tryParseProfile(StringRef Profile) {
-  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+struct ShaderModel {
+  StringRef TargetKind;
+  unsigned Major;
+  unsigned Minor;
+  bool OfflineLibMinor = false;
+};
+
+std::optional GetShaderModelFromString(StringRef Profile) {
   SmallVector Parts;
   Profile.split(Parts, "_");
   if (Parts.size() != 3)
 return std::nullopt;
 
+  unsigned long long Major = 0;
+  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
+return std::nullopt;
+
+  unsigned long long Minor = 0;
+  bool isOfflineLibMinor = false;
+  if (Parts[0] == "lib" && Parts[2] == "x")
+isOfflineLibMinor = true;
+  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
+return std::nullopt;
+
+  ShaderModel ret;
+  ret.TargetKind = Parts[0];
+  ret.Major = Major;
+  ret.Minor = Minor;
+  ret.OfflineLibMinor = isOfflineLibMinor;
+
+  return ret;
+}
+
+std::optional tryParseProfile(StringRef Profile) {
+  std::optional SM = GetShaderModelFromString(Profile);
+  if (!SM.has_value()) {
+return std::nullopt;
+  }
+  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+
   Triple::EnvironmentType Kind =
-  StringSwitch(Parts[0])
+  StringSwitch(SM.value().TargetKind)
   .Case("ps", Triple::EnvironmentType::Pixel)
   .Case("vs", Triple::EnvironmentType::Vertex)
   .Case("gs", Triple::EnvironmentType::Geometry)
@@ -88,21 +121,11 @@ std::optional tryParseProfile(StringRef 
Profile) {
   if (Kind == Triple::EnvironmentType::UnknownEnvironment)
 return std::nullopt;
 
-  unsigned long long Major = 0;
-  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
-return std::nullopt;
-
-  unsigned long long Minor = 0;
-  if (Parts[2] == "x" && Kind == Triple::EnvironmentType::Library)
-Minor = OfflineLibMinor;
-  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
-return std::nullopt;
-
   // dxil-unknown-shadermodel-hull
   llvm::Triple T;
   T.setArch(Triple::ArchType::dxil);
   T.setOSName(Triple::getOSTypeName(Triple::OSType::ShaderModel).str() +
-  VersionTuple(Major, Minor).getAsString());
+  VersionTuple(SM.value().Major, SM.value().Minor).getAsString());
   T.setEnvironment(Kind);
   if (isLegalShaderModel(T))
 return T.getTriple();
@@ -258,6 +281,41 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_fnative_half_type)) {
+
+bool HVArgIsValid = true;
+bool TPArgIsValid = true;
+
+const StringRef HVArg =
+DAL->getLastArgValue(options::OPT_std_EQ, "hlsl2021");
+
+const StringRef TPArg =
+DAL->getLastArgValue(options::OPT_target_profile, "");
+std::optional parsedTargetProfile =
+GetShaderModelFromString(TPArg);
+
+unsigned long long HV_year;
+StringRef HV_year_str = HVArg.drop_front(4);
+if (HV_year_str != "202x") {
+  llvm::getAsUnsignedInteger(HV_year_str, 0, HV_year);
+  if (HV_year < 2021)
+HVArgIsValid = false;
+}
+
+if (!parsedTargetProfile.has_value())
+  return DAL;
+else {
+

[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-18 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/85340

>From 3cdcfa4e63550b9677c8ffe2f33eab85899b2c45 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 14 Mar 2024 17:04:12 -0700
Subject: [PATCH 1/4] add test

---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 86 ---
 2 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e33a1f4c45b949..fae9132bd0a9c9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,7 +753,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types_option_invalid: Error<
+  "enable_16bit_types option only valid when target shader model [-T] is >= 
6.2 and Hlsl Version [-HV] is >= 2021">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 05aac9caa7fb29..bf8fc42a27816c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -66,15 +66,48 @@ bool isLegalShaderModel(Triple &T) {
   return false;
 }
 
-std::optional tryParseProfile(StringRef Profile) {
-  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+struct ShaderModel {
+  StringRef TargetKind;
+  unsigned Major;
+  unsigned Minor;
+  bool OfflineLibMinor = false;
+};
+
+std::optional GetShaderModelFromString(StringRef Profile) {
   SmallVector Parts;
   Profile.split(Parts, "_");
   if (Parts.size() != 3)
 return std::nullopt;
 
+  unsigned long long Major = 0;
+  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
+return std::nullopt;
+
+  unsigned long long Minor = 0;
+  bool isOfflineLibMinor = false;
+  if (Parts[0] == "lib" && Parts[2] == "x")
+isOfflineLibMinor = true;
+  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
+return std::nullopt;
+
+  ShaderModel ret;
+  ret.TargetKind = Parts[0];
+  ret.Major = Major;
+  ret.Minor = Minor;
+  ret.OfflineLibMinor = isOfflineLibMinor;
+
+  return ret;
+}
+
+std::optional tryParseProfile(StringRef Profile) {
+  std::optional SM = GetShaderModelFromString(Profile);
+  if (!SM.has_value()) {
+return std::nullopt;
+  }
+  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+
   Triple::EnvironmentType Kind =
-  StringSwitch(Parts[0])
+  StringSwitch(SM.value().TargetKind)
   .Case("ps", Triple::EnvironmentType::Pixel)
   .Case("vs", Triple::EnvironmentType::Vertex)
   .Case("gs", Triple::EnvironmentType::Geometry)
@@ -88,21 +121,11 @@ std::optional tryParseProfile(StringRef 
Profile) {
   if (Kind == Triple::EnvironmentType::UnknownEnvironment)
 return std::nullopt;
 
-  unsigned long long Major = 0;
-  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
-return std::nullopt;
-
-  unsigned long long Minor = 0;
-  if (Parts[2] == "x" && Kind == Triple::EnvironmentType::Library)
-Minor = OfflineLibMinor;
-  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
-return std::nullopt;
-
   // dxil-unknown-shadermodel-hull
   llvm::Triple T;
   T.setArch(Triple::ArchType::dxil);
   T.setOSName(Triple::getOSTypeName(Triple::OSType::ShaderModel).str() +
-  VersionTuple(Major, Minor).getAsString());
+  VersionTuple(SM.value().Major, SM.value().Minor).getAsString());
   T.setEnvironment(Kind);
   if (isLegalShaderModel(T))
 return T.getTriple();
@@ -258,6 +281,41 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_fnative_half_type)) {
+
+bool HVArgIsValid = true;
+bool TPArgIsValid = true;
+
+const StringRef HVArg =
+DAL->getLastArgValue(options::OPT_std_EQ, "hlsl2021");
+
+const StringRef TPArg =
+DAL->getLastArgValue(options::OPT_target_profile, "");
+std::optional parsedTargetProfile =
+GetShaderModelFromString(TPArg);
+
+unsigned long long HV_year;
+StringRef HV_year_str = HVArg.drop_front(4);
+if (HV_year_str != "202x") {
+  llvm::getAsUnsignedInteger(HV_year_str, 0, HV_year);
+  if (HV_year < 2021)
+HVArgIsValid = false;
+}
+
+if (!parsedTargetProfile.has_value())
+  return DAL;
+else {
+

[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-18 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/85340

>From 3cdcfa4e63550b9677c8ffe2f33eab85899b2c45 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 14 Mar 2024 17:04:12 -0700
Subject: [PATCH 1/5] add test

---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 86 ---
 2 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e33a1f4c45b949..fae9132bd0a9c9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,7 +753,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types_option_invalid: Error<
+  "enable_16bit_types option only valid when target shader model [-T] is >= 
6.2 and Hlsl Version [-HV] is >= 2021">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 05aac9caa7fb29..bf8fc42a27816c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -66,15 +66,48 @@ bool isLegalShaderModel(Triple &T) {
   return false;
 }
 
-std::optional tryParseProfile(StringRef Profile) {
-  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+struct ShaderModel {
+  StringRef TargetKind;
+  unsigned Major;
+  unsigned Minor;
+  bool OfflineLibMinor = false;
+};
+
+std::optional GetShaderModelFromString(StringRef Profile) {
   SmallVector Parts;
   Profile.split(Parts, "_");
   if (Parts.size() != 3)
 return std::nullopt;
 
+  unsigned long long Major = 0;
+  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
+return std::nullopt;
+
+  unsigned long long Minor = 0;
+  bool isOfflineLibMinor = false;
+  if (Parts[0] == "lib" && Parts[2] == "x")
+isOfflineLibMinor = true;
+  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
+return std::nullopt;
+
+  ShaderModel ret;
+  ret.TargetKind = Parts[0];
+  ret.Major = Major;
+  ret.Minor = Minor;
+  ret.OfflineLibMinor = isOfflineLibMinor;
+
+  return ret;
+}
+
+std::optional tryParseProfile(StringRef Profile) {
+  std::optional SM = GetShaderModelFromString(Profile);
+  if (!SM.has_value()) {
+return std::nullopt;
+  }
+  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+
   Triple::EnvironmentType Kind =
-  StringSwitch(Parts[0])
+  StringSwitch(SM.value().TargetKind)
   .Case("ps", Triple::EnvironmentType::Pixel)
   .Case("vs", Triple::EnvironmentType::Vertex)
   .Case("gs", Triple::EnvironmentType::Geometry)
@@ -88,21 +121,11 @@ std::optional tryParseProfile(StringRef 
Profile) {
   if (Kind == Triple::EnvironmentType::UnknownEnvironment)
 return std::nullopt;
 
-  unsigned long long Major = 0;
-  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
-return std::nullopt;
-
-  unsigned long long Minor = 0;
-  if (Parts[2] == "x" && Kind == Triple::EnvironmentType::Library)
-Minor = OfflineLibMinor;
-  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
-return std::nullopt;
-
   // dxil-unknown-shadermodel-hull
   llvm::Triple T;
   T.setArch(Triple::ArchType::dxil);
   T.setOSName(Triple::getOSTypeName(Triple::OSType::ShaderModel).str() +
-  VersionTuple(Major, Minor).getAsString());
+  VersionTuple(SM.value().Major, SM.value().Minor).getAsString());
   T.setEnvironment(Kind);
   if (isLegalShaderModel(T))
 return T.getTriple();
@@ -258,6 +281,41 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_fnative_half_type)) {
+
+bool HVArgIsValid = true;
+bool TPArgIsValid = true;
+
+const StringRef HVArg =
+DAL->getLastArgValue(options::OPT_std_EQ, "hlsl2021");
+
+const StringRef TPArg =
+DAL->getLastArgValue(options::OPT_target_profile, "");
+std::optional parsedTargetProfile =
+GetShaderModelFromString(TPArg);
+
+unsigned long long HV_year;
+StringRef HV_year_str = HVArg.drop_front(4);
+if (HV_year_str != "202x") {
+  llvm::getAsUnsignedInteger(HV_year_str, 0, HV_year);
+  if (HV_year < 2021)
+HVArgIsValid = false;
+}
+
+if (!parsedTargetProfile.has_value())
+  return DAL;
+else {
+

[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-19 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/85340

>From 3cdcfa4e63550b9677c8ffe2f33eab85899b2c45 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 14 Mar 2024 17:04:12 -0700
Subject: [PATCH 1/6] add test

---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 86 ---
 2 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e33a1f4c45b949..fae9132bd0a9c9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,7 +753,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types_option_invalid: Error<
+  "enable_16bit_types option only valid when target shader model [-T] is >= 
6.2 and Hlsl Version [-HV] is >= 2021">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 05aac9caa7fb29..bf8fc42a27816c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -66,15 +66,48 @@ bool isLegalShaderModel(Triple &T) {
   return false;
 }
 
-std::optional tryParseProfile(StringRef Profile) {
-  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+struct ShaderModel {
+  StringRef TargetKind;
+  unsigned Major;
+  unsigned Minor;
+  bool OfflineLibMinor = false;
+};
+
+std::optional GetShaderModelFromString(StringRef Profile) {
   SmallVector Parts;
   Profile.split(Parts, "_");
   if (Parts.size() != 3)
 return std::nullopt;
 
+  unsigned long long Major = 0;
+  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
+return std::nullopt;
+
+  unsigned long long Minor = 0;
+  bool isOfflineLibMinor = false;
+  if (Parts[0] == "lib" && Parts[2] == "x")
+isOfflineLibMinor = true;
+  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
+return std::nullopt;
+
+  ShaderModel ret;
+  ret.TargetKind = Parts[0];
+  ret.Major = Major;
+  ret.Minor = Minor;
+  ret.OfflineLibMinor = isOfflineLibMinor;
+
+  return ret;
+}
+
+std::optional tryParseProfile(StringRef Profile) {
+  std::optional SM = GetShaderModelFromString(Profile);
+  if (!SM.has_value()) {
+return std::nullopt;
+  }
+  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+
   Triple::EnvironmentType Kind =
-  StringSwitch(Parts[0])
+  StringSwitch(SM.value().TargetKind)
   .Case("ps", Triple::EnvironmentType::Pixel)
   .Case("vs", Triple::EnvironmentType::Vertex)
   .Case("gs", Triple::EnvironmentType::Geometry)
@@ -88,21 +121,11 @@ std::optional tryParseProfile(StringRef 
Profile) {
   if (Kind == Triple::EnvironmentType::UnknownEnvironment)
 return std::nullopt;
 
-  unsigned long long Major = 0;
-  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
-return std::nullopt;
-
-  unsigned long long Minor = 0;
-  if (Parts[2] == "x" && Kind == Triple::EnvironmentType::Library)
-Minor = OfflineLibMinor;
-  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
-return std::nullopt;
-
   // dxil-unknown-shadermodel-hull
   llvm::Triple T;
   T.setArch(Triple::ArchType::dxil);
   T.setOSName(Triple::getOSTypeName(Triple::OSType::ShaderModel).str() +
-  VersionTuple(Major, Minor).getAsString());
+  VersionTuple(SM.value().Major, SM.value().Minor).getAsString());
   T.setEnvironment(Kind);
   if (isLegalShaderModel(T))
 return T.getTriple();
@@ -258,6 +281,41 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_fnative_half_type)) {
+
+bool HVArgIsValid = true;
+bool TPArgIsValid = true;
+
+const StringRef HVArg =
+DAL->getLastArgValue(options::OPT_std_EQ, "hlsl2021");
+
+const StringRef TPArg =
+DAL->getLastArgValue(options::OPT_target_profile, "");
+std::optional parsedTargetProfile =
+GetShaderModelFromString(TPArg);
+
+unsigned long long HV_year;
+StringRef HV_year_str = HVArg.drop_front(4);
+if (HV_year_str != "202x") {
+  llvm::getAsUnsignedInteger(HV_year_str, 0, HV_year);
+  if (HV_year < 2021)
+HVArgIsValid = false;
+}
+
+if (!parsedTargetProfile.has_value())
+  return DAL;
+else {
+

[clang] Add clang_elementwise_builtin_alias (PR #86175)

2024-03-21 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 created 
https://github.com/llvm/llvm-project/pull/86175

RFC: 
https://discourse.llvm.org/t/rfc-elementwise-attribute-in-clang-front-end/76342/9
The above RFC gives the motivation for this PR. In summary, this PR adds an 
attribute that will simplify / obliviate the need to create separate 
elementwise builtins for pre-existing builtins. It will also allow users to 
create their own user-defined functions, and create elementwise variants of 
their functions.

This should help accelerate the process of using tan in an elementwise way.

>From 5e10b1e42a20a39c9a3d5ff332591713511832c8 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Wed, 20 Mar 2024 13:24:07 -0700
Subject: [PATCH 1/4] make elemnetwise alias an alias of builtin alias

---
 clang/include/clang/Basic/Attr.td |  9 
 clang/include/clang/Basic/AttrDocs.td | 22 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  3 ++-
 clang/lib/AST/Decl.cpp|  2 ++
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  2 ++
 5 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fd7970d0451acd..160e8ef730ef92 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -759,6 +759,15 @@ def BuiltinAlias : Attr {
   let Documentation = [BuiltinAliasDocs];
 }
 
+def ElementwiseBuiltinAlias : Attr {
+  let Spellings = [CXX11<"clang", "elementwise_builtin_alias">,
+   C23<"clang", "elementwise_builtin_alias">,
+   GNU<"clang_elementwise_builtin_alias">];
+  let Args = [IdentifierArgument<"BuiltinName">];
+  let Subjects = SubjectList<[Function], ErrorDiag>;
+  let Documentation = [ElementwiseBuiltinAliasDocs];
+}
+
 def ArmBuiltinAlias : InheritableAttr, TargetSpecificAttr {
   let Spellings = [Clang<"__clang_arm_builtin_alias">];
   let Args = [IdentifierArgument<"BuiltinName">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 2c07cd09b0d5b7..7ce83bc881f064 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -5462,6 +5462,28 @@ for clang builtin functions.
   }];
 }
 
+def ElementwiseBuiltinAliasDocs : Documentation {
+  let Category = DocCatFunction;
+  let Heading = "clang::elementwise_builtin_alias, 
clang_elementwise_builtin_alias";
+  let Content = [{
+This attribute is used in the implementation of the C intrinsics.
+It allows the C intrinsic functions to be declared using the names defined
+in target builtins, and still be recognized as clang builtins equivalent to the
+underlying name. It also declares that the given C intrinsic can accept 
+vector arguments. For example, ``hlsl_intrinsics.h`` declares the function 
``abs``
+with ``__attribute__((clang_elementwise_builtin_alias(__builtin_abs)))``.
+This ensures that both functions are recognized as that clang builtin,
+and in the latter case, the choice of which builtin to identify the
+function as can be deferred until after overload resolution. It also enables
+the ``abs`` function to take vector arguments.
+
+This attribute can only be used to set up the aliases for certain ARM/RISC-V
+C intrinsic functions; it is intended for use only inside ``arm_*.h`` and
+``riscv_*.h`` and is not a general mechanism for declaring arbitrary aliases
+for clang builtin functions.
+  }];
+}
+
 def PreferredNameDocs : Documentation {
   let Category = DocCatDecl;
   let Content = [{
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c54105507753eb..1252d3804131a6 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4412,7 +4412,8 @@ def err_attribute_preferred_name_arg_invalid : Error<
   "a specialization of %1">;
 def err_attribute_builtin_alias : Error<
   "%0 attribute can only be applied to a ARM, HLSL or RISC-V builtin">;
-
+def err_attribute_elementwise_builtin_alias : Error<
+  "%0 attribute can only be applied to a ARM, HLSL or RISC-V builtin">;
 // called-once attribute diagnostics.
 def err_called_once_attribute_wrong_type : Error<
   "'called_once' attribute only applies to function-like parameters">;
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 8626f04012f7d4..cb2c5cf6ceaf49 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3598,6 +3598,8 @@ unsigned FunctionDecl::getBuiltinID(bool 
ConsiderWrapperFunctions) const {
 BuiltinID = ABAA->getBuiltinName()->getBuiltinID();
   } else if (const auto *BAA = getAttr()) {
 BuiltinID = BAA->getBuiltinName()->getBuiltinID();
+  } else if (const auto *EBAA = getAttr()) {
+BuiltinID = EBAA->getBuiltinName()->getBuiltinID();
   } else if (const auto *A = getAttr()) {
 BuiltinID = A->getID();
   }
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/c

[clang] Add clang_elementwise_builtin_alias (PR #86175)

2024-03-21 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/86175

>From 5e10b1e42a20a39c9a3d5ff332591713511832c8 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Wed, 20 Mar 2024 13:24:07 -0700
Subject: [PATCH 1/4] make elemnetwise alias an alias of builtin alias

---
 clang/include/clang/Basic/Attr.td |  9 
 clang/include/clang/Basic/AttrDocs.td | 22 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  3 ++-
 clang/lib/AST/Decl.cpp|  2 ++
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  2 ++
 5 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fd7970d0451acd..160e8ef730ef92 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -759,6 +759,15 @@ def BuiltinAlias : Attr {
   let Documentation = [BuiltinAliasDocs];
 }
 
+def ElementwiseBuiltinAlias : Attr {
+  let Spellings = [CXX11<"clang", "elementwise_builtin_alias">,
+   C23<"clang", "elementwise_builtin_alias">,
+   GNU<"clang_elementwise_builtin_alias">];
+  let Args = [IdentifierArgument<"BuiltinName">];
+  let Subjects = SubjectList<[Function], ErrorDiag>;
+  let Documentation = [ElementwiseBuiltinAliasDocs];
+}
+
 def ArmBuiltinAlias : InheritableAttr, TargetSpecificAttr {
   let Spellings = [Clang<"__clang_arm_builtin_alias">];
   let Args = [IdentifierArgument<"BuiltinName">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 2c07cd09b0d5b7..7ce83bc881f064 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -5462,6 +5462,28 @@ for clang builtin functions.
   }];
 }
 
+def ElementwiseBuiltinAliasDocs : Documentation {
+  let Category = DocCatFunction;
+  let Heading = "clang::elementwise_builtin_alias, 
clang_elementwise_builtin_alias";
+  let Content = [{
+This attribute is used in the implementation of the C intrinsics.
+It allows the C intrinsic functions to be declared using the names defined
+in target builtins, and still be recognized as clang builtins equivalent to the
+underlying name. It also declares that the given C intrinsic can accept 
+vector arguments. For example, ``hlsl_intrinsics.h`` declares the function 
``abs``
+with ``__attribute__((clang_elementwise_builtin_alias(__builtin_abs)))``.
+This ensures that both functions are recognized as that clang builtin,
+and in the latter case, the choice of which builtin to identify the
+function as can be deferred until after overload resolution. It also enables
+the ``abs`` function to take vector arguments.
+
+This attribute can only be used to set up the aliases for certain ARM/RISC-V
+C intrinsic functions; it is intended for use only inside ``arm_*.h`` and
+``riscv_*.h`` and is not a general mechanism for declaring arbitrary aliases
+for clang builtin functions.
+  }];
+}
+
 def PreferredNameDocs : Documentation {
   let Category = DocCatDecl;
   let Content = [{
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c54105507753eb..1252d3804131a6 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4412,7 +4412,8 @@ def err_attribute_preferred_name_arg_invalid : Error<
   "a specialization of %1">;
 def err_attribute_builtin_alias : Error<
   "%0 attribute can only be applied to a ARM, HLSL or RISC-V builtin">;
-
+def err_attribute_elementwise_builtin_alias : Error<
+  "%0 attribute can only be applied to a ARM, HLSL or RISC-V builtin">;
 // called-once attribute diagnostics.
 def err_called_once_attribute_wrong_type : Error<
   "'called_once' attribute only applies to function-like parameters">;
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 8626f04012f7d4..cb2c5cf6ceaf49 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3598,6 +3598,8 @@ unsigned FunctionDecl::getBuiltinID(bool 
ConsiderWrapperFunctions) const {
 BuiltinID = ABAA->getBuiltinName()->getBuiltinID();
   } else if (const auto *BAA = getAttr()) {
 BuiltinID = BAA->getBuiltinName()->getBuiltinID();
+  } else if (const auto *EBAA = getAttr()) {
+BuiltinID = EBAA->getBuiltinName()->getBuiltinID();
   } else if (const auto *A = getAttr()) {
 BuiltinID = A->getID();
   }
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 45f8544392584e..b37c4d13b26e62 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -18,6 +18,8 @@ namespace hlsl {
 
 #define _HLSL_BUILTIN_ALIAS(builtin)   
\
   __attribute__((clang_builtin_alias(builtin)))
+#define _HLSL_ELEMENTWISE_BUILTIN_ALIAS(builtin)   
\
+  __attribute__((clang_elementwise_builti

[clang] Add clang_elementwise_builtin_alias (PR #86175)

2024-03-21 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/86175

>From 5e10b1e42a20a39c9a3d5ff332591713511832c8 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Wed, 20 Mar 2024 13:24:07 -0700
Subject: [PATCH 1/5] make elemnetwise alias an alias of builtin alias

---
 clang/include/clang/Basic/Attr.td |  9 
 clang/include/clang/Basic/AttrDocs.td | 22 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  3 ++-
 clang/lib/AST/Decl.cpp|  2 ++
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  2 ++
 5 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fd7970d0451acd..160e8ef730ef92 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -759,6 +759,15 @@ def BuiltinAlias : Attr {
   let Documentation = [BuiltinAliasDocs];
 }
 
+def ElementwiseBuiltinAlias : Attr {
+  let Spellings = [CXX11<"clang", "elementwise_builtin_alias">,
+   C23<"clang", "elementwise_builtin_alias">,
+   GNU<"clang_elementwise_builtin_alias">];
+  let Args = [IdentifierArgument<"BuiltinName">];
+  let Subjects = SubjectList<[Function], ErrorDiag>;
+  let Documentation = [ElementwiseBuiltinAliasDocs];
+}
+
 def ArmBuiltinAlias : InheritableAttr, TargetSpecificAttr {
   let Spellings = [Clang<"__clang_arm_builtin_alias">];
   let Args = [IdentifierArgument<"BuiltinName">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 2c07cd09b0d5b7..7ce83bc881f064 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -5462,6 +5462,28 @@ for clang builtin functions.
   }];
 }
 
+def ElementwiseBuiltinAliasDocs : Documentation {
+  let Category = DocCatFunction;
+  let Heading = "clang::elementwise_builtin_alias, 
clang_elementwise_builtin_alias";
+  let Content = [{
+This attribute is used in the implementation of the C intrinsics.
+It allows the C intrinsic functions to be declared using the names defined
+in target builtins, and still be recognized as clang builtins equivalent to the
+underlying name. It also declares that the given C intrinsic can accept 
+vector arguments. For example, ``hlsl_intrinsics.h`` declares the function 
``abs``
+with ``__attribute__((clang_elementwise_builtin_alias(__builtin_abs)))``.
+This ensures that both functions are recognized as that clang builtin,
+and in the latter case, the choice of which builtin to identify the
+function as can be deferred until after overload resolution. It also enables
+the ``abs`` function to take vector arguments.
+
+This attribute can only be used to set up the aliases for certain ARM/RISC-V
+C intrinsic functions; it is intended for use only inside ``arm_*.h`` and
+``riscv_*.h`` and is not a general mechanism for declaring arbitrary aliases
+for clang builtin functions.
+  }];
+}
+
 def PreferredNameDocs : Documentation {
   let Category = DocCatDecl;
   let Content = [{
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c54105507753eb..1252d3804131a6 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4412,7 +4412,8 @@ def err_attribute_preferred_name_arg_invalid : Error<
   "a specialization of %1">;
 def err_attribute_builtin_alias : Error<
   "%0 attribute can only be applied to a ARM, HLSL or RISC-V builtin">;
-
+def err_attribute_elementwise_builtin_alias : Error<
+  "%0 attribute can only be applied to a ARM, HLSL or RISC-V builtin">;
 // called-once attribute diagnostics.
 def err_called_once_attribute_wrong_type : Error<
   "'called_once' attribute only applies to function-like parameters">;
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 8626f04012f7d4..cb2c5cf6ceaf49 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3598,6 +3598,8 @@ unsigned FunctionDecl::getBuiltinID(bool 
ConsiderWrapperFunctions) const {
 BuiltinID = ABAA->getBuiltinName()->getBuiltinID();
   } else if (const auto *BAA = getAttr()) {
 BuiltinID = BAA->getBuiltinName()->getBuiltinID();
+  } else if (const auto *EBAA = getAttr()) {
+BuiltinID = EBAA->getBuiltinName()->getBuiltinID();
   } else if (const auto *A = getAttr()) {
 BuiltinID = A->getID();
   }
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 45f8544392584e..b37c4d13b26e62 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -18,6 +18,8 @@ namespace hlsl {
 
 #define _HLSL_BUILTIN_ALIAS(builtin)   
\
   __attribute__((clang_builtin_alias(builtin)))
+#define _HLSL_ELEMENTWISE_BUILTIN_ALIAS(builtin)   
\
+  __attribute__((clang_elementwise_builti

[clang] Add clang_elementwise_builtin_alias (PR #86175)

2024-03-21 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/86175

>From 5e10b1e42a20a39c9a3d5ff332591713511832c8 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Wed, 20 Mar 2024 13:24:07 -0700
Subject: [PATCH 1/6] make elemnetwise alias an alias of builtin alias

---
 clang/include/clang/Basic/Attr.td |  9 
 clang/include/clang/Basic/AttrDocs.td | 22 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  3 ++-
 clang/lib/AST/Decl.cpp|  2 ++
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  2 ++
 5 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fd7970d0451acd..160e8ef730ef92 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -759,6 +759,15 @@ def BuiltinAlias : Attr {
   let Documentation = [BuiltinAliasDocs];
 }
 
+def ElementwiseBuiltinAlias : Attr {
+  let Spellings = [CXX11<"clang", "elementwise_builtin_alias">,
+   C23<"clang", "elementwise_builtin_alias">,
+   GNU<"clang_elementwise_builtin_alias">];
+  let Args = [IdentifierArgument<"BuiltinName">];
+  let Subjects = SubjectList<[Function], ErrorDiag>;
+  let Documentation = [ElementwiseBuiltinAliasDocs];
+}
+
 def ArmBuiltinAlias : InheritableAttr, TargetSpecificAttr {
   let Spellings = [Clang<"__clang_arm_builtin_alias">];
   let Args = [IdentifierArgument<"BuiltinName">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 2c07cd09b0d5b7..7ce83bc881f064 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -5462,6 +5462,28 @@ for clang builtin functions.
   }];
 }
 
+def ElementwiseBuiltinAliasDocs : Documentation {
+  let Category = DocCatFunction;
+  let Heading = "clang::elementwise_builtin_alias, 
clang_elementwise_builtin_alias";
+  let Content = [{
+This attribute is used in the implementation of the C intrinsics.
+It allows the C intrinsic functions to be declared using the names defined
+in target builtins, and still be recognized as clang builtins equivalent to the
+underlying name. It also declares that the given C intrinsic can accept 
+vector arguments. For example, ``hlsl_intrinsics.h`` declares the function 
``abs``
+with ``__attribute__((clang_elementwise_builtin_alias(__builtin_abs)))``.
+This ensures that both functions are recognized as that clang builtin,
+and in the latter case, the choice of which builtin to identify the
+function as can be deferred until after overload resolution. It also enables
+the ``abs`` function to take vector arguments.
+
+This attribute can only be used to set up the aliases for certain ARM/RISC-V
+C intrinsic functions; it is intended for use only inside ``arm_*.h`` and
+``riscv_*.h`` and is not a general mechanism for declaring arbitrary aliases
+for clang builtin functions.
+  }];
+}
+
 def PreferredNameDocs : Documentation {
   let Category = DocCatDecl;
   let Content = [{
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c54105507753eb..1252d3804131a6 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4412,7 +4412,8 @@ def err_attribute_preferred_name_arg_invalid : Error<
   "a specialization of %1">;
 def err_attribute_builtin_alias : Error<
   "%0 attribute can only be applied to a ARM, HLSL or RISC-V builtin">;
-
+def err_attribute_elementwise_builtin_alias : Error<
+  "%0 attribute can only be applied to a ARM, HLSL or RISC-V builtin">;
 // called-once attribute diagnostics.
 def err_called_once_attribute_wrong_type : Error<
   "'called_once' attribute only applies to function-like parameters">;
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 8626f04012f7d4..cb2c5cf6ceaf49 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3598,6 +3598,8 @@ unsigned FunctionDecl::getBuiltinID(bool 
ConsiderWrapperFunctions) const {
 BuiltinID = ABAA->getBuiltinName()->getBuiltinID();
   } else if (const auto *BAA = getAttr()) {
 BuiltinID = BAA->getBuiltinName()->getBuiltinID();
+  } else if (const auto *EBAA = getAttr()) {
+BuiltinID = EBAA->getBuiltinName()->getBuiltinID();
   } else if (const auto *A = getAttr()) {
 BuiltinID = A->getID();
   }
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 45f8544392584e..b37c4d13b26e62 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -18,6 +18,8 @@ namespace hlsl {
 
 #define _HLSL_BUILTIN_ALIAS(builtin)   
\
   __attribute__((clang_builtin_alias(builtin)))
+#define _HLSL_ELEMENTWISE_BUILTIN_ALIAS(builtin)   
\
+  __attribute__((clang_elementwise_builti

[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-21 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/85340

>From 3cdcfa4e63550b9677c8ffe2f33eab85899b2c45 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 14 Mar 2024 17:04:12 -0700
Subject: [PATCH 1/7] add test

---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 86 ---
 2 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e33a1f4c45b949..fae9132bd0a9c9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,7 +753,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types_option_invalid: Error<
+  "enable_16bit_types option only valid when target shader model [-T] is >= 
6.2 and Hlsl Version [-HV] is >= 2021">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 05aac9caa7fb29..bf8fc42a27816c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -66,15 +66,48 @@ bool isLegalShaderModel(Triple &T) {
   return false;
 }
 
-std::optional tryParseProfile(StringRef Profile) {
-  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+struct ShaderModel {
+  StringRef TargetKind;
+  unsigned Major;
+  unsigned Minor;
+  bool OfflineLibMinor = false;
+};
+
+std::optional GetShaderModelFromString(StringRef Profile) {
   SmallVector Parts;
   Profile.split(Parts, "_");
   if (Parts.size() != 3)
 return std::nullopt;
 
+  unsigned long long Major = 0;
+  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
+return std::nullopt;
+
+  unsigned long long Minor = 0;
+  bool isOfflineLibMinor = false;
+  if (Parts[0] == "lib" && Parts[2] == "x")
+isOfflineLibMinor = true;
+  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
+return std::nullopt;
+
+  ShaderModel ret;
+  ret.TargetKind = Parts[0];
+  ret.Major = Major;
+  ret.Minor = Minor;
+  ret.OfflineLibMinor = isOfflineLibMinor;
+
+  return ret;
+}
+
+std::optional tryParseProfile(StringRef Profile) {
+  std::optional SM = GetShaderModelFromString(Profile);
+  if (!SM.has_value()) {
+return std::nullopt;
+  }
+  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+
   Triple::EnvironmentType Kind =
-  StringSwitch(Parts[0])
+  StringSwitch(SM.value().TargetKind)
   .Case("ps", Triple::EnvironmentType::Pixel)
   .Case("vs", Triple::EnvironmentType::Vertex)
   .Case("gs", Triple::EnvironmentType::Geometry)
@@ -88,21 +121,11 @@ std::optional tryParseProfile(StringRef 
Profile) {
   if (Kind == Triple::EnvironmentType::UnknownEnvironment)
 return std::nullopt;
 
-  unsigned long long Major = 0;
-  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
-return std::nullopt;
-
-  unsigned long long Minor = 0;
-  if (Parts[2] == "x" && Kind == Triple::EnvironmentType::Library)
-Minor = OfflineLibMinor;
-  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
-return std::nullopt;
-
   // dxil-unknown-shadermodel-hull
   llvm::Triple T;
   T.setArch(Triple::ArchType::dxil);
   T.setOSName(Triple::getOSTypeName(Triple::OSType::ShaderModel).str() +
-  VersionTuple(Major, Minor).getAsString());
+  VersionTuple(SM.value().Major, SM.value().Minor).getAsString());
   T.setEnvironment(Kind);
   if (isLegalShaderModel(T))
 return T.getTriple();
@@ -258,6 +281,41 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_fnative_half_type)) {
+
+bool HVArgIsValid = true;
+bool TPArgIsValid = true;
+
+const StringRef HVArg =
+DAL->getLastArgValue(options::OPT_std_EQ, "hlsl2021");
+
+const StringRef TPArg =
+DAL->getLastArgValue(options::OPT_target_profile, "");
+std::optional parsedTargetProfile =
+GetShaderModelFromString(TPArg);
+
+unsigned long long HV_year;
+StringRef HV_year_str = HVArg.drop_front(4);
+if (HV_year_str != "202x") {
+  llvm::getAsUnsignedInteger(HV_year_str, 0, HV_year);
+  if (HV_year < 2021)
+HVArgIsValid = false;
+}
+
+if (!parsedTargetProfile.has_value())
+  return DAL;
+else {
+

[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-21 Thread Joshua Batista via cfe-commits


@@ -4258,6 +4258,18 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
&Opts, ArgList &Args,
   } else {
 llvm_unreachable("expected DXIL or SPIR-V target");
   }
+  // validate that if fnative-half-type is given, that
+  // the language standard is at least hlsl2021, and that
+  // the target shader model is at least 6.2
+  if (Args.getLastArg(OPT_fnative_half_type)) {

bob80905 wrote:

I thought to put it outside because I assumed SPIRV would have an option for 
enabling half types? I am not sure, but I'll move it for now.

https://github.com/llvm/llvm-project/pull/85340
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-21 Thread Joshua Batista via cfe-commits


@@ -4258,6 +4258,18 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
&Opts, ArgList &Args,
   } else {
 llvm_unreachable("expected DXIL or SPIR-V target");
   }
+  // validate that if fnative-half-type is given, that
+  // the language standard is at least hlsl2021, and that
+  // the target shader model is at least 6.2
+  if (Args.getLastArg(OPT_fnative_half_type)) {
+bool LangStdArgIsValid = Opts.LangStd >= LangStandard::lang_hlsl2021;
+bool TPArgIsValid = T.getOSVersion() >= VersionTuple(6, 2);

bob80905 wrote:

TP originally stood for target profile. But yes, I think I'll just move the 
conditions directly into the `if`

https://github.com/llvm/llvm-project/pull/85340
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-21 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/85340

>From 3cdcfa4e63550b9677c8ffe2f33eab85899b2c45 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 14 Mar 2024 17:04:12 -0700
Subject: [PATCH 1/8] add test

---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 86 ---
 2 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e33a1f4c45b949..fae9132bd0a9c9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,7 +753,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types_option_invalid: Error<
+  "enable_16bit_types option only valid when target shader model [-T] is >= 
6.2 and Hlsl Version [-HV] is >= 2021">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 05aac9caa7fb29..bf8fc42a27816c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -66,15 +66,48 @@ bool isLegalShaderModel(Triple &T) {
   return false;
 }
 
-std::optional tryParseProfile(StringRef Profile) {
-  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+struct ShaderModel {
+  StringRef TargetKind;
+  unsigned Major;
+  unsigned Minor;
+  bool OfflineLibMinor = false;
+};
+
+std::optional GetShaderModelFromString(StringRef Profile) {
   SmallVector Parts;
   Profile.split(Parts, "_");
   if (Parts.size() != 3)
 return std::nullopt;
 
+  unsigned long long Major = 0;
+  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
+return std::nullopt;
+
+  unsigned long long Minor = 0;
+  bool isOfflineLibMinor = false;
+  if (Parts[0] == "lib" && Parts[2] == "x")
+isOfflineLibMinor = true;
+  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
+return std::nullopt;
+
+  ShaderModel ret;
+  ret.TargetKind = Parts[0];
+  ret.Major = Major;
+  ret.Minor = Minor;
+  ret.OfflineLibMinor = isOfflineLibMinor;
+
+  return ret;
+}
+
+std::optional tryParseProfile(StringRef Profile) {
+  std::optional SM = GetShaderModelFromString(Profile);
+  if (!SM.has_value()) {
+return std::nullopt;
+  }
+  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+
   Triple::EnvironmentType Kind =
-  StringSwitch(Parts[0])
+  StringSwitch(SM.value().TargetKind)
   .Case("ps", Triple::EnvironmentType::Pixel)
   .Case("vs", Triple::EnvironmentType::Vertex)
   .Case("gs", Triple::EnvironmentType::Geometry)
@@ -88,21 +121,11 @@ std::optional tryParseProfile(StringRef 
Profile) {
   if (Kind == Triple::EnvironmentType::UnknownEnvironment)
 return std::nullopt;
 
-  unsigned long long Major = 0;
-  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
-return std::nullopt;
-
-  unsigned long long Minor = 0;
-  if (Parts[2] == "x" && Kind == Triple::EnvironmentType::Library)
-Minor = OfflineLibMinor;
-  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
-return std::nullopt;
-
   // dxil-unknown-shadermodel-hull
   llvm::Triple T;
   T.setArch(Triple::ArchType::dxil);
   T.setOSName(Triple::getOSTypeName(Triple::OSType::ShaderModel).str() +
-  VersionTuple(Major, Minor).getAsString());
+  VersionTuple(SM.value().Major, SM.value().Minor).getAsString());
   T.setEnvironment(Kind);
   if (isLegalShaderModel(T))
 return T.getTriple();
@@ -258,6 +281,41 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_fnative_half_type)) {
+
+bool HVArgIsValid = true;
+bool TPArgIsValid = true;
+
+const StringRef HVArg =
+DAL->getLastArgValue(options::OPT_std_EQ, "hlsl2021");
+
+const StringRef TPArg =
+DAL->getLastArgValue(options::OPT_target_profile, "");
+std::optional parsedTargetProfile =
+GetShaderModelFromString(TPArg);
+
+unsigned long long HV_year;
+StringRef HV_year_str = HVArg.drop_front(4);
+if (HV_year_str != "202x") {
+  llvm::getAsUnsignedInteger(HV_year_str, 0, HV_year);
+  if (HV_year < 2021)
+HVArgIsValid = false;
+}
+
+if (!parsedTargetProfile.has_value())
+  return DAL;
+else {
+

[clang] [CMake][HLSL] Add SPIRV to target list for build (PR #86323)

2024-03-22 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 approved this pull request.


https://github.com/llvm/llvm-project/pull/86323
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-22 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/85340

>From 3cdcfa4e63550b9677c8ffe2f33eab85899b2c45 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 14 Mar 2024 17:04:12 -0700
Subject: [PATCH 1/9] add test

---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 86 ---
 2 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e33a1f4c45b949..fae9132bd0a9c9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,7 +753,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types_option_invalid: Error<
+  "enable_16bit_types option only valid when target shader model [-T] is >= 
6.2 and Hlsl Version [-HV] is >= 2021">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 05aac9caa7fb29..bf8fc42a27816c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -66,15 +66,48 @@ bool isLegalShaderModel(Triple &T) {
   return false;
 }
 
-std::optional tryParseProfile(StringRef Profile) {
-  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+struct ShaderModel {
+  StringRef TargetKind;
+  unsigned Major;
+  unsigned Minor;
+  bool OfflineLibMinor = false;
+};
+
+std::optional GetShaderModelFromString(StringRef Profile) {
   SmallVector Parts;
   Profile.split(Parts, "_");
   if (Parts.size() != 3)
 return std::nullopt;
 
+  unsigned long long Major = 0;
+  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
+return std::nullopt;
+
+  unsigned long long Minor = 0;
+  bool isOfflineLibMinor = false;
+  if (Parts[0] == "lib" && Parts[2] == "x")
+isOfflineLibMinor = true;
+  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
+return std::nullopt;
+
+  ShaderModel ret;
+  ret.TargetKind = Parts[0];
+  ret.Major = Major;
+  ret.Minor = Minor;
+  ret.OfflineLibMinor = isOfflineLibMinor;
+
+  return ret;
+}
+
+std::optional tryParseProfile(StringRef Profile) {
+  std::optional SM = GetShaderModelFromString(Profile);
+  if (!SM.has_value()) {
+return std::nullopt;
+  }
+  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+
   Triple::EnvironmentType Kind =
-  StringSwitch(Parts[0])
+  StringSwitch(SM.value().TargetKind)
   .Case("ps", Triple::EnvironmentType::Pixel)
   .Case("vs", Triple::EnvironmentType::Vertex)
   .Case("gs", Triple::EnvironmentType::Geometry)
@@ -88,21 +121,11 @@ std::optional tryParseProfile(StringRef 
Profile) {
   if (Kind == Triple::EnvironmentType::UnknownEnvironment)
 return std::nullopt;
 
-  unsigned long long Major = 0;
-  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
-return std::nullopt;
-
-  unsigned long long Minor = 0;
-  if (Parts[2] == "x" && Kind == Triple::EnvironmentType::Library)
-Minor = OfflineLibMinor;
-  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
-return std::nullopt;
-
   // dxil-unknown-shadermodel-hull
   llvm::Triple T;
   T.setArch(Triple::ArchType::dxil);
   T.setOSName(Triple::getOSTypeName(Triple::OSType::ShaderModel).str() +
-  VersionTuple(Major, Minor).getAsString());
+  VersionTuple(SM.value().Major, SM.value().Minor).getAsString());
   T.setEnvironment(Kind);
   if (isLegalShaderModel(T))
 return T.getTriple();
@@ -258,6 +281,41 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_fnative_half_type)) {
+
+bool HVArgIsValid = true;
+bool TPArgIsValid = true;
+
+const StringRef HVArg =
+DAL->getLastArgValue(options::OPT_std_EQ, "hlsl2021");
+
+const StringRef TPArg =
+DAL->getLastArgValue(options::OPT_target_profile, "");
+std::optional parsedTargetProfile =
+GetShaderModelFromString(TPArg);
+
+unsigned long long HV_year;
+StringRef HV_year_str = HVArg.drop_front(4);
+if (HV_year_str != "202x") {
+  llvm::getAsUnsignedInteger(HV_year_str, 0, HV_year);
+  if (HV_year < 2021)
+HVArgIsValid = false;
+}
+
+if (!parsedTargetProfile.has_value())
+  return DAL;
+else {
+

[clang] [HLSL] prevent generation of double intrinsics via the builtins (PR #86555)

2024-03-25 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 approved this pull request.


https://github.com/llvm/llvm-project/pull/86555
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-25 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/85340

>From 3ba14cb55a85bf8bd0ed0cae43af657c6946acb8 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 14 Mar 2024 17:04:12 -0700
Subject: [PATCH 01/15] add test

---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 86 ---
 2 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e33a1f4c45b949..fae9132bd0a9c9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,7 +753,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types_option_invalid: Error<
+  "enable_16bit_types option only valid when target shader model [-T] is >= 
6.2 and Hlsl Version [-HV] is >= 2021">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 05aac9caa7fb29..bf8fc42a27816c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -66,15 +66,48 @@ bool isLegalShaderModel(Triple &T) {
   return false;
 }
 
-std::optional tryParseProfile(StringRef Profile) {
-  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+struct ShaderModel {
+  StringRef TargetKind;
+  unsigned Major;
+  unsigned Minor;
+  bool OfflineLibMinor = false;
+};
+
+std::optional GetShaderModelFromString(StringRef Profile) {
   SmallVector Parts;
   Profile.split(Parts, "_");
   if (Parts.size() != 3)
 return std::nullopt;
 
+  unsigned long long Major = 0;
+  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
+return std::nullopt;
+
+  unsigned long long Minor = 0;
+  bool isOfflineLibMinor = false;
+  if (Parts[0] == "lib" && Parts[2] == "x")
+isOfflineLibMinor = true;
+  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
+return std::nullopt;
+
+  ShaderModel ret;
+  ret.TargetKind = Parts[0];
+  ret.Major = Major;
+  ret.Minor = Minor;
+  ret.OfflineLibMinor = isOfflineLibMinor;
+
+  return ret;
+}
+
+std::optional tryParseProfile(StringRef Profile) {
+  std::optional SM = GetShaderModelFromString(Profile);
+  if (!SM.has_value()) {
+return std::nullopt;
+  }
+  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+
   Triple::EnvironmentType Kind =
-  StringSwitch(Parts[0])
+  StringSwitch(SM.value().TargetKind)
   .Case("ps", Triple::EnvironmentType::Pixel)
   .Case("vs", Triple::EnvironmentType::Vertex)
   .Case("gs", Triple::EnvironmentType::Geometry)
@@ -88,21 +121,11 @@ std::optional tryParseProfile(StringRef 
Profile) {
   if (Kind == Triple::EnvironmentType::UnknownEnvironment)
 return std::nullopt;
 
-  unsigned long long Major = 0;
-  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
-return std::nullopt;
-
-  unsigned long long Minor = 0;
-  if (Parts[2] == "x" && Kind == Triple::EnvironmentType::Library)
-Minor = OfflineLibMinor;
-  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
-return std::nullopt;
-
   // dxil-unknown-shadermodel-hull
   llvm::Triple T;
   T.setArch(Triple::ArchType::dxil);
   T.setOSName(Triple::getOSTypeName(Triple::OSType::ShaderModel).str() +
-  VersionTuple(Major, Minor).getAsString());
+  VersionTuple(SM.value().Major, SM.value().Minor).getAsString());
   T.setEnvironment(Kind);
   if (isLegalShaderModel(T))
 return T.getTriple();
@@ -258,6 +281,41 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_fnative_half_type)) {
+
+bool HVArgIsValid = true;
+bool TPArgIsValid = true;
+
+const StringRef HVArg =
+DAL->getLastArgValue(options::OPT_std_EQ, "hlsl2021");
+
+const StringRef TPArg =
+DAL->getLastArgValue(options::OPT_target_profile, "");
+std::optional parsedTargetProfile =
+GetShaderModelFromString(TPArg);
+
+unsigned long long HV_year;
+StringRef HV_year_str = HVArg.drop_front(4);
+if (HV_year_str != "202x") {
+  llvm::getAsUnsignedInteger(HV_year_str, 0, HV_year);
+  if (HV_year < 2021)
+HVArgIsValid = false;
+}
+
+if (!parsedTargetProfile.has_value())
+  return DAL;
+else {
+  

[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-25 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/85340

>From 74a869a282d532ec426dbc1c954779ec2972aa5c Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 14 Mar 2024 17:04:12 -0700
Subject: [PATCH 01/15] add test

---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 86 ---
 2 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e33a1f4c45b949..fae9132bd0a9c9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,7 +753,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types_option_invalid: Error<
+  "enable_16bit_types option only valid when target shader model [-T] is >= 
6.2 and Hlsl Version [-HV] is >= 2021">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 05aac9caa7fb29..bf8fc42a27816c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -66,15 +66,48 @@ bool isLegalShaderModel(Triple &T) {
   return false;
 }
 
-std::optional tryParseProfile(StringRef Profile) {
-  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+struct ShaderModel {
+  StringRef TargetKind;
+  unsigned Major;
+  unsigned Minor;
+  bool OfflineLibMinor = false;
+};
+
+std::optional GetShaderModelFromString(StringRef Profile) {
   SmallVector Parts;
   Profile.split(Parts, "_");
   if (Parts.size() != 3)
 return std::nullopt;
 
+  unsigned long long Major = 0;
+  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
+return std::nullopt;
+
+  unsigned long long Minor = 0;
+  bool isOfflineLibMinor = false;
+  if (Parts[0] == "lib" && Parts[2] == "x")
+isOfflineLibMinor = true;
+  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
+return std::nullopt;
+
+  ShaderModel ret;
+  ret.TargetKind = Parts[0];
+  ret.Major = Major;
+  ret.Minor = Minor;
+  ret.OfflineLibMinor = isOfflineLibMinor;
+
+  return ret;
+}
+
+std::optional tryParseProfile(StringRef Profile) {
+  std::optional SM = GetShaderModelFromString(Profile);
+  if (!SM.has_value()) {
+return std::nullopt;
+  }
+  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+
   Triple::EnvironmentType Kind =
-  StringSwitch(Parts[0])
+  StringSwitch(SM.value().TargetKind)
   .Case("ps", Triple::EnvironmentType::Pixel)
   .Case("vs", Triple::EnvironmentType::Vertex)
   .Case("gs", Triple::EnvironmentType::Geometry)
@@ -88,21 +121,11 @@ std::optional tryParseProfile(StringRef 
Profile) {
   if (Kind == Triple::EnvironmentType::UnknownEnvironment)
 return std::nullopt;
 
-  unsigned long long Major = 0;
-  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
-return std::nullopt;
-
-  unsigned long long Minor = 0;
-  if (Parts[2] == "x" && Kind == Triple::EnvironmentType::Library)
-Minor = OfflineLibMinor;
-  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
-return std::nullopt;
-
   // dxil-unknown-shadermodel-hull
   llvm::Triple T;
   T.setArch(Triple::ArchType::dxil);
   T.setOSName(Triple::getOSTypeName(Triple::OSType::ShaderModel).str() +
-  VersionTuple(Major, Minor).getAsString());
+  VersionTuple(SM.value().Major, SM.value().Minor).getAsString());
   T.setEnvironment(Kind);
   if (isLegalShaderModel(T))
 return T.getTriple();
@@ -258,6 +281,41 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_fnative_half_type)) {
+
+bool HVArgIsValid = true;
+bool TPArgIsValid = true;
+
+const StringRef HVArg =
+DAL->getLastArgValue(options::OPT_std_EQ, "hlsl2021");
+
+const StringRef TPArg =
+DAL->getLastArgValue(options::OPT_target_profile, "");
+std::optional parsedTargetProfile =
+GetShaderModelFromString(TPArg);
+
+unsigned long long HV_year;
+StringRef HV_year_str = HVArg.drop_front(4);
+if (HV_year_str != "202x") {
+  llvm::getAsUnsignedInteger(HV_year_str, 0, HV_year);
+  if (HV_year < 2021)
+HVArgIsValid = false;
+}
+
+if (!parsedTargetProfile.has_value())
+  return DAL;
+else {
+  

[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-25 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/85340

>From 74a869a282d532ec426dbc1c954779ec2972aa5c Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 14 Mar 2024 17:04:12 -0700
Subject: [PATCH 01/16] add test

---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 86 ---
 2 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e33a1f4c45b949..fae9132bd0a9c9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,7 +753,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types_option_invalid: Error<
+  "enable_16bit_types option only valid when target shader model [-T] is >= 
6.2 and Hlsl Version [-HV] is >= 2021">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 05aac9caa7fb29..bf8fc42a27816c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -66,15 +66,48 @@ bool isLegalShaderModel(Triple &T) {
   return false;
 }
 
-std::optional tryParseProfile(StringRef Profile) {
-  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+struct ShaderModel {
+  StringRef TargetKind;
+  unsigned Major;
+  unsigned Minor;
+  bool OfflineLibMinor = false;
+};
+
+std::optional GetShaderModelFromString(StringRef Profile) {
   SmallVector Parts;
   Profile.split(Parts, "_");
   if (Parts.size() != 3)
 return std::nullopt;
 
+  unsigned long long Major = 0;
+  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
+return std::nullopt;
+
+  unsigned long long Minor = 0;
+  bool isOfflineLibMinor = false;
+  if (Parts[0] == "lib" && Parts[2] == "x")
+isOfflineLibMinor = true;
+  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
+return std::nullopt;
+
+  ShaderModel ret;
+  ret.TargetKind = Parts[0];
+  ret.Major = Major;
+  ret.Minor = Minor;
+  ret.OfflineLibMinor = isOfflineLibMinor;
+
+  return ret;
+}
+
+std::optional tryParseProfile(StringRef Profile) {
+  std::optional SM = GetShaderModelFromString(Profile);
+  if (!SM.has_value()) {
+return std::nullopt;
+  }
+  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+
   Triple::EnvironmentType Kind =
-  StringSwitch(Parts[0])
+  StringSwitch(SM.value().TargetKind)
   .Case("ps", Triple::EnvironmentType::Pixel)
   .Case("vs", Triple::EnvironmentType::Vertex)
   .Case("gs", Triple::EnvironmentType::Geometry)
@@ -88,21 +121,11 @@ std::optional tryParseProfile(StringRef 
Profile) {
   if (Kind == Triple::EnvironmentType::UnknownEnvironment)
 return std::nullopt;
 
-  unsigned long long Major = 0;
-  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
-return std::nullopt;
-
-  unsigned long long Minor = 0;
-  if (Parts[2] == "x" && Kind == Triple::EnvironmentType::Library)
-Minor = OfflineLibMinor;
-  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
-return std::nullopt;
-
   // dxil-unknown-shadermodel-hull
   llvm::Triple T;
   T.setArch(Triple::ArchType::dxil);
   T.setOSName(Triple::getOSTypeName(Triple::OSType::ShaderModel).str() +
-  VersionTuple(Major, Minor).getAsString());
+  VersionTuple(SM.value().Major, SM.value().Minor).getAsString());
   T.setEnvironment(Kind);
   if (isLegalShaderModel(T))
 return T.getTriple();
@@ -258,6 +281,41 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_fnative_half_type)) {
+
+bool HVArgIsValid = true;
+bool TPArgIsValid = true;
+
+const StringRef HVArg =
+DAL->getLastArgValue(options::OPT_std_EQ, "hlsl2021");
+
+const StringRef TPArg =
+DAL->getLastArgValue(options::OPT_target_profile, "");
+std::optional parsedTargetProfile =
+GetShaderModelFromString(TPArg);
+
+unsigned long long HV_year;
+StringRef HV_year_str = HVArg.drop_front(4);
+if (HV_year_str != "202x") {
+  llvm::getAsUnsignedInteger(HV_year_str, 0, HV_year);
+  if (HV_year < 2021)
+HVArgIsValid = false;
+}
+
+if (!parsedTargetProfile.has_value())
+  return DAL;
+else {
+  

[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-25 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/85340

>From 74a869a282d532ec426dbc1c954779ec2972aa5c Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 14 Mar 2024 17:04:12 -0700
Subject: [PATCH 01/17] add test

---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 86 ---
 2 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e33a1f4c45b949..fae9132bd0a9c9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,7 +753,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types_option_invalid: Error<
+  "enable_16bit_types option only valid when target shader model [-T] is >= 
6.2 and Hlsl Version [-HV] is >= 2021">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 05aac9caa7fb29..bf8fc42a27816c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -66,15 +66,48 @@ bool isLegalShaderModel(Triple &T) {
   return false;
 }
 
-std::optional tryParseProfile(StringRef Profile) {
-  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+struct ShaderModel {
+  StringRef TargetKind;
+  unsigned Major;
+  unsigned Minor;
+  bool OfflineLibMinor = false;
+};
+
+std::optional GetShaderModelFromString(StringRef Profile) {
   SmallVector Parts;
   Profile.split(Parts, "_");
   if (Parts.size() != 3)
 return std::nullopt;
 
+  unsigned long long Major = 0;
+  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
+return std::nullopt;
+
+  unsigned long long Minor = 0;
+  bool isOfflineLibMinor = false;
+  if (Parts[0] == "lib" && Parts[2] == "x")
+isOfflineLibMinor = true;
+  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
+return std::nullopt;
+
+  ShaderModel ret;
+  ret.TargetKind = Parts[0];
+  ret.Major = Major;
+  ret.Minor = Minor;
+  ret.OfflineLibMinor = isOfflineLibMinor;
+
+  return ret;
+}
+
+std::optional tryParseProfile(StringRef Profile) {
+  std::optional SM = GetShaderModelFromString(Profile);
+  if (!SM.has_value()) {
+return std::nullopt;
+  }
+  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+
   Triple::EnvironmentType Kind =
-  StringSwitch(Parts[0])
+  StringSwitch(SM.value().TargetKind)
   .Case("ps", Triple::EnvironmentType::Pixel)
   .Case("vs", Triple::EnvironmentType::Vertex)
   .Case("gs", Triple::EnvironmentType::Geometry)
@@ -88,21 +121,11 @@ std::optional tryParseProfile(StringRef 
Profile) {
   if (Kind == Triple::EnvironmentType::UnknownEnvironment)
 return std::nullopt;
 
-  unsigned long long Major = 0;
-  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
-return std::nullopt;
-
-  unsigned long long Minor = 0;
-  if (Parts[2] == "x" && Kind == Triple::EnvironmentType::Library)
-Minor = OfflineLibMinor;
-  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
-return std::nullopt;
-
   // dxil-unknown-shadermodel-hull
   llvm::Triple T;
   T.setArch(Triple::ArchType::dxil);
   T.setOSName(Triple::getOSTypeName(Triple::OSType::ShaderModel).str() +
-  VersionTuple(Major, Minor).getAsString());
+  VersionTuple(SM.value().Major, SM.value().Minor).getAsString());
   T.setEnvironment(Kind);
   if (isLegalShaderModel(T))
 return T.getTriple();
@@ -258,6 +281,41 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_fnative_half_type)) {
+
+bool HVArgIsValid = true;
+bool TPArgIsValid = true;
+
+const StringRef HVArg =
+DAL->getLastArgValue(options::OPT_std_EQ, "hlsl2021");
+
+const StringRef TPArg =
+DAL->getLastArgValue(options::OPT_target_profile, "");
+std::optional parsedTargetProfile =
+GetShaderModelFromString(TPArg);
+
+unsigned long long HV_year;
+StringRef HV_year_str = HVArg.drop_front(4);
+if (HV_year_str != "202x") {
+  llvm::getAsUnsignedInteger(HV_year_str, 0, HV_year);
+  if (HV_year < 2021)
+HVArgIsValid = false;
+}
+
+if (!parsedTargetProfile.has_value())
+  return DAL;
+else {
+  

[clang] Add clang_elementwise_builtin_alias (PR #86175)

2024-03-26 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/86175

>From 5e10b1e42a20a39c9a3d5ff332591713511832c8 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Wed, 20 Mar 2024 13:24:07 -0700
Subject: [PATCH 1/7] make elemnetwise alias an alias of builtin alias

---
 clang/include/clang/Basic/Attr.td |  9 
 clang/include/clang/Basic/AttrDocs.td | 22 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  3 ++-
 clang/lib/AST/Decl.cpp|  2 ++
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  2 ++
 5 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fd7970d0451acd..160e8ef730ef92 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -759,6 +759,15 @@ def BuiltinAlias : Attr {
   let Documentation = [BuiltinAliasDocs];
 }
 
+def ElementwiseBuiltinAlias : Attr {
+  let Spellings = [CXX11<"clang", "elementwise_builtin_alias">,
+   C23<"clang", "elementwise_builtin_alias">,
+   GNU<"clang_elementwise_builtin_alias">];
+  let Args = [IdentifierArgument<"BuiltinName">];
+  let Subjects = SubjectList<[Function], ErrorDiag>;
+  let Documentation = [ElementwiseBuiltinAliasDocs];
+}
+
 def ArmBuiltinAlias : InheritableAttr, TargetSpecificAttr {
   let Spellings = [Clang<"__clang_arm_builtin_alias">];
   let Args = [IdentifierArgument<"BuiltinName">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 2c07cd09b0d5b7..7ce83bc881f064 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -5462,6 +5462,28 @@ for clang builtin functions.
   }];
 }
 
+def ElementwiseBuiltinAliasDocs : Documentation {
+  let Category = DocCatFunction;
+  let Heading = "clang::elementwise_builtin_alias, 
clang_elementwise_builtin_alias";
+  let Content = [{
+This attribute is used in the implementation of the C intrinsics.
+It allows the C intrinsic functions to be declared using the names defined
+in target builtins, and still be recognized as clang builtins equivalent to the
+underlying name. It also declares that the given C intrinsic can accept 
+vector arguments. For example, ``hlsl_intrinsics.h`` declares the function 
``abs``
+with ``__attribute__((clang_elementwise_builtin_alias(__builtin_abs)))``.
+This ensures that both functions are recognized as that clang builtin,
+and in the latter case, the choice of which builtin to identify the
+function as can be deferred until after overload resolution. It also enables
+the ``abs`` function to take vector arguments.
+
+This attribute can only be used to set up the aliases for certain ARM/RISC-V
+C intrinsic functions; it is intended for use only inside ``arm_*.h`` and
+``riscv_*.h`` and is not a general mechanism for declaring arbitrary aliases
+for clang builtin functions.
+  }];
+}
+
 def PreferredNameDocs : Documentation {
   let Category = DocCatDecl;
   let Content = [{
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c54105507753eb..1252d3804131a6 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4412,7 +4412,8 @@ def err_attribute_preferred_name_arg_invalid : Error<
   "a specialization of %1">;
 def err_attribute_builtin_alias : Error<
   "%0 attribute can only be applied to a ARM, HLSL or RISC-V builtin">;
-
+def err_attribute_elementwise_builtin_alias : Error<
+  "%0 attribute can only be applied to a ARM, HLSL or RISC-V builtin">;
 // called-once attribute diagnostics.
 def err_called_once_attribute_wrong_type : Error<
   "'called_once' attribute only applies to function-like parameters">;
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 8626f04012f7d4..cb2c5cf6ceaf49 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3598,6 +3598,8 @@ unsigned FunctionDecl::getBuiltinID(bool 
ConsiderWrapperFunctions) const {
 BuiltinID = ABAA->getBuiltinName()->getBuiltinID();
   } else if (const auto *BAA = getAttr()) {
 BuiltinID = BAA->getBuiltinName()->getBuiltinID();
+  } else if (const auto *EBAA = getAttr()) {
+BuiltinID = EBAA->getBuiltinName()->getBuiltinID();
   } else if (const auto *A = getAttr()) {
 BuiltinID = A->getID();
   }
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 45f8544392584e..b37c4d13b26e62 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -18,6 +18,8 @@ namespace hlsl {
 
 #define _HLSL_BUILTIN_ALIAS(builtin)   
\
   __attribute__((clang_builtin_alias(builtin)))
+#define _HLSL_ELEMENTWISE_BUILTIN_ALIAS(builtin)   
\
+  __attribute__((clang_elementwise_builti

[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-26 Thread Joshua Batista via cfe-commits


@@ -0,0 +1,20 @@
+// RUN: not %clang_dxc -enable-16bit-types -T cs_6_0 -HV 2016 %s 2>&1  | 
FileCheck -check-prefix=both_invalid %s
+// RUN: not %clang_dxc -enable-16bit-types -T lib_6_4 -HV 2017 %s 2>&1 | 
FileCheck -check-prefix=HV_invalid %s
+// RUN: not %clang_dxc -enable-16bit-types -T cs_6_0 /HV 2021 %s 2>&1  | 
FileCheck -check-prefix=TP_invalid %s
+// RUN: %clang_dxc -enable-16bit-types -T lib_6_4 /HV 2021 %s 2>&1 -###   | 
FileCheck -check-prefix=valid %s
+
+
+// both_invalid: error: enable-16bit-types option only valid when target 
shader model [-T] is >= 6.2 and HLSL Version [-HV] is >= 2021
+// HV_invalid: error: enable-16bit-types option only valid when target shader 
model [-T] is >= 6.2 and HLSL Version [-HV] is >= 2021
+// TP_invalid: error: enable-16bit-types option only valid when target shader 
model [-T] is >= 6.2 and HLSL Version [-HV] is >= 2021

bob80905 wrote:

In the case that both requirements are not met, I don't think 2 diagnostics 
should be emitted. But I do think there is value to showing what the given 
values are. Maybe something like:
"16-bit types are only valid for shader model >= 6.2 and HLSL Version >= 2021, 
but shader model is '%1' and HLSL Version is '%2'" would be an improvement.
WDYT?

https://github.com/llvm/llvm-project/pull/85340
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-26 Thread Joshua Batista via cfe-commits


@@ -753,7 +753,10 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_dxc_enable_16bit_types_option_invalid: Error<
+  "enable-16bit-types option only valid when target shader model [-T] is >= 
6.2 and HLSL Version [-HV] is >= 2021">;

bob80905 wrote:

Thanks for pointing this out! I originally thought it was introduced in 2021, 
but it looks like it should be 2018.

https://github.com/llvm/llvm-project/pull/85340
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-26 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/85340

>From 74a869a282d532ec426dbc1c954779ec2972aa5c Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 14 Mar 2024 17:04:12 -0700
Subject: [PATCH 01/18] add test

---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 86 ---
 2 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e33a1f4c45b949..fae9132bd0a9c9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,7 +753,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types_option_invalid: Error<
+  "enable_16bit_types option only valid when target shader model [-T] is >= 
6.2 and Hlsl Version [-HV] is >= 2021">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 05aac9caa7fb29..bf8fc42a27816c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -66,15 +66,48 @@ bool isLegalShaderModel(Triple &T) {
   return false;
 }
 
-std::optional tryParseProfile(StringRef Profile) {
-  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+struct ShaderModel {
+  StringRef TargetKind;
+  unsigned Major;
+  unsigned Minor;
+  bool OfflineLibMinor = false;
+};
+
+std::optional GetShaderModelFromString(StringRef Profile) {
   SmallVector Parts;
   Profile.split(Parts, "_");
   if (Parts.size() != 3)
 return std::nullopt;
 
+  unsigned long long Major = 0;
+  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
+return std::nullopt;
+
+  unsigned long long Minor = 0;
+  bool isOfflineLibMinor = false;
+  if (Parts[0] == "lib" && Parts[2] == "x")
+isOfflineLibMinor = true;
+  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
+return std::nullopt;
+
+  ShaderModel ret;
+  ret.TargetKind = Parts[0];
+  ret.Major = Major;
+  ret.Minor = Minor;
+  ret.OfflineLibMinor = isOfflineLibMinor;
+
+  return ret;
+}
+
+std::optional tryParseProfile(StringRef Profile) {
+  std::optional SM = GetShaderModelFromString(Profile);
+  if (!SM.has_value()) {
+return std::nullopt;
+  }
+  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+
   Triple::EnvironmentType Kind =
-  StringSwitch(Parts[0])
+  StringSwitch(SM.value().TargetKind)
   .Case("ps", Triple::EnvironmentType::Pixel)
   .Case("vs", Triple::EnvironmentType::Vertex)
   .Case("gs", Triple::EnvironmentType::Geometry)
@@ -88,21 +121,11 @@ std::optional tryParseProfile(StringRef 
Profile) {
   if (Kind == Triple::EnvironmentType::UnknownEnvironment)
 return std::nullopt;
 
-  unsigned long long Major = 0;
-  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
-return std::nullopt;
-
-  unsigned long long Minor = 0;
-  if (Parts[2] == "x" && Kind == Triple::EnvironmentType::Library)
-Minor = OfflineLibMinor;
-  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
-return std::nullopt;
-
   // dxil-unknown-shadermodel-hull
   llvm::Triple T;
   T.setArch(Triple::ArchType::dxil);
   T.setOSName(Triple::getOSTypeName(Triple::OSType::ShaderModel).str() +
-  VersionTuple(Major, Minor).getAsString());
+  VersionTuple(SM.value().Major, SM.value().Minor).getAsString());
   T.setEnvironment(Kind);
   if (isLegalShaderModel(T))
 return T.getTriple();
@@ -258,6 +281,41 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_fnative_half_type)) {
+
+bool HVArgIsValid = true;
+bool TPArgIsValid = true;
+
+const StringRef HVArg =
+DAL->getLastArgValue(options::OPT_std_EQ, "hlsl2021");
+
+const StringRef TPArg =
+DAL->getLastArgValue(options::OPT_target_profile, "");
+std::optional parsedTargetProfile =
+GetShaderModelFromString(TPArg);
+
+unsigned long long HV_year;
+StringRef HV_year_str = HVArg.drop_front(4);
+if (HV_year_str != "202x") {
+  llvm::getAsUnsignedInteger(HV_year_str, 0, HV_year);
+  if (HV_year < 2021)
+HVArgIsValid = false;
+}
+
+if (!parsedTargetProfile.has_value())
+  return DAL;
+else {
+  

[clang] [HLSL] enforce unsigned types for reversebits (PR #86720)

2024-03-26 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 approved this pull request.


https://github.com/llvm/llvm-project/pull/86720
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-26 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/85340

>From 74a869a282d532ec426dbc1c954779ec2972aa5c Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 14 Mar 2024 17:04:12 -0700
Subject: [PATCH 01/19] add test

---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 86 ---
 2 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e33a1f4c45b949..fae9132bd0a9c9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,7 +753,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types_option_invalid: Error<
+  "enable_16bit_types option only valid when target shader model [-T] is >= 
6.2 and Hlsl Version [-HV] is >= 2021">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 05aac9caa7fb29..bf8fc42a27816c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -66,15 +66,48 @@ bool isLegalShaderModel(Triple &T) {
   return false;
 }
 
-std::optional tryParseProfile(StringRef Profile) {
-  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+struct ShaderModel {
+  StringRef TargetKind;
+  unsigned Major;
+  unsigned Minor;
+  bool OfflineLibMinor = false;
+};
+
+std::optional GetShaderModelFromString(StringRef Profile) {
   SmallVector Parts;
   Profile.split(Parts, "_");
   if (Parts.size() != 3)
 return std::nullopt;
 
+  unsigned long long Major = 0;
+  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
+return std::nullopt;
+
+  unsigned long long Minor = 0;
+  bool isOfflineLibMinor = false;
+  if (Parts[0] == "lib" && Parts[2] == "x")
+isOfflineLibMinor = true;
+  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
+return std::nullopt;
+
+  ShaderModel ret;
+  ret.TargetKind = Parts[0];
+  ret.Major = Major;
+  ret.Minor = Minor;
+  ret.OfflineLibMinor = isOfflineLibMinor;
+
+  return ret;
+}
+
+std::optional tryParseProfile(StringRef Profile) {
+  std::optional SM = GetShaderModelFromString(Profile);
+  if (!SM.has_value()) {
+return std::nullopt;
+  }
+  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+
   Triple::EnvironmentType Kind =
-  StringSwitch(Parts[0])
+  StringSwitch(SM.value().TargetKind)
   .Case("ps", Triple::EnvironmentType::Pixel)
   .Case("vs", Triple::EnvironmentType::Vertex)
   .Case("gs", Triple::EnvironmentType::Geometry)
@@ -88,21 +121,11 @@ std::optional tryParseProfile(StringRef 
Profile) {
   if (Kind == Triple::EnvironmentType::UnknownEnvironment)
 return std::nullopt;
 
-  unsigned long long Major = 0;
-  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
-return std::nullopt;
-
-  unsigned long long Minor = 0;
-  if (Parts[2] == "x" && Kind == Triple::EnvironmentType::Library)
-Minor = OfflineLibMinor;
-  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
-return std::nullopt;
-
   // dxil-unknown-shadermodel-hull
   llvm::Triple T;
   T.setArch(Triple::ArchType::dxil);
   T.setOSName(Triple::getOSTypeName(Triple::OSType::ShaderModel).str() +
-  VersionTuple(Major, Minor).getAsString());
+  VersionTuple(SM.value().Major, SM.value().Minor).getAsString());
   T.setEnvironment(Kind);
   if (isLegalShaderModel(T))
 return T.getTriple();
@@ -258,6 +281,41 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_fnative_half_type)) {
+
+bool HVArgIsValid = true;
+bool TPArgIsValid = true;
+
+const StringRef HVArg =
+DAL->getLastArgValue(options::OPT_std_EQ, "hlsl2021");
+
+const StringRef TPArg =
+DAL->getLastArgValue(options::OPT_target_profile, "");
+std::optional parsedTargetProfile =
+GetShaderModelFromString(TPArg);
+
+unsigned long long HV_year;
+StringRef HV_year_str = HVArg.drop_front(4);
+if (HV_year_str != "202x") {
+  llvm::getAsUnsignedInteger(HV_year_str, 0, HV_year);
+  if (HV_year < 2021)
+HVArgIsValid = false;
+}
+
+if (!parsedTargetProfile.has_value())
+  return DAL;
+else {
+  

[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-26 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/85340

>From 74a869a282d532ec426dbc1c954779ec2972aa5c Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 14 Mar 2024 17:04:12 -0700
Subject: [PATCH 01/20] add test

---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 86 ---
 2 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e33a1f4c45b949..fae9132bd0a9c9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,7 +753,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types_option_invalid: Error<
+  "enable_16bit_types option only valid when target shader model [-T] is >= 
6.2 and Hlsl Version [-HV] is >= 2021">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 05aac9caa7fb29..bf8fc42a27816c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -66,15 +66,48 @@ bool isLegalShaderModel(Triple &T) {
   return false;
 }
 
-std::optional tryParseProfile(StringRef Profile) {
-  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+struct ShaderModel {
+  StringRef TargetKind;
+  unsigned Major;
+  unsigned Minor;
+  bool OfflineLibMinor = false;
+};
+
+std::optional GetShaderModelFromString(StringRef Profile) {
   SmallVector Parts;
   Profile.split(Parts, "_");
   if (Parts.size() != 3)
 return std::nullopt;
 
+  unsigned long long Major = 0;
+  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
+return std::nullopt;
+
+  unsigned long long Minor = 0;
+  bool isOfflineLibMinor = false;
+  if (Parts[0] == "lib" && Parts[2] == "x")
+isOfflineLibMinor = true;
+  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
+return std::nullopt;
+
+  ShaderModel ret;
+  ret.TargetKind = Parts[0];
+  ret.Major = Major;
+  ret.Minor = Minor;
+  ret.OfflineLibMinor = isOfflineLibMinor;
+
+  return ret;
+}
+
+std::optional tryParseProfile(StringRef Profile) {
+  std::optional SM = GetShaderModelFromString(Profile);
+  if (!SM.has_value()) {
+return std::nullopt;
+  }
+  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+
   Triple::EnvironmentType Kind =
-  StringSwitch(Parts[0])
+  StringSwitch(SM.value().TargetKind)
   .Case("ps", Triple::EnvironmentType::Pixel)
   .Case("vs", Triple::EnvironmentType::Vertex)
   .Case("gs", Triple::EnvironmentType::Geometry)
@@ -88,21 +121,11 @@ std::optional tryParseProfile(StringRef 
Profile) {
   if (Kind == Triple::EnvironmentType::UnknownEnvironment)
 return std::nullopt;
 
-  unsigned long long Major = 0;
-  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
-return std::nullopt;
-
-  unsigned long long Minor = 0;
-  if (Parts[2] == "x" && Kind == Triple::EnvironmentType::Library)
-Minor = OfflineLibMinor;
-  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
-return std::nullopt;
-
   // dxil-unknown-shadermodel-hull
   llvm::Triple T;
   T.setArch(Triple::ArchType::dxil);
   T.setOSName(Triple::getOSTypeName(Triple::OSType::ShaderModel).str() +
-  VersionTuple(Major, Minor).getAsString());
+  VersionTuple(SM.value().Major, SM.value().Minor).getAsString());
   T.setEnvironment(Kind);
   if (isLegalShaderModel(T))
 return T.getTriple();
@@ -258,6 +281,41 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_fnative_half_type)) {
+
+bool HVArgIsValid = true;
+bool TPArgIsValid = true;
+
+const StringRef HVArg =
+DAL->getLastArgValue(options::OPT_std_EQ, "hlsl2021");
+
+const StringRef TPArg =
+DAL->getLastArgValue(options::OPT_target_profile, "");
+std::optional parsedTargetProfile =
+GetShaderModelFromString(TPArg);
+
+unsigned long long HV_year;
+StringRef HV_year_str = HVArg.drop_front(4);
+if (HV_year_str != "202x") {
+  llvm::getAsUnsignedInteger(HV_year_str, 0, HV_year);
+  if (HV_year < 2021)
+HVArgIsValid = false;
+}
+
+if (!parsedTargetProfile.has_value())
+  return DAL;
+else {
+  

[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-27 Thread Joshua Batista via cfe-commits


@@ -4284,11 +4284,31 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
&Opts, ArgList &Args,
   Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
   << ShaderModel << T.getOSName() << T.str();
 }
+// Validate that if fnative-half-type is given, that
+// the language standard is at least hlsl2018, and that
+// the target shader model is at least 6.2.
+if (Args.getLastArg(OPT_fnative_half_type)) {
+  const LangStandard &Std =
+  LangStandard::getLangStandardForKind(Opts.LangStd);
+  if (!(Opts.LangStd >= LangStandard::lang_hlsl2018 &&
+T.getOSVersion() >= VersionTuple(6, 2)))
+Diags.Report(diag::err_drv_hlsl_16bit_types_unsupported)
+<< "-enable-16bit-types" << true << Std.getName()
+<< T.getOSVersion().getAsString();
+}
   } else if (T.isSPIRVLogical()) {
 if (!T.isVulkanOS() || T.getVulkanVersion() == VersionTuple(0)) {
   Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
   << VulkanEnv << T.getOSName() << T.str();
 }
+if (Args.getLastArg(OPT_fnative_half_type)) {
+  const LangStandard &Std =
+  LangStandard::getLangStandardForKind(Opts.LangStd);
+  if (!(Opts.LangStd >= LangStandard::lang_hlsl2018))
+Diags.Report(diag::err_drv_hlsl_16bit_types_unsupported)
+<< "-fnative-half-type" << false << Std.getName()
+<< T.getOSVersion().getAsString();

bob80905 wrote:

I need that last parameter to the report function because that supplies the 
shader model information. It can indicate to the user whether or not the shader 
model is too low or high enough. The diagnostic uses parameters %0 - %3, so I 
do need 4 parameters.

https://github.com/llvm/llvm-project/pull/85340
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-27 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/85340

>From 74a869a282d532ec426dbc1c954779ec2972aa5c Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 14 Mar 2024 17:04:12 -0700
Subject: [PATCH 01/21] add test

---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 86 ---
 2 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e33a1f4c45b949..fae9132bd0a9c9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,7 +753,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types_option_invalid: Error<
+  "enable_16bit_types option only valid when target shader model [-T] is >= 
6.2 and Hlsl Version [-HV] is >= 2021">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 05aac9caa7fb29..bf8fc42a27816c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -66,15 +66,48 @@ bool isLegalShaderModel(Triple &T) {
   return false;
 }
 
-std::optional tryParseProfile(StringRef Profile) {
-  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+struct ShaderModel {
+  StringRef TargetKind;
+  unsigned Major;
+  unsigned Minor;
+  bool OfflineLibMinor = false;
+};
+
+std::optional GetShaderModelFromString(StringRef Profile) {
   SmallVector Parts;
   Profile.split(Parts, "_");
   if (Parts.size() != 3)
 return std::nullopt;
 
+  unsigned long long Major = 0;
+  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
+return std::nullopt;
+
+  unsigned long long Minor = 0;
+  bool isOfflineLibMinor = false;
+  if (Parts[0] == "lib" && Parts[2] == "x")
+isOfflineLibMinor = true;
+  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
+return std::nullopt;
+
+  ShaderModel ret;
+  ret.TargetKind = Parts[0];
+  ret.Major = Major;
+  ret.Minor = Minor;
+  ret.OfflineLibMinor = isOfflineLibMinor;
+
+  return ret;
+}
+
+std::optional tryParseProfile(StringRef Profile) {
+  std::optional SM = GetShaderModelFromString(Profile);
+  if (!SM.has_value()) {
+return std::nullopt;
+  }
+  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+
   Triple::EnvironmentType Kind =
-  StringSwitch(Parts[0])
+  StringSwitch(SM.value().TargetKind)
   .Case("ps", Triple::EnvironmentType::Pixel)
   .Case("vs", Triple::EnvironmentType::Vertex)
   .Case("gs", Triple::EnvironmentType::Geometry)
@@ -88,21 +121,11 @@ std::optional tryParseProfile(StringRef 
Profile) {
   if (Kind == Triple::EnvironmentType::UnknownEnvironment)
 return std::nullopt;
 
-  unsigned long long Major = 0;
-  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
-return std::nullopt;
-
-  unsigned long long Minor = 0;
-  if (Parts[2] == "x" && Kind == Triple::EnvironmentType::Library)
-Minor = OfflineLibMinor;
-  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
-return std::nullopt;
-
   // dxil-unknown-shadermodel-hull
   llvm::Triple T;
   T.setArch(Triple::ArchType::dxil);
   T.setOSName(Triple::getOSTypeName(Triple::OSType::ShaderModel).str() +
-  VersionTuple(Major, Minor).getAsString());
+  VersionTuple(SM.value().Major, SM.value().Minor).getAsString());
   T.setEnvironment(Kind);
   if (isLegalShaderModel(T))
 return T.getTriple();
@@ -258,6 +281,41 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_fnative_half_type)) {
+
+bool HVArgIsValid = true;
+bool TPArgIsValid = true;
+
+const StringRef HVArg =
+DAL->getLastArgValue(options::OPT_std_EQ, "hlsl2021");
+
+const StringRef TPArg =
+DAL->getLastArgValue(options::OPT_target_profile, "");
+std::optional parsedTargetProfile =
+GetShaderModelFromString(TPArg);
+
+unsigned long long HV_year;
+StringRef HV_year_str = HVArg.drop_front(4);
+if (HV_year_str != "202x") {
+  llvm::getAsUnsignedInteger(HV_year_str, 0, HV_year);
+  if (HV_year < 2021)
+HVArgIsValid = false;
+}
+
+if (!parsedTargetProfile.has_value())
+  return DAL;
+else {
+  

[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-28 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 closed 
https://github.com/llvm/llvm-project/pull/85340
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add clang_elementwise_builtin_alias (PR #86175)

2024-03-28 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/86175

>From 5e10b1e42a20a39c9a3d5ff332591713511832c8 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Wed, 20 Mar 2024 13:24:07 -0700
Subject: [PATCH 1/8] make elemnetwise alias an alias of builtin alias

---
 clang/include/clang/Basic/Attr.td |  9 
 clang/include/clang/Basic/AttrDocs.td | 22 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  3 ++-
 clang/lib/AST/Decl.cpp|  2 ++
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  2 ++
 5 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fd7970d0451acd..160e8ef730ef92 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -759,6 +759,15 @@ def BuiltinAlias : Attr {
   let Documentation = [BuiltinAliasDocs];
 }
 
+def ElementwiseBuiltinAlias : Attr {
+  let Spellings = [CXX11<"clang", "elementwise_builtin_alias">,
+   C23<"clang", "elementwise_builtin_alias">,
+   GNU<"clang_elementwise_builtin_alias">];
+  let Args = [IdentifierArgument<"BuiltinName">];
+  let Subjects = SubjectList<[Function], ErrorDiag>;
+  let Documentation = [ElementwiseBuiltinAliasDocs];
+}
+
 def ArmBuiltinAlias : InheritableAttr, TargetSpecificAttr {
   let Spellings = [Clang<"__clang_arm_builtin_alias">];
   let Args = [IdentifierArgument<"BuiltinName">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 2c07cd09b0d5b7..7ce83bc881f064 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -5462,6 +5462,28 @@ for clang builtin functions.
   }];
 }
 
+def ElementwiseBuiltinAliasDocs : Documentation {
+  let Category = DocCatFunction;
+  let Heading = "clang::elementwise_builtin_alias, 
clang_elementwise_builtin_alias";
+  let Content = [{
+This attribute is used in the implementation of the C intrinsics.
+It allows the C intrinsic functions to be declared using the names defined
+in target builtins, and still be recognized as clang builtins equivalent to the
+underlying name. It also declares that the given C intrinsic can accept 
+vector arguments. For example, ``hlsl_intrinsics.h`` declares the function 
``abs``
+with ``__attribute__((clang_elementwise_builtin_alias(__builtin_abs)))``.
+This ensures that both functions are recognized as that clang builtin,
+and in the latter case, the choice of which builtin to identify the
+function as can be deferred until after overload resolution. It also enables
+the ``abs`` function to take vector arguments.
+
+This attribute can only be used to set up the aliases for certain ARM/RISC-V
+C intrinsic functions; it is intended for use only inside ``arm_*.h`` and
+``riscv_*.h`` and is not a general mechanism for declaring arbitrary aliases
+for clang builtin functions.
+  }];
+}
+
 def PreferredNameDocs : Documentation {
   let Category = DocCatDecl;
   let Content = [{
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c54105507753eb..1252d3804131a6 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4412,7 +4412,8 @@ def err_attribute_preferred_name_arg_invalid : Error<
   "a specialization of %1">;
 def err_attribute_builtin_alias : Error<
   "%0 attribute can only be applied to a ARM, HLSL or RISC-V builtin">;
-
+def err_attribute_elementwise_builtin_alias : Error<
+  "%0 attribute can only be applied to a ARM, HLSL or RISC-V builtin">;
 // called-once attribute diagnostics.
 def err_called_once_attribute_wrong_type : Error<
   "'called_once' attribute only applies to function-like parameters">;
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 8626f04012f7d4..cb2c5cf6ceaf49 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3598,6 +3598,8 @@ unsigned FunctionDecl::getBuiltinID(bool 
ConsiderWrapperFunctions) const {
 BuiltinID = ABAA->getBuiltinName()->getBuiltinID();
   } else if (const auto *BAA = getAttr()) {
 BuiltinID = BAA->getBuiltinName()->getBuiltinID();
+  } else if (const auto *EBAA = getAttr()) {
+BuiltinID = EBAA->getBuiltinName()->getBuiltinID();
   } else if (const auto *A = getAttr()) {
 BuiltinID = A->getID();
   }
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 45f8544392584e..b37c4d13b26e62 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -18,6 +18,8 @@ namespace hlsl {
 
 #define _HLSL_BUILTIN_ALIAS(builtin)   
\
   __attribute__((clang_builtin_alias(builtin)))
+#define _HLSL_ELEMENTWISE_BUILTIN_ALIAS(builtin)   
\
+  __attribute__((clang_elementwise_builti

[clang] [Doc][HLSL] Add documentation for root signature. (PR #83933)

2024-03-28 Thread Joshua Batista via cfe-commits


@@ -0,0 +1,258 @@
+
+HLSL Root Signatures
+
+
+.. contents::
+   :local:
+
+Usage
+=
+
+In HLSL, the `root signature
+`_ 
+defines what types of resources are bound to the graphics pipeline. 
+
+A root signature can be specified in HLSL as a `string
+`_.
 
+The string contains a collection of comma-separated clauses that describe root 
+signature constituent components. 
+
+There are two mechanisms to compile an HLSL root signature. First, it is 
+possible to attach a root signature string to a particular shader via the 
+RootSignature attribute (in the following example, using the MyRS1 entry 

bob80905 wrote:

The following example only has "main" as an entry point right?

https://github.com/llvm/llvm-project/pull/83933
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC] Add API documentation and annotations (PR #78635)

2024-02-13 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 edited 
https://github.com/llvm/llvm-project/pull/78635
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC] Add API documentation and annotations (PR #78635)

2024-02-13 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 approved this pull request.


https://github.com/llvm/llvm-project/pull/78635
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC] Add API documentation and annotations (PR #78635)

2024-02-13 Thread Joshua Batista via cfe-commits


@@ -570,7 +716,13 @@ double4 sin(double4);
 
//===--===//
 // sqrt builtins
 
//===--===//
+
+/// \fn T sqrt(T Val)
+/// \brief Returns the square root of the input value, \a Val.
+/// \param Val The input value.
+
 #ifdef __HLSL_ENABLE_16_BIT
+_HLSL_AVAILABILITY(shadermodel, 6.2)

bob80905 wrote:

Surprisingly, it looks like there aren't function prototypes for half2/3/4, and 
I imagine we would want this new attribute applied to such aliases. Just a note 
for the future.

https://github.com/llvm/llvm-project/pull/78635
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

2024-03-05 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/83938

>From 7453ffdea39c624221c9696394bbd47be7eec662 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 13:42:02 -0800
Subject: [PATCH 1/4] first try

---
 clang/include/clang/Driver/Options.td | 4 
 clang/lib/Driver/ToolChains/HLSL.cpp  | 8 
 2 files changed, 12 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bef38738fde82e..6fe3dea1655b24 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,6 +8545,10 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
+def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+ Group,
+ Visibility<[DXCOption]>,
+ HelpText<"HLSL Version">;
 def dxc_validator_path_EQ : Joined<["--"], "dxv-path=">, Group,
   HelpText<"DXIL validator installation path">;
 def dxc_disable_validation : DXCFlag<"Vd">,
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index c6ad862b229420..0ffc15155e4db3 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,6 +226,14 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
+if (A->getOption().getID() == options::OPT_HLSL_Version) {
+  // Translate -HV into -std for llvm
+  DAL->AddSeparateArg(nullptr,
+  Opts.getOption(options::OPT_stdlibxx_isystem),
+  A->getValue());
+  A->claim();
+  continue;
+}
 DAL->append(A);
   }
 

>From 69953d737b842f2144ebe0519d810c57b5c031b9 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 17:11:37 -0800
Subject: [PATCH 2/4] add HV option, and translation test

---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 22 ++
 clang/test/Options/HV.hlsl| 13 +
 3 files changed, 32 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Options/HV.hlsl

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6fe3dea1655b24..c4caf232887b56 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,7 +8545,7 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
-def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+def dxc_hlsl_version : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"HLSL Version">;
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 0ffc15155e4db3..fe258919dedf3e 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,11 +226,25 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
-if (A->getOption().getID() == options::OPT_HLSL_Version) {
+if (A->getOption().getID() == options::OPT_dxc_hlsl_version) {
   // Translate -HV into -std for llvm
-  DAL->AddSeparateArg(nullptr,
-  Opts.getOption(options::OPT_stdlibxx_isystem),
-  A->getValue());
+  // depending on the value given, assign std to:
+  // c++14,c++17,c++20,c++latest,c11,c17
+  const char *value = A->getValue();
+  if (strcmp(value, "2016") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2016");
+  } else if (strcmp(value, "2017") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2017");
+  } else if (strcmp(value, "2018") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2018");
+  } else if (strcmp(value, "2021") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2021");
+  }
+
   A->claim();
   continue;
 }
diff --git a/clang/test/Options/HV.hlsl b/clang/test/Options/HV.hlsl
new file mode 100644
index 00..59158ff2f001ed
--- /dev/null
+++ b/clang/test/Options/HV.hlsl
@@ -0,0 +1,13 @@
+// RUN: %clang_dxc -T lib_6_4 -HV 2016 %s 2>&1 -###   | FileCheck 
-check-prefix=2016 %s
+// RUN: %clang_dxc -T lib_6_4 -HV 2017 %s 2>&1 -###   | FileCheck 
-check

[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

2024-03-05 Thread Joshua Batista via cfe-commits


@@ -226,6 +226,28 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
+if (A->getOption().getID() == options::OPT_dxc_hlsl_version) {
+  // Translate -HV into -std for llvm
+  // depending on the value given, assign std to:
+  // c++14,c++17,c++20,c++latest,c11,c17
+  const char *value = A->getValue();
+  if (strcmp(value, "2016") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2016");
+  } else if (strcmp(value, "2017") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2017");
+  } else if (strcmp(value, "2018") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2018");
+  } else if (strcmp(value, "2021") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2021");
+  }

bob80905 wrote:

Added a case for 202x and for unrecognized values. 
I notice 2015 used to be an accepted value, but I'm not sure how we want to 
treat that option, since DXC seems to treat it as a special option and has 
extra conditions for accepting it.

https://github.com/llvm/llvm-project/pull/83938
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

2024-03-05 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/83938

>From 7453ffdea39c624221c9696394bbd47be7eec662 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 13:42:02 -0800
Subject: [PATCH 1/5] first try

---
 clang/include/clang/Driver/Options.td | 4 
 clang/lib/Driver/ToolChains/HLSL.cpp  | 8 
 2 files changed, 12 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bef38738fde82e..6fe3dea1655b24 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,6 +8545,10 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
+def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+ Group,
+ Visibility<[DXCOption]>,
+ HelpText<"HLSL Version">;
 def dxc_validator_path_EQ : Joined<["--"], "dxv-path=">, Group,
   HelpText<"DXIL validator installation path">;
 def dxc_disable_validation : DXCFlag<"Vd">,
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index c6ad862b229420..0ffc15155e4db3 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,6 +226,14 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
+if (A->getOption().getID() == options::OPT_HLSL_Version) {
+  // Translate -HV into -std for llvm
+  DAL->AddSeparateArg(nullptr,
+  Opts.getOption(options::OPT_stdlibxx_isystem),
+  A->getValue());
+  A->claim();
+  continue;
+}
 DAL->append(A);
   }
 

>From 69953d737b842f2144ebe0519d810c57b5c031b9 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 17:11:37 -0800
Subject: [PATCH 2/5] add HV option, and translation test

---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 22 ++
 clang/test/Options/HV.hlsl| 13 +
 3 files changed, 32 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Options/HV.hlsl

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6fe3dea1655b24..c4caf232887b56 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,7 +8545,7 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
-def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+def dxc_hlsl_version : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"HLSL Version">;
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 0ffc15155e4db3..fe258919dedf3e 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,11 +226,25 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
-if (A->getOption().getID() == options::OPT_HLSL_Version) {
+if (A->getOption().getID() == options::OPT_dxc_hlsl_version) {
   // Translate -HV into -std for llvm
-  DAL->AddSeparateArg(nullptr,
-  Opts.getOption(options::OPT_stdlibxx_isystem),
-  A->getValue());
+  // depending on the value given, assign std to:
+  // c++14,c++17,c++20,c++latest,c11,c17
+  const char *value = A->getValue();
+  if (strcmp(value, "2016") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2016");
+  } else if (strcmp(value, "2017") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2017");
+  } else if (strcmp(value, "2018") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2018");
+  } else if (strcmp(value, "2021") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2021");
+  }
+
   A->claim();
   continue;
 }
diff --git a/clang/test/Options/HV.hlsl b/clang/test/Options/HV.hlsl
new file mode 100644
index 00..59158ff2f001ed
--- /dev/null
+++ b/clang/test/Options/HV.hlsl
@@ -0,0 +1,13 @@
+// RUN: %clang_dxc -T lib_6_4 -HV 2016 %s 2>&1 -###   | FileCheck 
-check-prefix=2016 %s
+// RUN: %clang_dxc -T lib_6_4 -HV 2017 %s 2>&1 -###   | FileCheck 
-check

[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

2024-03-06 Thread Joshua Batista via cfe-commits


@@ -8545,6 +8545,11 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
+def dxc_hlsl_version : Option<["/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+ Group,
+ Visibility<[DXCOption]>,
+ HelpText<"HLSL Version">,
+ Values<"2016, 2017, 2018, 2021, 202x">;

bob80905 wrote:

No, I added that logic myself.  I've manually checked all the valid values and 
emit an error if there are no matches in  HLSL.cpp:263.
Regardless, I wouldn't need that logic, because I need to perform a unique 
transformation exhaustively in every valid case, and if there are no matching 
valid cases, then I emit an error with `else`.

https://github.com/llvm/llvm-project/pull/83938
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

2024-03-07 Thread Joshua Batista via cfe-commits


@@ -8545,6 +8545,11 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
+def dxc_hlsl_version : Option<["/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+ Group,
+ Visibility<[DXCOption]>,
+ HelpText<"HLSL Version">,
+ Values<"2016, 2017, 2018, 2021, 202x">;

bob80905 wrote:

No, I need the change in OptTable.h to have access to the set of valid values 
to the argument. With it, I can then loop through the valid values and 
determine which transformation to apply. And, if there are 0 matches, I know 
that the given value is invalid, so I emit a diagnostic. I need some place to 
store all valid values, and I figured that the option object would be the most 
convenient.

https://github.com/llvm/llvm-project/pull/83938
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

2024-03-08 Thread Joshua Batista via cfe-commits


@@ -226,6 +226,47 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
+if (A->getOption().getID() == options::OPT_dxc_hlsl_version) {
+  // Translate -HV into -std for llvm
+  // depending on the value given
+  llvm::StringRef value(A->getValue());
+  llvm::StringRef acceptedValues(
+  Opts.getOptionValues(options::OPT_dxc_hlsl_version));
+  llvm::SmallVector validValues;
+  acceptedValues.split(validValues, ", ");
+  if (value == validValues[0]) {

bob80905 wrote:

The idea to use getOptionValues was an idea inspired by @llvm-beanz 's 
feedback, to prevent littering direct string comparisons into the code and 
unify string handling. Originally, I did have the direct "2016" comparison. I'm 
not sure if the LLVM community would want access to these option values, but it 
seems like the most convenient way to get around direct string comparisons. I 
do remember string comparisons were a pain point in the DXC codebase and want 
to try and avoid that.

https://github.com/llvm/llvm-project/pull/83938
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add diagnostic for enabling 16 bit types (PR #84537)

2024-03-08 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 created 
https://github.com/llvm/llvm-project/pull/84537

The -enable-16bit-types option was previously added without checking for a 
couple essential conditions. First, the target shader model must be greater 
than 6.2, and secondly, the hlsl version must be after HLSL 2018. 
This PR adds a check after option translation, to check that if the 
enable_16bit_types option exists, that the target shader model and hlsl 
versions are satisfactory. If not, a new diagnostic is emitted.
Fixes https://github.com/llvm/llvm-project/issues/57876

>From 55395c5c8a5b92e200aa2f1bf06774d20ac4afd9 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Fri, 8 Mar 2024 11:03:37 -0800
Subject: [PATCH] add check for enable 16 bit types

---
 clang/include/clang/Basic/DiagnosticDriverKinds.td |  3 ++-
 clang/lib/Driver/ToolChains/HLSL.cpp   | 14 ++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 1bc9885849d54b..23009117af0f37 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -750,7 +750,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types : Error<
+  "enable_16bit_types cannot be applied when shader model is <= 6.2 and hlsl 
version <= 2018. (SM: %0, HV: %1)">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index c6ad862b229420..e30ae78ca6553c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -243,6 +243,20 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_enable_16bit_types)) {
+llvm::opt::Arg *hvArg = DAL->getLastArg(options::OPT_dxc_hlsl_version);
+llvm::VersionTuple versionTuple = getTriple().getOSVersion();
+unsigned int major = versionTuple.getMajor();
+auto minor = versionTuple.getMinor();
+
+if (major < 6 || (major == 6 && minor.value() <= 2) ||
+strcmp(hvArg->getValue(), "2016") == 0 ||
+strcmp(hvArg->getValue(), "2017") == 0 ||
+strcmp(hvArg->getValue(), "2018") == 0) {
+  getDriver().Diag(diag::err_drv_hlsl_enable_16bit_types)
+  << versionTuple.getAsString() << hvArg->getValue();
+}
+  }
   return DAL;
 }
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add diagnostic for enabling 16 bit types (PR #84537)

2024-03-08 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/84537

>From 8205c6894a4c1deeeb28c2520d16a56c3fcf21ea Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Fri, 8 Mar 2024 11:03:37 -0800
Subject: [PATCH] add check for enable 16 bit types

---
 clang/include/clang/Basic/DiagnosticDriverKinds.td |  3 ++-
 clang/lib/Driver/ToolChains/HLSL.cpp   | 14 ++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 1bc9885849d54b..23009117af0f37 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -750,7 +750,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types : Error<
+  "enable_16bit_types cannot be applied when shader model is <= 6.2 and hlsl 
version <= 2018. (SM: %0, HV: %1)">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index c6ad862b229420..e30ae78ca6553c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -243,6 +243,20 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_enable_16bit_types)) {
+llvm::opt::Arg *hvArg = DAL->getLastArg(options::OPT_dxc_hlsl_version);
+llvm::VersionTuple versionTuple = getTriple().getOSVersion();
+unsigned int major = versionTuple.getMajor();
+auto minor = versionTuple.getMinor();
+
+if (major < 6 || (major == 6 && minor.value() <= 2) ||
+strcmp(hvArg->getValue(), "2016") == 0 ||
+strcmp(hvArg->getValue(), "2017") == 0 ||
+strcmp(hvArg->getValue(), "2018") == 0) {
+  getDriver().Diag(diag::err_drv_hlsl_enable_16bit_types)
+  << versionTuple.getAsString() << hvArg->getValue();
+}
+  }
   return DAL;
 }
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

2024-03-08 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/83938

>From 7453ffdea39c624221c9696394bbd47be7eec662 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 13:42:02 -0800
Subject: [PATCH 1/6] first try

---
 clang/include/clang/Driver/Options.td | 4 
 clang/lib/Driver/ToolChains/HLSL.cpp  | 8 
 2 files changed, 12 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bef38738fde82e..6fe3dea1655b24 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,6 +8545,10 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
+def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+ Group,
+ Visibility<[DXCOption]>,
+ HelpText<"HLSL Version">;
 def dxc_validator_path_EQ : Joined<["--"], "dxv-path=">, Group,
   HelpText<"DXIL validator installation path">;
 def dxc_disable_validation : DXCFlag<"Vd">,
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index c6ad862b229420..0ffc15155e4db3 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,6 +226,14 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
+if (A->getOption().getID() == options::OPT_HLSL_Version) {
+  // Translate -HV into -std for llvm
+  DAL->AddSeparateArg(nullptr,
+  Opts.getOption(options::OPT_stdlibxx_isystem),
+  A->getValue());
+  A->claim();
+  continue;
+}
 DAL->append(A);
   }
 

>From 69953d737b842f2144ebe0519d810c57b5c031b9 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 17:11:37 -0800
Subject: [PATCH 2/6] add HV option, and translation test

---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 22 ++
 clang/test/Options/HV.hlsl| 13 +
 3 files changed, 32 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Options/HV.hlsl

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6fe3dea1655b24..c4caf232887b56 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,7 +8545,7 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
-def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+def dxc_hlsl_version : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"HLSL Version">;
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 0ffc15155e4db3..fe258919dedf3e 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,11 +226,25 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
-if (A->getOption().getID() == options::OPT_HLSL_Version) {
+if (A->getOption().getID() == options::OPT_dxc_hlsl_version) {
   // Translate -HV into -std for llvm
-  DAL->AddSeparateArg(nullptr,
-  Opts.getOption(options::OPT_stdlibxx_isystem),
-  A->getValue());
+  // depending on the value given, assign std to:
+  // c++14,c++17,c++20,c++latest,c11,c17
+  const char *value = A->getValue();
+  if (strcmp(value, "2016") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2016");
+  } else if (strcmp(value, "2017") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2017");
+  } else if (strcmp(value, "2018") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2018");
+  } else if (strcmp(value, "2021") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2021");
+  }
+
   A->claim();
   continue;
 }
diff --git a/clang/test/Options/HV.hlsl b/clang/test/Options/HV.hlsl
new file mode 100644
index 00..59158ff2f001ed
--- /dev/null
+++ b/clang/test/Options/HV.hlsl
@@ -0,0 +1,13 @@
+// RUN: %clang_dxc -T lib_6_4 -HV 2016 %s 2>&1 -###   | FileCheck 
-check-prefix=2016 %s
+// RUN: %clang_dxc -T lib_6_4 -HV 2017 %s 2>&1 -###   | FileCheck 
-check

[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

2024-03-08 Thread Joshua Batista via cfe-commits


@@ -226,6 +226,47 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
+if (A->getOption().getID() == options::OPT_dxc_hlsl_version) {
+  // Translate -HV into -std for llvm
+  // depending on the value given
+  llvm::StringRef value(A->getValue());
+  llvm::StringRef acceptedValues(
+  Opts.getOptionValues(options::OPT_dxc_hlsl_version));
+  llvm::SmallVector validValues;
+  acceptedValues.split(validValues, ", ");
+  if (value == validValues[0]) {

bob80905 wrote:

I've added your recommended function, hopefully it is what you envisioned?

https://github.com/llvm/llvm-project/pull/83938
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add diagnostic for enabling 16 bit types (PR #84537)

2024-03-08 Thread Joshua Batista via cfe-commits


@@ -243,6 +243,20 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and

bob80905 wrote:

Yes, I'll remove the comment.

https://github.com/llvm/llvm-project/pull/84537
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add diagnostic for enabling 16 bit types (PR #84537)

2024-03-08 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/84537

>From 55395c5c8a5b92e200aa2f1bf06774d20ac4afd9 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Fri, 8 Mar 2024 11:03:37 -0800
Subject: [PATCH 1/3] add check for enable 16 bit types

---
 clang/include/clang/Basic/DiagnosticDriverKinds.td |  3 ++-
 clang/lib/Driver/ToolChains/HLSL.cpp   | 14 ++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 1bc9885849d54bf..23009117af0f378 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -750,7 +750,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types : Error<
+  "enable_16bit_types cannot be applied when shader model is <= 6.2 and hlsl 
version <= 2018. (SM: %0, HV: %1)">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index c6ad862b229420b..e30ae78ca6553cf 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -243,6 +243,20 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_enable_16bit_types)) {
+llvm::opt::Arg *hvArg = DAL->getLastArg(options::OPT_dxc_hlsl_version);
+llvm::VersionTuple versionTuple = getTriple().getOSVersion();
+unsigned int major = versionTuple.getMajor();
+auto minor = versionTuple.getMinor();
+
+if (major < 6 || (major == 6 && minor.value() <= 2) ||
+strcmp(hvArg->getValue(), "2016") == 0 ||
+strcmp(hvArg->getValue(), "2017") == 0 ||
+strcmp(hvArg->getValue(), "2018") == 0) {
+  getDriver().Diag(diag::err_drv_hlsl_enable_16bit_types)
+  << versionTuple.getAsString() << hvArg->getValue();
+}
+  }
   return DAL;
 }
 

>From 8205c6894a4c1deeeb28c2520d16a56c3fcf21ea Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Fri, 8 Mar 2024 11:03:37 -0800
Subject: [PATCH 2/3] add check for enable 16 bit types

---
 clang/include/clang/Basic/DiagnosticDriverKinds.td |  3 ++-
 clang/lib/Driver/ToolChains/HLSL.cpp   | 14 ++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 1bc9885849d54bf..23009117af0f378 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -750,7 +750,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types : Error<
+  "enable_16bit_types cannot be applied when shader model is <= 6.2 and hlsl 
version <= 2018. (SM: %0, HV: %1)">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index c6ad862b229420b..e30ae78ca6553cf 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -243,6 +243,20 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_enable_16bit_types)) {
+llvm::opt::Arg *hvArg = DAL->getLastArg(options::OPT_dxc_hlsl_version);
+llvm::VersionTuple versionTuple = getTriple().getOSVersion();
+unsigned int major = versionTuple.getMajor();
+auto minor = versionTuple.getMinor();
+
+if (major < 6 || (major == 6 && minor.value() <= 2) ||
+strcmp(hvArg->getValue(), "2016") == 0 ||
+strcmp(hvArg->getValue(), "2017") == 0 ||
+strcmp(hvArg->getValue(), "2018") == 0) {
+  getDriver().Diag(d

[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

2024-03-11 Thread Joshua Batista via cfe-commits


@@ -8545,6 +8545,11 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
+def dxc_hlsl_version : Option<["/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+ Group,
+ Visibility<[DXCOption]>,
+ HelpText<"HLSL Version">,
+ Values<"2016, 2017, 2018, 2021, 202x">;

bob80905 wrote:

I've decided to use NormalizedValues instead of values, but I no longer need 
access to valid values thanks to Xiang's suggestion. So I think I should just 
leave the values there for documentation's sake, but the values won't actually 
be read by option translation.

https://github.com/llvm/llvm-project/pull/83938
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

2024-03-11 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/83938

>From 7453ffdea39c624221c9696394bbd47be7eec662 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 13:42:02 -0800
Subject: [PATCH 1/7] first try

---
 clang/include/clang/Driver/Options.td | 4 
 clang/lib/Driver/ToolChains/HLSL.cpp  | 8 
 2 files changed, 12 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bef38738fde82e..6fe3dea1655b24 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,6 +8545,10 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
+def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+ Group,
+ Visibility<[DXCOption]>,
+ HelpText<"HLSL Version">;
 def dxc_validator_path_EQ : Joined<["--"], "dxv-path=">, Group,
   HelpText<"DXIL validator installation path">;
 def dxc_disable_validation : DXCFlag<"Vd">,
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index c6ad862b229420..0ffc15155e4db3 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,6 +226,14 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
+if (A->getOption().getID() == options::OPT_HLSL_Version) {
+  // Translate -HV into -std for llvm
+  DAL->AddSeparateArg(nullptr,
+  Opts.getOption(options::OPT_stdlibxx_isystem),
+  A->getValue());
+  A->claim();
+  continue;
+}
 DAL->append(A);
   }
 

>From 69953d737b842f2144ebe0519d810c57b5c031b9 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 17:11:37 -0800
Subject: [PATCH 2/7] add HV option, and translation test

---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 22 ++
 clang/test/Options/HV.hlsl| 13 +
 3 files changed, 32 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Options/HV.hlsl

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6fe3dea1655b24..c4caf232887b56 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,7 +8545,7 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
-def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+def dxc_hlsl_version : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"HLSL Version">;
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 0ffc15155e4db3..fe258919dedf3e 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,11 +226,25 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
-if (A->getOption().getID() == options::OPT_HLSL_Version) {
+if (A->getOption().getID() == options::OPT_dxc_hlsl_version) {
   // Translate -HV into -std for llvm
-  DAL->AddSeparateArg(nullptr,
-  Opts.getOption(options::OPT_stdlibxx_isystem),
-  A->getValue());
+  // depending on the value given, assign std to:
+  // c++14,c++17,c++20,c++latest,c11,c17
+  const char *value = A->getValue();
+  if (strcmp(value, "2016") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2016");
+  } else if (strcmp(value, "2017") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2017");
+  } else if (strcmp(value, "2018") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2018");
+  } else if (strcmp(value, "2021") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2021");
+  }
+
   A->claim();
   continue;
 }
diff --git a/clang/test/Options/HV.hlsl b/clang/test/Options/HV.hlsl
new file mode 100644
index 00..59158ff2f001ed
--- /dev/null
+++ b/clang/test/Options/HV.hlsl
@@ -0,0 +1,13 @@
+// RUN: %clang_dxc -T lib_6_4 -HV 2016 %s 2>&1 -###   | FileCheck 
-check-prefix=2016 %s
+// RUN: %clang_dxc -T lib_6_4 -HV 2017 %s 2>&1 -###   | FileCheck 
-check

[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

2024-03-11 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/83938

>From 7453ffdea39c624221c9696394bbd47be7eec662 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 13:42:02 -0800
Subject: [PATCH 1/8] first try

---
 clang/include/clang/Driver/Options.td | 4 
 clang/lib/Driver/ToolChains/HLSL.cpp  | 8 
 2 files changed, 12 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bef38738fde82e..6fe3dea1655b24 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,6 +8545,10 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
+def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+ Group,
+ Visibility<[DXCOption]>,
+ HelpText<"HLSL Version">;
 def dxc_validator_path_EQ : Joined<["--"], "dxv-path=">, Group,
   HelpText<"DXIL validator installation path">;
 def dxc_disable_validation : DXCFlag<"Vd">,
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index c6ad862b229420..0ffc15155e4db3 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,6 +226,14 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
+if (A->getOption().getID() == options::OPT_HLSL_Version) {
+  // Translate -HV into -std for llvm
+  DAL->AddSeparateArg(nullptr,
+  Opts.getOption(options::OPT_stdlibxx_isystem),
+  A->getValue());
+  A->claim();
+  continue;
+}
 DAL->append(A);
   }
 

>From 69953d737b842f2144ebe0519d810c57b5c031b9 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 17:11:37 -0800
Subject: [PATCH 2/8] add HV option, and translation test

---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 22 ++
 clang/test/Options/HV.hlsl| 13 +
 3 files changed, 32 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Options/HV.hlsl

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6fe3dea1655b24..c4caf232887b56 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,7 +8545,7 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
-def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+def dxc_hlsl_version : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"HLSL Version">;
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 0ffc15155e4db3..fe258919dedf3e 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,11 +226,25 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
-if (A->getOption().getID() == options::OPT_HLSL_Version) {
+if (A->getOption().getID() == options::OPT_dxc_hlsl_version) {
   // Translate -HV into -std for llvm
-  DAL->AddSeparateArg(nullptr,
-  Opts.getOption(options::OPT_stdlibxx_isystem),
-  A->getValue());
+  // depending on the value given, assign std to:
+  // c++14,c++17,c++20,c++latest,c11,c17
+  const char *value = A->getValue();
+  if (strcmp(value, "2016") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2016");
+  } else if (strcmp(value, "2017") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2017");
+  } else if (strcmp(value, "2018") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2018");
+  } else if (strcmp(value, "2021") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2021");
+  }
+
   A->claim();
   continue;
 }
diff --git a/clang/test/Options/HV.hlsl b/clang/test/Options/HV.hlsl
new file mode 100644
index 00..59158ff2f001ed
--- /dev/null
+++ b/clang/test/Options/HV.hlsl
@@ -0,0 +1,13 @@
+// RUN: %clang_dxc -T lib_6_4 -HV 2016 %s 2>&1 -###   | FileCheck 
-check-prefix=2016 %s
+// RUN: %clang_dxc -T lib_6_4 -HV 2017 %s 2>&1 -###   | FileCheck 
-check

[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

2024-03-12 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/83938

>From 7453ffdea39c624221c9696394bbd47be7eec662 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 13:42:02 -0800
Subject: [PATCH 1/7] first try

---
 clang/include/clang/Driver/Options.td | 4 
 clang/lib/Driver/ToolChains/HLSL.cpp  | 8 
 2 files changed, 12 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bef38738fde82e..6fe3dea1655b24 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,6 +8545,10 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
+def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+ Group,
+ Visibility<[DXCOption]>,
+ HelpText<"HLSL Version">;
 def dxc_validator_path_EQ : Joined<["--"], "dxv-path=">, Group,
   HelpText<"DXIL validator installation path">;
 def dxc_disable_validation : DXCFlag<"Vd">,
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index c6ad862b229420..0ffc15155e4db3 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,6 +226,14 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
+if (A->getOption().getID() == options::OPT_HLSL_Version) {
+  // Translate -HV into -std for llvm
+  DAL->AddSeparateArg(nullptr,
+  Opts.getOption(options::OPT_stdlibxx_isystem),
+  A->getValue());
+  A->claim();
+  continue;
+}
 DAL->append(A);
   }
 

>From 69953d737b842f2144ebe0519d810c57b5c031b9 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 17:11:37 -0800
Subject: [PATCH 2/7] add HV option, and translation test

---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 22 ++
 clang/test/Options/HV.hlsl| 13 +
 3 files changed, 32 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Options/HV.hlsl

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6fe3dea1655b24..c4caf232887b56 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,7 +8545,7 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
-def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+def dxc_hlsl_version : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"HLSL Version">;
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 0ffc15155e4db3..fe258919dedf3e 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,11 +226,25 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
-if (A->getOption().getID() == options::OPT_HLSL_Version) {
+if (A->getOption().getID() == options::OPT_dxc_hlsl_version) {
   // Translate -HV into -std for llvm
-  DAL->AddSeparateArg(nullptr,
-  Opts.getOption(options::OPT_stdlibxx_isystem),
-  A->getValue());
+  // depending on the value given, assign std to:
+  // c++14,c++17,c++20,c++latest,c11,c17
+  const char *value = A->getValue();
+  if (strcmp(value, "2016") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2016");
+  } else if (strcmp(value, "2017") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2017");
+  } else if (strcmp(value, "2018") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2018");
+  } else if (strcmp(value, "2021") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2021");
+  }
+
   A->claim();
   continue;
 }
diff --git a/clang/test/Options/HV.hlsl b/clang/test/Options/HV.hlsl
new file mode 100644
index 00..59158ff2f001ed
--- /dev/null
+++ b/clang/test/Options/HV.hlsl
@@ -0,0 +1,13 @@
+// RUN: %clang_dxc -T lib_6_4 -HV 2016 %s 2>&1 -###   | FileCheck 
-check-prefix=2016 %s
+// RUN: %clang_dxc -T lib_6_4 -HV 2017 %s 2>&1 -###   | FileCheck 
-check

[clang] [llvm] [HLSL] implement the any intrinsic (PR #83903)

2024-03-04 Thread Joshua Batista via cfe-commits

bob80905 wrote:

For these intrinsic addition changes, do we need to add a note to 
"clang\docs\ReleaseNotes.rst"?

https://github.com/llvm/llvm-project/pull/83903
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL] implement the any intrinsic (PR #83903)

2024-03-04 Thread Joshua Batista via cfe-commits

bob80905 wrote:

I mention it because when I added the elementwise builtins (pow, abs, log, 
etc), I had to add a release note for each one.

https://github.com/llvm/llvm-project/pull/83903
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL] implement the any intrinsic (PR #83903)

2024-03-04 Thread Joshua Batista via cfe-commits

bob80905 wrote:

@bogner or @llvm-beanz can you confirm?

> I mention it because when I added the elementwise builtins (pow, abs, log, 
> etc), I had to add a release note for each one. I had made changes to 
> Builtins.def, so that could be the reason. It is possible that we also want 
> an entry into LanguageExtensions.rst too. For your reference, here's a link 
> to such a commit: 
> [3a98e73#diff-66de04ca3d677cd4946ce2482117909d67539bb9c54ee0ce850925845b94da96](https://github.com/llvm/llvm-project/commit/3a98e73169e1d8e4fbb739462eea62445db1a6c8#diff-66de04ca3d677cd4946ce2482117909d67539bb9c54ee0ce850925845b94da96)



https://github.com/llvm/llvm-project/pull/83903
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

2024-03-04 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 created 
https://github.com/llvm/llvm-project/pull/83938

Previously, clang-dxc.exe would not recognize -HV as a valid argument to DXC, 
and would be unable to translate the argument to a legal clang argument. This 
PR implements a translation of the HV option and its value to the appropriate 
clang flag and the appropriate value. It adds a test by using the -### option 
to spit out the translated options, and checks to see that the correct option 
was generated.
Fixes #83479

>From 7453ffdea39c624221c9696394bbd47be7eec662 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 13:42:02 -0800
Subject: [PATCH 1/2] first try

---
 clang/include/clang/Driver/Options.td | 4 
 clang/lib/Driver/ToolChains/HLSL.cpp  | 8 
 2 files changed, 12 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bef38738fde82e..6fe3dea1655b24 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,6 +8545,10 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
+def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+ Group,
+ Visibility<[DXCOption]>,
+ HelpText<"HLSL Version">;
 def dxc_validator_path_EQ : Joined<["--"], "dxv-path=">, Group,
   HelpText<"DXIL validator installation path">;
 def dxc_disable_validation : DXCFlag<"Vd">,
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index c6ad862b229420..0ffc15155e4db3 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,6 +226,14 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
+if (A->getOption().getID() == options::OPT_HLSL_Version) {
+  // Translate -HV into -std for llvm
+  DAL->AddSeparateArg(nullptr,
+  Opts.getOption(options::OPT_stdlibxx_isystem),
+  A->getValue());
+  A->claim();
+  continue;
+}
 DAL->append(A);
   }
 

>From 69953d737b842f2144ebe0519d810c57b5c031b9 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Mon, 4 Mar 2024 17:11:37 -0800
Subject: [PATCH 2/2] add HV option, and translation test

---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 22 ++
 clang/test/Options/HV.hlsl| 13 +
 3 files changed, 32 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Options/HV.hlsl

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6fe3dea1655b24..c4caf232887b56 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8545,7 +8545,7 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
-def dxc_HlslVersion : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+def dxc_hlsl_version : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"HLSL Version">;
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 0ffc15155e4db3..fe258919dedf3e 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,11 +226,25 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   A->claim();
   continue;
 }
-if (A->getOption().getID() == options::OPT_HLSL_Version) {
+if (A->getOption().getID() == options::OPT_dxc_hlsl_version) {
   // Translate -HV into -std for llvm
-  DAL->AddSeparateArg(nullptr,
-  Opts.getOption(options::OPT_stdlibxx_isystem),
-  A->getValue());
+  // depending on the value given, assign std to:
+  // c++14,c++17,c++20,c++latest,c11,c17
+  const char *value = A->getValue();
+  if (strcmp(value, "2016") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2016");
+  } else if (strcmp(value, "2017") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2017");
+  } else if (strcmp(value, "2018") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+"hlsl2018");
+  } else if (strcmp(value, "2021") == 0) {
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+  

[clang] 26eb708 - Add builtin_elementwise_log

2023-02-02 Thread Joshua Batista via cfe-commits

Author: Joshua Batista
Date: 2023-02-02T11:36:22-08:00
New Revision: 26eb70820fb860ccf97c57ee26502ff621cf4ed2

URL: 
https://github.com/llvm/llvm-project/commit/26eb70820fb860ccf97c57ee26502ff621cf4ed2
DIFF: 
https://github.com/llvm/llvm-project/commit/26eb70820fb860ccf97c57ee26502ff621cf4ed2.diff

LOG: Add builtin_elementwise_log

Add codegen for llvm log elementwise builtin
The log elementwise builtin is necessary for HLSL codegen.
Tests were added to make sure that the expected errors are encountered when 
these functions are given inputs of incompatible types.
The new builtin is restricted to floating point types only.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D140489

Added: 
clang/test/Sema/aarch64-sve-vector-log-ops.c
clang/test/Sema/riscv-sve-vector-log-ops.c

Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Builtins.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/builtins-elementwise-math.c
clang/test/Sema/builtins-elementwise-math.c
clang/test/SemaCXX/builtins-elementwise-math.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 0b533a2ff7596..90e7943510608 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -635,6 +635,7 @@ Unless specified otherwise operation(±0) = ±0 and 
operation(±infinity) = ±in
  T __builtin_elementwise_sin(T x)return the sine of x interpreted 
as an angle in radians  floating point types
  T __builtin_elementwise_cos(T x)return the cosine of x 
interpreted as an angle in radiansfloating point types
  T __builtin_elementwise_floor(T x)  return the largest integral value 
less than or equal to xfloating point types
+ T __builtin_elementwise_log(T x)return the natural logarithm of x 
   floating point types
  T __builtin_elementwise_roundeven(T x)  round x to the nearest integer 
value in floating point format,   floating point types
  rounding halfway cases to even 
(that is, to the nearest value
  that is an even integer), 
regardless of the current rounding

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3ed971ec5847a..8e93be1041c3a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -183,6 +183,7 @@ Arm and AArch64 Support in Clang
 
 Floating Point Support in Clang
 ---
+- Add ``__builtin_elementwise_log``builtin for floating point types only.
 
 Internal API Changes
 

diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 6b54ff7c40e82..07e0a2d7748c5 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -662,6 +662,7 @@ BUILTIN(__builtin_elementwise_min, "v.", "nct")
 BUILTIN(__builtin_elementwise_ceil, "v.", "nct")
 BUILTIN(__builtin_elementwise_cos, "v.", "nct")
 BUILTIN(__builtin_elementwise_floor, "v.", "nct")
+BUILTIN(__builtin_elementwise_log, "v.", "nct")
 BUILTIN(__builtin_elementwise_roundeven, "v.", "nct")
 BUILTIN(__builtin_elementwise_sin, "v.", "nct")
 BUILTIN(__builtin_elementwise_trunc, "v.", "nct")

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index bf1c9acc7bec7..8f733d7d14c6e 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3079,6 +3079,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   case Builtin::BI__builtin_elementwise_ceil:
 return RValue::get(
 emitUnaryBuiltin(*this, E, llvm::Intrinsic::ceil, "elt.ceil"));
+  case Builtin::BI__builtin_elementwise_log:
+return RValue::get(
+emitUnaryBuiltin(*this, E, llvm::Intrinsic::log, "elt.log"));
   case Builtin::BI__builtin_elementwise_cos:
 return RValue::get(
 emitUnaryBuiltin(*this, E, llvm::Intrinsic::cos, "elt.cos"));

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 4602284309491..f1c4aabadef5f 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2609,6 +2609,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
   case Builtin::BI__builtin_elementwise_ceil:
   case Builtin::BI__builtin_elementwise_cos:
   case Builtin::BI__builtin_elementwise_floor:
+  case Builtin::BI__builtin_elementwise_log:
   case Builtin::BI__builtin_elementwise_roundeven:
   case Builtin::BI__builtin_elementwise_sin:
   case Builtin::BI__builtin_elementwise_trunc:

diff  --git a/clang/test/CodeGen/builtins-elementwise-math.c 
b/clang/test/CodeGen/builtins-elementwise-math.c
inde

[clang] a11a675 - Repair sphinx doc generation

2023-02-02 Thread Joshua Batista via cfe-commits

Author: Joshua Batista
Date: 2023-02-02T12:33:53-08:00
New Revision: a11a6752c15b76f165bcb9c733c6c7dce9bcec6b

URL: 
https://github.com/llvm/llvm-project/commit/a11a6752c15b76f165bcb9c733c6c7dce9bcec6b
DIFF: 
https://github.com/llvm/llvm-project/commit/a11a6752c15b76f165bcb9c733c6c7dce9bcec6b.diff

LOG: Repair sphinx doc generation

mistake in the log commit neglected to place a space after the `` literal,
which messed up the build by incapacitating the sphinx generator.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D143208

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3f1f492c3ccd..c7b084ef8e29 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -186,7 +186,7 @@ Arm and AArch64 Support in Clang
 
 Floating Point Support in Clang
 ---
-- Add ``__builtin_elementwise_log``builtin for floating point types only.
+- Add ``__builtin_elementwise_log`` builtin for floating point types only.
 
 Internal API Changes
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3a98e73 - clang: Add elementwise pow builtin

2023-07-24 Thread Joshua Batista via cfe-commits

Author: Joshua Batista
Date: 2023-07-24T14:03:58-07:00
New Revision: 3a98e73169e1d8e4fbb739462eea62445db1a6c8

URL: 
https://github.com/llvm/llvm-project/commit/3a98e73169e1d8e4fbb739462eea62445db1a6c8
DIFF: 
https://github.com/llvm/llvm-project/commit/3a98e73169e1d8e4fbb739462eea62445db1a6c8.diff

LOG:  clang: Add elementwise pow builtin

Add codegen for llvm pow elementwise builtin
The pow elementwise builtin is necessary for HLSL codegen.
Tests were added to make sure that the expected errors are encountered when 
these functions are given inputs of incompatible types, or too many inputs.
The new builtin is restricted to floating point types only.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D153310

Added: 
clang/test/Sema/aarch64-sve-vector-pow-ops.c
clang/test/Sema/riscv-sve-vector-pow-ops.c

Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Builtins.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/builtins-elementwise-math.c
clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
clang/test/Sema/builtins-elementwise-math.c
clang/test/SemaCXX/builtins-elementwise-math.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 6705ee176196cc..1830480b1285d7 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -639,6 +639,7 @@ Unless specified otherwise operation(±0) = ±0 and 
operation(±infinity) = ±in
  T __builtin_elementwise_log(T x)return the natural logarithm of x 
   floating point types
  T __builtin_elementwise_log2(T x)   return the base 2 logarithm of x  
   floating point types
  T __builtin_elementwise_log10(T x)  return the base 10 logarithm of x 
   floating point types
+ T __builtin_elementwise_pow(T x, T y)   return x raised to the power of y 
   floating point types
  T __builtin_elementwise_exp(T x)returns the base-e exponential, 
e^x, of the specified value  floating point types
  T __builtin_elementwise_exp2(T x)   returns the base-2 exponential, 
2^x, of the specified value  floating point types
  T __builtin_elementwise_roundeven(T x)  round x to the nearest integer 
value in floating point format,   floating point types

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d6cf96bee488d1..4f82edd0d03d14 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -961,6 +961,7 @@ Floating Point Support in Clang
 - Add ``__builtin_elementwise_exp`` builtin for floating point types only.
 - Add ``__builtin_elementwise_exp2`` builtin for floating point types only.
 - Add ``__builtin_set_flt_rounds`` builtin for X86, x86_64, Arm and AArch64 
only.
+- Add ``__builtin_elementwise_pow`` builtin for floating point types only.
 
 AST Matchers
 

diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index fe00a2f69922a1..6dad8b512bd2df 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -687,6 +687,7 @@ BUILTIN(__builtin_elementwise_floor, "v.", "nct")
 BUILTIN(__builtin_elementwise_log, "v.", "nct")
 BUILTIN(__builtin_elementwise_log2, "v.", "nct")
 BUILTIN(__builtin_elementwise_log10, "v.", "nct")
+BUILTIN(__builtin_elementwise_pow, "v.", "nct")
 BUILTIN(__builtin_elementwise_roundeven, "v.", "nct")
 BUILTIN(__builtin_elementwise_round, "v.", "nct")
 BUILTIN(__builtin_elementwise_rint, "v.", "nct")

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d5ad35c0c93602..30f5f4e7061c05 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3234,6 +3234,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   case Builtin::BI__builtin_elementwise_log10:
 return RValue::get(
 emitUnaryBuiltin(*this, E, llvm::Intrinsic::log10, "elt.log10"));
+  case Builtin::BI__builtin_elementwise_pow: {
+return RValue::get(emitBinaryBuiltin(*this, E, llvm::Intrinsic::pow));
+  }
   case Builtin::BI__builtin_elementwise_cos:
 return RValue::get(
 emitUnaryBuiltin(*this, E, llvm::Intrinsic::cos, "elt.cos"));

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 17d9889da85e2d..f8e48728da6647 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2657,6 +2657,22 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
   return ExprError();
 break;
   }
+
+  // These builtins restrict the element type to floating point
+  // types only, and take in two arguments.
+

[clang] 57f879c - clang: Add elementwise bitreverse builtin

2023-07-31 Thread Joshua Batista via cfe-commits

Author: Joshua Batista
Date: 2023-07-31T10:59:13-07:00
New Revision: 57f879cdd4c63189c569bdc1ce4e87e7342eea46

URL: 
https://github.com/llvm/llvm-project/commit/57f879cdd4c63189c569bdc1ce4e87e7342eea46
DIFF: 
https://github.com/llvm/llvm-project/commit/57f879cdd4c63189c569bdc1ce4e87e7342eea46.diff

LOG: clang: Add elementwise bitreverse builtin

Add codegen for llvm bitreverse elementwise builtin
The bitreverse elementwise builtin is necessary for HLSL codegen.
Tests were added to make sure that the expected errors are encountered when 
these functions are given inputs of incompatible types, or too many inputs.
The new builtin is restricted to integer types only.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D156357

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Builtins.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/builtins-elementwise-math.c
clang/test/Sema/builtins-elementwise-math.c
clang/test/SemaCXX/builtins-elementwise-math.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 1830480b1285d7..fbe240dd79b848 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -631,7 +631,7 @@ Unless specified otherwise operation(±0) = ±0 and 
operation(±infinity) = ±in
 === 
 
=
  T __builtin_elementwise_abs(T x)return the absolute value of a 
number x; the absolute value of   signed integer and floating point types
  the most negative integer remains 
the most negative integer
- T __builtin_elementwise_fma(T x, T y, T z)  fused multiply add, (x * y) +  z. 
 floating point types
+ T __builtin_elementwise_fma(T x, T y, T z)  fused multiply add, (x * y) +  z. 
   floating point types
  T __builtin_elementwise_ceil(T x)   return the smallest integral 
value greater than or equal to xfloating point types
  T __builtin_elementwise_sin(T x)return the sine of x interpreted 
as an angle in radians  floating point types
  T __builtin_elementwise_cos(T x)return the cosine of x 
interpreted as an angle in radiansfloating point types
@@ -640,6 +640,7 @@ Unless specified otherwise operation(±0) = ±0 and 
operation(±infinity) = ±in
  T __builtin_elementwise_log2(T x)   return the base 2 logarithm of x  
   floating point types
  T __builtin_elementwise_log10(T x)  return the base 10 logarithm of x 
   floating point types
  T __builtin_elementwise_pow(T x, T y)   return x raised to the power of y 
   floating point types
+ T __builtin_elementwise_bitreverse(T x) return the integer represented 
after reversing the bits of x integer types
  T __builtin_elementwise_exp(T x)returns the base-e exponential, 
e^x, of the specified value  floating point types
  T __builtin_elementwise_exp2(T x)   returns the base-2 exponential, 
2^x, of the specified value  floating point types
  T __builtin_elementwise_roundeven(T x)  round x to the nearest integer 
value in floating point format,   floating point types

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d369af7944ebeb..55189cbd659087 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -182,6 +182,14 @@ DWARF Support in Clang
 
 Floating Point Support in Clang
 ---
+- Add ``__builtin_elementwise_log`` builtin for floating point types only.
+- Add ``__builtin_elementwise_log10`` builtin for floating point types only.
+- Add ``__builtin_elementwise_log2`` builtin for floating point types only.
+- Add ``__builtin_elementwise_exp`` builtin for floating point types only.
+- Add ``__builtin_elementwise_exp2`` builtin for floating point types only.
+- Add ``__builtin_set_flt_rounds`` builtin for X86, x86_64, Arm and AArch64 
only.
+- Add ``__builtin_elementwise_pow`` builtin for floating point types only.
+- Add ``__builtin_elementwise_bitreverse`` builtin for integer types only.
 
 AST Matchers
 

diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 6dad8b512bd2df..843cc7f334f564 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -677,6 +677,7 @@ BUILTIN(__builtin_call_with_static_chain, "v.", "nt")
 BUILTIN(__builtin_nondeterministic_value, "v.", "nt")
 
 BUILTIN(__builtin_elementwise_abs, "v.", "nct")
+BUILTIN

[clang] e545392 - [HLSL] Add reversebits library function

2023-08-02 Thread Joshua Batista via cfe-commits

Author: Joshua Batista
Date: 2023-08-02T20:50:40-07:00
New Revision: e545392b1de304d3bf2776f671cb7327e335b90b

URL: 
https://github.com/llvm/llvm-project/commit/e545392b1de304d3bf2776f671cb7327e335b90b
DIFF: 
https://github.com/llvm/llvm-project/commit/e545392b1de304d3bf2776f671cb7327e335b90b.diff

LOG: [HLSL] Add reversebits library function

This change exposes the reversebits library function for HLSL, excluding 
floating point types.
The reversebits function is supported for all scalar, vector, and matrix types.

The full documentation of the HLSL reversebits function is available here:
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/reversebits

Reviewed By: python3kgae

Differential Revision: https://reviews.llvm.org/D156933

Added: 
clang/test/CodeGenHLSL/builtins/bitreverse.hlsl
clang/test/CodeGenHLSL/builtins/reversebits.hlsl

Modified: 
clang/lib/Headers/hlsl/hlsl_intrinsics.h

Removed: 




diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 1a34e1626e5a60..6f1aa5f26294ef 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -476,5 +476,61 @@ double3 min(double3, double3);
 __attribute__((clang_builtin_alias(__builtin_elementwise_min)))
 double4 min(double4, double4);
 
+// reversebits builtins
+#ifdef __HLSL_ENABLE_16_BIT
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
+int16_t reversebits(int16_t);
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
+int16_t2 reversebits(int16_t2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
+int16_t3 reversebits(int16_t3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
+int16_t4 reversebits(int16_t4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
+uint16_t reversebits(uint16_t);
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
+uint16_t2 reversebits(uint16_t2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
+uint16_t3 reversebits(uint16_t3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
+uint16_t4 reversebits(uint16_t4);
+#endif
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) int
+reversebits(int);
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
+int2 reversebits(int2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
+int3 reversebits(int3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
+int4 reversebits(int4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
+uint reversebits(uint);
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
+uint2 reversebits(uint2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
+uint3 reversebits(uint3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
+uint4 reversebits(uint4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
+int64_t reversebits(int64_t);
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
+int64_t2 reversebits(int64_t2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
+int64_t3 reversebits(int64_t3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
+int64_t4 reversebits(int64_t4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
+uint64_t reversebits(uint64_t);
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
+uint64_t2 reversebits(uint64_t2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
+uint64_t3 reversebits(uint64_t3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
+uint64_t4 reversebits(uint64_t4);
 } // namespace hlsl
 #endif //_HLSL_HLSL_INTRINSICS_H_

diff  --git a/clang/test/CodeGenHLSL/builtins/bitreverse.hlsl 
b/clang/test/CodeGenHLSL/builtins/bitreverse.hlsl
new file mode 100644
index 00..e7609a2b61e259
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/bitreverse.hlsl
@@ -0,0 +1,155 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -D__HLSL_ENABLE_16_BIT \
+// RUN:   -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s
+
+#ifdef __HLSL_ENABLE_16_BIT
+// CHECK: define noundef i16 @
+// CHECK: call i16 @llvm.bitreverse.i16(
+int16_t test_bitreverse_short(int16_t p0)
+{
+   return reversebits(p0);
+}
+// CHECK: define noundef <2 x i16> @
+// CHECK: call <2 x i16> @llvm.bitreverse.v2i16(
+int16_t2 test_bitreverse_short2(int16_t2 p0)
+{
+   return reversebits(p0);
+}
+// CHECK: define noundef <3 x i16> @
+// CHECK: call <3 x i16> @llvm.bitreverse.v3i16
+int16_t3 test_bitreverse_short3(int16_t3 p0)
+{
+   return reversebi

[clang] df5137e - [HLSL] add pow library function

2023-08-08 Thread Joshua Batista via cfe-commits

Author: Joshua Batista
Date: 2023-08-08T13:07:36-07:00
New Revision: df5137e984a607248cd31ed67aa3822e8ac2a083

URL: 
https://github.com/llvm/llvm-project/commit/df5137e984a607248cd31ed67aa3822e8ac2a083
DIFF: 
https://github.com/llvm/llvm-project/commit/df5137e984a607248cd31ed67aa3822e8ac2a083.diff

LOG: [HLSL] add pow library function

This change exposes the pow library function for HLSL, only available for 
floating point types.
The pow function is supported for all scalar, vector, and matrix types that 
contain floating point types.

The full documentation of the HLSL pow function is available here:
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-pow

Reviewed By: bogner

Differential Revision: https://reviews.llvm.org/D156178

Added: 
clang/test/CodeGenHLSL/builtins/pow.hlsl

Modified: 
clang/lib/Headers/hlsl/hlsl_intrinsics.h

Removed: 




diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 6f1aa5f26294ef..22d9ec24e6a210 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -532,5 +532,36 @@ 
__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
 uint64_t3 reversebits(uint64_t3);
 __attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse)))
 uint64_t4 reversebits(uint64_t4);
+
+// pow builtins
+#ifdef __HLSL_ENABLE_16_BIT
+__attribute__((clang_builtin_alias(__builtin_elementwise_pow)))
+half pow(half, half);
+__attribute__((clang_builtin_alias(__builtin_elementwise_pow)))
+half2 pow(half2, half2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_pow)))
+half3 pow(half3, half3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_pow)))
+half4 pow(half4, half4);
+#endif
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_pow))) float
+pow(float, float);
+__attribute__((clang_builtin_alias(__builtin_elementwise_pow)))
+float2 pow(float2, float2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_pow)))
+float3 pow(float3, float3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_pow)))
+float4 pow(float4, float4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_pow))) double
+pow(double, double);
+__attribute__((clang_builtin_alias(__builtin_elementwise_pow)))
+double2 pow(double2, double2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_pow)))
+double3 pow(double3, double3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_pow)))
+double4 pow(double4, double4);
+
 } // namespace hlsl
 #endif //_HLSL_HLSL_INTRINSICS_H_

diff  --git a/clang/test/CodeGenHLSL/builtins/pow.hlsl 
b/clang/test/CodeGenHLSL/builtins/pow.hlsl
new file mode 100644
index 00..bb186f75d86ac3
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/pow.hlsl
@@ -0,0 +1,89 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF
+
+// CHECK: define noundef half @
+// CHECK: call half @llvm.pow.f16(
+// NO_HALF: define noundef float @"?test_pow_half@@YA$halff@$halff@0@Z"(
+// NO_HALF: call float @llvm.pow.f32(
+half test_pow_half(half p0, half p1)
+{
+return pow(p0, p1);
+}
+// CHECK: define noundef <2 x half> 
@"?test_pow_half2@@YAT?$__vector@$f16@$01@__clang@@T12@0@Z"(
+// CHECK: call <2 x half> @llvm.pow.v2f16
+// NO_HALF: define noundef <2 x float> 
@"?test_pow_float2@@YAT?$__vector@M$01@__clang@@T12@0@Z"(
+// NO_HALF: call <2 x float> @llvm.pow.v2f32(
+half2 test_pow_half2(half2 p0, half2 p1)
+{
+return pow(p0, p1);
+}
+// CHECK: define noundef <3 x half> 
@"?test_pow_half3@@YAT?$__vector@$f16@$02@__clang@@T12@0@Z"(
+// CHECK: call <3 x half> @llvm.pow.v3f16
+// NO_HALF: define noundef <3 x float> 
@"?test_pow_float3@@YAT?$__vector@M$02@__clang@@T12@0@Z"(
+// NO_HALF: call <3 x float> @llvm.pow.v3f32(
+half3 test_pow_half3(half3 p0, half3 p1)
+{
+return pow(p0, p1);
+}
+// CHECK: define noundef <4 x half> 
@"?test_pow_half4@@YAT?$__vector@$f16@$03@__clang@@T12@0@Z"(
+// CHECK: call <4 x half> @llvm.pow.v4f16
+// NO_HALF: define noundef <4 x float> 
@"?test_pow_float4@@YAT?$__vector@M$03@__clang@@T12@0@Z"(
+// NO_HALF: call <4 x float> @llvm.pow.v4f32(
+half4 test_pow_half4(half4 p0, half4 p1)
+{
+return pow(p0, p1);
+}
+
+// CHECK: define noundef float @"?test_pow_float@@YAMMM@Z"(
+// CHECK: call float @llvm.pow.f32(
+float test_pow_float(float p0, float p1)
+{
+return pow(p0, p1);
+}
+// CHECK: define noundef <2 x float> 
@"?test_pow_float2@@YAT?$__vector@M$01@__clang@@T12@0@Z"(
+// CHECK: call <2 x flo

[clang] 7ac0551 - [HLSL] add max/min library functions

2023-03-03 Thread Joshua Batista via cfe-commits

Author: Joshua Batista
Date: 2023-03-03T09:31:50-08:00
New Revision: 7ac0551e77f4adab18f3ac6ae428d4c09f9b6c49

URL: 
https://github.com/llvm/llvm-project/commit/7ac0551e77f4adab18f3ac6ae428d4c09f9b6c49
DIFF: 
https://github.com/llvm/llvm-project/commit/7ac0551e77f4adab18f3ac6ae428d4c09f9b6c49.diff

LOG: [HLSL] add max/min library functions

This change exposes the max and min library functions for HLSL, excluding long, 
and long long doubles.
The max / min functions are supported for all scalar, vector, and matrix types.
Long and long long double support is missing in this patch because those types
don't exist in HLSL.

The full documentation of the HLSL max / min functions are available here:
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-max
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-min

Reviewed By: python3kgae

Differential Revision: https://reviews.llvm.org/D144309

Added: 
clang/test/CodeGenHLSL/builtins/max.hlsl
clang/test/CodeGenHLSL/builtins/min.hlsl

Modified: 
clang/lib/Headers/hlsl/hlsl_intrinsics.h

Removed: 




diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 570552367215b..1a34e1626e5a6 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -308,5 +308,173 @@ double3 log10(double3);
 __attribute__((clang_builtin_alias(__builtin_elementwise_log10)))
 double4 log10(double4);
 
+// max builtins
+#ifdef __HLSL_ENABLE_16_BIT
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+half max(half, half);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+half2 max(half2, half2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+half3 max(half3, half3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+half4 max(half4, half4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+int16_t max(int16_t, int16_t);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+int16_t2 max(int16_t2, int16_t2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+int16_t3 max(int16_t3, int16_t3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+int16_t4 max(int16_t4, int16_t4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint16_t max(uint16_t, uint16_t);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint16_t2 max(uint16_t2, uint16_t2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint16_t3 max(uint16_t3, uint16_t3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint16_t4 max(uint16_t4, uint16_t4);
+#endif
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_max))) int max(int,
+int);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+int2 max(int2, int2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+int3 max(int3, int3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+int4 max(int4, int4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint max(uint, uint);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint2 max(uint2, uint2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint3 max(uint3, uint3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint4 max(uint4, uint4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+int64_t max(int64_t, int64_t);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+int64_t2 max(int64_t2, int64_t2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+int64_t3 max(int64_t3, int64_t3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+int64_t4 max(int64_t4, int64_t4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint64_t max(uint64_t, uint64_t);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint64_t2 max(uint64_t2, uint64_t2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint64_t3 max(uint64_t3, uint64_t3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+uint64_t4 max(uint64_t4, uint64_t4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_max))) float
+max(float, float);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+float2 max(float2, float2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+float3 max(float3, float3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+float4 max(float4, float4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_max))) double
+max(double, double);
+__attribute__((clang_builtin_alias(__builtin_elementwise_max)))
+double2 max(double2, double2);
+__attribute__((clang_builtin_a

[clang] 4c82050 - Add codegen for llvm exp/exp2 elementwise builtins

2023-03-09 Thread Joshua Batista via cfe-commits

Author: Joshua Batista
Date: 2023-03-09T12:14:59-08:00
New Revision: 4c82050c56926d840e4ccf253ad10e6ae3ee6cc7

URL: 
https://github.com/llvm/llvm-project/commit/4c82050c56926d840e4ccf253ad10e6ae3ee6cc7
DIFF: 
https://github.com/llvm/llvm-project/commit/4c82050c56926d840e4ccf253ad10e6ae3ee6cc7.diff

LOG: Add codegen for llvm exp/exp2 elementwise builtins

Add codegen for llvm exp/exp2 elementwise builtin
The exp/exp2 elementwise builtins are necessary for HLSL codegen.
Tests were added to make sure that the expected errors are encountered when 
these functions are given inputs of incompatible types.
The new builtins are restricted to floating point types only.

Reviewed By: fhahn

Differential Revision: https://reviews.llvm.org/D145270

Added: 
clang/test/Sema/aarch64-sve-vector-exp-ops.c
clang/test/Sema/riscv-sve-vector-exp-ops.c

Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Builtins.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/builtins-elementwise-math.c
clang/test/Sema/builtins-elementwise-math.c
clang/test/SemaCXX/builtins-elementwise-math.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index c0ea8afad6cb2..413ad8de3215c 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -639,6 +639,8 @@ Unless specified otherwise operation(±0) = ±0 and 
operation(±infinity) = ±in
  T __builtin_elementwise_log(T x)return the natural logarithm of x 
   floating point types
  T __builtin_elementwise_log2(T x)   return the base 2 logarithm of x  
   floating point types
  T __builtin_elementwise_log10(T x)  return the base 10 logarithm of x 
   floating point types
+ T __builtin_elementwise_exp(T x)returns the base-e exponential, 
e^x, of the specified value  floating point types
+ T __builtin_elementwise_exp2(T x)   returns the base-2 exponential, 
2^x, of the specified value  floating point types
  T __builtin_elementwise_roundeven(T x)  round x to the nearest integer 
value in floating point format,   floating point types
  rounding halfway cases to even 
(that is, to the nearest value
  that is an even integer), 
regardless of the current rounding

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 59c8c5c799f1a..332431e08ce07 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -270,6 +270,8 @@ Floating Point Support in Clang
 - Add ``__builtin_elementwise_log`` builtin for floating point types only.
 - Add ``__builtin_elementwise_log10`` builtin for floating point types only.
 - Add ``__builtin_elementwise_log2`` builtin for floating point types only.
+- Add ``__builtin_elementwise_exp`` builtin for floating point types only.
+- Add ``__builtin_elementwise_exp2`` builtin for floating point types only.
 
 AST Matchers
 

diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 478eb59bb7712..814461636729e 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -667,6 +667,8 @@ BUILTIN(__builtin_elementwise_max, "v.", "nct")
 BUILTIN(__builtin_elementwise_min, "v.", "nct")
 BUILTIN(__builtin_elementwise_ceil, "v.", "nct")
 BUILTIN(__builtin_elementwise_cos, "v.", "nct")
+BUILTIN(__builtin_elementwise_exp, "v.", "nct")
+BUILTIN(__builtin_elementwise_exp2, "v.", "nct")
 BUILTIN(__builtin_elementwise_floor, "v.", "nct")
 BUILTIN(__builtin_elementwise_log, "v.", "nct")
 BUILTIN(__builtin_elementwise_log2, "v.", "nct")

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index cea4727422c0b..e4d65fe2d806c 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3100,6 +3100,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   case Builtin::BI__builtin_elementwise_ceil:
 return RValue::get(
 emitUnaryBuiltin(*this, E, llvm::Intrinsic::ceil, "elt.ceil"));
+  case Builtin::BI__builtin_elementwise_exp:
+return RValue::get(
+emitUnaryBuiltin(*this, E, llvm::Intrinsic::exp, "elt.exp"));
+  case Builtin::BI__builtin_elementwise_exp2:
+return RValue::get(
+emitUnaryBuiltin(*this, E, llvm::Intrinsic::exp2, "elt.exp2"));
   case Builtin::BI__builtin_elementwise_log:
 return RValue::get(
 emitUnaryBuiltin(*this, E, llvm::Intrinsic::log, "elt.log"));

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 485351f157fde..01f73f6aeb470 100644
--- a/clang/lib/Sema/SemaChecking.cpp

[clang] 836249b - Add codegen for llvm log2/log10 elementwise builtins

2023-02-07 Thread Joshua Batista via cfe-commits

Author: Joshua Batista
Date: 2023-02-07T12:23:48-08:00
New Revision: 836249b1c2f0540ed0c886d6c3558b2f4f179249

URL: 
https://github.com/llvm/llvm-project/commit/836249b1c2f0540ed0c886d6c3558b2f4f179249
DIFF: 
https://github.com/llvm/llvm-project/commit/836249b1c2f0540ed0c886d6c3558b2f4f179249.diff

LOG: Add codegen for llvm log2/log10 elementwise builtins

Add codegen for llvm log2 / log10 elementwise builtin
The log2/log10 elementwise builtin is necessary for HLSL codegen.
Tests were added to make sure that the expected errors are encountered when 
these functions are given inputs of incompatible types.
The new builtins are restricted to floating point types only.

Reviewed By: fhahn

Differential Revision: https://reviews.llvm.org/D143207

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Builtins.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/builtins-elementwise-math.c
clang/test/Sema/aarch64-sve-vector-log-ops.c
clang/test/Sema/builtins-elementwise-math.c
clang/test/Sema/riscv-sve-vector-log-ops.c
clang/test/SemaCXX/builtins-elementwise-math.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 9d5a4d78e8040..84d5b0ed98108 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -636,6 +636,8 @@ Unless specified otherwise operation(±0) = ±0 and 
operation(±infinity) = ±in
  T __builtin_elementwise_cos(T x)return the cosine of x 
interpreted as an angle in radiansfloating point types
  T __builtin_elementwise_floor(T x)  return the largest integral value 
less than or equal to xfloating point types
  T __builtin_elementwise_log(T x)return the natural logarithm of x 
   floating point types
+ T __builtin_elementwise_log2(T x)   return the base 2 logarithm of x  
   floating point types
+ T __builtin_elementwise_log10(T x)  return the base 10 logarithm of x 
   floating point types
  T __builtin_elementwise_roundeven(T x)  round x to the nearest integer 
value in floating point format,   floating point types
  rounding halfway cases to even 
(that is, to the nearest value
  that is an even integer), 
regardless of the current rounding

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 50c647a4faaf7..35c3fa5780368 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -184,6 +184,8 @@ Arm and AArch64 Support in Clang
 Floating Point Support in Clang
 ---
 - Add ``__builtin_elementwise_log`` builtin for floating point types only.
+- Add ``__builtin_elementwise_log10`` builtin for floating point types only.
+- Add ``__builtin_elementwise_log2`` builtin for floating point types only.
 
 Internal API Changes
 

diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 2d25a030fd682..41288410786b0 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -664,6 +664,8 @@ BUILTIN(__builtin_elementwise_ceil, "v.", "nct")
 BUILTIN(__builtin_elementwise_cos, "v.", "nct")
 BUILTIN(__builtin_elementwise_floor, "v.", "nct")
 BUILTIN(__builtin_elementwise_log, "v.", "nct")
+BUILTIN(__builtin_elementwise_log2, "v.", "nct")
+BUILTIN(__builtin_elementwise_log10, "v.", "nct")
 BUILTIN(__builtin_elementwise_roundeven, "v.", "nct")
 BUILTIN(__builtin_elementwise_sin, "v.", "nct")
 BUILTIN(__builtin_elementwise_trunc, "v.", "nct")

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 53dde119abce1..fbb3ffc6f080b 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3091,6 +3091,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   case Builtin::BI__builtin_elementwise_log:
 return RValue::get(
 emitUnaryBuiltin(*this, E, llvm::Intrinsic::log, "elt.log"));
+  case Builtin::BI__builtin_elementwise_log2:
+return RValue::get(
+emitUnaryBuiltin(*this, E, llvm::Intrinsic::log2, "elt.log2"));
+  case Builtin::BI__builtin_elementwise_log10:
+return RValue::get(
+emitUnaryBuiltin(*this, E, llvm::Intrinsic::log10, "elt.log10"));
   case Builtin::BI__builtin_elementwise_cos:
 return RValue::get(
 emitUnaryBuiltin(*this, E, llvm::Intrinsic::cos, "elt.cos"));

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index a57c7f0c94780..9fdfac652448f 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2613

[clang] f842b7a - [HLSL] add log library functions

2023-02-16 Thread Joshua Batista via cfe-commits

Author: Joshua Batista
Date: 2023-02-16T09:50:12-08:00
New Revision: f842b7a6b8f40d817d6d43143e09521bd586a756

URL: 
https://github.com/llvm/llvm-project/commit/f842b7a6b8f40d817d6d43143e09521bd586a756
DIFF: 
https://github.com/llvm/llvm-project/commit/f842b7a6b8f40d817d6d43143e09521bd586a756.diff

LOG: [HLSL] add log library functions

This change exposes the log library functions for HLSL,excluding long, int, and 
long long doubles. The log functions are supported for all scalar, vector, and 
matrix types.
Long and long long double support is missing in this patch because those types
don't exist in HLSL. Int is missing because the log functions only work on 
floating type arguments.

The full documentation of the HLSL log functions are available here:
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-log
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-log2
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-log10

Reviewed By: python3kgae

Differential Revision: https://reviews.llvm.org/D144120

Added: 
clang/test/CodeGenHLSL/builtins/log.hlsl
clang/test/CodeGenHLSL/builtins/log10.hlsl
clang/test/CodeGenHLSL/builtins/log2.hlsl

Modified: 
clang/lib/Headers/hlsl/hlsl_intrinsics.h

Removed: 




diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index d811a28a43350..570552367215b 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -219,5 +219,94 @@ double3 trunc(double3);
 __attribute__((clang_builtin_alias(__builtin_elementwise_trunc)))
 double4 trunc(double4);
 
+// log builtins
+#ifdef __HLSL_ENABLE_16_BIT
+__attribute__((clang_builtin_alias(__builtin_elementwise_log))) half log(half);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log)))
+half2 log(half2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log)))
+half3 log(half3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log)))
+half4 log(half4);
+#endif
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_log))) float
+log(float);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log)))
+float2 log(float2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log)))
+float3 log(float3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log)))
+float4 log(float4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_log))) double
+log(double);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log)))
+double2 log(double2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log)))
+double3 log(double3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log)))
+double4 log(double4);
+
+// log2 builtins
+#ifdef __HLSL_ENABLE_16_BIT
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2)))
+half log2(half);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2)))
+half2 log2(half2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2)))
+half3 log2(half3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2)))
+half4 log2(half4);
+#endif
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2))) float
+log2(float);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2)))
+float2 log2(float2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2)))
+float3 log2(float3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2)))
+float4 log2(float4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2))) double
+log2(double);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2)))
+double2 log2(double2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2)))
+double3 log2(double3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log2)))
+double4 log2(double4);
+
+// log10 builtins
+#ifdef __HLSL_ENABLE_16_BIT
+__attribute__((clang_builtin_alias(__builtin_elementwise_log10)))
+half log10(half);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log10)))
+half2 log10(half2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log10)))
+half3 log10(half3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log10)))
+half4 log10(half4);
+#endif
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_log10))) float
+log10(float);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log10)))
+float2 log10(float2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log10)))
+float3 log10(float3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log10)))
+float4 log10(float4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_log10))) double
+log10(double);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log10)))
+double2 log10(double2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_log10)))
+double3 log10(

[clang] 500e729 - add floor library function

2022-12-08 Thread Joshua Batista via cfe-commits

Author: Joshua Batista
Date: 2022-12-08T15:41:54-08:00
New Revision: 500e72924305c4a1fac2ffd45b16114d49c3a7d2

URL: 
https://github.com/llvm/llvm-project/commit/500e72924305c4a1fac2ffd45b16114d49c3a7d2
DIFF: 
https://github.com/llvm/llvm-project/commit/500e72924305c4a1fac2ffd45b16114d49c3a7d2.diff

LOG: add floor library function

This change exposes the floor library function for HLSL,
excluding long, int, and long long doubles.
Floor is supported for all scalar, vector, and matrix types.

Long and long long double support is missing in this patch because those types
don't exist in HLSL. Int is missing because the floor function only works on 
floating type arguments.

The full documentation of the HLSL floor function is available here:
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-floor

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D139137

Added: 
clang/test/CodeGenHLSL/builtins/floor.hlsl

Modified: 
clang/lib/Headers/hlsl/hlsl_intrinsics.h

Removed: 




diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 35891d80d5953..e5a6869e625ab 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -101,6 +101,36 @@ double3 ceil(double3);
 __attribute__((clang_builtin_alias(__builtin_elementwise_ceil)))
 double4 ceil(double4);
 
+// floor builtins
+#ifdef __HLSL_ENABLE_16_BIT
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
+half floor(half);
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
+half2 floor(half2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
+half3 floor(half3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
+half4 floor(half4);
+#endif
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor))) float
+floor(float);
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
+float2 floor(float2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
+float3 floor(float3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
+float4 floor(float4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor))) double
+floor(double);
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
+double2 floor(double2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
+double3 floor(double3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
+double4 floor(double4);
+
 // cos builtins
 #ifdef __HLSL_ENABLE_16_BIT
 __attribute__((clang_builtin_alias(__builtin_elementwise_cos))) half cos(half);

diff  --git a/clang/test/CodeGenHLSL/builtins/floor.hlsl 
b/clang/test/CodeGenHLSL/builtins/floor.hlsl
new file mode 100644
index 0..38834a146206f
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/floor.hlsl
@@ -0,0 +1,79 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF
+
+using hlsl::floor;
+
+// CHECK: define noundef half @
+// CHECK: call half @llvm.floor.f16(
+// NO_HALF: define noundef float @"?test_floor_half@@YA$halff@$halff@@Z"(
+// NO_HALF: call float @llvm.floor.f32(float %0)
+half test_floor_half ( half p0 ) {
+  return floor ( p0 );
+}
+// CHECK: define noundef <2 x half> @
+// CHECK: call <2 x half> @llvm.floor.v2f16(
+// NO_HALF: define noundef <2 x float> 
@"?test_floor_half2@@YAT?$__vector@$halff@$01@__clang@@T12@@Z"(
+// NO_HALF: call <2 x float> @llvm.floor.v2f32(
+half2 test_floor_half2 ( half2 p0 ) {
+  return floor ( p0 );
+}
+// CHECK: define noundef <3 x half> @
+// CHECK: call <3 x half> @llvm.floor.v3f16(
+// NO_HALF: define noundef <3 x float> 
@"?test_floor_half3@@YAT?$__vector@$halff@$02@__clang@@T12@@Z"(
+// NO_HALF: call <3 x float> @llvm.floor.v3f32(
+half3 test_floor_half3 ( half3 p0 ) {
+  return floor ( p0 );
+}
+// CHECK: define noundef <4 x half> @
+// CHECK: call <4 x half> @llvm.floor.v4f16(
+// NO_HALF: define noundef <4 x float> 
@"?test_floor_half4@@YAT?$__vector@$halff@$03@__clang@@T12@@Z"(
+// NO_HALF: call <4 x float> @llvm.floor.v4f32(
+half4 test_floor_half4 ( half4 p0 ) {
+  return floor ( p0 );
+}
+
+// CHECK: define noundef float @
+// CHECK: call float @llvm.floor.f32(
+float test_floor_float ( float p0 ) {
+  return floor ( p0 );
+}
+// CHECK: define noundef <2 x float> @
+// CHECK: call <2 x float> @llvm.floor.v2f32(
+float2 test_floor_float2 ( float2 p0 ) {
+  return floor ( p0 );
+}
+// CHECK: define noundef <3 x float> @
+// CHECK: call <3 x float

[clang] 6fbcb3f - [HLSL] Add trunc library function

2022-12-14 Thread Joshua Batista via cfe-commits

Author: Joshua Batista
Date: 2022-12-14T12:54:05-08:00
New Revision: 6fbcb3f4baa86e04c67cb0646312a648334700cb

URL: 
https://github.com/llvm/llvm-project/commit/6fbcb3f4baa86e04c67cb0646312a648334700cb
DIFF: 
https://github.com/llvm/llvm-project/commit/6fbcb3f4baa86e04c67cb0646312a648334700cb.diff

LOG: [HLSL] Add trunc library function

Reviewed By: python3kgae

Differential Revision: https://reviews.llvm.org/D139742

Added: 
clang/test/CodeGenHLSL/builtins/trunc.hlsl

Modified: 
clang/lib/Headers/hlsl/hlsl_intrinsics.h

Removed: 




diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index e5a6869e625ab..d811a28a43350 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -189,5 +189,35 @@ double3 sin(double3);
 __attribute__((clang_builtin_alias(__builtin_elementwise_sin)))
 double4 sin(double4);
 
+// trunc builtins
+#ifdef __HLSL_ENABLE_16_BIT
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc)))
+half trunc(half);
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc)))
+half2 trunc(half2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc)))
+half3 trunc(half3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc)))
+half4 trunc(half4);
+#endif
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc))) float
+trunc(float);
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc)))
+float2 trunc(float2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc)))
+float3 trunc(float3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc)))
+float4 trunc(float4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc))) double
+trunc(double);
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc)))
+double2 trunc(double2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc)))
+double3 trunc(double3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_trunc)))
+double4 trunc(double4);
+
 } // namespace hlsl
 #endif //_HLSL_HLSL_INTRINSICS_H_

diff  --git a/clang/test/CodeGenHLSL/builtins/trunc.hlsl 
b/clang/test/CodeGenHLSL/builtins/trunc.hlsl
new file mode 100644
index 0..9166c1e394124
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/trunc.hlsl
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF
+
+// CHECK: define noundef half @
+// CHECK: call half @llvm.trunc.f16(
+// NO_HALF: define noundef float @"?test_trunc_half@@YA$halff@$halff@@Z"(
+// NO_HALF: call float @llvm.trunc.f32(
+half test_trunc_half ( half p0 ) {
+  return trunc ( p0 );
+}
+// CHECK: define noundef <2 x half> @
+// CHECK: call <2 x half> @llvm.trunc.v2f16
+// NO_HALF: define noundef <2 x float> 
@"?test_trunc_float2@@YAT?$__vector@M$01@__clang@@T12@@Z"(
+// NO_HALF: call <2 x float> @llvm.trunc.v2f32(
+half2 test_trunc_half2 ( half2 p0 ) {
+  return trunc ( p0 );
+}
+// CHECK: define noundef <3 x half> @
+// CHECK: call <3 x half> @llvm.trunc.v3f16
+// NO_HALF: define noundef <3 x float> 
@"?test_trunc_float3@@YAT?$__vector@M$02@__clang@@T12@@Z"(
+// NO_HALF: call <3 x float> @llvm.trunc.v3f32(
+half3 test_trunc_half3 ( half3 p0 ) {
+  return trunc ( p0 );
+}
+// CHECK: define noundef <4 x half> @
+// CHECK: call <4 x half> @llvm.trunc.v4f16
+// NO_HALF: define noundef <4 x float> 
@"?test_trunc_float4@@YAT?$__vector@M$03@__clang@@T12@@Z"(
+// NO_HALF: call <4 x float> @llvm.trunc.v4f32(
+half4 test_trunc_half4 ( half4 p0 ) {
+  return trunc ( p0 );
+}
+
+// CHECK: define noundef float @
+// CHECK: call float @llvm.trunc.f32(
+float test_trunc_float ( float p0 ) {
+  return trunc ( p0 );
+}
+// CHECK: define noundef <2 x float> @
+// CHECK: call <2 x float> @llvm.trunc.v2f32
+float2 test_trunc_float2 ( float2 p0 ) {
+  return trunc ( p0 );
+}
+// CHECK: define noundef <3 x float> @
+// CHECK: call <3 x float> @llvm.trunc.v3f32
+float3 test_trunc_float3 ( float3 p0 ) {
+  return trunc ( p0 );
+}
+// CHECK: define noundef <4 x float> @
+// CHECK: call <4 x float> @llvm.trunc.v4f32
+float4 test_trunc_float4 ( float4 p0 ) {
+  return trunc ( p0 );
+}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Expose `half` types and intrinsics always (PR #81782)

2024-02-14 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 approved this pull request.


https://github.com/llvm/llvm-project/pull/81782
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Implement resource binding type prefix mismatch flag setting logic (PR #97103)

2024-07-01 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/97103

>From c784272b3f66ca06be4ab8e72a0963e5ebb6a869 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Fri, 28 Jun 2024 12:40:56 -0700
Subject: [PATCH 1/4] update tests, update code

---
 clang/include/clang/Basic/Attr.td |   2 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Sema/SemaHLSL.h   |   2 +
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  26 +-
 clang/lib/Sema/SemaHLSL.cpp   | 232 +-
 .../ast-dump-comment-cbuffe-tbufferr.hlsl |   2 +
 clang/test/AST/HLSL/cbuffer_tbuffer.hlsl  |   6 +-
 clang/test/AST/HLSL/packoffset.hlsl   |   1 +
 clang/test/AST/HLSL/pch_hlsl_buffer.hlsl  |   2 +
 .../test/AST/HLSL/resource_binding_attr.hlsl  |   6 +-
 .../SemaHLSL/resource_binding_attr_error.hlsl |  21 +-
 .../resource_binding_attr_error_mismatch.hlsl |  74 ++
 12 files changed, 346 insertions(+), 33 deletions(-)
 create mode 100644 
clang/test/SemaHLSL/resource_binding_attr_error_mismatch.hlsl

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 452cd1810f653..c3d67e19656da 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4467,7 +4467,7 @@ def HLSLSV_GroupIndex: HLSLAnnotationAttr {
 
 def HLSLResourceBinding: InheritableAttr {
   let Spellings = [HLSLAnnotation<"register">];
-  let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar]>;
+  let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar], ErrorDiag>;
   let LangOpts = [HLSL];
   let Args = [StringArgument<"Slot">, StringArgument<"Space", 1>];
   let Documentation = [HLSLResourceBindingDocs];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 96f0c0f0205c2..3bf15ff5f2657 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12303,7 +12303,10 @@ def err_hlsl_missing_semantic_annotation : Error<
 def err_hlsl_init_priority_unsupported : Error<
   "initializer priorities are not supported in HLSL">;
 
-def err_hlsl_unsupported_register_type : Error<"invalid resource class 
specifier '%0' used; expected 'b', 's', 't', or 'u'">;
+def err_hlsl_mismatching_register_resource_type_and_name: Error<"invalid 
register name prefix '%0' for register resource type '%1' (expected 
%select{'t'|'u'|'b'|'s'}2)">;
+def err_hlsl_mismatching_register_builtin_type_and_name: Error<"invalid 
register name prefix '%0' for '%1' (expected %2)">;
+def err_hlsl_unsupported_register_prefix : Error<"invalid resource class 
specifier '%0' used; expected 't', 'u', 'b', or 's'">;
+def err_hlsl_unsupported_register_resource_type : Error<"invalid resource '%0' 
used">;
 def err_hlsl_unsupported_register_number : Error<"register number should be an 
integer">;
 def err_hlsl_expected_space : Error<"invalid space specifier '%0' used; 
expected 'space' followed by an integer, like space1">;
 def warn_hlsl_packoffset_mix : Warning<"cannot mix packoffset elements with 
nonpackoffset elements in a cbuffer">,
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index 4d6958a1be3e5..d3d36d04d1019 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -22,6 +22,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/SemaBase.h"
+#include "clang/Sema/Sema.h"
 #include 
 
 namespace clang {
@@ -31,6 +32,7 @@ class SemaHLSL : public SemaBase {
 public:
   SemaHLSL(Sema &S);
 
+  HLSLResourceAttr *mergeHLSLResourceAttr(bool CBuffer);
   Decl *ActOnStartBuffer(Scope *BufferScope, bool CBuffer, SourceLocation 
KwLoc,
  IdentifierInfo *Ident, SourceLocation IdentLoc,
  SourceLocation LBrace);
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index a2b29a7bdf505..b82cd8373403a 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -490,23 +490,24 @@ void HLSLExternalSemaSource::defineTrivialHLSLTypes() {
 }
 
 /// Set up common members and attributes for buffer types
-static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S,
-  ResourceClass RC, ResourceKind 
RK,
-  bool IsROV) {
+static BuiltinTypeDeclBuilder setupBufferHandle(CXXRecordDecl *Decl, Sema &S,
+ResourceClass RC) {
   return BuiltinTypeDeclBuilder(Decl)
   .addHandleMember()
-  .addDefaultHandleConstructor(S, RC)
-  .annotateResourceClass(RC, RK, IsROV);
+  .addDefaultHandleConstructor(S, RC);
 }
 
 void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
   CXXRecordDecl *Decl;
-  Decl = Bu

[clang] Implement resource binding type prefix mismatch flag setting logic (PR #97103)

2024-07-01 Thread Joshua Batista via cfe-commits


@@ -21,6 +21,7 @@
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Sema/Scope.h"
+#include "clang/Sema/Sema.h"

bob80905 wrote:

Yes, done

https://github.com/llvm/llvm-project/pull/97103
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Implement resource binding type prefix mismatch flag setting logic (PR #97103)

2024-07-01 Thread Joshua Batista via cfe-commits


@@ -437,7 +460,206 @@ void SemaHLSL::handleShaderAttr(Decl *D, const ParsedAttr 
&AL) {
 D->addAttr(NewAttr);
 }
 
+struct register_binding_flags {
+  bool resource = false;
+  bool udt = false;
+  bool other = false;
+  bool basic = false;
+
+  bool srv = false;
+  bool uav = false;
+  bool cbv = false;
+  bool sampler = false;
+
+  bool contains_numeric = false;
+  bool default_globals = false;
+};
+
+bool isDeclaredWithinCOrTBuffer(const Decl *decl) {
+  if (!decl)
+return false;
+
+  // Traverse up the parent contexts
+  const DeclContext *context = decl->getDeclContext();
+  while (context) {
+if (isa(context)) {
+  return true;
+}
+context = context->getParent();
+  }
+
+  return false;
+}
+
+const HLSLResourceAttr *
+getHLSLResourceAttrFromVarDecl(VarDecl *SamplerUAVOrSRV) {
+  const Type *Ty = SamplerUAVOrSRV->getType()->getPointeeOrArrayElementType();
+  if (!Ty)
+llvm_unreachable("Resource class must have an element type.");
+
+  if (const BuiltinType *BTy = dyn_cast(Ty)) {
+/* QualType QT = SamplerUAVOrSRV->getType();
+PrintingPolicy PP = S.getPrintingPolicy();
+std::string typestr = QualType::getAsString(QT.split(), PP);
+
+S.Diag(ArgLoc, diag::err_hlsl_unsupported_register_resource_type)
+<< typestr;
+return; */
+return nullptr;
+  }
+
+  const CXXRecordDecl *TheRecordDecl = Ty->getAsCXXRecordDecl();
+  if (!TheRecordDecl)
+llvm_unreachable("Resource class should have a resource type 
declaration.");
+
+  if (auto TDecl = dyn_cast(TheRecordDecl))
+TheRecordDecl = TDecl->getSpecializedTemplate()->getTemplatedDecl();
+  TheRecordDecl = TheRecordDecl->getCanonicalDecl();
+  const auto *Attr = TheRecordDecl->getAttr();
+  return Attr;
+}
+
+void traverseType(QualType T, register_binding_flags &r) {
+  if (T->isIntegralOrEnumerationType() || T->isFloatingType()) {
+r.contains_numeric = true;
+return;
+  } else if (const RecordType *RT = T->getAs()) {
+RecordDecl *SubRD = RT->getDecl();
+if (auto TDecl = dyn_cast(SubRD)) {
+  auto TheRecordDecl = TDecl->getSpecializedTemplate()->getTemplatedDecl();
+  TheRecordDecl = TheRecordDecl->getCanonicalDecl();
+  const auto *Attr = TheRecordDecl->getAttr();
+  llvm::hlsl::ResourceClass DeclResourceClass = Attr->getResourceClass();
+  switch (DeclResourceClass) {
+  case llvm::hlsl::ResourceClass::SRV: {
+r.srv = true;
+break;
+  }
+  case llvm::hlsl::ResourceClass::UAV: {
+r.uav = true;
+break;
+  }
+  case llvm::hlsl::ResourceClass::CBuffer: {
+r.cbv = true;
+break;
+  }
+  case llvm::hlsl::ResourceClass::Sampler: {
+r.sampler = true;
+break;
+  }
+  }
+}
+
+else if (SubRD->isCompleteDefinition()) {
+  for (auto Field : SubRD->fields()) {
+QualType T = Field->getType();
+traverseType(T, r);
+  }
+}
+  }
+}
+
+void setResourceClassFlagsFromRecordDecl(register_binding_flags &r,
+ const RecordDecl *RD) {
+  if (!RD)
+return;
+
+  if (RD->isCompleteDefinition()) {
+for (auto Field : RD->fields()) {
+  QualType T = Field->getType();

bob80905 wrote:

This behavior has been discussed by the team and described by the spec (which 
is in the description of the PR), and we've agreed this breaking change should 
only occur when the specified resource in the register annotation isn't found 
in the struct. If it is found in the struct, there shouldn't be any errors 
emitted, and that resource should be bound according to the register annotation.

https://github.com/llvm/llvm-project/pull/97103
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Implement resource binding type prefix mismatch flag setting logic (PR #97103)

2024-07-01 Thread Joshua Batista via cfe-commits


@@ -437,7 +460,206 @@ void SemaHLSL::handleShaderAttr(Decl *D, const ParsedAttr 
&AL) {
 D->addAttr(NewAttr);
 }
 
+struct register_binding_flags {
+  bool resource = false;
+  bool udt = false;
+  bool other = false;
+  bool basic = false;
+
+  bool srv = false;
+  bool uav = false;
+  bool cbv = false;
+  bool sampler = false;
+
+  bool contains_numeric = false;
+  bool default_globals = false;
+};
+
+bool isDeclaredWithinCOrTBuffer(const Decl *decl) {
+  if (!decl)
+return false;
+
+  // Traverse up the parent contexts
+  const DeclContext *context = decl->getDeclContext();
+  while (context) {
+if (isa(context)) {
+  return true;
+}
+context = context->getParent();
+  }
+
+  return false;
+}
+
+const HLSLResourceAttr *
+getHLSLResourceAttrFromVarDecl(VarDecl *SamplerUAVOrSRV) {
+  const Type *Ty = SamplerUAVOrSRV->getType()->getPointeeOrArrayElementType();
+  if (!Ty)
+llvm_unreachable("Resource class must have an element type.");
+
+  if (const BuiltinType *BTy = dyn_cast(Ty)) {
+/* QualType QT = SamplerUAVOrSRV->getType();
+PrintingPolicy PP = S.getPrintingPolicy();
+std::string typestr = QualType::getAsString(QT.split(), PP);
+
+S.Diag(ArgLoc, diag::err_hlsl_unsupported_register_resource_type)
+<< typestr;
+return; */
+return nullptr;
+  }
+
+  const CXXRecordDecl *TheRecordDecl = Ty->getAsCXXRecordDecl();
+  if (!TheRecordDecl)
+llvm_unreachable("Resource class should have a resource type 
declaration.");
+
+  if (auto TDecl = dyn_cast(TheRecordDecl))
+TheRecordDecl = TDecl->getSpecializedTemplate()->getTemplatedDecl();
+  TheRecordDecl = TheRecordDecl->getCanonicalDecl();
+  const auto *Attr = TheRecordDecl->getAttr();
+  return Attr;
+}
+
+void traverseType(QualType T, register_binding_flags &r) {
+  if (T->isIntegralOrEnumerationType() || T->isFloatingType()) {
+r.contains_numeric = true;
+return;
+  } else if (const RecordType *RT = T->getAs()) {
+RecordDecl *SubRD = RT->getDecl();
+if (auto TDecl = dyn_cast(SubRD)) {
+  auto TheRecordDecl = TDecl->getSpecializedTemplate()->getTemplatedDecl();
+  TheRecordDecl = TheRecordDecl->getCanonicalDecl();
+  const auto *Attr = TheRecordDecl->getAttr();
+  llvm::hlsl::ResourceClass DeclResourceClass = Attr->getResourceClass();
+  switch (DeclResourceClass) {
+  case llvm::hlsl::ResourceClass::SRV: {
+r.srv = true;
+break;
+  }
+  case llvm::hlsl::ResourceClass::UAV: {
+r.uav = true;
+break;
+  }
+  case llvm::hlsl::ResourceClass::CBuffer: {
+r.cbv = true;
+break;
+  }
+  case llvm::hlsl::ResourceClass::Sampler: {
+r.sampler = true;
+break;
+  }
+  }
+}
+
+else if (SubRD->isCompleteDefinition()) {
+  for (auto Field : SubRD->fields()) {
+QualType T = Field->getType();
+traverseType(T, r);
+  }
+}
+  }
+}
+
+void setResourceClassFlagsFromRecordDecl(register_binding_flags &r,
+ const RecordDecl *RD) {
+  if (!RD)
+return;
+
+  if (RD->isCompleteDefinition()) {
+for (auto Field : RD->fields()) {
+  QualType T = Field->getType();

bob80905 wrote:

Correct, the warning that would be emitted here, 
`warn_hlsl_UDT_missing_resource_type_member`, will not be treated as an error 
by default when the diagnostics implementation PR is created.

https://github.com/llvm/llvm-project/pull/97103
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Implement resource binding type prefix mismatch flag setting logic (PR #97103)

2024-07-02 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/97103

>From c784272b3f66ca06be4ab8e72a0963e5ebb6a869 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Fri, 28 Jun 2024 12:40:56 -0700
Subject: [PATCH 1/7] update tests, update code

---
 clang/include/clang/Basic/Attr.td |   2 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Sema/SemaHLSL.h   |   2 +
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  26 +-
 clang/lib/Sema/SemaHLSL.cpp   | 232 +-
 .../ast-dump-comment-cbuffe-tbufferr.hlsl |   2 +
 clang/test/AST/HLSL/cbuffer_tbuffer.hlsl  |   6 +-
 clang/test/AST/HLSL/packoffset.hlsl   |   1 +
 clang/test/AST/HLSL/pch_hlsl_buffer.hlsl  |   2 +
 .../test/AST/HLSL/resource_binding_attr.hlsl  |   6 +-
 .../SemaHLSL/resource_binding_attr_error.hlsl |  21 +-
 .../resource_binding_attr_error_mismatch.hlsl |  74 ++
 12 files changed, 346 insertions(+), 33 deletions(-)
 create mode 100644 
clang/test/SemaHLSL/resource_binding_attr_error_mismatch.hlsl

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 452cd1810f653..c3d67e19656da 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4467,7 +4467,7 @@ def HLSLSV_GroupIndex: HLSLAnnotationAttr {
 
 def HLSLResourceBinding: InheritableAttr {
   let Spellings = [HLSLAnnotation<"register">];
-  let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar]>;
+  let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar], ErrorDiag>;
   let LangOpts = [HLSL];
   let Args = [StringArgument<"Slot">, StringArgument<"Space", 1>];
   let Documentation = [HLSLResourceBindingDocs];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 96f0c0f0205c2..3bf15ff5f2657 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12303,7 +12303,10 @@ def err_hlsl_missing_semantic_annotation : Error<
 def err_hlsl_init_priority_unsupported : Error<
   "initializer priorities are not supported in HLSL">;
 
-def err_hlsl_unsupported_register_type : Error<"invalid resource class 
specifier '%0' used; expected 'b', 's', 't', or 'u'">;
+def err_hlsl_mismatching_register_resource_type_and_name: Error<"invalid 
register name prefix '%0' for register resource type '%1' (expected 
%select{'t'|'u'|'b'|'s'}2)">;
+def err_hlsl_mismatching_register_builtin_type_and_name: Error<"invalid 
register name prefix '%0' for '%1' (expected %2)">;
+def err_hlsl_unsupported_register_prefix : Error<"invalid resource class 
specifier '%0' used; expected 't', 'u', 'b', or 's'">;
+def err_hlsl_unsupported_register_resource_type : Error<"invalid resource '%0' 
used">;
 def err_hlsl_unsupported_register_number : Error<"register number should be an 
integer">;
 def err_hlsl_expected_space : Error<"invalid space specifier '%0' used; 
expected 'space' followed by an integer, like space1">;
 def warn_hlsl_packoffset_mix : Warning<"cannot mix packoffset elements with 
nonpackoffset elements in a cbuffer">,
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index 4d6958a1be3e5..d3d36d04d1019 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -22,6 +22,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/SemaBase.h"
+#include "clang/Sema/Sema.h"
 #include 
 
 namespace clang {
@@ -31,6 +32,7 @@ class SemaHLSL : public SemaBase {
 public:
   SemaHLSL(Sema &S);
 
+  HLSLResourceAttr *mergeHLSLResourceAttr(bool CBuffer);
   Decl *ActOnStartBuffer(Scope *BufferScope, bool CBuffer, SourceLocation 
KwLoc,
  IdentifierInfo *Ident, SourceLocation IdentLoc,
  SourceLocation LBrace);
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index a2b29a7bdf505..b82cd8373403a 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -490,23 +490,24 @@ void HLSLExternalSemaSource::defineTrivialHLSLTypes() {
 }
 
 /// Set up common members and attributes for buffer types
-static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S,
-  ResourceClass RC, ResourceKind 
RK,
-  bool IsROV) {
+static BuiltinTypeDeclBuilder setupBufferHandle(CXXRecordDecl *Decl, Sema &S,
+ResourceClass RC) {
   return BuiltinTypeDeclBuilder(Decl)
   .addHandleMember()
-  .addDefaultHandleConstructor(S, RC)
-  .annotateResourceClass(RC, RK, IsROV);
+  .addDefaultHandleConstructor(S, RC);
 }
 
 void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
   CXXRecordDecl *Decl;
-  Decl = Bu

[clang] Implement resource binding type prefix mismatch flag setting logic (PR #97103)

2024-07-02 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/97103

>From c784272b3f66ca06be4ab8e72a0963e5ebb6a869 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Fri, 28 Jun 2024 12:40:56 -0700
Subject: [PATCH 1/8] update tests, update code

---
 clang/include/clang/Basic/Attr.td |   2 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Sema/SemaHLSL.h   |   2 +
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  26 +-
 clang/lib/Sema/SemaHLSL.cpp   | 232 +-
 .../ast-dump-comment-cbuffe-tbufferr.hlsl |   2 +
 clang/test/AST/HLSL/cbuffer_tbuffer.hlsl  |   6 +-
 clang/test/AST/HLSL/packoffset.hlsl   |   1 +
 clang/test/AST/HLSL/pch_hlsl_buffer.hlsl  |   2 +
 .../test/AST/HLSL/resource_binding_attr.hlsl  |   6 +-
 .../SemaHLSL/resource_binding_attr_error.hlsl |  21 +-
 .../resource_binding_attr_error_mismatch.hlsl |  74 ++
 12 files changed, 346 insertions(+), 33 deletions(-)
 create mode 100644 
clang/test/SemaHLSL/resource_binding_attr_error_mismatch.hlsl

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 452cd1810f653..c3d67e19656da 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4467,7 +4467,7 @@ def HLSLSV_GroupIndex: HLSLAnnotationAttr {
 
 def HLSLResourceBinding: InheritableAttr {
   let Spellings = [HLSLAnnotation<"register">];
-  let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar]>;
+  let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar], ErrorDiag>;
   let LangOpts = [HLSL];
   let Args = [StringArgument<"Slot">, StringArgument<"Space", 1>];
   let Documentation = [HLSLResourceBindingDocs];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 96f0c0f0205c2..3bf15ff5f2657 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12303,7 +12303,10 @@ def err_hlsl_missing_semantic_annotation : Error<
 def err_hlsl_init_priority_unsupported : Error<
   "initializer priorities are not supported in HLSL">;
 
-def err_hlsl_unsupported_register_type : Error<"invalid resource class 
specifier '%0' used; expected 'b', 's', 't', or 'u'">;
+def err_hlsl_mismatching_register_resource_type_and_name: Error<"invalid 
register name prefix '%0' for register resource type '%1' (expected 
%select{'t'|'u'|'b'|'s'}2)">;
+def err_hlsl_mismatching_register_builtin_type_and_name: Error<"invalid 
register name prefix '%0' for '%1' (expected %2)">;
+def err_hlsl_unsupported_register_prefix : Error<"invalid resource class 
specifier '%0' used; expected 't', 'u', 'b', or 's'">;
+def err_hlsl_unsupported_register_resource_type : Error<"invalid resource '%0' 
used">;
 def err_hlsl_unsupported_register_number : Error<"register number should be an 
integer">;
 def err_hlsl_expected_space : Error<"invalid space specifier '%0' used; 
expected 'space' followed by an integer, like space1">;
 def warn_hlsl_packoffset_mix : Warning<"cannot mix packoffset elements with 
nonpackoffset elements in a cbuffer">,
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index 4d6958a1be3e5..d3d36d04d1019 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -22,6 +22,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/SemaBase.h"
+#include "clang/Sema/Sema.h"
 #include 
 
 namespace clang {
@@ -31,6 +32,7 @@ class SemaHLSL : public SemaBase {
 public:
   SemaHLSL(Sema &S);
 
+  HLSLResourceAttr *mergeHLSLResourceAttr(bool CBuffer);
   Decl *ActOnStartBuffer(Scope *BufferScope, bool CBuffer, SourceLocation 
KwLoc,
  IdentifierInfo *Ident, SourceLocation IdentLoc,
  SourceLocation LBrace);
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index a2b29a7bdf505..b82cd8373403a 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -490,23 +490,24 @@ void HLSLExternalSemaSource::defineTrivialHLSLTypes() {
 }
 
 /// Set up common members and attributes for buffer types
-static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S,
-  ResourceClass RC, ResourceKind 
RK,
-  bool IsROV) {
+static BuiltinTypeDeclBuilder setupBufferHandle(CXXRecordDecl *Decl, Sema &S,
+ResourceClass RC) {
   return BuiltinTypeDeclBuilder(Decl)
   .addHandleMember()
-  .addDefaultHandleConstructor(S, RC)
-  .annotateResourceClass(RC, RK, IsROV);
+  .addDefaultHandleConstructor(S, RC);
 }
 
 void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
   CXXRecordDecl *Decl;
-  Decl = Bu

[clang-tools-extra] Fix Default Asset File locator for clang docs (PR #97505)

2024-07-02 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 created 
https://github.com/llvm/llvm-project/pull/97505

In `clang-tools-extra\clang-doc\tool\ClangDocMain.cpp`, there is a function, 
`getDefaultAssetFiles` that tries to find the location of 
`\share\clang-doc\index.js`, but fails. This is because there are 
alternate configurations in setting up the llvm project, and executables in 
different locations may be run. In some cases, executables are built and run in 
this location:
`\bin\`
and in other cases, this location:
`\[Debug | Release]\bin\`

The locator assumed that the executable that is running was in the first 
example above, and in the case that an executable under Debug / Release was 
run, the index.js file wouldn't be found.
This PR adjusts the locator to be agnostic to either scenario described above, 
and ascends an extra directory if the Debug directory is detected.

>From 1c190c9c6b55aec23bab6d7b2a0f489c59285dc7 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Tue, 2 Jul 2024 18:38:24 -0700
Subject: [PATCH] if debug exists, go up an extra dir

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 6198a6e0cdcc3..b97fa715f9e67 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -167,7 +167,13 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
 
   llvm::SmallString<128> AssetsPath;
   AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath);
-  llvm::sys::path::append(AssetsPath, "..", "share", "clang-doc");
+  llvm::sys::path::append(AssetsPath, "..");
+  llvm::SmallString<128> tempCopyDbg = AssetsPath;
+  llvm::sys::path::append(tempCopyDbg, "Debug");
+  // index.js may be in the debug
+  if (!llvm::sys::fs::is_directory(tempCopyDbg))
+llvm::sys::path::append(AssetsPath, "..");
+  llvm::sys::path::append(AssetsPath, "share", "clang-doc");
   llvm::SmallString<128> DefaultStylesheet;
   llvm::sys::path::native(AssetsPath, DefaultStylesheet);
   llvm::sys::path::append(DefaultStylesheet,

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Fix Default Asset File locator for clang docs (PR #97505)

2024-07-02 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/97505

>From 1c190c9c6b55aec23bab6d7b2a0f489c59285dc7 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Tue, 2 Jul 2024 18:38:24 -0700
Subject: [PATCH 1/2] if debug exists, go up an extra dir

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 6198a6e0cdcc3..b97fa715f9e67 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -167,7 +167,13 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
 
   llvm::SmallString<128> AssetsPath;
   AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath);
-  llvm::sys::path::append(AssetsPath, "..", "share", "clang-doc");
+  llvm::sys::path::append(AssetsPath, "..");
+  llvm::SmallString<128> tempCopyDbg = AssetsPath;
+  llvm::sys::path::append(tempCopyDbg, "Debug");
+  // index.js may be in the debug
+  if (!llvm::sys::fs::is_directory(tempCopyDbg))
+llvm::sys::path::append(AssetsPath, "..");
+  llvm::sys::path::append(AssetsPath, "share", "clang-doc");
   llvm::SmallString<128> DefaultStylesheet;
   llvm::sys::path::native(AssetsPath, DefaultStylesheet);
   llvm::sys::path::append(DefaultStylesheet,

>From 07662a63e1b3ab2886871f3960246be8219c6ecd Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Tue, 2 Jul 2024 18:45:23 -0700
Subject: [PATCH 2/2] cleanup comment

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index b97fa715f9e67..ebd0675cd5501 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -170,7 +170,7 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
   llvm::sys::path::append(AssetsPath, "..");
   llvm::SmallString<128> tempCopyDbg = AssetsPath;
   llvm::sys::path::append(tempCopyDbg, "Debug");
-  // index.js may be in the debug
+  // The executable that ran clangDoc may be in the Debug directory.
   if (!llvm::sys::fs::is_directory(tempCopyDbg))
 llvm::sys::path::append(AssetsPath, "..");
   llvm::sys::path::append(AssetsPath, "share", "clang-doc");

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Fix Default Asset File locator for clang docs (PR #97505)

2024-07-02 Thread Joshua Batista via cfe-commits

bob80905 wrote:

An important assumption I'm making here is that the Debug directory cannot 
exist without the Release directory. If this assumption doesn't hold, then this 
fix will fail if only the release directory exists and debug is missing. I 
believe by the nature of how the llvm project is generated, both directories 
are generated at all times.

https://github.com/llvm/llvm-project/pull/97505
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Implement resource binding type prefix mismatch flag setting logic (PR #97103)

2024-07-02 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/97103

>From c784272b3f66ca06be4ab8e72a0963e5ebb6a869 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Fri, 28 Jun 2024 12:40:56 -0700
Subject: [PATCH 1/9] update tests, update code

---
 clang/include/clang/Basic/Attr.td |   2 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Sema/SemaHLSL.h   |   2 +
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  26 +-
 clang/lib/Sema/SemaHLSL.cpp   | 232 +-
 .../ast-dump-comment-cbuffe-tbufferr.hlsl |   2 +
 clang/test/AST/HLSL/cbuffer_tbuffer.hlsl  |   6 +-
 clang/test/AST/HLSL/packoffset.hlsl   |   1 +
 clang/test/AST/HLSL/pch_hlsl_buffer.hlsl  |   2 +
 .../test/AST/HLSL/resource_binding_attr.hlsl  |   6 +-
 .../SemaHLSL/resource_binding_attr_error.hlsl |  21 +-
 .../resource_binding_attr_error_mismatch.hlsl |  74 ++
 12 files changed, 346 insertions(+), 33 deletions(-)
 create mode 100644 
clang/test/SemaHLSL/resource_binding_attr_error_mismatch.hlsl

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 452cd1810f653..c3d67e19656da 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4467,7 +4467,7 @@ def HLSLSV_GroupIndex: HLSLAnnotationAttr {
 
 def HLSLResourceBinding: InheritableAttr {
   let Spellings = [HLSLAnnotation<"register">];
-  let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar]>;
+  let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar], ErrorDiag>;
   let LangOpts = [HLSL];
   let Args = [StringArgument<"Slot">, StringArgument<"Space", 1>];
   let Documentation = [HLSLResourceBindingDocs];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 96f0c0f0205c2..3bf15ff5f2657 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12303,7 +12303,10 @@ def err_hlsl_missing_semantic_annotation : Error<
 def err_hlsl_init_priority_unsupported : Error<
   "initializer priorities are not supported in HLSL">;
 
-def err_hlsl_unsupported_register_type : Error<"invalid resource class 
specifier '%0' used; expected 'b', 's', 't', or 'u'">;
+def err_hlsl_mismatching_register_resource_type_and_name: Error<"invalid 
register name prefix '%0' for register resource type '%1' (expected 
%select{'t'|'u'|'b'|'s'}2)">;
+def err_hlsl_mismatching_register_builtin_type_and_name: Error<"invalid 
register name prefix '%0' for '%1' (expected %2)">;
+def err_hlsl_unsupported_register_prefix : Error<"invalid resource class 
specifier '%0' used; expected 't', 'u', 'b', or 's'">;
+def err_hlsl_unsupported_register_resource_type : Error<"invalid resource '%0' 
used">;
 def err_hlsl_unsupported_register_number : Error<"register number should be an 
integer">;
 def err_hlsl_expected_space : Error<"invalid space specifier '%0' used; 
expected 'space' followed by an integer, like space1">;
 def warn_hlsl_packoffset_mix : Warning<"cannot mix packoffset elements with 
nonpackoffset elements in a cbuffer">,
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index 4d6958a1be3e5..d3d36d04d1019 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -22,6 +22,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/SemaBase.h"
+#include "clang/Sema/Sema.h"
 #include 
 
 namespace clang {
@@ -31,6 +32,7 @@ class SemaHLSL : public SemaBase {
 public:
   SemaHLSL(Sema &S);
 
+  HLSLResourceAttr *mergeHLSLResourceAttr(bool CBuffer);
   Decl *ActOnStartBuffer(Scope *BufferScope, bool CBuffer, SourceLocation 
KwLoc,
  IdentifierInfo *Ident, SourceLocation IdentLoc,
  SourceLocation LBrace);
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index a2b29a7bdf505..b82cd8373403a 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -490,23 +490,24 @@ void HLSLExternalSemaSource::defineTrivialHLSLTypes() {
 }
 
 /// Set up common members and attributes for buffer types
-static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S,
-  ResourceClass RC, ResourceKind 
RK,
-  bool IsROV) {
+static BuiltinTypeDeclBuilder setupBufferHandle(CXXRecordDecl *Decl, Sema &S,
+ResourceClass RC) {
   return BuiltinTypeDeclBuilder(Decl)
   .addHandleMember()
-  .addDefaultHandleConstructor(S, RC)
-  .annotateResourceClass(RC, RK, IsROV);
+  .addDefaultHandleConstructor(S, RC);
 }
 
 void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
   CXXRecordDecl *Decl;
-  Decl = Bu

[clang] Implement resource binding type prefix mismatch flag setting logic (PR #97103)

2024-07-03 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/97103

>From c784272b3f66ca06be4ab8e72a0963e5ebb6a869 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Fri, 28 Jun 2024 12:40:56 -0700
Subject: [PATCH 01/10] update tests, update code

---
 clang/include/clang/Basic/Attr.td |   2 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Sema/SemaHLSL.h   |   2 +
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  26 +-
 clang/lib/Sema/SemaHLSL.cpp   | 232 +-
 .../ast-dump-comment-cbuffe-tbufferr.hlsl |   2 +
 clang/test/AST/HLSL/cbuffer_tbuffer.hlsl  |   6 +-
 clang/test/AST/HLSL/packoffset.hlsl   |   1 +
 clang/test/AST/HLSL/pch_hlsl_buffer.hlsl  |   2 +
 .../test/AST/HLSL/resource_binding_attr.hlsl  |   6 +-
 .../SemaHLSL/resource_binding_attr_error.hlsl |  21 +-
 .../resource_binding_attr_error_mismatch.hlsl |  74 ++
 12 files changed, 346 insertions(+), 33 deletions(-)
 create mode 100644 
clang/test/SemaHLSL/resource_binding_attr_error_mismatch.hlsl

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 452cd1810f653..c3d67e19656da 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4467,7 +4467,7 @@ def HLSLSV_GroupIndex: HLSLAnnotationAttr {
 
 def HLSLResourceBinding: InheritableAttr {
   let Spellings = [HLSLAnnotation<"register">];
-  let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar]>;
+  let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar], ErrorDiag>;
   let LangOpts = [HLSL];
   let Args = [StringArgument<"Slot">, StringArgument<"Space", 1>];
   let Documentation = [HLSLResourceBindingDocs];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 96f0c0f0205c2..3bf15ff5f2657 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12303,7 +12303,10 @@ def err_hlsl_missing_semantic_annotation : Error<
 def err_hlsl_init_priority_unsupported : Error<
   "initializer priorities are not supported in HLSL">;
 
-def err_hlsl_unsupported_register_type : Error<"invalid resource class 
specifier '%0' used; expected 'b', 's', 't', or 'u'">;
+def err_hlsl_mismatching_register_resource_type_and_name: Error<"invalid 
register name prefix '%0' for register resource type '%1' (expected 
%select{'t'|'u'|'b'|'s'}2)">;
+def err_hlsl_mismatching_register_builtin_type_and_name: Error<"invalid 
register name prefix '%0' for '%1' (expected %2)">;
+def err_hlsl_unsupported_register_prefix : Error<"invalid resource class 
specifier '%0' used; expected 't', 'u', 'b', or 's'">;
+def err_hlsl_unsupported_register_resource_type : Error<"invalid resource '%0' 
used">;
 def err_hlsl_unsupported_register_number : Error<"register number should be an 
integer">;
 def err_hlsl_expected_space : Error<"invalid space specifier '%0' used; 
expected 'space' followed by an integer, like space1">;
 def warn_hlsl_packoffset_mix : Warning<"cannot mix packoffset elements with 
nonpackoffset elements in a cbuffer">,
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index 4d6958a1be3e5..d3d36d04d1019 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -22,6 +22,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/SemaBase.h"
+#include "clang/Sema/Sema.h"
 #include 
 
 namespace clang {
@@ -31,6 +32,7 @@ class SemaHLSL : public SemaBase {
 public:
   SemaHLSL(Sema &S);
 
+  HLSLResourceAttr *mergeHLSLResourceAttr(bool CBuffer);
   Decl *ActOnStartBuffer(Scope *BufferScope, bool CBuffer, SourceLocation 
KwLoc,
  IdentifierInfo *Ident, SourceLocation IdentLoc,
  SourceLocation LBrace);
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index a2b29a7bdf505..b82cd8373403a 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -490,23 +490,24 @@ void HLSLExternalSemaSource::defineTrivialHLSLTypes() {
 }
 
 /// Set up common members and attributes for buffer types
-static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S,
-  ResourceClass RC, ResourceKind 
RK,
-  bool IsROV) {
+static BuiltinTypeDeclBuilder setupBufferHandle(CXXRecordDecl *Decl, Sema &S,
+ResourceClass RC) {
   return BuiltinTypeDeclBuilder(Decl)
   .addHandleMember()
-  .addDefaultHandleConstructor(S, RC)
-  .annotateResourceClass(RC, RK, IsROV);
+  .addDefaultHandleConstructor(S, RC);
 }
 
 void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
   CXXRecordDecl *Decl;
-  Decl = 

[clang-tools-extra] Fix Default Asset File locator for clang docs (PR #97505)

2024-07-03 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/97505

>From 1c190c9c6b55aec23bab6d7b2a0f489c59285dc7 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Tue, 2 Jul 2024 18:38:24 -0700
Subject: [PATCH 1/3] if debug exists, go up an extra dir

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 6198a6e0cdcc3..b97fa715f9e67 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -167,7 +167,13 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
 
   llvm::SmallString<128> AssetsPath;
   AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath);
-  llvm::sys::path::append(AssetsPath, "..", "share", "clang-doc");
+  llvm::sys::path::append(AssetsPath, "..");
+  llvm::SmallString<128> tempCopyDbg = AssetsPath;
+  llvm::sys::path::append(tempCopyDbg, "Debug");
+  // index.js may be in the debug
+  if (!llvm::sys::fs::is_directory(tempCopyDbg))
+llvm::sys::path::append(AssetsPath, "..");
+  llvm::sys::path::append(AssetsPath, "share", "clang-doc");
   llvm::SmallString<128> DefaultStylesheet;
   llvm::sys::path::native(AssetsPath, DefaultStylesheet);
   llvm::sys::path::append(DefaultStylesheet,

>From 07662a63e1b3ab2886871f3960246be8219c6ecd Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Tue, 2 Jul 2024 18:45:23 -0700
Subject: [PATCH 2/3] cleanup comment

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index b97fa715f9e67..ebd0675cd5501 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -170,7 +170,7 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
   llvm::sys::path::append(AssetsPath, "..");
   llvm::SmallString<128> tempCopyDbg = AssetsPath;
   llvm::sys::path::append(tempCopyDbg, "Debug");
-  // index.js may be in the debug
+  // The executable that ran clangDoc may be in the Debug directory.
   if (!llvm::sys::fs::is_directory(tempCopyDbg))
 llvm::sys::path::append(AssetsPath, "..");
   llvm::sys::path::append(AssetsPath, "share", "clang-doc");

>From ea1d0ce1c2893297e67eebf0a52885681c6a866d Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Wed, 3 Jul 2024 03:12:38 -0700
Subject: [PATCH 3/3] use native to copy path, instead of assignment operator

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index ebd0675cd5501..6ec35acfc2db3 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -168,7 +168,8 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
   llvm::SmallString<128> AssetsPath;
   AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath);
   llvm::sys::path::append(AssetsPath, "..");
-  llvm::SmallString<128> tempCopyDbg = AssetsPath;
+  llvm::SmallString<128> tempCopyDbg;
+  llvm::sys::path::native(AssetsPath, tempCopyDbg);
   llvm::sys::path::append(tempCopyDbg, "Debug");
   // The executable that ran clangDoc may be in the Debug directory.
   if (!llvm::sys::fs::is_directory(tempCopyDbg))

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Fix Default Asset File locator for clang docs (PR #97505)

2024-07-03 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/97505

>From 1c190c9c6b55aec23bab6d7b2a0f489c59285dc7 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Tue, 2 Jul 2024 18:38:24 -0700
Subject: [PATCH 1/4] if debug exists, go up an extra dir

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 6198a6e0cdcc32..b97fa715f9e67f 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -167,7 +167,13 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
 
   llvm::SmallString<128> AssetsPath;
   AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath);
-  llvm::sys::path::append(AssetsPath, "..", "share", "clang-doc");
+  llvm::sys::path::append(AssetsPath, "..");
+  llvm::SmallString<128> tempCopyDbg = AssetsPath;
+  llvm::sys::path::append(tempCopyDbg, "Debug");
+  // index.js may be in the debug
+  if (!llvm::sys::fs::is_directory(tempCopyDbg))
+llvm::sys::path::append(AssetsPath, "..");
+  llvm::sys::path::append(AssetsPath, "share", "clang-doc");
   llvm::SmallString<128> DefaultStylesheet;
   llvm::sys::path::native(AssetsPath, DefaultStylesheet);
   llvm::sys::path::append(DefaultStylesheet,

>From 07662a63e1b3ab2886871f3960246be8219c6ecd Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Tue, 2 Jul 2024 18:45:23 -0700
Subject: [PATCH 2/4] cleanup comment

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index b97fa715f9e67f..ebd0675cd55014 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -170,7 +170,7 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
   llvm::sys::path::append(AssetsPath, "..");
   llvm::SmallString<128> tempCopyDbg = AssetsPath;
   llvm::sys::path::append(tempCopyDbg, "Debug");
-  // index.js may be in the debug
+  // The executable that ran clangDoc may be in the Debug directory.
   if (!llvm::sys::fs::is_directory(tempCopyDbg))
 llvm::sys::path::append(AssetsPath, "..");
   llvm::sys::path::append(AssetsPath, "share", "clang-doc");

>From ea1d0ce1c2893297e67eebf0a52885681c6a866d Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Wed, 3 Jul 2024 03:12:38 -0700
Subject: [PATCH 3/4] use native to copy path, instead of assignment operator

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index ebd0675cd55014..6ec35acfc2db3a 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -168,7 +168,8 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
   llvm::SmallString<128> AssetsPath;
   AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath);
   llvm::sys::path::append(AssetsPath, "..");
-  llvm::SmallString<128> tempCopyDbg = AssetsPath;
+  llvm::SmallString<128> tempCopyDbg;
+  llvm::sys::path::native(AssetsPath, tempCopyDbg);
   llvm::sys::path::append(tempCopyDbg, "Debug");
   // The executable that ran clangDoc may be in the Debug directory.
   if (!llvm::sys::fs::is_directory(tempCopyDbg))

>From b7484828d96d23dd7d2d88ee8d44f5aad6e23140 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Wed, 3 Jul 2024 13:37:17 -0700
Subject: [PATCH 4/4] revert change in .cpp, make attempt at fixing cmake

---
 clang-tools-extra/clang-doc/tool/CMakeLists.txt   | 10 --
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp |  9 +
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/clang-tools-extra/clang-doc/tool/CMakeLists.txt 
b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
index e93a5728d6b6b0..31ff0aca72b88f 100644
--- a/clang-tools-extra/clang-doc/tool/CMakeLists.txt
+++ b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
@@ -25,15 +25,16 @@ set(assets
 )
 
 set(asset_dir "${CMAKE_CURRENT_SOURCE_DIR}/../assets")
-set(resource_dir "${CMAKE_BINARY_DIR}/share/clang-doc")
 set(out_files)
 
 function(copy_files_to_dst src_dir dst_dir file)
   set(src "${src_dir}/${file}")
   set(dst "${dst_dir}/${file}")
+  message(here)
   add_custom_command(OUTPUT ${dst}
 DEPENDS ${src}
 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
+message(here2)
 COMMENT "Copying ${file} to ${dst_dir}"
   )
   list(APPEND out_files ${dst})
@@ -44,7 +45,12 @@ foreach(f ${assets})
   install(FILES ${asset_dir}/${f}
 DESTINATION "${CMAKE_INSTALL_DATADIR}/clang-doc"
 COMPONENT clang-doc)
-  copy_files_to_dst(${asset_dir} ${resource_dir} ${f})
+   foreach(config ${CMAKE_CONFIG

[clang-tools-extra] Fix Default Asset File locator for clang docs (PR #97505)

2024-07-03 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/97505

>From 1c190c9c6b55aec23bab6d7b2a0f489c59285dc7 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Tue, 2 Jul 2024 18:38:24 -0700
Subject: [PATCH 1/5] if debug exists, go up an extra dir

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 6198a6e0cdcc32..b97fa715f9e67f 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -167,7 +167,13 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
 
   llvm::SmallString<128> AssetsPath;
   AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath);
-  llvm::sys::path::append(AssetsPath, "..", "share", "clang-doc");
+  llvm::sys::path::append(AssetsPath, "..");
+  llvm::SmallString<128> tempCopyDbg = AssetsPath;
+  llvm::sys::path::append(tempCopyDbg, "Debug");
+  // index.js may be in the debug
+  if (!llvm::sys::fs::is_directory(tempCopyDbg))
+llvm::sys::path::append(AssetsPath, "..");
+  llvm::sys::path::append(AssetsPath, "share", "clang-doc");
   llvm::SmallString<128> DefaultStylesheet;
   llvm::sys::path::native(AssetsPath, DefaultStylesheet);
   llvm::sys::path::append(DefaultStylesheet,

>From 07662a63e1b3ab2886871f3960246be8219c6ecd Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Tue, 2 Jul 2024 18:45:23 -0700
Subject: [PATCH 2/5] cleanup comment

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index b97fa715f9e67f..ebd0675cd55014 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -170,7 +170,7 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
   llvm::sys::path::append(AssetsPath, "..");
   llvm::SmallString<128> tempCopyDbg = AssetsPath;
   llvm::sys::path::append(tempCopyDbg, "Debug");
-  // index.js may be in the debug
+  // The executable that ran clangDoc may be in the Debug directory.
   if (!llvm::sys::fs::is_directory(tempCopyDbg))
 llvm::sys::path::append(AssetsPath, "..");
   llvm::sys::path::append(AssetsPath, "share", "clang-doc");

>From ea1d0ce1c2893297e67eebf0a52885681c6a866d Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Wed, 3 Jul 2024 03:12:38 -0700
Subject: [PATCH 3/5] use native to copy path, instead of assignment operator

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index ebd0675cd55014..6ec35acfc2db3a 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -168,7 +168,8 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
   llvm::SmallString<128> AssetsPath;
   AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath);
   llvm::sys::path::append(AssetsPath, "..");
-  llvm::SmallString<128> tempCopyDbg = AssetsPath;
+  llvm::SmallString<128> tempCopyDbg;
+  llvm::sys::path::native(AssetsPath, tempCopyDbg);
   llvm::sys::path::append(tempCopyDbg, "Debug");
   // The executable that ran clangDoc may be in the Debug directory.
   if (!llvm::sys::fs::is_directory(tempCopyDbg))

>From b7484828d96d23dd7d2d88ee8d44f5aad6e23140 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Wed, 3 Jul 2024 13:37:17 -0700
Subject: [PATCH 4/5] revert change in .cpp, make attempt at fixing cmake

---
 clang-tools-extra/clang-doc/tool/CMakeLists.txt   | 10 --
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp |  9 +
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/clang-tools-extra/clang-doc/tool/CMakeLists.txt 
b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
index e93a5728d6b6b0..31ff0aca72b88f 100644
--- a/clang-tools-extra/clang-doc/tool/CMakeLists.txt
+++ b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
@@ -25,15 +25,16 @@ set(assets
 )
 
 set(asset_dir "${CMAKE_CURRENT_SOURCE_DIR}/../assets")
-set(resource_dir "${CMAKE_BINARY_DIR}/share/clang-doc")
 set(out_files)
 
 function(copy_files_to_dst src_dir dst_dir file)
   set(src "${src_dir}/${file}")
   set(dst "${dst_dir}/${file}")
+  message(here)
   add_custom_command(OUTPUT ${dst}
 DEPENDS ${src}
 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
+message(here2)
 COMMENT "Copying ${file} to ${dst_dir}"
   )
   list(APPEND out_files ${dst})
@@ -44,7 +45,12 @@ foreach(f ${assets})
   install(FILES ${asset_dir}/${f}
 DESTINATION "${CMAKE_INSTALL_DATADIR}/clang-doc"
 COMPONENT clang-doc)
-  copy_files_to_dst(${asset_dir} ${resource_dir} ${f})
+   foreach(config ${CMAKE_CONFIG

[clang-tools-extra] Fix Default Asset File locator for clang docs (PR #97505)

2024-07-03 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 edited 
https://github.com/llvm/llvm-project/pull/97505
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Fix Default Asset File locator for clang docs (PR #97505)

2024-07-03 Thread Joshua Batista via cfe-commits

bob80905 wrote:

Updated the description.
In my tests, there are at least 5 copies of this file in the overall build 
output directory:
```
//Debug/share/clang-doc
//Release/share/clang-doc
//MinSizeRel/share/clang-doc
//RelWithDebInfo/share/clang-doc
//share/clang-doc
```
Yes, one per configuration, and one underneath the binary directory.
I am unsure if we still need the copy in the binary directory, because I'm not 
sure which executable is run by default when running tests. 

https://github.com/llvm/llvm-project/pull/97505
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Implement resource binding type prefix mismatch flag setting logic (PR #97103)

2024-07-05 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/97103

>From c784272b3f66ca06be4ab8e72a0963e5ebb6a869 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Fri, 28 Jun 2024 12:40:56 -0700
Subject: [PATCH 01/11] update tests, update code

---
 clang/include/clang/Basic/Attr.td |   2 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Sema/SemaHLSL.h   |   2 +
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  26 +-
 clang/lib/Sema/SemaHLSL.cpp   | 232 +-
 .../ast-dump-comment-cbuffe-tbufferr.hlsl |   2 +
 clang/test/AST/HLSL/cbuffer_tbuffer.hlsl  |   6 +-
 clang/test/AST/HLSL/packoffset.hlsl   |   1 +
 clang/test/AST/HLSL/pch_hlsl_buffer.hlsl  |   2 +
 .../test/AST/HLSL/resource_binding_attr.hlsl  |   6 +-
 .../SemaHLSL/resource_binding_attr_error.hlsl |  21 +-
 .../resource_binding_attr_error_mismatch.hlsl |  74 ++
 12 files changed, 346 insertions(+), 33 deletions(-)
 create mode 100644 
clang/test/SemaHLSL/resource_binding_attr_error_mismatch.hlsl

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 452cd1810f653..c3d67e19656da 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4467,7 +4467,7 @@ def HLSLSV_GroupIndex: HLSLAnnotationAttr {
 
 def HLSLResourceBinding: InheritableAttr {
   let Spellings = [HLSLAnnotation<"register">];
-  let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar]>;
+  let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar], ErrorDiag>;
   let LangOpts = [HLSL];
   let Args = [StringArgument<"Slot">, StringArgument<"Space", 1>];
   let Documentation = [HLSLResourceBindingDocs];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 96f0c0f0205c2..3bf15ff5f2657 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12303,7 +12303,10 @@ def err_hlsl_missing_semantic_annotation : Error<
 def err_hlsl_init_priority_unsupported : Error<
   "initializer priorities are not supported in HLSL">;
 
-def err_hlsl_unsupported_register_type : Error<"invalid resource class 
specifier '%0' used; expected 'b', 's', 't', or 'u'">;
+def err_hlsl_mismatching_register_resource_type_and_name: Error<"invalid 
register name prefix '%0' for register resource type '%1' (expected 
%select{'t'|'u'|'b'|'s'}2)">;
+def err_hlsl_mismatching_register_builtin_type_and_name: Error<"invalid 
register name prefix '%0' for '%1' (expected %2)">;
+def err_hlsl_unsupported_register_prefix : Error<"invalid resource class 
specifier '%0' used; expected 't', 'u', 'b', or 's'">;
+def err_hlsl_unsupported_register_resource_type : Error<"invalid resource '%0' 
used">;
 def err_hlsl_unsupported_register_number : Error<"register number should be an 
integer">;
 def err_hlsl_expected_space : Error<"invalid space specifier '%0' used; 
expected 'space' followed by an integer, like space1">;
 def warn_hlsl_packoffset_mix : Warning<"cannot mix packoffset elements with 
nonpackoffset elements in a cbuffer">,
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index 4d6958a1be3e5..d3d36d04d1019 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -22,6 +22,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/SemaBase.h"
+#include "clang/Sema/Sema.h"
 #include 
 
 namespace clang {
@@ -31,6 +32,7 @@ class SemaHLSL : public SemaBase {
 public:
   SemaHLSL(Sema &S);
 
+  HLSLResourceAttr *mergeHLSLResourceAttr(bool CBuffer);
   Decl *ActOnStartBuffer(Scope *BufferScope, bool CBuffer, SourceLocation 
KwLoc,
  IdentifierInfo *Ident, SourceLocation IdentLoc,
  SourceLocation LBrace);
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index a2b29a7bdf505..b82cd8373403a 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -490,23 +490,24 @@ void HLSLExternalSemaSource::defineTrivialHLSLTypes() {
 }
 
 /// Set up common members and attributes for buffer types
-static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S,
-  ResourceClass RC, ResourceKind 
RK,
-  bool IsROV) {
+static BuiltinTypeDeclBuilder setupBufferHandle(CXXRecordDecl *Decl, Sema &S,
+ResourceClass RC) {
   return BuiltinTypeDeclBuilder(Decl)
   .addHandleMember()
-  .addDefaultHandleConstructor(S, RC)
-  .annotateResourceClass(RC, RK, IsROV);
+  .addDefaultHandleConstructor(S, RC);
 }
 
 void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
   CXXRecordDecl *Decl;
-  Decl = 

[clang] Implement resource binding type prefix mismatch flag setting logic (PR #97103)

2024-07-05 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/97103

>From c784272b3f66ca06be4ab8e72a0963e5ebb6a869 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Fri, 28 Jun 2024 12:40:56 -0700
Subject: [PATCH 01/12] update tests, update code

---
 clang/include/clang/Basic/Attr.td |   2 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Sema/SemaHLSL.h   |   2 +
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  26 +-
 clang/lib/Sema/SemaHLSL.cpp   | 232 +-
 .../ast-dump-comment-cbuffe-tbufferr.hlsl |   2 +
 clang/test/AST/HLSL/cbuffer_tbuffer.hlsl  |   6 +-
 clang/test/AST/HLSL/packoffset.hlsl   |   1 +
 clang/test/AST/HLSL/pch_hlsl_buffer.hlsl  |   2 +
 .../test/AST/HLSL/resource_binding_attr.hlsl  |   6 +-
 .../SemaHLSL/resource_binding_attr_error.hlsl |  21 +-
 .../resource_binding_attr_error_mismatch.hlsl |  74 ++
 12 files changed, 346 insertions(+), 33 deletions(-)
 create mode 100644 
clang/test/SemaHLSL/resource_binding_attr_error_mismatch.hlsl

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 452cd1810f653..c3d67e19656da 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4467,7 +4467,7 @@ def HLSLSV_GroupIndex: HLSLAnnotationAttr {
 
 def HLSLResourceBinding: InheritableAttr {
   let Spellings = [HLSLAnnotation<"register">];
-  let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar]>;
+  let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar], ErrorDiag>;
   let LangOpts = [HLSL];
   let Args = [StringArgument<"Slot">, StringArgument<"Space", 1>];
   let Documentation = [HLSLResourceBindingDocs];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 96f0c0f0205c2..3bf15ff5f2657 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12303,7 +12303,10 @@ def err_hlsl_missing_semantic_annotation : Error<
 def err_hlsl_init_priority_unsupported : Error<
   "initializer priorities are not supported in HLSL">;
 
-def err_hlsl_unsupported_register_type : Error<"invalid resource class 
specifier '%0' used; expected 'b', 's', 't', or 'u'">;
+def err_hlsl_mismatching_register_resource_type_and_name: Error<"invalid 
register name prefix '%0' for register resource type '%1' (expected 
%select{'t'|'u'|'b'|'s'}2)">;
+def err_hlsl_mismatching_register_builtin_type_and_name: Error<"invalid 
register name prefix '%0' for '%1' (expected %2)">;
+def err_hlsl_unsupported_register_prefix : Error<"invalid resource class 
specifier '%0' used; expected 't', 'u', 'b', or 's'">;
+def err_hlsl_unsupported_register_resource_type : Error<"invalid resource '%0' 
used">;
 def err_hlsl_unsupported_register_number : Error<"register number should be an 
integer">;
 def err_hlsl_expected_space : Error<"invalid space specifier '%0' used; 
expected 'space' followed by an integer, like space1">;
 def warn_hlsl_packoffset_mix : Warning<"cannot mix packoffset elements with 
nonpackoffset elements in a cbuffer">,
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index 4d6958a1be3e5..d3d36d04d1019 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -22,6 +22,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/SemaBase.h"
+#include "clang/Sema/Sema.h"
 #include 
 
 namespace clang {
@@ -31,6 +32,7 @@ class SemaHLSL : public SemaBase {
 public:
   SemaHLSL(Sema &S);
 
+  HLSLResourceAttr *mergeHLSLResourceAttr(bool CBuffer);
   Decl *ActOnStartBuffer(Scope *BufferScope, bool CBuffer, SourceLocation 
KwLoc,
  IdentifierInfo *Ident, SourceLocation IdentLoc,
  SourceLocation LBrace);
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index a2b29a7bdf505..b82cd8373403a 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -490,23 +490,24 @@ void HLSLExternalSemaSource::defineTrivialHLSLTypes() {
 }
 
 /// Set up common members and attributes for buffer types
-static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S,
-  ResourceClass RC, ResourceKind 
RK,
-  bool IsROV) {
+static BuiltinTypeDeclBuilder setupBufferHandle(CXXRecordDecl *Decl, Sema &S,
+ResourceClass RC) {
   return BuiltinTypeDeclBuilder(Decl)
   .addHandleMember()
-  .addDefaultHandleConstructor(S, RC)
-  .annotateResourceClass(RC, RK, IsROV);
+  .addDefaultHandleConstructor(S, RC);
 }
 
 void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
   CXXRecordDecl *Decl;
-  Decl = 

[clang] Implement resource binding type prefix mismatch flag setting logic (PR #97103)

2024-07-07 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/97103

>From c784272b3f66ca06be4ab8e72a0963e5ebb6a869 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Fri, 28 Jun 2024 12:40:56 -0700
Subject: [PATCH 01/13] update tests, update code

---
 clang/include/clang/Basic/Attr.td |   2 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Sema/SemaHLSL.h   |   2 +
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  26 +-
 clang/lib/Sema/SemaHLSL.cpp   | 232 +-
 .../ast-dump-comment-cbuffe-tbufferr.hlsl |   2 +
 clang/test/AST/HLSL/cbuffer_tbuffer.hlsl  |   6 +-
 clang/test/AST/HLSL/packoffset.hlsl   |   1 +
 clang/test/AST/HLSL/pch_hlsl_buffer.hlsl  |   2 +
 .../test/AST/HLSL/resource_binding_attr.hlsl  |   6 +-
 .../SemaHLSL/resource_binding_attr_error.hlsl |  21 +-
 .../resource_binding_attr_error_mismatch.hlsl |  74 ++
 12 files changed, 346 insertions(+), 33 deletions(-)
 create mode 100644 
clang/test/SemaHLSL/resource_binding_attr_error_mismatch.hlsl

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 452cd1810f653..c3d67e19656da 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4467,7 +4467,7 @@ def HLSLSV_GroupIndex: HLSLAnnotationAttr {
 
 def HLSLResourceBinding: InheritableAttr {
   let Spellings = [HLSLAnnotation<"register">];
-  let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar]>;
+  let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar], ErrorDiag>;
   let LangOpts = [HLSL];
   let Args = [StringArgument<"Slot">, StringArgument<"Space", 1>];
   let Documentation = [HLSLResourceBindingDocs];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 96f0c0f0205c2..3bf15ff5f2657 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12303,7 +12303,10 @@ def err_hlsl_missing_semantic_annotation : Error<
 def err_hlsl_init_priority_unsupported : Error<
   "initializer priorities are not supported in HLSL">;
 
-def err_hlsl_unsupported_register_type : Error<"invalid resource class 
specifier '%0' used; expected 'b', 's', 't', or 'u'">;
+def err_hlsl_mismatching_register_resource_type_and_name: Error<"invalid 
register name prefix '%0' for register resource type '%1' (expected 
%select{'t'|'u'|'b'|'s'}2)">;
+def err_hlsl_mismatching_register_builtin_type_and_name: Error<"invalid 
register name prefix '%0' for '%1' (expected %2)">;
+def err_hlsl_unsupported_register_prefix : Error<"invalid resource class 
specifier '%0' used; expected 't', 'u', 'b', or 's'">;
+def err_hlsl_unsupported_register_resource_type : Error<"invalid resource '%0' 
used">;
 def err_hlsl_unsupported_register_number : Error<"register number should be an 
integer">;
 def err_hlsl_expected_space : Error<"invalid space specifier '%0' used; 
expected 'space' followed by an integer, like space1">;
 def warn_hlsl_packoffset_mix : Warning<"cannot mix packoffset elements with 
nonpackoffset elements in a cbuffer">,
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index 4d6958a1be3e5..d3d36d04d1019 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -22,6 +22,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/SemaBase.h"
+#include "clang/Sema/Sema.h"
 #include 
 
 namespace clang {
@@ -31,6 +32,7 @@ class SemaHLSL : public SemaBase {
 public:
   SemaHLSL(Sema &S);
 
+  HLSLResourceAttr *mergeHLSLResourceAttr(bool CBuffer);
   Decl *ActOnStartBuffer(Scope *BufferScope, bool CBuffer, SourceLocation 
KwLoc,
  IdentifierInfo *Ident, SourceLocation IdentLoc,
  SourceLocation LBrace);
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index a2b29a7bdf505..b82cd8373403a 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -490,23 +490,24 @@ void HLSLExternalSemaSource::defineTrivialHLSLTypes() {
 }
 
 /// Set up common members and attributes for buffer types
-static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S,
-  ResourceClass RC, ResourceKind 
RK,
-  bool IsROV) {
+static BuiltinTypeDeclBuilder setupBufferHandle(CXXRecordDecl *Decl, Sema &S,
+ResourceClass RC) {
   return BuiltinTypeDeclBuilder(Decl)
   .addHandleMember()
-  .addDefaultHandleConstructor(S, RC)
-  .annotateResourceClass(RC, RK, IsROV);
+  .addDefaultHandleConstructor(S, RC);
 }
 
 void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
   CXXRecordDecl *Decl;
-  Decl = 

[clang] Implement resource binding type prefix mismatch flag setting logic (PR #97103)

2024-07-08 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/97103

>From c784272b3f66ca06be4ab8e72a0963e5ebb6a869 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Fri, 28 Jun 2024 12:40:56 -0700
Subject: [PATCH 01/14] update tests, update code

---
 clang/include/clang/Basic/Attr.td |   2 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Sema/SemaHLSL.h   |   2 +
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  26 +-
 clang/lib/Sema/SemaHLSL.cpp   | 232 +-
 .../ast-dump-comment-cbuffe-tbufferr.hlsl |   2 +
 clang/test/AST/HLSL/cbuffer_tbuffer.hlsl  |   6 +-
 clang/test/AST/HLSL/packoffset.hlsl   |   1 +
 clang/test/AST/HLSL/pch_hlsl_buffer.hlsl  |   2 +
 .../test/AST/HLSL/resource_binding_attr.hlsl  |   6 +-
 .../SemaHLSL/resource_binding_attr_error.hlsl |  21 +-
 .../resource_binding_attr_error_mismatch.hlsl |  74 ++
 12 files changed, 346 insertions(+), 33 deletions(-)
 create mode 100644 
clang/test/SemaHLSL/resource_binding_attr_error_mismatch.hlsl

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 452cd1810f6539..c3d67e19656da2 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4467,7 +4467,7 @@ def HLSLSV_GroupIndex: HLSLAnnotationAttr {
 
 def HLSLResourceBinding: InheritableAttr {
   let Spellings = [HLSLAnnotation<"register">];
-  let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar]>;
+  let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar], ErrorDiag>;
   let LangOpts = [HLSL];
   let Args = [StringArgument<"Slot">, StringArgument<"Space", 1>];
   let Documentation = [HLSLResourceBindingDocs];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 96f0c0f0205c2d..3bf15ff5f26576 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12303,7 +12303,10 @@ def err_hlsl_missing_semantic_annotation : Error<
 def err_hlsl_init_priority_unsupported : Error<
   "initializer priorities are not supported in HLSL">;
 
-def err_hlsl_unsupported_register_type : Error<"invalid resource class 
specifier '%0' used; expected 'b', 's', 't', or 'u'">;
+def err_hlsl_mismatching_register_resource_type_and_name: Error<"invalid 
register name prefix '%0' for register resource type '%1' (expected 
%select{'t'|'u'|'b'|'s'}2)">;
+def err_hlsl_mismatching_register_builtin_type_and_name: Error<"invalid 
register name prefix '%0' for '%1' (expected %2)">;
+def err_hlsl_unsupported_register_prefix : Error<"invalid resource class 
specifier '%0' used; expected 't', 'u', 'b', or 's'">;
+def err_hlsl_unsupported_register_resource_type : Error<"invalid resource '%0' 
used">;
 def err_hlsl_unsupported_register_number : Error<"register number should be an 
integer">;
 def err_hlsl_expected_space : Error<"invalid space specifier '%0' used; 
expected 'space' followed by an integer, like space1">;
 def warn_hlsl_packoffset_mix : Warning<"cannot mix packoffset elements with 
nonpackoffset elements in a cbuffer">,
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index 4d6958a1be3e5b..d3d36d04d1019d 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -22,6 +22,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/SemaBase.h"
+#include "clang/Sema/Sema.h"
 #include 
 
 namespace clang {
@@ -31,6 +32,7 @@ class SemaHLSL : public SemaBase {
 public:
   SemaHLSL(Sema &S);
 
+  HLSLResourceAttr *mergeHLSLResourceAttr(bool CBuffer);
   Decl *ActOnStartBuffer(Scope *BufferScope, bool CBuffer, SourceLocation 
KwLoc,
  IdentifierInfo *Ident, SourceLocation IdentLoc,
  SourceLocation LBrace);
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index a2b29a7bdf505c..b82cd8373403ab 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -490,23 +490,24 @@ void HLSLExternalSemaSource::defineTrivialHLSLTypes() {
 }
 
 /// Set up common members and attributes for buffer types
-static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S,
-  ResourceClass RC, ResourceKind 
RK,
-  bool IsROV) {
+static BuiltinTypeDeclBuilder setupBufferHandle(CXXRecordDecl *Decl, Sema &S,
+ResourceClass RC) {
   return BuiltinTypeDeclBuilder(Decl)
   .addHandleMember()
-  .addDefaultHandleConstructor(S, RC)
-  .annotateResourceClass(RC, RK, IsROV);
+  .addDefaultHandleConstructor(S, RC);
 }
 
 void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
   CXXRecordDecl *Decl;
- 

[clang-tools-extra] Fix Default Asset File locator for clang docs (PR #97505)

2024-07-08 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 edited 
https://github.com/llvm/llvm-project/pull/97505
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Fix Default Asset File locator for clang docs (PR #97505)

2024-07-08 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/97505

>From 1c190c9c6b55aec23bab6d7b2a0f489c59285dc7 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Tue, 2 Jul 2024 18:38:24 -0700
Subject: [PATCH 1/6] if debug exists, go up an extra dir

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 6198a6e0cdcc3..b97fa715f9e67 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -167,7 +167,13 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
 
   llvm::SmallString<128> AssetsPath;
   AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath);
-  llvm::sys::path::append(AssetsPath, "..", "share", "clang-doc");
+  llvm::sys::path::append(AssetsPath, "..");
+  llvm::SmallString<128> tempCopyDbg = AssetsPath;
+  llvm::sys::path::append(tempCopyDbg, "Debug");
+  // index.js may be in the debug
+  if (!llvm::sys::fs::is_directory(tempCopyDbg))
+llvm::sys::path::append(AssetsPath, "..");
+  llvm::sys::path::append(AssetsPath, "share", "clang-doc");
   llvm::SmallString<128> DefaultStylesheet;
   llvm::sys::path::native(AssetsPath, DefaultStylesheet);
   llvm::sys::path::append(DefaultStylesheet,

>From 07662a63e1b3ab2886871f3960246be8219c6ecd Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Tue, 2 Jul 2024 18:45:23 -0700
Subject: [PATCH 2/6] cleanup comment

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index b97fa715f9e67..ebd0675cd5501 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -170,7 +170,7 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
   llvm::sys::path::append(AssetsPath, "..");
   llvm::SmallString<128> tempCopyDbg = AssetsPath;
   llvm::sys::path::append(tempCopyDbg, "Debug");
-  // index.js may be in the debug
+  // The executable that ran clangDoc may be in the Debug directory.
   if (!llvm::sys::fs::is_directory(tempCopyDbg))
 llvm::sys::path::append(AssetsPath, "..");
   llvm::sys::path::append(AssetsPath, "share", "clang-doc");

>From ea1d0ce1c2893297e67eebf0a52885681c6a866d Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Wed, 3 Jul 2024 03:12:38 -0700
Subject: [PATCH 3/6] use native to copy path, instead of assignment operator

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index ebd0675cd5501..6ec35acfc2db3 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -168,7 +168,8 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
   llvm::SmallString<128> AssetsPath;
   AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath);
   llvm::sys::path::append(AssetsPath, "..");
-  llvm::SmallString<128> tempCopyDbg = AssetsPath;
+  llvm::SmallString<128> tempCopyDbg;
+  llvm::sys::path::native(AssetsPath, tempCopyDbg);
   llvm::sys::path::append(tempCopyDbg, "Debug");
   // The executable that ran clangDoc may be in the Debug directory.
   if (!llvm::sys::fs::is_directory(tempCopyDbg))

>From b7484828d96d23dd7d2d88ee8d44f5aad6e23140 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Wed, 3 Jul 2024 13:37:17 -0700
Subject: [PATCH 4/6] revert change in .cpp, make attempt at fixing cmake

---
 clang-tools-extra/clang-doc/tool/CMakeLists.txt   | 10 --
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp |  9 +
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/clang-tools-extra/clang-doc/tool/CMakeLists.txt 
b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
index e93a5728d6b6b..31ff0aca72b88 100644
--- a/clang-tools-extra/clang-doc/tool/CMakeLists.txt
+++ b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
@@ -25,15 +25,16 @@ set(assets
 )
 
 set(asset_dir "${CMAKE_CURRENT_SOURCE_DIR}/../assets")
-set(resource_dir "${CMAKE_BINARY_DIR}/share/clang-doc")
 set(out_files)
 
 function(copy_files_to_dst src_dir dst_dir file)
   set(src "${src_dir}/${file}")
   set(dst "${dst_dir}/${file}")
+  message(here)
   add_custom_command(OUTPUT ${dst}
 DEPENDS ${src}
 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
+message(here2)
 COMMENT "Copying ${file} to ${dst_dir}"
   )
   list(APPEND out_files ${dst})
@@ -44,7 +45,12 @@ foreach(f ${assets})
   install(FILES ${asset_dir}/${f}
 DESTINATION "${CMAKE_INSTALL_DATADIR}/clang-doc"
 COMPONENT clang-doc)
-  copy_files_to_dst(${asset_dir} ${resource_dir} ${f})
+   foreach(config ${CMAKE_CONFIGURATION_

  1   2   3   4   5   6   >