1
+ #include < llvm/CodeGen/MachineBasicBlock.h>
2
+ #include < llvm/CodeGen/MachineBranchProbabilityInfo.h>
3
+ #include < llvm/CodeGen/MachineDominators.h>
1
4
#include < llvm/CodeGen/MachineFunctionPass.h>
5
+ #include < llvm/CodeGen/MachineLoopInfo.h>
6
+ #include < llvm/CodeGen/SSAIfConv.h>
7
+ #include < llvm/CodeGen/TargetInstrInfo.h>
8
+ #include < llvm/CodeGen/TargetRegisterInfo.h>
9
+ #include < llvm/CodeGen/TargetSchedule.h>
10
+ #include < llvm/CodeGen/TargetSubtargetInfo.h>
11
+ #include < llvm/InitializePasses.h>
2
12
3
13
#include " AMDGPU.h"
4
14
@@ -9,24 +19,72 @@ namespace {
9
19
const char PassName[] = " AMDGPU if conversion" ;
10
20
11
21
class AMDGPUIfConverter : public MachineFunctionPass {
22
+ const TargetInstrInfo *TII = nullptr ;
23
+ const TargetRegisterInfo *TRI = nullptr ;
24
+ TargetSchedModel SchedModel;
25
+ MachineRegisterInfo *MRI = nullptr ;
26
+ MachineDominatorTree *DomTree = nullptr ;
27
+ MachineBranchProbabilityInfo *MBPI = nullptr ;
28
+ MachineLoopInfo *Loops = nullptr ;
29
+
30
+ static constexpr unsigned BlockInstrLimit = 30 ;
31
+ static constexpr bool Stress = false ;
32
+ SSAIfConv IfConv{DEBUG_TYPE, BlockInstrLimit, Stress};
33
+
12
34
public:
13
35
static char ID;
14
36
15
37
AMDGPUIfConverter () : MachineFunctionPass(ID) {}
16
38
17
- bool runOnMachineFunction (MachineFunction &MF) override { return false ; }
39
+ bool runOnMachineFunction (MachineFunction &MF) override ;
40
+
41
+ void getAnalysisUsage (AnalysisUsage &AU) const override ;
18
42
19
- void getAnalysisUsage (AnalysisUsage &AU) const override {
20
- MachineFunctionPass::getAnalysisUsage (AU);
21
- }
43
+ bool tryConvertIf (MachineBasicBlock *);
22
44
23
45
StringRef getPassName () const override { return PassName; }
24
46
};
25
47
26
48
char AMDGPUIfConverter::ID = 0 ;
27
49
50
+ void AMDGPUIfConverter::getAnalysisUsage (AnalysisUsage &AU) const {
51
+ AU.addRequired <MachineBranchProbabilityInfoWrapperPass>();
52
+ AU.addRequired <MachineDominatorTreeWrapperPass>();
53
+ AU.addPreserved <MachineDominatorTreeWrapperPass>();
54
+ AU.addRequired <MachineLoopInfoWrapperPass>();
55
+ AU.addPreserved <MachineLoopInfoWrapperPass>();
56
+ MachineFunctionPass::getAnalysisUsage (AU);
57
+ }
58
+
59
+ bool AMDGPUIfConverter::runOnMachineFunction (MachineFunction &MF) {
60
+ if (skipFunction (MF.getFunction ()))
61
+ return false ;
62
+
63
+ const TargetSubtargetInfo &STI = MF.getSubtarget ();
64
+ TII = STI.getInstrInfo ();
65
+ TRI = STI.getRegisterInfo ();
66
+ MRI = &MF.getRegInfo ();
67
+ SchedModel.init (&STI);
68
+ DomTree = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree ();
69
+ Loops = &getAnalysis<MachineLoopInfoWrapperPass>().getLI ();
70
+ MBPI = &getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI ();
71
+
72
+ bool Changed = false ;
73
+ IfConv.runOnMachineFunction (MF);
74
+
75
+ for (auto *DomNode : post_order (DomTree))
76
+ if (tryConvertIf (DomNode->getBlock ()))
77
+ Changed = true ;
78
+
79
+ return Changed;
80
+ }
81
+
82
+ bool AMDGPUIfConverter::tryConvertIf (MachineBasicBlock *MBB) { return false ; }
83
+
28
84
} // namespace
29
85
30
86
char &llvm::AMDGPUIfConverterID = AMDGPUIfConverter::ID;
31
87
INITIALIZE_PASS_BEGIN (AMDGPUIfConverter, DEBUG_TYPE, PassName, false , false )
88
+ INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass)
89
+ INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfoWrapperPass)
32
90
INITIALIZE_PASS_END(AMDGPUIfConverter, DEBUG_TYPE, PassName, false , false )
0 commit comments