30
30
#include " llvm/CodeGen/MachineInstrBuilder.h"
31
31
#include " llvm/CodeGen/MachineLoopInfo.h"
32
32
#include " llvm/CodeGen/MachineOperand.h"
33
+ #include " llvm/CodeGen/MachinePostDominators.h"
33
34
#include " llvm/CodeGen/MachineRegisterInfo.h"
34
35
#include " llvm/CodeGen/SlotIndexes.h"
35
36
#include " llvm/CodeGen/TargetInstrInfo.h"
@@ -72,6 +73,7 @@ class PHIEliminationImpl {
72
73
LiveIntervals *LIS = nullptr ;
73
74
MachineLoopInfo *MLI = nullptr ;
74
75
MachineDominatorTree *MDT = nullptr ;
76
+ MachinePostDominatorTree *PDT = nullptr ;
75
77
76
78
// / EliminatePHINodes - Eliminate phi nodes by inserting copy instructions
77
79
// / in predecessor basic blocks.
@@ -123,17 +125,22 @@ class PHIEliminationImpl {
123
125
auto *MLIWrapper = P->getAnalysisIfAvailable <MachineLoopInfoWrapperPass>();
124
126
auto *MDTWrapper =
125
127
P->getAnalysisIfAvailable <MachineDominatorTreeWrapperPass>();
128
+ auto *PDTWrapper =
129
+ P->getAnalysisIfAvailable <MachinePostDominatorTreeWrapperPass>();
126
130
LV = LVWrapper ? &LVWrapper->getLV () : nullptr ;
127
131
LIS = LISWrapper ? &LISWrapper->getLIS () : nullptr ;
128
132
MLI = MLIWrapper ? &MLIWrapper->getLI () : nullptr ;
129
133
MDT = MDTWrapper ? &MDTWrapper->getDomTree () : nullptr ;
134
+ PDT = PDTWrapper ? &PDTWrapper->getPostDomTree () : nullptr ;
130
135
}
131
136
132
137
PHIEliminationImpl (MachineFunction &MF, MachineFunctionAnalysisManager &AM)
133
138
: LV(AM.getCachedResult<LiveVariablesAnalysis>(MF)),
134
139
LIS (AM.getCachedResult<LiveIntervalsAnalysis>(MF)),
135
140
MLI(AM.getCachedResult<MachineLoopAnalysis>(MF)),
136
- MDT(AM.getCachedResult<MachineDominatorTreeAnalysis>(MF)), MFAM(&AM) {}
141
+ MDT(AM.getCachedResult<MachineDominatorTreeAnalysis>(MF)),
142
+ PDT(AM.getCachedResult<MachinePostDominatorTreeAnalysis>(MF)),
143
+ MFAM(&AM) {}
137
144
138
145
bool run (MachineFunction &MF);
139
146
};
@@ -172,6 +179,7 @@ PHIEliminationPass::run(MachineFunction &MF,
172
179
PA.preserve <LiveVariablesAnalysis>();
173
180
PA.preserve <SlotIndexesAnalysis>();
174
181
PA.preserve <MachineDominatorTreeAnalysis>();
182
+ PA.preserve <MachinePostDominatorTreeAnalysis>();
175
183
PA.preserve <MachineLoopAnalysis>();
176
184
return PA;
177
185
}
@@ -197,22 +205,16 @@ void PHIElimination::getAnalysisUsage(AnalysisUsage &AU) const {
197
205
AU.addPreserved <SlotIndexesWrapperPass>();
198
206
AU.addPreserved <LiveIntervalsWrapperPass>();
199
207
AU.addPreserved <MachineDominatorTreeWrapperPass>();
208
+ AU.addPreserved <MachinePostDominatorTreeWrapperPass>();
200
209
AU.addPreserved <MachineLoopInfoWrapperPass>();
201
210
MachineFunctionPass::getAnalysisUsage (AU);
202
211
}
203
212
204
213
bool PHIEliminationImpl::run (MachineFunction &MF) {
205
214
MRI = &MF.getRegInfo ();
206
215
207
- MachineDominatorTree *MDT = nullptr ;
208
- if (P) {
209
- auto *MDTWrapper =
210
- P->getAnalysisIfAvailable <MachineDominatorTreeWrapperPass>();
211
- MDT = MDTWrapper ? &MDTWrapper->getDomTree () : nullptr ;
212
- } else {
213
- MDT = MFAM->getCachedResult <MachineDominatorTreeAnalysis>(MF);
214
- }
215
- MachineDomTreeUpdater MDTU (MDT, MachineDomTreeUpdater::UpdateStrategy::Lazy);
216
+ MachineDomTreeUpdater MDTU (MDT, PDT,
217
+ MachineDomTreeUpdater::UpdateStrategy::Lazy);
216
218
217
219
bool Changed = false ;
218
220
0 commit comments