Index: llvm/lib/Target/AMDGPU/AMDGPU.h =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPU.h +++ llvm/lib/Target/AMDGPU/AMDGPU.h @@ -16,6 +16,7 @@ namespace llvm { +class AMDGPUTargetMachine; class TargetMachine; // GlobalISel passes @@ -53,7 +54,7 @@ FunctionPass *createAMDGPULateCodeGenPreparePass(); FunctionPass *createAMDGPUMachineCFGStructurizerPass(); FunctionPass *createAMDGPURewriteOutArgumentsPass(); -ModulePass *createAMDGPULowerModuleLDSPass(); +ModulePass *createAMDGPULowerModuleLDSPass(const AMDGPUTargetMachine &TM); FunctionPass *createSIModeRegisterPass(); FunctionPass *createGCNPreRAOptimizationsPass(); @@ -116,6 +117,9 @@ extern char &AMDGPULowerModuleLDSID; struct AMDGPULowerModuleLDSPass : PassInfoMixin { + const AMDGPUTargetMachine &TM; + AMDGPULowerModuleLDSPass(const AMDGPUTargetMachine &TM_) : TM(TM_) {} + PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); }; Index: llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp +++ llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp @@ -253,6 +253,7 @@ } class AMDGPULowerModuleLDS : public ModulePass { + const AMDGPUTargetMachine &TM; static void removeLocalVarsFromUsedLists(Module &M, @@ -328,7 +329,8 @@ public: static char ID; - AMDGPULowerModuleLDS() : ModulePass(ID) { + AMDGPULowerModuleLDS(const AMDGPUTargetMachine &TM_) + : ModulePass(ID), TM(TM_) { initializeAMDGPULowerModuleLDSPass(*PassRegistry::getPassRegistry()); } @@ -1539,12 +1541,13 @@ "Lower uses of LDS variables from non-kernel functions", false, false) -ModulePass *llvm::createAMDGPULowerModuleLDSPass() { - return new AMDGPULowerModuleLDS(); +ModulePass * +llvm::createAMDGPULowerModuleLDSPass(const AMDGPUTargetMachine &TM) { + return new AMDGPULowerModuleLDS(TM); } PreservedAnalyses AMDGPULowerModuleLDSPass::run(Module &M, ModuleAnalysisManager &) { - return AMDGPULowerModuleLDS().runOnModule(M) ? PreservedAnalyses::none() - : PreservedAnalyses::all(); + return AMDGPULowerModuleLDS(TM).runOnModule(M) ? PreservedAnalyses::none() + : PreservedAnalyses::all(); } Index: llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp +++ llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp @@ -601,8 +601,8 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) { PB.registerPipelineParsingCallback( - [](StringRef PassName, ModulePassManager &PM, - ArrayRef) { + [this](StringRef PassName, ModulePassManager &PM, + ArrayRef) { if (PassName == "amdgpu-unify-metadata") { PM.addPass(AMDGPUUnifyMetadataPass()); return true; @@ -616,7 +616,7 @@ return true; } if (PassName == "amdgpu-lower-module-lds") { - PM.addPass(AMDGPULowerModuleLDSPass()); + PM.addPass(AMDGPULowerModuleLDSPass(*this)); return true; } if (PassName == "amdgpu-lower-ctor-dtor") { @@ -995,7 +995,7 @@ // Runs before PromoteAlloca so the latter can account for function uses if (EnableLowerModuleLDS) { - addPass(createAMDGPULowerModuleLDSPass()); + addPass(createAMDGPULowerModuleLDSPass(TM)); } // AMDGPUAttributor infers lack of llvm.amdgcn.lds.kernel.id calls, so run