Skip to content

Commit e953eaa

Browse files
committed
Move update code to MachineBasicBlock
1 parent 9d871ba commit e953eaa

File tree

3 files changed

+18
-27
lines changed

3 files changed

+18
-27
lines changed

llvm/lib/CodeGen/MachineBasicBlock.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
#include "llvm/CodeGen/LiveIntervals.h"
1717
#include "llvm/CodeGen/LivePhysRegs.h"
1818
#include "llvm/CodeGen/LiveVariables.h"
19+
#include "llvm/CodeGen/MachineDomTreeUpdater.h"
1920
#include "llvm/CodeGen/MachineDominators.h"
2021
#include "llvm/CodeGen/MachineFunction.h"
2122
#include "llvm/CodeGen/MachineInstrBuilder.h"
2223
#include "llvm/CodeGen/MachineJumpTableInfo.h"
2324
#include "llvm/CodeGen/MachineLoopInfo.h"
25+
#include "llvm/CodeGen/MachinePostDominators.h"
2426
#include "llvm/CodeGen/MachineRegisterInfo.h"
2527
#include "llvm/CodeGen/SlotIndexes.h"
2628
#include "llvm/CodeGen/TargetInstrInfo.h"
@@ -1363,6 +1365,18 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(
13631365
}
13641366
}
13651367

1368+
auto *MDTWrapper =
1369+
P.getAnalysisIfAvailable<MachineDominatorTreeWrapperPass>();
1370+
auto *MPDTWrapper =
1371+
P.getAnalysisIfAvailable<MachinePostDominatorTreeWrapperPass>();
1372+
auto *MDT = MDTWrapper ? &MDTWrapper->getDomTree() : nullptr;
1373+
auto *MPDT = MPDTWrapper ? &MPDTWrapper->getPostDomTree() : nullptr;
1374+
MachineDomTreeUpdater MDTU(MDT, MPDT,
1375+
MachineDomTreeUpdater::UpdateStrategy::Eager);
1376+
MDTU.applyUpdates({{MachineDominatorTree::Insert, this, NMBB},
1377+
{MachineDominatorTree::Insert, NMBB, Succ},
1378+
{MachineDominatorTree::Delete, this, Succ}});
1379+
13661380
return NMBB;
13671381
}
13681382

llvm/lib/CodeGen/MachineSink.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
3131
#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
3232
#include "llvm/CodeGen/MachineCycleAnalysis.h"
33-
#include "llvm/CodeGen/MachineDomTreeUpdater.h"
3433
#include "llvm/CodeGen/MachineDominators.h"
3534
#include "llvm/CodeGen/MachineFunction.h"
3635
#include "llvm/CodeGen/MachineFunctionPass.h"
@@ -722,10 +721,6 @@ bool MachineSinking::runOnMachineFunction(MachineFunction &MF) {
722721
bool EverMadeChange = false;
723722

724723
while (true) {
725-
// Ensure that the dominant tree is up-to-date after splitting the critical
726-
// edge.
727-
MachineDomTreeUpdater MDTU(DT, PDT,
728-
MachineDomTreeUpdater::UpdateStrategy::Lazy);
729724
bool MadeChange = false;
730725

731726
// Process all basic blocks.
@@ -748,11 +743,6 @@ bool MachineSinking::runOnMachineFunction(MachineFunction &MF) {
748743
MadeChange = true;
749744
++NumSplit;
750745
CI->splitCriticalEdge(Pair.first, Pair.second, NewSucc);
751-
752-
MDTU.applyUpdates(
753-
{{MachineDominatorTree::Insert, Pair.first, NewSucc},
754-
{MachineDominatorTree::Insert, NewSucc, Pair.second},
755-
{MachineDominatorTree::Delete, Pair.first, Pair.second}});
756746
} else
757747
LLVM_DEBUG(dbgs() << " *** Not legal to break critical edge\n");
758748
}

llvm/lib/CodeGen/PHIElimination.cpp

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "llvm/CodeGen/LiveIntervals.h"
2222
#include "llvm/CodeGen/LiveVariables.h"
2323
#include "llvm/CodeGen/MachineBasicBlock.h"
24-
#include "llvm/CodeGen/MachineDomTreeUpdater.h"
2524
#include "llvm/CodeGen/MachineDominators.h"
2625
#include "llvm/CodeGen/MachineFunction.h"
2726
#include "llvm/CodeGen/MachineFunctionPass.h"
@@ -96,8 +95,7 @@ namespace {
9695
/// Split critical edges where necessary for good coalescer performance.
9796
bool SplitPHIEdges(MachineFunction &MF, MachineBasicBlock &MBB,
9897
MachineLoopInfo *MLI,
99-
std::vector<SparseBitVector<>> *LiveInSets,
100-
MachineDomTreeUpdater *MDTU);
98+
std::vector<SparseBitVector<>> *LiveInSets);
10199

102100
// These functions are temporary abstractions around LiveVariables and
103101
// LiveIntervals, so they can go away when LiveVariables does.
@@ -185,13 +183,8 @@ bool PHIElimination::runOnMachineFunction(MachineFunction &MF) {
185183
}
186184

187185
MachineLoopInfo *MLI = getAnalysisIfAvailable<MachineLoopInfo>();
188-
auto *DTWrapper = getAnalysisIfAvailable<MachineDominatorTreeWrapperPass>();
189-
MachineDominatorTree *MDT = DTWrapper ? &DTWrapper->getDomTree() : nullptr;
190-
MachineDomTreeUpdater MDTU(MDT,
191-
MachineDomTreeUpdater::UpdateStrategy::Lazy);
192186
for (auto &MBB : MF)
193-
Changed |= SplitPHIEdges(MF, MBB, MLI, (LV ? &LiveInSets : nullptr),
194-
DTWrapper ? &MDTU : nullptr);
187+
Changed |= SplitPHIEdges(MF, MBB, MLI, (LV ? &LiveInSets : nullptr));
195188
}
196189

197190
// This pass takes the function out of SSA form.
@@ -677,8 +670,7 @@ void PHIElimination::analyzePHINodes(const MachineFunction& MF) {
677670

678671
bool PHIElimination::SplitPHIEdges(MachineFunction &MF, MachineBasicBlock &MBB,
679672
MachineLoopInfo *MLI,
680-
std::vector<SparseBitVector<>> *LiveInSets,
681-
MachineDomTreeUpdater *MDTU) {
673+
std::vector<SparseBitVector<>> *LiveInSets) {
682674
if (MBB.empty() || !MBB.front().isPHI() || MBB.isEHPad())
683675
return false; // Quick exit for basic blocks without PHIs.
684676

@@ -745,12 +737,7 @@ bool PHIElimination::SplitPHIEdges(MachineFunction &MF, MachineBasicBlock &MBB,
745737
}
746738
if (!ShouldSplit && !SplitAllCriticalEdges)
747739
continue;
748-
if (auto *NewMBB = PreMBB->SplitCriticalEdge(&MBB, *this, LiveInSets)) {
749-
if (MDTU)
750-
MDTU->applyUpdates({{MachineDominatorTree::Insert, PreMBB, NewMBB},
751-
{MachineDominatorTree::Insert, NewMBB, &MBB},
752-
{MachineDominatorTree::Delete, PreMBB, &MBB}});
753-
} else {
740+
if (!PreMBB->SplitCriticalEdge(&MBB, *this, LiveInSets)) {
754741
LLVM_DEBUG(dbgs() << "Failed to split critical edge.\n");
755742
continue;
756743
}

0 commit comments

Comments
 (0)