Skip to content

Commit e4fd6ba

Browse files
authored
[PHIElimination] Preserve MachinePostDominatorTree (#153346)
Minor changes to allow preservation of post dominator tree through PHI elimination pass. Also remove duplicate retrieval of dominator tree analysis. This is a speculative change to support reworking on passes in AMDGPU backend.
1 parent b671979 commit e4fd6ba

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

llvm/lib/CodeGen/PHIElimination.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "llvm/CodeGen/MachineInstrBuilder.h"
3131
#include "llvm/CodeGen/MachineLoopInfo.h"
3232
#include "llvm/CodeGen/MachineOperand.h"
33+
#include "llvm/CodeGen/MachinePostDominators.h"
3334
#include "llvm/CodeGen/MachineRegisterInfo.h"
3435
#include "llvm/CodeGen/SlotIndexes.h"
3536
#include "llvm/CodeGen/TargetInstrInfo.h"
@@ -72,6 +73,7 @@ class PHIEliminationImpl {
7273
LiveIntervals *LIS = nullptr;
7374
MachineLoopInfo *MLI = nullptr;
7475
MachineDominatorTree *MDT = nullptr;
76+
MachinePostDominatorTree *PDT = nullptr;
7577

7678
/// EliminatePHINodes - Eliminate phi nodes by inserting copy instructions
7779
/// in predecessor basic blocks.
@@ -123,17 +125,22 @@ class PHIEliminationImpl {
123125
auto *MLIWrapper = P->getAnalysisIfAvailable<MachineLoopInfoWrapperPass>();
124126
auto *MDTWrapper =
125127
P->getAnalysisIfAvailable<MachineDominatorTreeWrapperPass>();
128+
auto *PDTWrapper =
129+
P->getAnalysisIfAvailable<MachinePostDominatorTreeWrapperPass>();
126130
LV = LVWrapper ? &LVWrapper->getLV() : nullptr;
127131
LIS = LISWrapper ? &LISWrapper->getLIS() : nullptr;
128132
MLI = MLIWrapper ? &MLIWrapper->getLI() : nullptr;
129133
MDT = MDTWrapper ? &MDTWrapper->getDomTree() : nullptr;
134+
PDT = PDTWrapper ? &PDTWrapper->getPostDomTree() : nullptr;
130135
}
131136

132137
PHIEliminationImpl(MachineFunction &MF, MachineFunctionAnalysisManager &AM)
133138
: LV(AM.getCachedResult<LiveVariablesAnalysis>(MF)),
134139
LIS(AM.getCachedResult<LiveIntervalsAnalysis>(MF)),
135140
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) {}
137144

138145
bool run(MachineFunction &MF);
139146
};
@@ -172,6 +179,7 @@ PHIEliminationPass::run(MachineFunction &MF,
172179
PA.preserve<LiveVariablesAnalysis>();
173180
PA.preserve<SlotIndexesAnalysis>();
174181
PA.preserve<MachineDominatorTreeAnalysis>();
182+
PA.preserve<MachinePostDominatorTreeAnalysis>();
175183
PA.preserve<MachineLoopAnalysis>();
176184
return PA;
177185
}
@@ -197,22 +205,16 @@ void PHIElimination::getAnalysisUsage(AnalysisUsage &AU) const {
197205
AU.addPreserved<SlotIndexesWrapperPass>();
198206
AU.addPreserved<LiveIntervalsWrapperPass>();
199207
AU.addPreserved<MachineDominatorTreeWrapperPass>();
208+
AU.addPreserved<MachinePostDominatorTreeWrapperPass>();
200209
AU.addPreserved<MachineLoopInfoWrapperPass>();
201210
MachineFunctionPass::getAnalysisUsage(AU);
202211
}
203212

204213
bool PHIEliminationImpl::run(MachineFunction &MF) {
205214
MRI = &MF.getRegInfo();
206215

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);
216218

217219
bool Changed = false;
218220

0 commit comments

Comments
 (0)