From 23341a84cacfa57722a6d0807846f164317f9d8d Mon Sep 17 00:00:00 2001 From: Quentin Colombet Date: Thu, 21 Apr 2016 21:01:13 +0000 Subject: [PATCH] [MachineBasicBlock] Make the pass argument truly mandatory when splitting edges. MachineBasicBlock::SplitCriticalEdges will crash if a nullptr would have been passed for the Pass argument. Do not allow that by turning this argument into a reference. The alternative would have been to make the Pass a truly optional argument, but although this is easy to do, I was afraid users using it like this would not be aware the livness information, dominator tree and such would silently be broken. llvm-svn: 267052 --- llvm/include/llvm/CodeGen/MachineBasicBlock.h | 2 +- llvm/lib/CodeGen/MachineBasicBlock.cpp | 14 +++++++------- llvm/lib/CodeGen/MachineLICM.cpp | 2 +- llvm/lib/CodeGen/MachineSink.cpp | 2 +- llvm/lib/CodeGen/PHIElimination.cpp | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/llvm/include/llvm/CodeGen/MachineBasicBlock.h b/llvm/include/llvm/CodeGen/MachineBasicBlock.h index bd6f3986413f..da30243bcd43 100644 --- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h +++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h @@ -506,7 +506,7 @@ public: /// /// This function updates LiveVariables, MachineDominatorTree, and /// MachineLoopInfo, as applicable. - MachineBasicBlock *SplitCriticalEdge(MachineBasicBlock *Succ, Pass *P); + MachineBasicBlock *SplitCriticalEdge(MachineBasicBlock *Succ, Pass &P); /// Check if the edge between this block and the given successor \p /// Succ, can be split. If this returns true a subsequent call to diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp index 6310859e4b57..318a2aa69d45 100644 --- a/llvm/lib/CodeGen/MachineBasicBlock.cpp +++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp @@ -711,8 +711,8 @@ bool MachineBasicBlock::canFallThrough() { return FBB == nullptr; } -MachineBasicBlock * -MachineBasicBlock::SplitCriticalEdge(MachineBasicBlock *Succ, Pass *P) { +MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(MachineBasicBlock *Succ, + Pass &P) { if (!canSplitCriticalEdge(Succ)) return nullptr; @@ -726,8 +726,8 @@ MachineBasicBlock::SplitCriticalEdge(MachineBasicBlock *Succ, Pass *P) { << " -- BB#" << NMBB->getNumber() << " -- BB#" << Succ->getNumber() << '\n'); - LiveIntervals *LIS = P->getAnalysisIfAvailable(); - SlotIndexes *Indexes = P->getAnalysisIfAvailable(); + LiveIntervals *LIS = P.getAnalysisIfAvailable(); + SlotIndexes *Indexes = P.getAnalysisIfAvailable(); if (LIS) LIS->insertMBBInMaps(NMBB); else if (Indexes) @@ -736,7 +736,7 @@ MachineBasicBlock::SplitCriticalEdge(MachineBasicBlock *Succ, Pass *P) { // On some targets like Mips, branches may kill virtual registers. Make sure // that LiveVariables is properly updated after updateTerminator replaces the // terminators. - LiveVariables *LV = P->getAnalysisIfAvailable(); + LiveVariables *LV = P.getAnalysisIfAvailable(); // Collect a list of virtual registers killed by the terminators. SmallVector KilledRegs; @@ -916,10 +916,10 @@ MachineBasicBlock::SplitCriticalEdge(MachineBasicBlock *Succ, Pass *P) { } if (MachineDominatorTree *MDT = - P->getAnalysisIfAvailable()) + P.getAnalysisIfAvailable()) MDT->recordSplitCriticalEdge(this, Succ, NMBB); - if (MachineLoopInfo *MLI = P->getAnalysisIfAvailable()) + if (MachineLoopInfo *MLI = P.getAnalysisIfAvailable()) if (MachineLoop *TIL = MLI->getLoopFor(this)) { // If one or the other blocks were not in a loop, the new block is not // either, and thus LI doesn't need to be updated. diff --git a/llvm/lib/CodeGen/MachineLICM.cpp b/llvm/lib/CodeGen/MachineLICM.cpp index 7d0221fdc46f..2827efaab1c7 100644 --- a/llvm/lib/CodeGen/MachineLICM.cpp +++ b/llvm/lib/CodeGen/MachineLICM.cpp @@ -1382,7 +1382,7 @@ MachineBasicBlock *MachineLICM::getCurPreheader() { return nullptr; } - CurPreheader = Pred->SplitCriticalEdge(CurLoop->getHeader(), this); + CurPreheader = Pred->SplitCriticalEdge(CurLoop->getHeader(), *this); if (!CurPreheader) { CurPreheader = reinterpret_cast(-1); return nullptr; diff --git a/llvm/lib/CodeGen/MachineSink.cpp b/llvm/lib/CodeGen/MachineSink.cpp index c42281b14554..13924edbb942 100644 --- a/llvm/lib/CodeGen/MachineSink.cpp +++ b/llvm/lib/CodeGen/MachineSink.cpp @@ -284,7 +284,7 @@ bool MachineSinking::runOnMachineFunction(MachineFunction &MF) { // If we have anything we marked as toSplit, split it now. for (auto &Pair : ToSplit) { - auto NewSucc = Pair.first->SplitCriticalEdge(Pair.second, this); + auto NewSucc = Pair.first->SplitCriticalEdge(Pair.second, *this); if (NewSucc != nullptr) { DEBUG(dbgs() << " *** Splitting critical edge:" " BB#" << Pair.first->getNumber() diff --git a/llvm/lib/CodeGen/PHIElimination.cpp b/llvm/lib/CodeGen/PHIElimination.cpp index 4a0c1633308f..9cbb318f0c81 100644 --- a/llvm/lib/CodeGen/PHIElimination.cpp +++ b/llvm/lib/CodeGen/PHIElimination.cpp @@ -610,7 +610,7 @@ bool PHIElimination::SplitPHIEdges(MachineFunction &MF, } if (!ShouldSplit && !SplitAllCriticalEdges) continue; - if (!PreMBB->SplitCriticalEdge(&MBB, this)) { + if (!PreMBB->SplitCriticalEdge(&MBB, *this)) { DEBUG(dbgs() << "Failed to split critical edge.\n"); continue; }