[clang] bad2e6c - [HLSL] clang codeGen for HLSLNumThreadsAttr
Xiang Li via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 22 15:31:06 PDT 2022
Author: Xiang Li
Date: 2022-09-22T15:30:52-07:00
New Revision: bad2e6c830de8c6ddc72f7ba3ace068fb62448ff
URL: https://github.com/llvm/llvm-project/commit/bad2e6c830de8c6ddc72f7ba3ace068fb62448ff
DIFF: https://github.com/llvm/llvm-project/commit/bad2e6c830de8c6ddc72f7ba3ace068fb62448ff.diff
LOG: [HLSL] clang codeGen for HLSLNumThreadsAttr
Translate HLSLNumThreadsAttr into function attribute with name "dx.numthreads" and value format as "x,y,z".
Reviewed By: beanz
Differential Revision: https://reviews.llvm.org/D131799
Added:
Modified:
clang/lib/CodeGen/CGHLSLRuntime.cpp
clang/test/CodeGenHLSL/entry.hlsl
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index c61a65813aea..20106ab66483 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -19,6 +19,7 @@
#include "llvm/IR/IntrinsicsDirectX.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
+#include "llvm/Support/FormatVariadic.h"
using namespace clang;
using namespace CodeGen;
@@ -107,6 +108,13 @@ void clang::CodeGen::CGHLSLRuntime::setHLSLEntryAttributes(
const StringRef ShaderAttrKindStr = "hlsl.shader";
Fn->addFnAttr(ShaderAttrKindStr,
ShaderAttr->ConvertShaderTypeToStr(ShaderAttr->getType()));
+ if (HLSLNumThreadsAttr *NumThreadsAttr = FD->getAttr<HLSLNumThreadsAttr>()) {
+ const StringRef NumThreadsKindStr = "hlsl.numthreads";
+ std::string NumThreadsStr =
+ formatv("{0},{1},{2}", NumThreadsAttr->getX(), NumThreadsAttr->getY(),
+ NumThreadsAttr->getZ());
+ Fn->addFnAttr(NumThreadsKindStr, NumThreadsStr);
+ }
}
llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> &B,
diff --git a/clang/test/CodeGenHLSL/entry.hlsl b/clang/test/CodeGenHLSL/entry.hlsl
index 9757a2be582f..ec4254e76fb6 100644
--- a/clang/test/CodeGenHLSL/entry.hlsl
+++ b/clang/test/CodeGenHLSL/entry.hlsl
@@ -4,9 +4,10 @@
// Make sure not mangle entry.
// CHECK:define void @foo()
-// Make sure add function attribute.
+// Make sure add function attribute and numthreads attribute.
+// CHECK:"hlsl.numthreads"="16,8,1"
// CHECK:"hlsl.shader"="compute"
-[numthreads(1,1,1)]
+[numthreads(16,8,1)]
void foo() {
}
More information about the cfe-commits
mailing list