Skip to content

Commit

Permalink
[HLSL] clang codeGen for HLSLNumThreadsAttr
Browse files Browse the repository at this point in the history
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
  • Loading branch information
python3kgae committed Sep 22, 2022
1 parent 1ab2b00 commit bad2e6c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 8 additions & 0 deletions clang/lib/CodeGen/CGHLSLRuntime.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions clang/test/CodeGenHLSL/entry.hlsl
Expand Up @@ -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() {

}

0 comments on commit bad2e6c

Please sign in to comment.