@@ -42,35 +42,21 @@ static cl::opt<bool>
4242namespace {
4343
4444class AMDGPULateCodeGenPrepare
45- : public FunctionPass,
46- public InstVisitor<AMDGPULateCodeGenPrepare, bool > {
45+ : public InstVisitor<AMDGPULateCodeGenPrepare, bool > {
4746 Module *Mod = nullptr ;
4847 const DataLayout *DL = nullptr ;
48+ const GCNSubtarget &ST;
4949
5050 AssumptionCache *AC = nullptr ;
5151 UniformityInfo *UA = nullptr ;
5252
5353 SmallVector<WeakTrackingVH, 8 > DeadInsts;
5454
5555public:
56- static char ID;
57-
58- AMDGPULateCodeGenPrepare () : FunctionPass(ID) {}
59-
60- StringRef getPassName () const override {
61- return " AMDGPU IR late optimizations" ;
62- }
63-
64- void getAnalysisUsage (AnalysisUsage &AU) const override {
65- AU.addRequired <TargetPassConfig>();
66- AU.addRequired <AssumptionCacheTracker>();
67- AU.addRequired <UniformityInfoWrapperPass>();
68- AU.setPreservesAll ();
69- }
70-
71- bool doInitialization (Module &M) override ;
72- bool runOnFunction (Function &F) override ;
73-
56+ AMDGPULateCodeGenPrepare (Module &M, const GCNSubtarget &ST,
57+ AssumptionCache *AC, UniformityInfo *UA)
58+ : Mod(&M), DL(&M.getDataLayout()), ST(ST), AC(AC), UA(UA) {}
59+ bool run (Function &F);
7460 bool visitInstruction (Instruction &) { return false ; }
7561
7662 // Check if the specified value is at least DWORD aligned.
@@ -148,23 +134,7 @@ class LiveRegOptimizer {
148134
149135} // end anonymous namespace
150136
151- bool AMDGPULateCodeGenPrepare::doInitialization (Module &M) {
152- Mod = &M;
153- DL = &Mod->getDataLayout ();
154- return false ;
155- }
156-
157- bool AMDGPULateCodeGenPrepare::runOnFunction (Function &F) {
158- if (skipFunction (F))
159- return false ;
160-
161- const TargetPassConfig &TPC = getAnalysis<TargetPassConfig>();
162- const TargetMachine &TM = TPC.getTM <TargetMachine>();
163- const GCNSubtarget &ST = TM.getSubtarget <GCNSubtarget>(F);
164-
165- AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache (F);
166- UA = &getAnalysis<UniformityInfoWrapperPass>().getUniformityInfo ();
167-
137+ bool AMDGPULateCodeGenPrepare::run (Function &F) {
168138 // "Optimize" the virtual regs that cross basic block boundaries. When
169139 // building the SelectionDAG, vectors of illegal types that cross basic blocks
170140 // will be scalarized and widened, with each scalar living in its
@@ -505,16 +475,72 @@ bool AMDGPULateCodeGenPrepare::visitLoadInst(LoadInst &LI) {
505475 return true ;
506476}
507477
508- INITIALIZE_PASS_BEGIN (AMDGPULateCodeGenPrepare, DEBUG_TYPE,
478+ PreservedAnalyses
479+ AMDGPULateCodeGenPreparePass::run (Function &F, FunctionAnalysisManager &FAM) {
480+ const GCNSubtarget &ST = TM.getSubtarget <GCNSubtarget>(F);
481+
482+ AssumptionCache &AC = FAM.getResult <AssumptionAnalysis>(F);
483+ UniformityInfo &UI = FAM.getResult <UniformityInfoAnalysis>(F);
484+
485+ AMDGPULateCodeGenPrepare Impl (*F.getParent (), ST, &AC, &UI);
486+
487+ bool Changed = Impl.run (F);
488+
489+ PreservedAnalyses PA = PreservedAnalyses::none ();
490+ if (!Changed)
491+ return PA;
492+ PA.preserveSet <CFGAnalyses>();
493+ return PA;
494+ }
495+
496+ class AMDGPULateCodeGenPrepareLegacy : public FunctionPass {
497+ public:
498+ static char ID;
499+
500+ AMDGPULateCodeGenPrepareLegacy () : FunctionPass(ID) {}
501+
502+ StringRef getPassName () const override {
503+ return " AMDGPU IR late optimizations" ;
504+ }
505+
506+ void getAnalysisUsage (AnalysisUsage &AU) const override {
507+ AU.addRequired <TargetPassConfig>();
508+ AU.addRequired <AssumptionCacheTracker>();
509+ AU.addRequired <UniformityInfoWrapperPass>();
510+ AU.setPreservesAll ();
511+ }
512+
513+ bool runOnFunction (Function &F) override ;
514+ };
515+
516+ bool AMDGPULateCodeGenPrepareLegacy::runOnFunction (Function &F) {
517+ if (skipFunction (F))
518+ return false ;
519+
520+ const TargetPassConfig &TPC = getAnalysis<TargetPassConfig>();
521+ const TargetMachine &TM = TPC.getTM <TargetMachine>();
522+ const GCNSubtarget &ST = TM.getSubtarget <GCNSubtarget>(F);
523+
524+ AssumptionCache &AC =
525+ getAnalysis<AssumptionCacheTracker>().getAssumptionCache (F);
526+ UniformityInfo &UI =
527+ getAnalysis<UniformityInfoWrapperPass>().getUniformityInfo ();
528+
529+ AMDGPULateCodeGenPrepare Impl (*F.getParent (), ST, &AC, &UI);
530+
531+ return Impl.run (F);
532+ }
533+
534+ INITIALIZE_PASS_BEGIN (AMDGPULateCodeGenPrepareLegacy, DEBUG_TYPE,
509535 " AMDGPU IR late optimizations" , false , false )
510536INITIALIZE_PASS_DEPENDENCY(TargetPassConfig)
511537INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
512538INITIALIZE_PASS_DEPENDENCY(UniformityInfoWrapperPass)
513- INITIALIZE_PASS_END(AMDGPULateCodeGenPrepare , DEBUG_TYPE,
539+ INITIALIZE_PASS_END(AMDGPULateCodeGenPrepareLegacy , DEBUG_TYPE,
514540 " AMDGPU IR late optimizations" , false , false )
515541
516- char AMDGPULateCodeGenPrepare ::ID = 0;
542+ char AMDGPULateCodeGenPrepareLegacy ::ID = 0;
517543
518- FunctionPass *llvm::createAMDGPULateCodeGenPreparePass () {
519- return new AMDGPULateCodeGenPrepare ();
544+ FunctionPass *llvm::createAMDGPULateCodeGenPrepareLegacyPass () {
545+ return new AMDGPULateCodeGenPrepareLegacy ();
520546}
0 commit comments