12
12
// ===----------------------------------------------------------------------===//
13
13
14
14
#include " AMDGPU.h"
15
+ #include " AMDGPUTargetMachine.h"
15
16
#include " GCNSubtarget.h"
16
17
#include " llvm/Analysis/LoopInfo.h"
17
18
#include " llvm/Analysis/UniformityAnalysis.h"
@@ -36,7 +37,8 @@ namespace {
36
37
using StackEntry = std::pair<BasicBlock *, Value *>;
37
38
using StackVector = SmallVector<StackEntry, 16 >;
38
39
39
- class SIAnnotateControlFlow : public FunctionPass {
40
+ class SIAnnotateControlFlow {
41
+ private:
40
42
UniformityInfo *UA;
41
43
42
44
Type *Boolean;
@@ -89,37 +91,17 @@ class SIAnnotateControlFlow : public FunctionPass {
89
91
bool closeControlFlow (BasicBlock *BB);
90
92
91
93
public:
92
- static char ID;
93
-
94
- SIAnnotateControlFlow () : FunctionPass(ID) {}
95
-
96
- bool runOnFunction (Function &F) override ;
97
-
98
- StringRef getPassName () const override { return " SI annotate control flow" ; }
99
-
100
- void getAnalysisUsage (AnalysisUsage &AU) const override {
101
- AU.addRequired <LoopInfoWrapperPass>();
102
- AU.addRequired <DominatorTreeWrapperPass>();
103
- AU.addRequired <UniformityInfoWrapperPass>();
104
- AU.addPreserved <LoopInfoWrapperPass>();
105
- AU.addPreserved <DominatorTreeWrapperPass>();
106
- AU.addRequired <TargetPassConfig>();
107
- FunctionPass::getAnalysisUsage (AU);
94
+ SIAnnotateControlFlow (Module &M, const GCNSubtarget &ST, DominatorTree &DT,
95
+ LoopInfo &LI, UniformityInfo &UA)
96
+ : UA(&UA), DT(&DT), LI(&LI) {
97
+ initialize (M, ST);
108
98
}
99
+
100
+ bool run (Function &F);
109
101
};
110
102
111
103
} // end anonymous namespace
112
104
113
- INITIALIZE_PASS_BEGIN (SIAnnotateControlFlow, DEBUG_TYPE,
114
- " Annotate SI Control Flow" , false , false )
115
- INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
116
- INITIALIZE_PASS_DEPENDENCY(UniformityInfoWrapperPass)
117
- INITIALIZE_PASS_DEPENDENCY(TargetPassConfig)
118
- INITIALIZE_PASS_END(SIAnnotateControlFlow, DEBUG_TYPE,
119
- " Annotate SI Control Flow" , false , false )
120
-
121
- char SIAnnotateControlFlow::ID = 0;
122
-
123
105
// / Initialize all the types and constants used in the pass
124
106
void SIAnnotateControlFlow::initialize (Module &M, const GCNSubtarget &ST) {
125
107
LLVMContext &Context = M.getContext ();
@@ -349,15 +331,9 @@ bool SIAnnotateControlFlow::closeControlFlow(BasicBlock *BB) {
349
331
350
332
// / Annotate the control flow with intrinsics so the backend can
351
333
// / recognize if/then/else and loops.
352
- bool SIAnnotateControlFlow::runOnFunction (Function &F) {
353
- DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree ();
354
- LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo ();
355
- UA = &getAnalysis<UniformityInfoWrapperPass>().getUniformityInfo ();
356
- TargetPassConfig &TPC = getAnalysis<TargetPassConfig>();
357
- const TargetMachine &TM = TPC.getTM <TargetMachine>();
358
-
334
+ bool SIAnnotateControlFlow::run (Function &F) {
359
335
bool Changed = false ;
360
- initialize (*F. getParent (), TM. getSubtarget <GCNSubtarget>(F));
336
+
361
337
for (df_iterator<BasicBlock *> I = df_begin (&F.getEntryBlock ()),
362
338
E = df_end (&F.getEntryBlock ()); I != E; ++I) {
363
339
BasicBlock *BB = *I;
@@ -401,7 +377,70 @@ bool SIAnnotateControlFlow::runOnFunction(Function &F) {
401
377
return Changed;
402
378
}
403
379
380
+ PreservedAnalyses SIAnnotateControlFlowPass::run (Function &F,
381
+ FunctionAnalysisManager &FAM) {
382
+ const GCNSubtarget &ST = TM.getSubtarget <GCNSubtarget>(F);
383
+
384
+ DominatorTree &DT = FAM.getResult <DominatorTreeAnalysis>(F);
385
+ UniformityInfo &UI = FAM.getResult <UniformityInfoAnalysis>(F);
386
+ LoopInfo &LI = FAM.getResult <LoopAnalysis>(F);
387
+
388
+ SIAnnotateControlFlow Impl (*F.getParent (), ST, DT, LI, UI);
389
+
390
+ // FIXME: We introduce dead declarations of intrinsics even if never used.
391
+ bool Changed = Impl.run (F);
392
+ if (!Changed)
393
+ return PreservedAnalyses::none ();
394
+
395
+ // TODO: Is LoopInfo preserved?
396
+ PreservedAnalyses PA = PreservedAnalyses::none ();
397
+ PA.preserve <DominatorTreeAnalysis>();
398
+ return PA;
399
+ }
400
+
401
+ class SIAnnotateControlFlowLegacy : public FunctionPass {
402
+ public:
403
+ static char ID;
404
+
405
+ SIAnnotateControlFlowLegacy () : FunctionPass(ID) {}
406
+
407
+ StringRef getPassName () const override { return " SI annotate control flow" ; }
408
+
409
+ void getAnalysisUsage (AnalysisUsage &AU) const override {
410
+ AU.addRequired <LoopInfoWrapperPass>();
411
+ AU.addRequired <DominatorTreeWrapperPass>();
412
+ AU.addRequired <UniformityInfoWrapperPass>();
413
+ AU.addPreserved <LoopInfoWrapperPass>();
414
+ AU.addPreserved <DominatorTreeWrapperPass>();
415
+ AU.addRequired <TargetPassConfig>();
416
+ FunctionPass::getAnalysisUsage (AU);
417
+ }
418
+
419
+ bool runOnFunction (Function &F) override {
420
+ DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree ();
421
+ LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo ();
422
+ UniformityInfo &UI =
423
+ getAnalysis<UniformityInfoWrapperPass>().getUniformityInfo ();
424
+ TargetPassConfig &TPC = getAnalysis<TargetPassConfig>();
425
+ const TargetMachine &TM = TPC.getTM <TargetMachine>();
426
+ const GCNSubtarget &ST = TM.getSubtarget <GCNSubtarget>(F);
427
+
428
+ SIAnnotateControlFlow Impl (*F.getParent (), ST, DT, LI, UI);
429
+ return Impl.run (F);
430
+ }
431
+ };
432
+
433
+ INITIALIZE_PASS_BEGIN (SIAnnotateControlFlowLegacy, DEBUG_TYPE,
434
+ " Annotate SI Control Flow" , false , false )
435
+ INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
436
+ INITIALIZE_PASS_DEPENDENCY(UniformityInfoWrapperPass)
437
+ INITIALIZE_PASS_DEPENDENCY(TargetPassConfig)
438
+ INITIALIZE_PASS_END(SIAnnotateControlFlowLegacy, DEBUG_TYPE,
439
+ " Annotate SI Control Flow" , false , false )
440
+
441
+ char SIAnnotateControlFlowLegacy::ID = 0;
442
+
404
443
// / Create the annotation pass
405
- FunctionPass *llvm::createSIAnnotateControlFlowPass () {
406
- return new SIAnnotateControlFlow ();
444
+ FunctionPass *llvm::createSIAnnotateControlFlowLegacyPass () {
445
+ return new SIAnnotateControlFlowLegacy ();
407
446
}
0 commit comments