[clang] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 4 17:33:51 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-driver
Author: Joshua Batista (bob80905)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/83938.diff
3 Files Affected:
- (modified) clang/include/clang/Driver/Options.td (+4)
- (modified) clang/lib/Driver/ToolChains/HLSL.cpp (+22)
- (added) clang/test/Options/HV.hlsl (+13)
``````````diff
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index bef38738fde82e..c4caf232887b56 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<dxc_Group>,
Visibility<[DXCOption]>,
HelpText<"Entry point name">;
+def dxc_hlsl_version : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+ Group<dxc_Group>,
+ Visibility<[DXCOption]>,
+ HelpText<"HLSL Version">;
def dxc_validator_path_EQ : Joined<["--"], "dxv-path=">, Group<dxc_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..fe258919dedf3e 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -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");
+ }
+
+ A->claim();
+ continue;
+ }
DAL->append(A);
}
diff --git a/clang/test/Options/HV.hlsl b/clang/test/Options/HV.hlsl
new file mode 100644
index 00000000000000..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-prefix=2017 %s
+// RUN: %clang_dxc -T lib_6_4 -HV 2018 %s 2>&1 -### | FileCheck -check-prefix=2018 %s
+// RUN: %clang_dxc -T lib_6_4 -HV 2021 %s 2>&1 -### | FileCheck -check-prefix=2021 %s
+
+// 2016: "-std=hlsl2016"
+// 2017: "-std=hlsl2017"
+// 2018: "-std=hlsl2018"
+// 2021: "-std=hlsl2021"
+float4 main(float4 a : A) : SV_TARGET
+{
+ return -a.yxxx;
+}
\ No newline at end of file
``````````
</details>
https://github.com/llvm/llvm-project/pull/83938
More information about the cfe-commits
mailing list