Skip to content

Commit

Permalink
Move update code to MachineBasicBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
paperchalice committed Jul 1, 2024
1 parent 89fbc18 commit 12e7c82
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
14 changes: 14 additions & 0 deletions llvm/lib/CodeGen/MachineBasicBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
#include "llvm/CodeGen/LiveIntervals.h"
#include "llvm/CodeGen/LivePhysRegs.h"
#include "llvm/CodeGen/LiveVariables.h"
#include "llvm/CodeGen/MachineDomTreeUpdater.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineJumpTableInfo.h"
#include "llvm/CodeGen/MachineLoopInfo.h"
#include "llvm/CodeGen/MachinePostDominators.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/SlotIndexes.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
Expand Down Expand Up @@ -1336,6 +1338,18 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(
LIS->repairIntervalsInRange(this, getFirstTerminator(), end(), UsedRegs);
}

auto *MDTWrapper =
P.getAnalysisIfAvailable<MachineDominatorTreeWrapperPass>();
auto *MPDTWrapper =
P.getAnalysisIfAvailable<MachinePostDominatorTreeWrapperPass>();
auto *MDT = MDTWrapper ? &MDTWrapper->getDomTree() : nullptr;
auto *MPDT = MPDTWrapper ? &MPDTWrapper->getPostDomTree() : nullptr;
MachineDomTreeUpdater MDTU(MDT, MPDT,
MachineDomTreeUpdater::UpdateStrategy::Eager);
MDTU.applyUpdates({{MachineDominatorTree::Insert, this, NMBB},
{MachineDominatorTree::Insert, NMBB, Succ},
{MachineDominatorTree::Delete, this, Succ}});

if (MachineLoopInfo *MLI = P.getAnalysisIfAvailable<MachineLoopInfo>())
if (MachineLoop *TIL = MLI->getLoopFor(this)) {
// If one or the other blocks were not in a loop, the new block is not
Expand Down
10 changes: 0 additions & 10 deletions llvm/lib/CodeGen/MachineSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
#include "llvm/CodeGen/MachineCycleAnalysis.h"
#include "llvm/CodeGen/MachineDomTreeUpdater.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
Expand Down Expand Up @@ -722,10 +721,6 @@ bool MachineSinking::runOnMachineFunction(MachineFunction &MF) {
bool EverMadeChange = false;

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

// Process all basic blocks.
Expand All @@ -748,11 +743,6 @@ bool MachineSinking::runOnMachineFunction(MachineFunction &MF) {
MadeChange = true;
++NumSplit;
CI->splitCriticalEdge(Pair.first, Pair.second, NewSucc);

MDTU.applyUpdates(
{{MachineDominatorTree::Insert, Pair.first, NewSucc},
{MachineDominatorTree::Insert, NewSucc, Pair.second},
{MachineDominatorTree::Delete, Pair.first, Pair.second}});
} else
LLVM_DEBUG(dbgs() << " *** Not legal to break critical edge\n");
}
Expand Down
21 changes: 4 additions & 17 deletions llvm/lib/CodeGen/PHIElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#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"
Expand Down Expand Up @@ -96,8 +95,7 @@ namespace {
/// Split critical edges where necessary for good coalescer performance.
bool SplitPHIEdges(MachineFunction &MF, MachineBasicBlock &MBB,
MachineLoopInfo *MLI,
std::vector<SparseBitVector<>> *LiveInSets,
MachineDomTreeUpdater *MDTU);
std::vector<SparseBitVector<>> *LiveInSets);

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

MachineLoopInfo *MLI = getAnalysisIfAvailable<MachineLoopInfo>();
auto *DTWrapper = getAnalysisIfAvailable<MachineDominatorTreeWrapperPass>();
MachineDominatorTree *MDT = DTWrapper ? &DTWrapper->getDomTree() : nullptr;
MachineDomTreeUpdater MDTU(MDT,
MachineDomTreeUpdater::UpdateStrategy::Lazy);
for (auto &MBB : MF)
Changed |= SplitPHIEdges(MF, MBB, MLI, (LV ? &LiveInSets : nullptr),
DTWrapper ? &MDTU : nullptr);
Changed |= SplitPHIEdges(MF, MBB, MLI, (LV ? &LiveInSets : nullptr));
}

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

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

Expand Down Expand Up @@ -745,12 +737,7 @@ bool PHIElimination::SplitPHIEdges(MachineFunction &MF, MachineBasicBlock &MBB,
}
if (!ShouldSplit && !SplitAllCriticalEdges)
continue;
if (auto *NewMBB = PreMBB->SplitCriticalEdge(&MBB, *this, LiveInSets)) {
if (MDTU)
MDTU->applyUpdates({{MachineDominatorTree::Insert, PreMBB, NewMBB},
{MachineDominatorTree::Insert, NewMBB, &MBB},
{MachineDominatorTree::Delete, PreMBB, &MBB}});
} else {
if (!PreMBB->SplitCriticalEdge(&MBB, *this, LiveInSets)) {
LLVM_DEBUG(dbgs() << "Failed to split critical edge.\n");
continue;
}
Expand Down

0 comments on commit 12e7c82

Please sign in to comment.