[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)
Joshua Batista via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 13 14:07:26 PDT 2024
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 <jbatista at microsoft.com>
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<dxc_Group>,
Visibility<[DXCOption]>,
HelpText<"Entry point name">;
+def dxc_HlslVersion : 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..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 <jbatista at microsoft.com>
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<dxc_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<dxc_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 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
>From 87ae56a7d129e0f04197757d50189a3921c75161 Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Tue, 5 Mar 2024 10:55:52 -0800
Subject: [PATCH 03/14] address Justin
---
clang/include/clang/Driver/Options.td | 2 +-
clang/test/Options/HV.hlsl | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index c4caf232887b56..541d3e954a4e2b 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<dxc_Group>,
Visibility<[DXCOption]>,
HelpText<"Entry point name">;
-def dxc_hlsl_version : Option<["--", "/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+def dxc_hlsl_version : Option<["/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
Group<dxc_Group>,
Visibility<[DXCOption]>,
HelpText<"HLSL Version">;
diff --git a/clang/test/Options/HV.hlsl b/clang/test/Options/HV.hlsl
index 59158ff2f001ed..e17cdfec1127cc 100644
--- a/clang/test/Options/HV.hlsl
+++ b/clang/test/Options/HV.hlsl
@@ -1,7 +1,7 @@
// 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
+// 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"
>From 79f5172bc97fb2c8591d46198e8eee7beaa66786 Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Tue, 5 Mar 2024 15:20:09 -0800
Subject: [PATCH 04/14] address Chris
---
.../clang/Basic/DiagnosticDriverKinds.td | 3 ++
clang/include/clang/Driver/Options.td | 3 +-
clang/lib/Driver/ToolChains/HLSL.cpp | 41 ++++++++++++++-----
clang/test/Options/HV.hlsl | 7 +++-
llvm/include/llvm/Option/OptTable.h | 6 +++
5 files changed, 47 insertions(+), 13 deletions(-)
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 1bc9885849d54b..c2ce342cac3bf1 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,6 +753,9 @@ def err_drv_hlsl_bad_shader_required_in_target : Error<
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 err_drv_hlsl_dxc_bad_argument_value : Error<
+ "'%0' dxc argument has invalid value '%1'">;
+
def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
"Resulting DXIL will not be validated or signed for use in release environments.">,
InGroup<DXILValidation>;
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 541d3e954a4e2b..3f0781e3efb98b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8548,7 +8548,8 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", KIND_JOINED_OR_SEPARATE>,
def dxc_hlsl_version : Option<["/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
Group<dxc_Group>,
Visibility<[DXCOption]>,
- HelpText<"HLSL Version">;
+ HelpText<"HLSL Version">,
+ Values<"2016, 2017, 2018, 2021, 202x">;
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 fe258919dedf3e..5692d1ea061c9e 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -228,21 +228,40 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
}
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) {
+ // depending on the value given
+ llvm::StringRef value(A->getValue());
+ llvm::StringRef acceptedValues(
+ Opts.getOptionValues(options::OPT_dxc_hlsl_version));
+ llvm::SmallVector<StringRef, 8> validValues;
+ acceptedValues.split(validValues, ", ");
+ if (value == validValues[0]) {
+ LangStandard l =
+ LangStandard::getLangStandardForKind(LangStandard::lang_hlsl2016);
DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
- "hlsl2016");
- } else if (strcmp(value, "2017") == 0) {
+ l.getName());
+ } else if (value == validValues[1]) {
+ LangStandard l =
+ LangStandard::getLangStandardForKind(LangStandard::lang_hlsl2017);
DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
- "hlsl2017");
- } else if (strcmp(value, "2018") == 0) {
+ l.getName());
+ } else if (value == validValues[2]) {
+ LangStandard l =
+ LangStandard::getLangStandardForKind(LangStandard::lang_hlsl2018);
DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
- "hlsl2018");
- } else if (strcmp(value, "2021") == 0) {
+ l.getName());
+ } else if (value == validValues[3]) {
+ LangStandard l =
+ LangStandard::getLangStandardForKind(LangStandard::lang_hlsl2021);
DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
- "hlsl2021");
+ l.getName());
+ } else if (value == validValues[4]) {
+ LangStandard l =
+ LangStandard::getLangStandardForKind(LangStandard::lang_hlsl202x);
+ DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+ l.getName());
+ } else {
+ getDriver().Diag(diag::err_drv_hlsl_dxc_bad_argument_value)
+ << "HV" << value;
}
A->claim();
diff --git a/clang/test/Options/HV.hlsl b/clang/test/Options/HV.hlsl
index e17cdfec1127cc..497591aa5900f7 100644
--- a/clang/test/Options/HV.hlsl
+++ b/clang/test/Options/HV.hlsl
@@ -2,12 +2,17 @@
// 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
+// RUN: %clang_dxc -T lib_6_4 /HV 202x %s 2>&1 -### | FileCheck -check-prefix=202x %s
+// RUN: not %clang_dxc -T lib_6_4 /HV gibberish -### %s 2>&1 | FileCheck -check-prefix=CHECK-ERR %s
// 2016: "-std=hlsl2016"
// 2017: "-std=hlsl2017"
// 2018: "-std=hlsl2018"
// 2021: "-std=hlsl2021"
+// 202x: "-std=hlsl202x"
+// CHECK-ERR: error: 'HV' dxc argument has invalid value 'gibberish'
float4 main(float4 a : A) : SV_TARGET
{
return -a.yxxx;
-}
\ No newline at end of file
+}
+
diff --git a/llvm/include/llvm/Option/OptTable.h b/llvm/include/llvm/Option/OptTable.h
index bb3b665a16319f..a3106374543302 100644
--- a/llvm/include/llvm/Option/OptTable.h
+++ b/llvm/include/llvm/Option/OptTable.h
@@ -154,6 +154,12 @@ class OptTable {
return getInfo(id).MetaVar;
}
+ /// Get the meta-variable name to use when describing
+ /// this options values in the help text.
+ const char *getOptionValues(OptSpecifier id) const {
+ return getInfo(id).Values;
+ }
+
/// Specify the environment variable where initial options should be read.
void setInitialOptionsFromEnvironment(const char *E) { EnvVar = E; }
>From 443e85523d612ed163af5d405262f9a5a8f271f2 Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Tue, 5 Mar 2024 15:27:33 -0800
Subject: [PATCH 05/14] clarify comment, format
---
llvm/include/llvm/Option/OptTable.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/include/llvm/Option/OptTable.h b/llvm/include/llvm/Option/OptTable.h
index a3106374543302..11c528c95f150d 100644
--- a/llvm/include/llvm/Option/OptTable.h
+++ b/llvm/include/llvm/Option/OptTable.h
@@ -154,8 +154,8 @@ class OptTable {
return getInfo(id).MetaVar;
}
- /// Get the meta-variable name to use when describing
- /// this options values in the help text.
+ /// Get the string of acceptable argument value choices
+ /// that could be supplied to this option.
const char *getOptionValues(OptSpecifier id) const {
return getInfo(id).Values;
}
>From 1df7e9a8f5a3446bd4f36181733a40e8cbb62b7e Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Fri, 8 Mar 2024 13:11:18 -0800
Subject: [PATCH 06/14] address Xiang
---
clang/include/clang/Basic/LangStandard.h | 1 +
clang/lib/Basic/LangStandards.cpp | 15 +++++++++++
clang/lib/Driver/ToolChains/HLSL.cpp | 33 +++---------------------
3 files changed, 20 insertions(+), 29 deletions(-)
diff --git a/clang/include/clang/Basic/LangStandard.h b/clang/include/clang/Basic/LangStandard.h
index bc49669a82ad2d..199e24c6731603 100644
--- a/clang/include/clang/Basic/LangStandard.h
+++ b/clang/include/clang/Basic/LangStandard.h
@@ -139,6 +139,7 @@ struct LangStandard {
bool isOpenCL() const { return Flags & OpenCL; }
static Kind getLangKind(StringRef Name);
+ static Kind getHLSLLangKind(StringRef Name);
static const LangStandard &getLangStandardForKind(Kind K);
static const LangStandard *getLangStandardForName(StringRef Name);
};
diff --git a/clang/lib/Basic/LangStandards.cpp b/clang/lib/Basic/LangStandards.cpp
index ab09c7221dda92..87c078c2e38622 100644
--- a/clang/lib/Basic/LangStandards.cpp
+++ b/clang/lib/Basic/LangStandards.cpp
@@ -69,6 +69,21 @@ LangStandard::Kind LangStandard::getLangKind(StringRef Name) {
.Default(lang_unspecified);
}
+LangStandard::Kind LangStandard::getHLSLLangKind(StringRef Name) {
+ if (Name == "2016")
+ return LangStandard::lang_hlsl2016;
+ if (Name == "2017")
+ return LangStandard::lang_hlsl2017;
+ if (Name == "2018")
+ return LangStandard::lang_hlsl2018;
+ if (Name == "2021")
+ return LangStandard::lang_hlsl2021;
+ if (Name == "202x")
+ return LangStandard::lang_hlsl202x;
+
+ return LangStandard::lang_unspecified;
+}
+
const LangStandard *LangStandard::getLangStandardForName(StringRef Name) {
Kind K = getLangKind(Name);
if (K == lang_unspecified)
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp b/clang/lib/Driver/ToolChains/HLSL.cpp
index 5692d1ea061c9e..85eedab9e54389 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -229,39 +229,14 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
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<StringRef, 8> validValues;
- acceptedValues.split(validValues, ", ");
- if (value == validValues[0]) {
- LangStandard l =
- LangStandard::getLangStandardForKind(LangStandard::lang_hlsl2016);
- DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
- l.getName());
- } else if (value == validValues[1]) {
- LangStandard l =
- LangStandard::getLangStandardForKind(LangStandard::lang_hlsl2017);
- DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
- l.getName());
- } else if (value == validValues[2]) {
- LangStandard l =
- LangStandard::getLangStandardForKind(LangStandard::lang_hlsl2018);
- DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
- l.getName());
- } else if (value == validValues[3]) {
- LangStandard l =
- LangStandard::getLangStandardForKind(LangStandard::lang_hlsl2021);
- DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
- l.getName());
- } else if (value == validValues[4]) {
- LangStandard l =
- LangStandard::getLangStandardForKind(LangStandard::lang_hlsl202x);
+ LangStandard::Kind LangStd = LangStandard::getHLSLLangKind(A->getValue());
+ if (LangStd != LangStandard::lang_unspecified) {
+ LangStandard l = LangStandard::getLangStandardForKind(LangStd);
DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
l.getName());
} else {
getDriver().Diag(diag::err_drv_hlsl_dxc_bad_argument_value)
- << "HV" << value;
+ << "HV" << A->getValue();
}
A->claim();
>From 03dc916ce0410e2b9cfe0645869b2a206e60a9e6 Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Mon, 11 Mar 2024 10:49:55 -0700
Subject: [PATCH 07/14] add string switch, remove new function in opttable.h
---
clang/include/clang/Driver/Options.td | 2 +-
clang/lib/Basic/LangStandards.cpp | 19 +++++++------------
llvm/include/llvm/Option/OptTable.h | 6 ------
3 files changed, 8 insertions(+), 19 deletions(-)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 3f0781e3efb98b..f17af7aee6c6e4 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8549,7 +8549,7 @@ def dxc_hlsl_version : Option<["/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
Group<dxc_Group>,
Visibility<[DXCOption]>,
HelpText<"HLSL Version">,
- Values<"2016, 2017, 2018, 2021, 202x">;
+ NormalizedValues<["2016", "2017", "2018", "2021", "202x"]>;
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/Basic/LangStandards.cpp b/clang/lib/Basic/LangStandards.cpp
index 87c078c2e38622..cb2c0772349982 100644
--- a/clang/lib/Basic/LangStandards.cpp
+++ b/clang/lib/Basic/LangStandards.cpp
@@ -70,18 +70,13 @@ LangStandard::Kind LangStandard::getLangKind(StringRef Name) {
}
LangStandard::Kind LangStandard::getHLSLLangKind(StringRef Name) {
- if (Name == "2016")
- return LangStandard::lang_hlsl2016;
- if (Name == "2017")
- return LangStandard::lang_hlsl2017;
- if (Name == "2018")
- return LangStandard::lang_hlsl2018;
- if (Name == "2021")
- return LangStandard::lang_hlsl2021;
- if (Name == "202x")
- return LangStandard::lang_hlsl202x;
-
- return LangStandard::lang_unspecified;
+ return llvm::StringSwitch<LangStandard::Kind>(Name)
+ .Case("2016", LangStandard::lang_hlsl2016)
+ .Case("2017", LangStandard::lang_hlsl2017)
+ .Case("2018", LangStandard::lang_hlsl2018)
+ .Case("2021", LangStandard::lang_hlsl2021)
+ .Case("202x", LangStandard::lang_hlsl202x)
+ .Default(LangStandard::lang_unspecified);
}
const LangStandard *LangStandard::getLangStandardForName(StringRef Name) {
diff --git a/llvm/include/llvm/Option/OptTable.h b/llvm/include/llvm/Option/OptTable.h
index 11c528c95f150d..bb3b665a16319f 100644
--- a/llvm/include/llvm/Option/OptTable.h
+++ b/llvm/include/llvm/Option/OptTable.h
@@ -154,12 +154,6 @@ class OptTable {
return getInfo(id).MetaVar;
}
- /// Get the string of acceptable argument value choices
- /// that could be supplied to this option.
- const char *getOptionValues(OptSpecifier id) const {
- return getInfo(id).Values;
- }
-
/// Specify the environment variable where initial options should be read.
void setInitialOptionsFromEnvironment(const char *E) { EnvVar = E; }
>From 08a6acee090869fc840d8284426ef692bfc2c990 Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Tue, 12 Mar 2024 18:41:12 -0700
Subject: [PATCH 08/14] add extra test when HV isn't supplied
---
clang/test/Options/HV.hlsl | 2 ++
1 file changed, 2 insertions(+)
diff --git a/clang/test/Options/HV.hlsl b/clang/test/Options/HV.hlsl
index 497591aa5900f7..7fb63fefbbff0c 100644
--- a/clang/test/Options/HV.hlsl
+++ b/clang/test/Options/HV.hlsl
@@ -3,6 +3,7 @@
// 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
// RUN: %clang_dxc -T lib_6_4 /HV 202x %s 2>&1 -### | FileCheck -check-prefix=202x %s
+// RUN: %clang_dxc -T lib_6_4 %s 2>&1 -### | FileCheck -check-prefix=NO_HV %s
// RUN: not %clang_dxc -T lib_6_4 /HV gibberish -### %s 2>&1 | FileCheck -check-prefix=CHECK-ERR %s
// 2016: "-std=hlsl2016"
@@ -10,6 +11,7 @@
// 2018: "-std=hlsl2018"
// 2021: "-std=hlsl2021"
// 202x: "-std=hlsl202x"
+// NO_HV-NOT: "-std="
// CHECK-ERR: error: 'HV' dxc argument has invalid value 'gibberish'
float4 main(float4 a : A) : SV_TARGET
{
>From 518cb7e1be8ef5e23ae3ca27f3087016ea8fde7e Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Wed, 13 Mar 2024 11:12:17 -0700
Subject: [PATCH 09/14] change diagnostic
---
clang/include/clang/Basic/DiagnosticDriverKinds.td | 2 --
clang/include/clang/Driver/Options.td | 2 ++
clang/lib/Driver/ToolChains/HLSL.cpp | 2 +-
clang/test/Options/HV.hlsl | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index c2ce342cac3bf1..02c6c878d049d9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,8 +753,6 @@ def err_drv_hlsl_bad_shader_required_in_target : Error<
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 err_drv_hlsl_dxc_bad_argument_value : Error<
- "'%0' dxc argument has invalid value '%1'">;
def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
"Resulting DXIL will not be validated or signed for use in release environments.">,
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index f17af7aee6c6e4..21c3865e30b510 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8549,6 +8549,8 @@ def dxc_hlsl_version : Option<["/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
Group<dxc_Group>,
Visibility<[DXCOption]>,
HelpText<"HLSL Version">,
+ Values<"hlsl2016, hlsl2017, hlsl2018, hlsl2021, hlsl202x">,
+ NormalizedValuesScope<"LangStandard">,
NormalizedValues<["2016", "2017", "2018", "2021", "202x"]>;
def dxc_validator_path_EQ : Joined<["--"], "dxv-path=">, Group<dxc_Group>,
HelpText<"DXIL validator installation path">;
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp b/clang/lib/Driver/ToolChains/HLSL.cpp
index 85eedab9e54389..0138a7866aca7d 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -235,7 +235,7 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
l.getName());
} else {
- getDriver().Diag(diag::err_drv_hlsl_dxc_bad_argument_value)
+ getDriver().Diag(diag::err_drv_invalid_value)
<< "HV" << A->getValue();
}
diff --git a/clang/test/Options/HV.hlsl b/clang/test/Options/HV.hlsl
index 7fb63fefbbff0c..6ede3cb8edb9af 100644
--- a/clang/test/Options/HV.hlsl
+++ b/clang/test/Options/HV.hlsl
@@ -12,7 +12,7 @@
// 2021: "-std=hlsl2021"
// 202x: "-std=hlsl202x"
// NO_HV-NOT: "-std="
-// CHECK-ERR: error: 'HV' dxc argument has invalid value 'gibberish'
+// CHECK-ERR: error: Driver argument 'HV' has invalid value 'gibberish'
float4 main(float4 a : A) : SV_TARGET
{
return -a.yxxx;
>From ba7f8cc8cdcda3f28a6ae435334f6bd069789e08 Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Wed, 13 Mar 2024 11:48:14 -0700
Subject: [PATCH 10/14] update
---
clang/include/clang/Driver/Options.td | 4 ++--
clang/test/Options/HV.hlsl | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 21c3865e30b510..f71f5df9dd62d6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8549,9 +8549,9 @@ def dxc_hlsl_version : Option<["/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
Group<dxc_Group>,
Visibility<[DXCOption]>,
HelpText<"HLSL Version">,
- Values<"hlsl2016, hlsl2017, hlsl2018, hlsl2021, hlsl202x">,
+ Values<"2016, 2017, 2018, 2021, 202x">,
NormalizedValuesScope<"LangStandard">,
- NormalizedValues<["2016", "2017", "2018", "2021", "202x"]>;
+ NormalizedValues<["hlsl2016", "hlsl2017", "hlsl2018", "hlsl2021", "hlsl202x"]>;
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/test/Options/HV.hlsl b/clang/test/Options/HV.hlsl
index 6ede3cb8edb9af..9f7e1ebc02f251 100644
--- a/clang/test/Options/HV.hlsl
+++ b/clang/test/Options/HV.hlsl
@@ -12,7 +12,7 @@
// 2021: "-std=hlsl2021"
// 202x: "-std=hlsl202x"
// NO_HV-NOT: "-std="
-// CHECK-ERR: error: Driver argument 'HV' has invalid value 'gibberish'
+// CHECK-ERR: error: invalid value 'gibberish' in 'HV'
float4 main(float4 a : A) : SV_TARGET
{
return -a.yxxx;
>From 777a785f33c9a2b1910ecec0dcbe74758ac7d3e1 Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Wed, 13 Mar 2024 12:21:36 -0700
Subject: [PATCH 11/14] Update
clang/include/clang/Basic/DiagnosticDriverKinds.td
Co-authored-by: Chris B <cbieneman at microsoft.com>
---
clang/include/clang/Basic/DiagnosticDriverKinds.td | 1 -
1 file changed, 1 deletion(-)
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 02c6c878d049d9..1bc9885849d54b 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,7 +753,6 @@ def err_drv_hlsl_bad_shader_required_in_target : Error<
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. "
"Resulting DXIL will not be validated or signed for use in release environments.">,
InGroup<DXILValidation>;
>From 3060f62cd3a3c60089fc5286b748221590a7b544 Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Wed, 13 Mar 2024 12:21:46 -0700
Subject: [PATCH 12/14] Update clang/include/clang/Driver/Options.td
Co-authored-by: Chris B <cbieneman at microsoft.com>
---
clang/include/clang/Driver/Options.td | 2 --
1 file changed, 2 deletions(-)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index f71f5df9dd62d6..402107687bfdb7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8550,8 +8550,6 @@ def dxc_hlsl_version : Option<["/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
Visibility<[DXCOption]>,
HelpText<"HLSL Version">,
Values<"2016, 2017, 2018, 2021, 202x">,
- NormalizedValuesScope<"LangStandard">,
- NormalizedValues<["hlsl2016", "hlsl2017", "hlsl2018", "hlsl2021", "hlsl202x"]>;
def dxc_validator_path_EQ : Joined<["--"], "dxv-path=">, Group<dxc_Group>,
HelpText<"DXIL validator installation path">;
def dxc_disable_validation : DXCFlag<"Vd">,
>From 44ee342496fa46e6ffa2a3e1ad912a15f54b2020 Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Wed, 13 Mar 2024 12:27:39 -0700
Subject: [PATCH 13/14] clang format
---
clang/lib/Driver/ToolChains/HLSL.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp b/clang/lib/Driver/ToolChains/HLSL.cpp
index 0138a7866aca7d..05aac9caa7fb29 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -235,8 +235,7 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
l.getName());
} else {
- getDriver().Diag(diag::err_drv_invalid_value)
- << "HV" << A->getValue();
+ getDriver().Diag(diag::err_drv_invalid_value) << "HV" << A->getValue();
}
A->claim();
>From cbb0f2eeb075b37e52eb3ef6d2d31b3658a7831b Mon Sep 17 00:00:00 2001
From: Joshua Batista <jbatista at microsoft.com>
Date: Wed, 13 Mar 2024 14:07:08 -0700
Subject: [PATCH 14/14] add semi
---
clang/include/clang/Driver/Options.td | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 402107687bfdb7..3f0781e3efb98b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8549,7 +8549,7 @@ def dxc_hlsl_version : Option<["/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
Group<dxc_Group>,
Visibility<[DXCOption]>,
HelpText<"HLSL Version">,
- Values<"2016, 2017, 2018, 2021, 202x">,
+ Values<"2016, 2017, 2018, 2021, 202x">;
def dxc_validator_path_EQ : Joined<["--"], "dxv-path=">, Group<dxc_Group>,
HelpText<"DXIL validator installation path">;
def dxc_disable_validation : DXCFlag<"Vd">,
More information about the cfe-commits
mailing list