[PATCH] D131799: [HLSL] clang codeGen for HLSLNumThreadsAttr
Xiang Li via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 12 11:51:23 PDT 2022
python3kgae created this revision.
python3kgae added reviewers: bogner, beanz, pow2clk.
Herald added a subscriber: Anastasia.
Herald added a project: All.
python3kgae requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Translate HLSLNumThreadsAttr into function attribute with name "dx.numthreads" and value format as "x,y,z".
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D131799
Files:
clang/lib/CodeGen/CGHLSLRuntime.cpp
clang/test/CodeGenHLSL/entry.hlsl
Index: clang/test/CodeGenHLSL/entry.hlsl
===================================================================
--- clang/test/CodeGenHLSL/entry.hlsl
+++ clang/test/CodeGenHLSL/entry.hlsl
@@ -3,8 +3,9 @@
// Make sure not mangle entry.
// CHECK:define void @foo()
// Make sure add function attribute.
-// CHECK:"dx.shader"="compute"
-[numthreads(1,1,1)]
+// CHECK:"dx.numthreads"="16,8,1"
+// CHECK-SAME:"dx.shader"="compute"
+[numthreads(16,8,1)]
void foo() {
}
Index: clang/lib/CodeGen/CGHLSLRuntime.cpp
===================================================================
--- clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -94,4 +94,13 @@
F->addFnAttr(ShaderAttrKindStr,
ShaderAttr->ConvertShaderTypeToStr(ShaderAttr->getType()));
}
+ if (HLSLNumThreadsAttr *NumThreadsAttr = FD->getAttr<HLSLNumThreadsAttr>()) {
+ const StringRef NumThreadsKindStr = "dx.numthreads";
+ std::string NumThreadsStr;
+ raw_string_ostream OS(NumThreadsStr);
+ OS << NumThreadsAttr->getX() << "," << NumThreadsAttr->getY() << ","
+ << NumThreadsAttr->getZ();
+ OS.flush();
+ F->addFnAttr(NumThreadsKindStr, NumThreadsStr);
+ }
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131799.452262.patch
Type: text/x-patch
Size: 1197 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220812/dc944d56/attachment.bin>
More information about the cfe-commits
mailing list