Skip to content

Commit c749790

Browse files
committed
[AMDGPU][AMDGPUIfConverter] Add more boilerplate (copy from EarlyIfConversion)
1 parent cac805e commit c749790

File tree

1 file changed

+62
-4
lines changed

1 file changed

+62
-4
lines changed
Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
#include <llvm/CodeGen/MachineBasicBlock.h>
2+
#include <llvm/CodeGen/MachineBranchProbabilityInfo.h>
3+
#include <llvm/CodeGen/MachineDominators.h>
14
#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>
212

313
#include "AMDGPU.h"
414

@@ -9,24 +19,72 @@ namespace {
919
const char PassName[] = "AMDGPU if conversion";
1020

1121
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+
1234
public:
1335
static char ID;
1436

1537
AMDGPUIfConverter() : MachineFunctionPass(ID) {}
1638

17-
bool runOnMachineFunction(MachineFunction &MF) override { return false; }
39+
bool runOnMachineFunction(MachineFunction &MF) override;
40+
41+
void getAnalysisUsage(AnalysisUsage &AU) const override;
1842

19-
void getAnalysisUsage(AnalysisUsage &AU) const override {
20-
MachineFunctionPass::getAnalysisUsage(AU);
21-
}
43+
bool tryConvertIf(MachineBasicBlock *);
2244

2345
StringRef getPassName() const override { return PassName; }
2446
};
2547

2648
char AMDGPUIfConverter::ID = 0;
2749

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+
2884
} // namespace
2985

3086
char &llvm::AMDGPUIfConverterID = AMDGPUIfConverter::ID;
3187
INITIALIZE_PASS_BEGIN(AMDGPUIfConverter, DEBUG_TYPE, PassName, false, false)
88+
INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass)
89+
INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfoWrapperPass)
3290
INITIALIZE_PASS_END(AMDGPUIfConverter, DEBUG_TYPE, PassName, false, false)

0 commit comments

Comments
 (0)