diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -94,4 +94,13 @@ F->addFnAttr(ShaderAttrKindStr, ShaderAttr->ConvertShaderTypeToStr(ShaderAttr->getType())); } + if (HLSLNumThreadsAttr *NumThreadsAttr = FD->getAttr()) { + const StringRef NumThreadsKindStr = "hlsl.numthreads"; + std::string NumThreadsStr; + raw_string_ostream OS(NumThreadsStr); + OS << NumThreadsAttr->getX() << "," << NumThreadsAttr->getY() << "," + << NumThreadsAttr->getZ(); + OS.flush(); + F->addFnAttr(NumThreadsKindStr, NumThreadsStr); + } } diff --git a/clang/test/CodeGenHLSL/entry.hlsl b/clang/test/CodeGenHLSL/entry.hlsl --- a/clang/test/CodeGenHLSL/entry.hlsl +++ b/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() { }