[PATCH] D131799: [HLSL] clang codeGen for HLSLNumThreadsAttr

Xiang Li via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 19 09:50:11 PDT 2022


python3kgae updated this revision to Diff 454051.
python3kgae marked 2 inline comments as done.
python3kgae added a comment.

Use llvm::formatv.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131799/new/

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:"hlsl.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
@@ -17,6 +17,7 @@
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/IR/Metadata.h"
 #include "llvm/IR/Module.h"
+#include "llvm/Support/FormatVariadic.h"
 
 using namespace clang;
 using namespace CodeGen;
@@ -94,4 +95,11 @@
     F->addFnAttr(ShaderAttrKindStr,
                  ShaderAttr->ConvertShaderTypeToStr(ShaderAttr->getType()));
   }
+  if (HLSLNumThreadsAttr *NumThreadsAttr = FD->getAttr<HLSLNumThreadsAttr>()) {
+    const StringRef NumThreadsKindStr = "hlsl.numthreads";
+    StringRef NumThreadsStr =
+        formatv("{0},{1},{2}", NumThreadsAttr->getX(), NumThreadsAttr->getY(),
+                NumThreadsAttr->getZ());
+    F->addFnAttr(NumThreadsKindStr, NumThreadsStr);
+  }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131799.454051.patch
Type: text/x-patch
Size: 1365 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220819/73358efc/attachment.bin>


More information about the cfe-commits mailing list