[clang] [HLSL] generate hlsl.wavesize attribute (PR #107176)
Xiang Li via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 11 13:26:17 PDT 2024
https://github.com/python3kgae updated https://github.com/llvm/llvm-project/pull/107176
>From 3b4ba1436220d6eef11bce713618aefb272ea74f Mon Sep 17 00:00:00 2001
From: Xiang Li <python3kgae at outlook.com>
Date: Tue, 3 Sep 2024 22:56:21 -0400
Subject: [PATCH 1/2] [HLSL] generate hlsl.wavesize attribute
Generate function attribute hlsl.wavesize from [WaveSize].
For #70118
---
clang/lib/CodeGen/CGHLSLRuntime.cpp | 7 +++++++
clang/test/CodeGenHLSL/wavesize.hlsl | 25 +++++++++++++++++++++++++
2 files changed, 32 insertions(+)
create mode 100644 clang/test/CodeGenHLSL/wavesize.hlsl
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 4bd7b6ba58de0d..28ff1153c8e1e3 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -337,6 +337,13 @@ void clang::CodeGen::CGHLSLRuntime::setHLSLEntryAttributes(
NumThreadsAttr->getZ());
Fn->addFnAttr(NumThreadsKindStr, NumThreadsStr);
}
+ if (HLSLWaveSizeAttr *WaveSizeAttr = FD->getAttr<HLSLWaveSizeAttr>()) {
+ const StringRef WaveSizeKindStr = "hlsl.wavesize";
+ std::string WaveSizeStr =
+ formatv("{0},{1},{2}", WaveSizeAttr->getMin(), WaveSizeAttr->getMax(),
+ WaveSizeAttr->getPreferred());
+ Fn->addFnAttr(WaveSizeKindStr, WaveSizeStr);
+ }
}
static Value *buildVectorInput(IRBuilder<> &B, Function *F, llvm::Type *Ty) {
diff --git a/clang/test/CodeGenHLSL/wavesize.hlsl b/clang/test/CodeGenHLSL/wavesize.hlsl
new file mode 100644
index 00000000000000..ae4b2f17c543e0
--- /dev/null
+++ b/clang/test/CodeGenHLSL/wavesize.hlsl
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN: dxil-pc-shadermodel6.6-compute %s -DSM66 -hlsl-entry foo \
+// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN: dxil-pc-shadermodel6.8-compute %s -hlsl-entry foo \
+// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s --check-prefix=CHECK-SM68
+
+
+// Make sure wavesize attribute get correct value for sm66 and sm68.
+// CHECK:define void @foo()
+// CHECK:"hlsl.wavesize"="8,0,0"
+
+// CHECK-SM68:define void @foo()
+// CHECK-SM68:"hlsl.wavesize"="8,128,64"
+
+[numthreads(16,8,1)]
+#ifdef SM66
+[WaveSize(8)]
+#else
+[WaveSize(8, 128, 64)]
+#endif
+void foo() {
+
+}
>From 89b2e88060adfa219e97026c14155a903ab4ecc0 Mon Sep 17 00:00:00 2001
From: Xiang Li <python3kgae at outlook.com>
Date: Wed, 11 Sep 2024 16:26:02 -0400
Subject: [PATCH 2/2] Add another test.
---
clang/test/CodeGenHLSL/wavesize.hlsl | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/clang/test/CodeGenHLSL/wavesize.hlsl b/clang/test/CodeGenHLSL/wavesize.hlsl
index ae4b2f17c543e0..fcb817ce0d0629 100644
--- a/clang/test/CodeGenHLSL/wavesize.hlsl
+++ b/clang/test/CodeGenHLSL/wavesize.hlsl
@@ -2,6 +2,10 @@
// RUN: dxil-pc-shadermodel6.6-compute %s -DSM66 -hlsl-entry foo \
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN: dxil-pc-shadermodel6.8-compute %s -DNO_PREFERR -hlsl-entry foo \
+// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s --check-prefix=NO_PREFERR
+
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
// RUN: dxil-pc-shadermodel6.8-compute %s -hlsl-entry foo \
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s --check-prefix=CHECK-SM68
@@ -11,12 +15,17 @@
// CHECK:define void @foo()
// CHECK:"hlsl.wavesize"="8,0,0"
+// NO_PREFERR:define void @foo()
+// NO_PREFERR:"hlsl.wavesize"="8,128,0"
+
// CHECK-SM68:define void @foo()
// CHECK-SM68:"hlsl.wavesize"="8,128,64"
[numthreads(16,8,1)]
#ifdef SM66
[WaveSize(8)]
+#elif NO_PREFERR
+[WaveSize(8, 128)]
#else
[WaveSize(8, 128, 64)]
#endif
More information about the cfe-commits
mailing list