@@ -42,35 +42,21 @@ static cl::opt<bool>
42
42
namespace {
43
43
44
44
class AMDGPULateCodeGenPrepare
45
- : public FunctionPass,
46
- public InstVisitor<AMDGPULateCodeGenPrepare, bool > {
45
+ : public InstVisitor<AMDGPULateCodeGenPrepare, bool > {
47
46
Module *Mod = nullptr ;
48
47
const DataLayout *DL = nullptr ;
48
+ const GCNSubtarget &ST;
49
49
50
50
AssumptionCache *AC = nullptr ;
51
51
UniformityInfo *UA = nullptr ;
52
52
53
53
SmallVector<WeakTrackingVH, 8 > DeadInsts;
54
54
55
55
public:
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);
74
60
bool visitInstruction (Instruction &) { return false ; }
75
61
76
62
// Check if the specified value is at least DWORD aligned.
@@ -148,23 +134,7 @@ class LiveRegOptimizer {
148
134
149
135
} // end anonymous namespace
150
136
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) {
168
138
// "Optimize" the virtual regs that cross basic block boundaries. When
169
139
// building the SelectionDAG, vectors of illegal types that cross basic blocks
170
140
// will be scalarized and widened, with each scalar living in its
@@ -505,16 +475,72 @@ bool AMDGPULateCodeGenPrepare::visitLoadInst(LoadInst &LI) {
505
475
return true ;
506
476
}
507
477
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,
509
535
" AMDGPU IR late optimizations" , false , false )
510
536
INITIALIZE_PASS_DEPENDENCY(TargetPassConfig)
511
537
INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
512
538
INITIALIZE_PASS_DEPENDENCY(UniformityInfoWrapperPass)
513
- INITIALIZE_PASS_END(AMDGPULateCodeGenPrepare , DEBUG_TYPE,
539
+ INITIALIZE_PASS_END(AMDGPULateCodeGenPrepareLegacy , DEBUG_TYPE,
514
540
" AMDGPU IR late optimizations" , false , false )
515
541
516
- char AMDGPULateCodeGenPrepare ::ID = 0;
542
+ char AMDGPULateCodeGenPrepareLegacy ::ID = 0;
517
543
518
- FunctionPass *llvm::createAMDGPULateCodeGenPreparePass () {
519
- return new AMDGPULateCodeGenPrepare ();
544
+ FunctionPass *llvm::createAMDGPULateCodeGenPrepareLegacyPass () {
545
+ return new AMDGPULateCodeGenPrepareLegacy ();
520
546
}
0 commit comments