2424using namespace llvm ;
2525using namespace hlsl ;
2626
27- class DxilScalarizeVectorLoadStores : public ModulePass {
28- private:
29- void scalarizeVectorLoad (hlsl::OP *HlslOP, const DataLayout &DL,
30- CallInst *CI);
31- void scalarizeVectorStore (hlsl::OP *HlslOP, const DataLayout &DL,
32- CallInst *CI);
27+ static void scalarizeVectorLoad (hlsl::OP *HlslOP, const DataLayout &DL,
28+ CallInst *CI);
29+ static void scalarizeVectorStore (hlsl::OP *HlslOP, const DataLayout &DL,
30+ CallInst *CI);
3331
32+ class DxilScalarizeVectorLoadStores : public ModulePass {
3433public:
3534 static char ID; // Pass identification, replacement for typeid
3635 explicit DxilScalarizeVectorLoadStores () : ModulePass(ID) {}
@@ -48,25 +47,22 @@ class DxilScalarizeVectorLoadStores : public ModulePass {
4847 bool Changed = false ;
4948
5049 hlsl::OP *HlslOP = DM.GetOP ();
51- for (auto F = M.functions ().begin (), E = M.functions ().end (); F != E;) {
52- Function *Func = &*(F++);
53- DXIL::OpCodeClass OpClass;
54- if (HlslOP->GetOpCodeClass (Func, OpClass)) {
55- if (OpClass == DXIL::OpCodeClass::RawBufferVectorLoad) {
56- for (auto U = Func->user_begin (), UE = Func->user_end (); U != UE;) {
57- CallInst *CI = cast<CallInst>(*(U++));
58- scalarizeVectorLoad (HlslOP, M.getDataLayout (), CI);
59- Changed = true ;
60- }
61- Func->eraseFromParent ();
62- } else if (OpClass == DXIL::OpCodeClass::RawBufferVectorStore) {
63- for (auto U = Func->user_begin (), UE = Func->user_end (); U != UE;) {
64- CallInst *CI = cast<CallInst>(*(U++));
65- scalarizeVectorStore (HlslOP, M.getDataLayout (), CI);
66- Changed = true ;
67- }
68- Func->eraseFromParent ();
69- }
50+ for (auto FIt : HlslOP->GetOpFuncList (DXIL::OpCode::RawBufferVectorLoad)) {
51+ Function *Func = FIt.second ;
52+ if (!Func) continue ;
53+ for (auto U = Func->user_begin (), UE = Func->user_end (); U != UE;) {
54+ CallInst *CI = cast<CallInst>(*(U++));
55+ scalarizeVectorLoad (HlslOP, M.getDataLayout (), CI);
56+ Changed = true ;
57+ }
58+ }
59+ for (auto FIt : HlslOP->GetOpFuncList (DXIL::OpCode::RawBufferVectorStore)) {
60+ Function *Func = FIt.second ;
61+ if (!Func) continue ;
62+ for (auto U = Func->user_begin (), UE = Func->user_end (); U != UE;) {
63+ CallInst *CI = cast<CallInst>(*(U++));
64+ scalarizeVectorStore (HlslOP, M.getDataLayout (), CI);
65+ Changed = true ;
7066 }
7167 }
7268 return Changed;
@@ -90,16 +86,15 @@ static unsigned GetRawBufferMask(unsigned NumComponents) {
9086 return DXIL::kCompMask_All ;
9187}
9288
93- void DxilScalarizeVectorLoadStores::scalarizeVectorLoad (hlsl::OP *HlslOP,
94- const DataLayout &DL,
95- CallInst *CI) {
89+ static void scalarizeVectorLoad (hlsl::OP *HlslOP, const DataLayout &DL,
90+ CallInst *CI) {
9691 IRBuilder<> Builder (CI);
9792 // Collect the information required to break this into scalar ops from args.
9893 DxilInst_RawBufferVectorLoad VecLd (CI);
9994 OP::OpCode OpCode = OP::OpCode::RawBufferLoad;
100- llvm::Constant *opArg = Builder.getInt32 ((unsigned )OpCode);
95+ llvm::Constant *OpArg = Builder.getInt32 ((unsigned )OpCode);
10196 SmallVector<Value *, 10 > Args;
102- Args.emplace_back (opArg ); // opcode @0.
97+ Args.emplace_back (OpArg ); // opcode @0.
10398 Args.emplace_back (VecLd.get_buf ()); // Resource handle @1.
10499 Args.emplace_back (VecLd.get_index ()); // Index @2.
105100 Args.emplace_back (VecLd.get_elementOffset ()); // Offset @3.
@@ -161,16 +156,15 @@ void DxilScalarizeVectorLoadStores::scalarizeVectorLoad(hlsl::OP *HlslOP,
161156 CI->eraseFromParent ();
162157}
163158
164- void DxilScalarizeVectorLoadStores::scalarizeVectorStore (hlsl::OP *HlslOP,
165- const DataLayout &DL,
166- CallInst *CI) {
159+ static void scalarizeVectorStore (hlsl::OP *HlslOP, const DataLayout &DL,
160+ CallInst *CI) {
167161 IRBuilder<> Builder (CI);
168162 // Collect the information required to break this into scalar ops from args.
169163 DxilInst_RawBufferVectorStore VecSt (CI);
170164 OP::OpCode OpCode = OP::OpCode::RawBufferStore;
171- llvm::Constant *opArg = Builder.getInt32 ((unsigned )OpCode);
165+ llvm::Constant *OpArg = Builder.getInt32 ((unsigned )OpCode);
172166 SmallVector<Value *, 10 > Args;
173- Args.emplace_back (opArg ); // opcode @0.
167+ Args.emplace_back (OpArg ); // opcode @0.
174168 Args.emplace_back (VecSt.get_uav ()); // Resource handle @1.
175169 Args.emplace_back (VecSt.get_index ()); // Index @2.
176170 Args.emplace_back (VecSt.get_elementOffset ()); // Offset @3.
0 commit comments