[clang] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)
@@ -8545,6 +8545,10 @@ 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">; bogner wrote: This doesn't look right - I don't think `--HV` is valid. 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 -HV option translation to clang-dxc.exe (PR #83938)
@@ -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 bogner wrote: Please also include at least one test of the `/HV` spelling 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 -HV option translation to clang-dxc.exe (PR #83938)
@@ -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 llvm-beanz wrote: I think your comment here is wrong. 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 -HV option translation to clang-dxc.exe (PR #83938)
https://github.com/llvm-beanz edited 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 -HV option translation to clang-dxc.exe (PR #83938)
https://github.com/llvm-beanz commented: I worry this pattern will also lend to us having multiple places that parse and translate HLSL versions. Can you look at other places in Clang where we handle these numbers and see if there is a good way to unify the string handling? It would be ideal for us to only have one place we need to modify when we add new language versions. 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 -HV option translation to clang-dxc.exe (PR #83938)
@@ -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"); + } llvm-beanz wrote: What about 202x? What about unrecognized values? 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 -HV option translation to clang-dxc.exe (PR #83938)
llvmbot wrote: @llvm/pr-subscribers-clang-driver Author: Joshua Batista (bob80905) Changes 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, Visibility<[DXCOption]>, HelpText<"Entry point name">; +def dxc_hlsl_version : 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..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 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-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 `` 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 -HV option translation to clang-dxc.exe (PR #83938)
llvmbot wrote: @llvm/pr-subscribers-hlsl Author: Joshua Batista (bob80905) Changes 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, Visibility<[DXCOption]>, HelpText<"Entry point name">; +def dxc_hlsl_version : 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..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 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-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 `` 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 -HV option translation to clang-dxc.exe (PR #83938)
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), +