aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/PHIElimination.cpp
diff options
context:
space:
mode:
authorpaperchalice <liujunchang97@outlook.com>2024-12-13 11:43:09 +0800
committerGitHub <noreply@github.com>2024-12-13 11:43:09 +0800
commit1562b70eaf6e0b95910fa684dfc53bd5ca6252e7 (patch)
tree415d937ed1f8667229f71565f4e93cdc7f1562f6 /llvm/lib/CodeGen/PHIElimination.cpp
parentada517b40c6f90a78ea69b9d2d0997c82065c9fd (diff)
downloadllvm-1562b70eaf6e0b95910fa684dfc53bd5ca6252e7.zip
llvm-1562b70eaf6e0b95910fa684dfc53bd5ca6252e7.tar.gz
llvm-1562b70eaf6e0b95910fa684dfc53bd5ca6252e7.tar.bz2
Reapply "[DomTreeUpdater] Move critical edge splitting code to updater" (#119547)
This relands commit #115111. Use traditional way to update post dominator tree, i.e. break critical edge splitting into insert, insert, delete sequence. When splitting critical edges, the post dominator tree may change its root node, and `setNewRoot` only works in normal dominator tree... See https://github.com/llvm/llvm-project/blob/6c7e5827eda26990e872eb7c3f0d7866ee3c3171/llvm/include/llvm/Support/GenericDomTree.h#L684-L687
Diffstat (limited to 'llvm/lib/CodeGen/PHIElimination.cpp')
-rw-r--r--llvm/lib/CodeGen/PHIElimination.cpp27
1 files changed, 18 insertions, 9 deletions
diff --git a/llvm/lib/CodeGen/PHIElimination.cpp b/llvm/lib/CodeGen/PHIElimination.cpp
index e5f4077..b71e5b8 100644
--- a/llvm/lib/CodeGen/PHIElimination.cpp
+++ b/llvm/lib/CodeGen/PHIElimination.cpp
@@ -22,6 +22,7 @@
#include "llvm/CodeGen/LiveIntervals.h"
#include "llvm/CodeGen/LiveVariables.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
+#include "llvm/CodeGen/MachineDomTreeUpdater.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
@@ -90,7 +91,8 @@ class PHIEliminationImpl {
/// Split critical edges where necessary for good coalescer performance.
bool SplitPHIEdges(MachineFunction &MF, MachineBasicBlock &MBB,
MachineLoopInfo *MLI,
- std::vector<SparseBitVector<>> *LiveInSets);
+ std::vector<SparseBitVector<>> *LiveInSets,
+ MachineDomTreeUpdater &MDTU);
// These functions are temporary abstractions around LiveVariables and
// LiveIntervals, so they can go away when LiveVariables does.
@@ -203,6 +205,16 @@ void PHIElimination::getAnalysisUsage(AnalysisUsage &AU) const {
bool PHIEliminationImpl::run(MachineFunction &MF) {
MRI = &MF.getRegInfo();
+ MachineDominatorTree *MDT = nullptr;
+ if (P) {
+ 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;
// Split critical edges to help the coalescer.
@@ -237,7 +249,8 @@ bool PHIEliminationImpl::run(MachineFunction &MF) {
}
for (auto &MBB : MF)
- Changed |= SplitPHIEdges(MF, MBB, MLI, (LV ? &LiveInSets : nullptr));
+ Changed |=
+ SplitPHIEdges(MF, MBB, MLI, (LV ? &LiveInSets : nullptr), MDTU);
}
// This pass takes the function out of SSA form.
@@ -268,10 +281,6 @@ bool PHIEliminationImpl::run(MachineFunction &MF) {
MF.deleteMachineInstr(I.first);
}
- // TODO: we should use the incremental DomTree updater here.
- if (Changed && MDT)
- MDT->getBase().recalculate(MF);
-
LoweredPHIs.clear();
ImpDefs.clear();
VRegPHIUseCount.clear();
@@ -752,7 +761,7 @@ void PHIEliminationImpl::analyzePHINodes(const MachineFunction &MF) {
bool PHIEliminationImpl::SplitPHIEdges(
MachineFunction &MF, MachineBasicBlock &MBB, MachineLoopInfo *MLI,
- std::vector<SparseBitVector<>> *LiveInSets) {
+ std::vector<SparseBitVector<>> *LiveInSets, MachineDomTreeUpdater &MDTU) {
if (MBB.empty() || !MBB.front().isPHI() || MBB.isEHPad())
return false; // Quick exit for basic blocks without PHIs.
@@ -819,8 +828,8 @@ bool PHIEliminationImpl::SplitPHIEdges(
}
if (!ShouldSplit && !SplitAllCriticalEdges)
continue;
- if (!(P ? PreMBB->SplitCriticalEdge(&MBB, *P, LiveInSets)
- : PreMBB->SplitCriticalEdge(&MBB, *MFAM, LiveInSets))) {
+ if (!(P ? PreMBB->SplitCriticalEdge(&MBB, *P, LiveInSets, &MDTU)
+ : PreMBB->SplitCriticalEdge(&MBB, *MFAM, LiveInSets, &MDTU))) {
LLVM_DEBUG(dbgs() << "Failed to split critical edge.\n");
continue;
}