================ @@ -342,8 +343,19 @@ llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> &B, return B.CreateCall(FunctionCallee(DxGroupIndex)); } if (D.hasAttr<HLSLSV_DispatchThreadIDAttr>()) { - llvm::Function *DxThreadID = CGM.getIntrinsic(Intrinsic::dx_thread_id); - return buildVectorInput(B, DxThreadID, Ty); + llvm::Function *ThreadIDIntrinsic; + switch (CGM.getTarget().getTriple().getArch()) { + case llvm::Triple::dxil: + ThreadIDIntrinsic = CGM.getIntrinsic(Intrinsic::dx_thread_id); + break; + case llvm::Triple::spirv: + ThreadIDIntrinsic = CGM.getIntrinsic(Intrinsic::spv_thread_id); + break; + default: + llvm_unreachable("Input semantic not supported by target"); + break; + } + return buildVectorInput(B, ThreadIDIntrinsic, Ty); ---------------- llvm-beanz wrote:
We could do something like this: ```c++ // Generated target intrinsic enums by gen_intrin enum DXIntrinsics { dx_thread_id, }; enum SPIRVIntrinsics { spv_thread_id, }; // Target-agnostic define we maintain somewhere... enum class HLSLIntrinsic { thread_id, }; template<HLSLIntrinsic V> struct HLSLTargetIntrinsicMapping; #define HLSL_TARGET_INTRINSIC_MAPPING(Generic, DX, SPV) \ template<> \ struct HLSLTargetIntrinsicMapping<Generic>{ \ static DXIntrinsics DirectX() { \ return DX; \ } \ static SPIRVIntrinsics SPIRV() { \ return SPV; \ } \ } ``` [Compler Explorer](https://godbolt.org/z/Wxv65KPdz) Then we just need to define the generic enum case and the mapping and the template foo is generated by macros. This makes the expression `HLSLTargetIntrinsicMapping<HLSLIntrinsic::thread_id>::SPIRV()` or `HLSLTargetIntrinsicMapping<HLSLIntrinsic::thread_id>::DirectX()` compile-time resolvable. https://github.com/llvm/llvm-project/pull/82536 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits