Skip to content

Commit 24b2204

Browse files
committed
[MachineBasicBlock] Decouple SplitCriticalEdges from pass manager
New clients should use this overload that accepts analyses directly.
1 parent c366c19 commit 24b2204

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

llvm/include/llvm/CodeGen/MachineBasicBlock.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ namespace llvm {
3434
class BasicBlock;
3535
class MachineDomTreeUpdater;
3636
class MachineFunction;
37+
class MachineLoopInfo;
3738
class MCSymbol;
3839
class ModuleSlotTracker;
3940
class Pass;
@@ -42,6 +43,7 @@ class SlotIndexes;
4243
class StringRef;
4344
class raw_ostream;
4445
class LiveIntervals;
46+
class LiveVariables;
4547
class TargetRegisterClass;
4648
class TargetRegisterInfo;
4749
template <typename IRUnitT, typename... ExtraArgTs> class AnalysisManager;
@@ -971,6 +973,13 @@ class MachineBasicBlock
971973
///
972974
/// This function updates LiveVariables, MachineDominatorTree, and
973975
/// MachineLoopInfo, as applicable.
976+
struct SplitCriticalEdgeAnalyses {
977+
LiveIntervals *LIS;
978+
SlotIndexes *SI;
979+
LiveVariables *LV;
980+
MachineLoopInfo *MLI;
981+
};
982+
974983
MachineBasicBlock *
975984
SplitCriticalEdge(MachineBasicBlock *Succ, Pass &P,
976985
std::vector<SparseBitVector<>> *LiveInSets = nullptr,
@@ -987,6 +996,10 @@ class MachineBasicBlock
987996
}
988997

989998
// Helper method for new pass manager migration.
999+
MachineBasicBlock *SplitCriticalEdge(
1000+
MachineBasicBlock *Succ, const SplitCriticalEdgeAnalyses &Analyses,
1001+
std::vector<SparseBitVector<>> *LiveInSets, MachineDomTreeUpdater *MDTU);
1002+
9901003
MachineBasicBlock *SplitCriticalEdge(
9911004
MachineBasicBlock *Succ, Pass *P, MachineFunctionAnalysisManager *MFAM,
9921005
std::vector<SparseBitVector<>> *LiveInSets, MachineDomTreeUpdater *MDTU);

llvm/lib/CodeGen/MachineBasicBlock.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,9 @@ class SlotIndexUpdateDelegate : public MachineFunction::Delegate {
11371137
}
11381138
};
11391139

1140+
MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(
1141+
MachineBasicBlock *Succ, Pass *P, MachineFunctionAnalysisManager *MFAM,
1142+
std::vector<SparseBitVector<>> *LiveInSets, MachineDomTreeUpdater *MDTU) {
11401143
#define GET_RESULT(RESULT, GETTER, INFIX) \
11411144
[MF, P, MFAM]() { \
11421145
if (P) { \
@@ -1146,10 +1149,19 @@ class SlotIndexUpdateDelegate : public MachineFunction::Delegate {
11461149
return MFAM->getCachedResult<RESULT##Analysis>(*MF); \
11471150
}()
11481151

1152+
assert((P || MFAM) && "Need a way to get analysis results!");
1153+
MachineFunction *MF = getParent();
1154+
LiveIntervals *LIS = GET_RESULT(LiveIntervals, getLIS, );
1155+
SlotIndexes *Indexes = GET_RESULT(SlotIndexes, getSI, );
1156+
LiveVariables *LV = GET_RESULT(LiveVariables, getLV, );
1157+
MachineLoopInfo *MLI = GET_RESULT(MachineLoop, getLI, Info);
1158+
return SplitCriticalEdge(Succ, {LIS, Indexes, LV, MLI}, LiveInSets, MDTU);
1159+
#undef GET_RESULT
1160+
}
1161+
11491162
MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(
1150-
MachineBasicBlock *Succ, Pass *P, MachineFunctionAnalysisManager *MFAM,
1163+
MachineBasicBlock *Succ, const SplitCriticalEdgeAnalyses &Analyses,
11511164
std::vector<SparseBitVector<>> *LiveInSets, MachineDomTreeUpdater *MDTU) {
1152-
assert((P || MFAM) && "Need a way to get analysis results!");
11531165
if (!canSplitCriticalEdge(Succ))
11541166
return nullptr;
11551167

@@ -1172,19 +1184,16 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(
11721184
LLVM_DEBUG(dbgs() << "Splitting critical edge: " << printMBBReference(*this)
11731185
<< " -- " << printMBBReference(*NMBB) << " -- "
11741186
<< printMBBReference(*Succ) << '\n');
1175-
1176-
LiveIntervals *LIS = GET_RESULT(LiveIntervals, getLIS, );
1177-
SlotIndexes *Indexes = GET_RESULT(SlotIndexes, getSI, );
1187+
auto *LIS = Analyses.LIS;
11781188
if (LIS)
11791189
LIS->insertMBBInMaps(NMBB);
1180-
else if (Indexes)
1181-
Indexes->insertMBBInMaps(NMBB);
1190+
else if (Analyses.SI)
1191+
Analyses.SI->insertMBBInMaps(NMBB);
11821192

11831193
// On some targets like Mips, branches may kill virtual registers. Make sure
11841194
// that LiveVariables is properly updated after updateTerminator replaces the
11851195
// terminators.
1186-
LiveVariables *LV = GET_RESULT(LiveVariables, getLV, );
1187-
1196+
auto *LV = Analyses.LV;
11881197
// Collect a list of virtual registers killed by the terminators.
11891198
SmallVector<Register, 4> KilledRegs;
11901199
if (LV)
@@ -1223,7 +1232,7 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(
12231232
// as the fallthrough successor
12241233
if (Succ == PrevFallthrough)
12251234
PrevFallthrough = NMBB;
1226-
1235+
auto *Indexes = Analyses.SI;
12271236
if (!ChangedIndirectJump) {
12281237
SlotIndexUpdateDelegate SlotUpdater(*MF, Indexes);
12291238
updateTerminator(PrevFallthrough);
@@ -1351,7 +1360,7 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(
13511360
if (MDTU)
13521361
MDTU->splitCriticalEdge(this, Succ, NMBB);
13531362

1354-
if (MachineLoopInfo *MLI = GET_RESULT(MachineLoop, getLI, Info))
1363+
if (MachineLoopInfo *MLI = Analyses.MLI)
13551364
if (MachineLoop *TIL = MLI->getLoopFor(this)) {
13561365
// If one or the other blocks were not in a loop, the new block is not
13571366
// either, and thus LI doesn't need to be updated.

0 commit comments

Comments
 (0)