From 25350b65d0d9e0de326049cc182112b7ee5f23c6 Mon Sep 17 00:00:00 2001 From: Ashley Coleman Date: Thu, 9 Oct 2025 17:48:15 -0600 Subject: [PATCH 1/2] [NFC] Fix clang-tidy warnings --- lib/HLSL/DxilScalarizeVectorIntrinsics.cpp | 165 ++++++++++----------- lib/HLSL/HLOperationLower.cpp | 2 +- 2 files changed, 81 insertions(+), 86 deletions(-) diff --git a/lib/HLSL/DxilScalarizeVectorIntrinsics.cpp b/lib/HLSL/DxilScalarizeVectorIntrinsics.cpp index 5a5941e8fa..cac5595780 100644 --- a/lib/HLSL/DxilScalarizeVectorIntrinsics.cpp +++ b/lib/HLSL/DxilScalarizeVectorIntrinsics.cpp @@ -28,85 +28,9 @@ using namespace llvm; using namespace hlsl; -static bool scalarizeVectorLoad(hlsl::OP *HlslOP, const DataLayout &DL, - CallInst *CI); -static bool scalarizeVectorStore(hlsl::OP *HlslOP, const DataLayout &DL, - CallInst *CI); -static bool scalarizeVectorIntrinsic(hlsl::OP *HlslOP, CallInst *CI); -static bool scalarizeVectorReduce(hlsl::OP *HlslOP, CallInst *CI); -static bool scalarizeVectorDot(hlsl::OP *HlslOP, CallInst *CI); -static bool scalarizeVectorWaveMatch(hlsl::OP *HlslOP, CallInst *CI); +namespace { -class DxilScalarizeVectorIntrinsics : public ModulePass { -public: - static char ID; // Pass identification, replacement for typeid - explicit DxilScalarizeVectorIntrinsics() : ModulePass(ID) {} - - StringRef getPassName() const override { - return "DXIL scalarize vector load/stores"; - } - - bool runOnModule(Module &M) override { - DxilModule &DM = M.GetOrCreateDxilModule(); - // Shader Model 6.9 allows native vectors and doesn't need this pass. - if (DM.GetShaderModel()->IsSM69Plus()) - return false; - - bool Changed = false; - - hlsl::OP *HlslOP = DM.GetOP(); - - // Iterate and scalarize native vector loads, stores, and other intrinsics. - for (auto F = M.functions().begin(); F != M.functions().end();) { - Function *Func = &*(F++); - DXIL::OpCodeClass OpClass; - if (!HlslOP->GetOpCodeClass(Func, OpClass)) - continue; - - const bool CouldRewrite = - (Func->getReturnType()->isVectorTy() || - OpClass == DXIL::OpCodeClass::RawBufferVectorLoad || - OpClass == DXIL::OpCodeClass::RawBufferVectorStore || - OpClass == DXIL::OpCodeClass::VectorReduce || - OpClass == DXIL::OpCodeClass::Dot || - OpClass == DXIL::OpCodeClass::WaveMatch); - if (!CouldRewrite) - continue; - - for (auto U = Func->user_begin(), UE = Func->user_end(); U != UE;) { - CallInst *CI = cast(*(U++)); - - // Handle DXIL operations with complex signatures separately - switch (OpClass) { - case DXIL::OpCodeClass::RawBufferVectorLoad: - Changed |= scalarizeVectorLoad(HlslOP, M.getDataLayout(), CI); - continue; - case DXIL::OpCodeClass::RawBufferVectorStore: - Changed |= scalarizeVectorStore(HlslOP, M.getDataLayout(), CI); - continue; - case DXIL::OpCodeClass::VectorReduce: - Changed |= scalarizeVectorReduce(HlslOP, CI); - continue; - case DXIL::OpCodeClass::Dot: - Changed |= scalarizeVectorDot(HlslOP, CI); - continue; - case DXIL::OpCodeClass::WaveMatch: - Changed |= scalarizeVectorWaveMatch(HlslOP, CI); - continue; - default: - break; - } - - // Handle DXIL Ops with vector return matching the vector params - if (Func->getReturnType()->isVectorTy()) - Changed |= scalarizeVectorIntrinsic(HlslOP, CI); - } - } - return Changed; - } -}; - -static unsigned GetRawBufferMask(unsigned NumComponents) { +unsigned GetRawBufferMask(unsigned NumComponents) { switch (NumComponents) { case 0: return 0; @@ -123,7 +47,7 @@ static unsigned GetRawBufferMask(unsigned NumComponents) { return DXIL::kCompMask_All; } -static bool scalarizeVectorLoad(hlsl::OP *HlslOP, const DataLayout &DL, +bool scalarizeVectorLoad(hlsl::OP *HlslOP, const DataLayout &DL, CallInst *CI) { IRBuilder<> Builder(CI); // Collect the information required to break this into scalar ops from args. @@ -177,7 +101,7 @@ static bool scalarizeVectorLoad(hlsl::OP *HlslOP, const DataLayout &DL, // Replace users of the vector extracted from the vector load resret. Value *Status = nullptr; for (auto CU = CI->user_begin(), CE = CI->user_end(); CU != CE;) { - auto EV = cast(*(CU++)); + auto *EV = cast(*(CU++)); unsigned Ix = EV->getIndices()[0]; if (Ix == 0) { // Handle value uses. @@ -195,7 +119,7 @@ static bool scalarizeVectorLoad(hlsl::OP *HlslOP, const DataLayout &DL, return true; } -static bool scalarizeVectorStore(hlsl::OP *HlslOP, const DataLayout &DL, +bool scalarizeVectorStore(hlsl::OP *HlslOP, const DataLayout &DL, CallInst *CI) { IRBuilder<> Builder(CI); // Collect the information required to break this into scalar ops from args. @@ -259,7 +183,7 @@ static bool scalarizeVectorStore(hlsl::OP *HlslOP, const DataLayout &DL, return true; } -static bool scalarizeVectorReduce(hlsl::OP *HlslOP, CallInst *CI) { +bool scalarizeVectorReduce(CallInst *CI) { IRBuilder<> Builder(CI); OP::OpCode ReduceOp = OP::getOpCode(CI); @@ -288,7 +212,7 @@ static bool scalarizeVectorReduce(hlsl::OP *HlslOP, CallInst *CI) { return true; } -static bool scalarizeVectorWaveMatch(hlsl::OP *HlslOP, CallInst *CI) { +bool scalarizeVectorWaveMatch(hlsl::OP *HlslOP, CallInst *CI) { IRBuilder<> Builder(CI); OP::OpCode Opcode = OP::getOpCode(CI); Value *VecArg = CI->getArgOperand(1); @@ -344,7 +268,7 @@ static bool scalarizeVectorWaveMatch(hlsl::OP *HlslOP, CallInst *CI) { } // Scalarize vectorized dot product -static bool scalarizeVectorDot(hlsl::OP *HlslOP, CallInst *CI) { +bool scalarizeVectorDot(hlsl::OP *HlslOP, CallInst *CI) { IRBuilder<> Builder(CI); Value *AVecArg = CI->getArgOperand(1); @@ -406,7 +330,7 @@ static bool scalarizeVectorDot(hlsl::OP *HlslOP, CallInst *CI) { // Scalarize native vector operation represented by `CI`, generating // scalar calls for each element of the its vector parameters. // Use `HlslOP` to retrieve the associated scalar op function. -static bool scalarizeVectorIntrinsic(hlsl::OP *HlslOP, CallInst *CI) { +bool scalarizeVectorIntrinsic(hlsl::OP *HlslOP, CallInst *CI) { IRBuilder<> Builder(CI); VectorType *VT = cast(CI->getType()); @@ -440,6 +364,77 @@ static bool scalarizeVectorIntrinsic(hlsl::OP *HlslOP, CallInst *CI) { return true; } +} // namespace + +class DxilScalarizeVectorIntrinsics : public ModulePass { +public: + static char ID; // Pass identification, replacement for typeid + explicit DxilScalarizeVectorIntrinsics() : ModulePass(ID) {} + + StringRef getPassName() const override { + return "DXIL scalarize vector load/stores"; + } + + bool runOnModule(Module &M) override { + DxilModule &DM = M.GetOrCreateDxilModule(); + // Shader Model 6.9 allows native vectors and doesn't need this pass. + if (DM.GetShaderModel()->IsSM69Plus()) + return false; + + bool Changed = false; + + hlsl::OP *HlslOP = DM.GetOP(); + + // Iterate and scalarize native vector loads, stores, and other intrinsics. + for (auto F = M.functions().begin(); F != M.functions().end();) { + Function *Func = &*(F++); + DXIL::OpCodeClass OpClass; + if (!HlslOP->GetOpCodeClass(Func, OpClass)) + continue; + + const bool CouldRewrite = + (Func->getReturnType()->isVectorTy() || + OpClass == DXIL::OpCodeClass::RawBufferVectorLoad || + OpClass == DXIL::OpCodeClass::RawBufferVectorStore || + OpClass == DXIL::OpCodeClass::VectorReduce || + OpClass == DXIL::OpCodeClass::Dot || + OpClass == DXIL::OpCodeClass::WaveMatch); + if (!CouldRewrite) + continue; + + for (auto U = Func->user_begin(), UE = Func->user_end(); U != UE;) { + CallInst *CI = cast(*(U++)); + + // Handle DXIL operations with complex signatures separately + switch (OpClass) { + case DXIL::OpCodeClass::RawBufferVectorLoad: + Changed |= scalarizeVectorLoad(HlslOP, M.getDataLayout(), CI); + continue; + case DXIL::OpCodeClass::RawBufferVectorStore: + Changed |= scalarizeVectorStore(HlslOP, M.getDataLayout(), CI); + continue; + case DXIL::OpCodeClass::VectorReduce: + Changed |= scalarizeVectorReduce(CI); + continue; + case DXIL::OpCodeClass::Dot: + Changed |= scalarizeVectorDot(HlslOP, CI); + continue; + case DXIL::OpCodeClass::WaveMatch: + Changed |= scalarizeVectorWaveMatch(HlslOP, CI); + continue; + default: + break; + } + + // Handle DXIL Ops with vector return matching the vector params + if (Func->getReturnType()->isVectorTy()) + Changed |= scalarizeVectorIntrinsic(HlslOP, CI); + } + } + return Changed; + } +}; + char DxilScalarizeVectorIntrinsics::ID = 0; ModulePass *llvm::createDxilScalarizeVectorIntrinsicsPass() { diff --git a/lib/HLSL/HLOperationLower.cpp b/lib/HLSL/HLOperationLower.cpp index c9c9bb4c88..2f06069915 100644 --- a/lib/HLSL/HLOperationLower.cpp +++ b/lib/HLSL/HLOperationLower.cpp @@ -2606,7 +2606,7 @@ Value *TranslateDot(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode, Type *EltTy = Ty->getScalarType(); // SM6.9 introduced a DXIL operation for vectorized dot product - // The operation is only advantageous for vect size>1, vec1s will be + // The operation is only advantageous for vec size>1, vec1s will be // lowered to a single Mul. if (hlslOP->GetModule()->GetHLModule().GetShaderModel()->IsSM69Plus() && EltTy->isFloatingPointTy() && Ty->getVectorNumElements() > 1) { From d7caac320d215de93ed1aaa49c833105eb423260 Mon Sep 17 00:00:00 2001 From: Ashley Coleman Date: Thu, 9 Oct 2025 17:49:14 -0600 Subject: [PATCH 2/2] format --- lib/HLSL/DxilScalarizeVectorIntrinsics.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/HLSL/DxilScalarizeVectorIntrinsics.cpp b/lib/HLSL/DxilScalarizeVectorIntrinsics.cpp index cac5595780..9d04cd3529 100644 --- a/lib/HLSL/DxilScalarizeVectorIntrinsics.cpp +++ b/lib/HLSL/DxilScalarizeVectorIntrinsics.cpp @@ -47,8 +47,7 @@ unsigned GetRawBufferMask(unsigned NumComponents) { return DXIL::kCompMask_All; } -bool scalarizeVectorLoad(hlsl::OP *HlslOP, const DataLayout &DL, - CallInst *CI) { +bool scalarizeVectorLoad(hlsl::OP *HlslOP, const DataLayout &DL, CallInst *CI) { IRBuilder<> Builder(CI); // Collect the information required to break this into scalar ops from args. DxilInst_RawBufferVectorLoad VecLd(CI); @@ -120,7 +119,7 @@ bool scalarizeVectorLoad(hlsl::OP *HlslOP, const DataLayout &DL, } bool scalarizeVectorStore(hlsl::OP *HlslOP, const DataLayout &DL, - CallInst *CI) { + CallInst *CI) { IRBuilder<> Builder(CI); // Collect the information required to break this into scalar ops from args. DxilInst_RawBufferVectorStore VecSt(CI);