[clang] [llvm] [HLSL] Add QuadAll Emulation support (PR #240645)
Helena Kotas via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 13 00:18:58 PST 2026
================
@@ -1000,6 +1001,37 @@ void CGHLSLRuntime::addHLSLBufferLayoutType(const RecordType *StructType,
LayoutTypes[StructType] = LayoutTy;
}
+static void addSPIRVQuadAllExecutionModes(llvm::Module &M) {
+ Function *QuadAll =
+ Intrinsic::getDeclarationIfExists(&M, Intrinsic::spv_quad_all);
+ if (!QuadAll)
+ return;
+
+ SmallVector<Function *, 8> Worklist{QuadAll};
+ SmallPtrSet<Function *, 16> Visited;
+ IRBuilder<> B(M);
+ while (!Worklist.empty()) {
+ Function *F = Worklist.pop_back_val();
+ if (!Visited.insert(F).second)
+ continue;
+
+ if (F->hasFnAttribute("hlsl.numthreads")) {
+ StringRef NumThreads =
+ F->getFnAttribute("hlsl.numthreads").getValueAsString();
+ // DerivativeGroupLinearKHR is 5290; DerivativeGroupQuadsKHR is 5289.
+ unsigned Mode = NumThreads.ends_with(",1,1") ? 5290 : 5289;
----------------
hekota wrote:
It would be good to define a subset of the SPIRV execution mode values as a class enum instead of using the numbers directly:
```
enum class SPIRVExecutionMode : uint32_t {
DerivativeGroupQuadsKHR = 5289,
DerivativeGroupLinearKHR = 5290
};
```
A good place would be to either put them a header in `llvm/include/llvm/Frontend/HLSL`, though none of the existing headers seems like a good fit. Maybe create a new one `SPIRVConstants.h`? Or I guess it could go here in CGHLSLRuntime.cpp (at the top of the file after `using`).
https://github.com/llvm/llvm-project/pull/240645
More information about the cfe-commits
mailing list