[clang] 162180d - [HLSL] Add -HV option translation to clang-dxc.exe (#83938)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 13 21:55:13 PDT 2024
Author: Joshua Batista
Date: 2024-03-13T21:55:09-07:00
New Revision: 162180decf532acd31c9aa4b876804848d1761c0
URL: https://github.com/llvm/llvm-project/commit/162180decf532acd31c9aa4b876804848d1761c0
DIFF: https://github.com/llvm/llvm-project/commit/162180decf532acd31c9aa4b876804848d1761c0.diff
LOG: [HLSL] Add -HV option translation to clang-dxc.exe (#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
---------
Co-authored-by: Chris B <cbieneman at microsoft.com>
Added:
clang/test/Options/HV.hlsl
Modified:
clang/include/clang/Basic/LangStandard.h
clang/include/clang/Driver/Options.td
clang/lib/Basic/LangStandards.cpp
clang/lib/Driver/ToolChains/HLSL.cpp
Removed:
################################################################################
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/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 1fac7b6f0093d8..a7e43b4d179a4d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8578,6 +8578,11 @@ 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">,
+ 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/Basic/LangStandards.cpp b/clang/lib/Basic/LangStandards.cpp
index ab09c7221dda92..cb2c0772349982 100644
--- a/clang/lib/Basic/LangStandards.cpp
+++ b/clang/lib/Basic/LangStandards.cpp
@@ -69,6 +69,16 @@ LangStandard::Kind LangStandard::getLangKind(StringRef Name) {
.Default(lang_unspecified);
}
+LangStandard::Kind LangStandard::getHLSLLangKind(StringRef Name) {
+ 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) {
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 c6ad862b229420..05aac9caa7fb29 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,6 +226,21 @@ 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
+ 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_invalid_value) << "HV" << A->getValue();
+ }
+
+ 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..9f7e1ebc02f251
--- /dev/null
+++ b/clang/test/Options/HV.hlsl
@@ -0,0 +1,20 @@
+// 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 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"
+// 2017: "-std=hlsl2017"
+// 2018: "-std=hlsl2018"
+// 2021: "-std=hlsl2021"
+// 202x: "-std=hlsl202x"
+// NO_HV-NOT: "-std="
+// CHECK-ERR: error: invalid value 'gibberish' in 'HV'
+float4 main(float4 a : A) : SV_TARGET
+{
+ return -a.yxxx;
+}
+
More information about the cfe-commits
mailing list