[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.
This commit is contained in:
Carl Ritson 2025-08-14 10:50:46 +09:00 committed by GitHub
parent b671979b7e
commit e4fd6ba682
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -30,6 +30,7 @@
#include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineLoopInfo.h" #include "llvm/CodeGen/MachineLoopInfo.h"
#include "llvm/CodeGen/MachineOperand.h" #include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/MachinePostDominators.h"
#include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/SlotIndexes.h" #include "llvm/CodeGen/SlotIndexes.h"
#include "llvm/CodeGen/TargetInstrInfo.h" #include "llvm/CodeGen/TargetInstrInfo.h"
@ -72,6 +73,7 @@ class PHIEliminationImpl {
LiveIntervals *LIS = nullptr; LiveIntervals *LIS = nullptr;
MachineLoopInfo *MLI = nullptr; MachineLoopInfo *MLI = nullptr;
MachineDominatorTree *MDT = nullptr; MachineDominatorTree *MDT = nullptr;
MachinePostDominatorTree *PDT = nullptr;
/// EliminatePHINodes - Eliminate phi nodes by inserting copy instructions /// EliminatePHINodes - Eliminate phi nodes by inserting copy instructions
/// in predecessor basic blocks. /// in predecessor basic blocks.
@ -123,17 +125,22 @@ public:
auto *MLIWrapper = P->getAnalysisIfAvailable<MachineLoopInfoWrapperPass>(); auto *MLIWrapper = P->getAnalysisIfAvailable<MachineLoopInfoWrapperPass>();
auto *MDTWrapper = auto *MDTWrapper =
P->getAnalysisIfAvailable<MachineDominatorTreeWrapperPass>(); P->getAnalysisIfAvailable<MachineDominatorTreeWrapperPass>();
auto *PDTWrapper =
P->getAnalysisIfAvailable<MachinePostDominatorTreeWrapperPass>();
LV = LVWrapper ? &LVWrapper->getLV() : nullptr; LV = LVWrapper ? &LVWrapper->getLV() : nullptr;
LIS = LISWrapper ? &LISWrapper->getLIS() : nullptr; LIS = LISWrapper ? &LISWrapper->getLIS() : nullptr;
MLI = MLIWrapper ? &MLIWrapper->getLI() : nullptr; MLI = MLIWrapper ? &MLIWrapper->getLI() : nullptr;
MDT = MDTWrapper ? &MDTWrapper->getDomTree() : nullptr; MDT = MDTWrapper ? &MDTWrapper->getDomTree() : nullptr;
PDT = PDTWrapper ? &PDTWrapper->getPostDomTree() : nullptr;
} }
PHIEliminationImpl(MachineFunction &MF, MachineFunctionAnalysisManager &AM) PHIEliminationImpl(MachineFunction &MF, MachineFunctionAnalysisManager &AM)
: LV(AM.getCachedResult<LiveVariablesAnalysis>(MF)), : LV(AM.getCachedResult<LiveVariablesAnalysis>(MF)),
LIS(AM.getCachedResult<LiveIntervalsAnalysis>(MF)), LIS(AM.getCachedResult<LiveIntervalsAnalysis>(MF)),
MLI(AM.getCachedResult<MachineLoopAnalysis>(MF)), MLI(AM.getCachedResult<MachineLoopAnalysis>(MF)),
MDT(AM.getCachedResult<MachineDominatorTreeAnalysis>(MF)), MFAM(&AM) {} MDT(AM.getCachedResult<MachineDominatorTreeAnalysis>(MF)),
PDT(AM.getCachedResult<MachinePostDominatorTreeAnalysis>(MF)),
MFAM(&AM) {}
bool run(MachineFunction &MF); bool run(MachineFunction &MF);
}; };
@ -172,6 +179,7 @@ PHIEliminationPass::run(MachineFunction &MF,
PA.preserve<LiveVariablesAnalysis>(); PA.preserve<LiveVariablesAnalysis>();
PA.preserve<SlotIndexesAnalysis>(); PA.preserve<SlotIndexesAnalysis>();
PA.preserve<MachineDominatorTreeAnalysis>(); PA.preserve<MachineDominatorTreeAnalysis>();
PA.preserve<MachinePostDominatorTreeAnalysis>();
PA.preserve<MachineLoopAnalysis>(); PA.preserve<MachineLoopAnalysis>();
return PA; return PA;
} }
@ -197,6 +205,7 @@ void PHIElimination::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addPreserved<SlotIndexesWrapperPass>(); AU.addPreserved<SlotIndexesWrapperPass>();
AU.addPreserved<LiveIntervalsWrapperPass>(); AU.addPreserved<LiveIntervalsWrapperPass>();
AU.addPreserved<MachineDominatorTreeWrapperPass>(); AU.addPreserved<MachineDominatorTreeWrapperPass>();
AU.addPreserved<MachinePostDominatorTreeWrapperPass>();
AU.addPreserved<MachineLoopInfoWrapperPass>(); AU.addPreserved<MachineLoopInfoWrapperPass>();
MachineFunctionPass::getAnalysisUsage(AU); MachineFunctionPass::getAnalysisUsage(AU);
} }
@ -204,15 +213,8 @@ void PHIElimination::getAnalysisUsage(AnalysisUsage &AU) const {
bool PHIEliminationImpl::run(MachineFunction &MF) { bool PHIEliminationImpl::run(MachineFunction &MF) {
MRI = &MF.getRegInfo(); MRI = &MF.getRegInfo();
MachineDominatorTree *MDT = nullptr; MachineDomTreeUpdater MDTU(MDT, PDT,
if (P) { MachineDomTreeUpdater::UpdateStrategy::Lazy);
auto *MDTWrapper =
P->getAnalysisIfAvailable<MachineDominatorTreeWrapperPass>();
MDT = MDTWrapper ? &MDTWrapper->getDomTree() : nullptr;
} else {
MDT = MFAM->getCachedResult<MachineDominatorTreeAnalysis>(MF);
}
MachineDomTreeUpdater MDTU(MDT, MachineDomTreeUpdater::UpdateStrategy::Lazy);
bool Changed = false; bool Changed = false;