[clang] [SPIRV] Add -spirv option to DXC driver (PR #65989)
Natalie Chouinard via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 11 11:11:40 PDT 2023
https://github.com/sudonatalie created https://github.com/llvm/llvm-project/pull/65989:
Add an option to target SPIR-V to the clang-dxc driver, which sets the target triple's architecture to logical SPIR-V.
>From 699235b506e1949293305973429bd3ec3ee1b9e4 Mon Sep 17 00:00:00 2001
From: Natalie Chouinard <chouinard at google.com>
Date: Mon, 11 Sep 2023 18:08:17 +0000
Subject: [PATCH] [SPIRV] Add -spirv option to DXC driver
Add an option to target SPIR-V to the clang-dxc driver, which sets the
target triple's architecture to logical SPIR-V.
---
clang/include/clang/Driver/Options.td | 2 ++
clang/lib/Driver/Driver.cpp | 6 ++++++
clang/test/Driver/dxc_spirv.hlsl | 4 ++++
clang/test/Driver/hlsl-lang-targets.hlsl | 5 ++---
4 files changed, 14 insertions(+), 3 deletions(-)
create mode 100644 clang/test/Driver/dxc_spirv.hlsl
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index a5f5ca29053b43b..a7b8f1d9a0e0f2d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8258,3 +8258,5 @@ def dxc_disable_validation : DXCFlag<"Vd">,
def : Option<["/", "-"], "Qembed_debug", KIND_FLAG>, Group<dxc_Group>,
Flags<[Ignored, NoXarchOption]>, Visibility<[DXCOption]>,
HelpText<"Embed PDB in shader container (ignored)">;
+def spirv : DXCFlag<"spirv">,
+ HelpText<"Generate SPIR-V code">;
\ No newline at end of file
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ba723eac2a7ee74..39b1df45a410db7 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1302,6 +1302,12 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
Diag(diag::err_drv_invalid_directx_shader_module) << TargetProfile;
A->claim();
+
+ if (Args.hasArg(options::OPT_spirv)) {
+ llvm::Triple T(TargetTriple);
+ T.setArch(llvm::Triple::spirv);
+ TargetTriple = T.str();
+ }
} else {
Diag(diag::err_drv_dxc_missing_target_profile);
}
diff --git a/clang/test/Driver/dxc_spirv.hlsl b/clang/test/Driver/dxc_spirv.hlsl
new file mode 100644
index 000000000000000..387b71ca58ada18
--- /dev/null
+++ b/clang/test/Driver/dxc_spirv.hlsl
@@ -0,0 +1,4 @@
+// RUN: %clang_dxc -T cs_6_0 -spirv -### %s 2>&1 | FileCheck %s
+
+// CHECK: "-triple" "spirv-unknown-shadermodel6.0-compute"
+// CHECK-SAME: "-x" "hlsl"
\ No newline at end of file
diff --git a/clang/test/Driver/hlsl-lang-targets.hlsl b/clang/test/Driver/hlsl-lang-targets.hlsl
index a757e2a3cdf74de..9adfeb3d0753b40 100644
--- a/clang/test/Driver/hlsl-lang-targets.hlsl
+++ b/clang/test/Driver/hlsl-lang-targets.hlsl
@@ -1,7 +1,7 @@
// RUN: not %clang -target x86_64-unknown-unknown %s 2>&1 | FileCheck %s --check-prefix=X86
// RUN: not %clang -target dxil-unknown-unknown %s 2>&1 | FileCheck %s --check-prefix=DXIL
// RUN: not %clang -target x86_64-unknown-shadermodel %s 2>&1 | FileCheck %s --check-prefix=SM
-// RUN: not %clang -target spirv64-unknown-unknown %s 2>&1 | FileCheck %s --check-prefix=SPIRV
+// RUN: not %clang -target spirv-unknown-unknown %s 2>&1 | FileCheck %s --check-prefix=SPIRV
// A completely unsupported target...
@@ -10,5 +10,4 @@
// Poorly specified targets
// DXIL: error: HLSL code generation is unsupported for target 'dxil-unknown-unknown'
// SM: error: HLSL code generation is unsupported for target 'x86_64-unknown-shadermodel'
-
-// FIXME// SPIRV: error: HLSL code generation is unsupported for target 'spirv64-unknown-unknown'
+// SPIRV: error: HLSL code generation is unsupported for target 'spirv-unknown-unknown'
More information about the cfe-commits
mailing list