[PM] Replace the Pass argument to SplitEdge with specific analyses used

and updated.

This may appear to remove handling for things like alias analysis when
splitting critical edges here, but in fact no callers of SplitEdge
relied on this. Similarly, all of them wanted to preserve LCSSA if there
was any update of the loop info. That makes the interface much simpler.

With this, all of BasicBlockUtils.h is free of Pass arguments and
prepared for the new pass manager. This is tho majority of utilities
that relied on pass arguments.

llvm-svn: 226459
This commit is contained in:
Chandler Carruth 2015-01-19 12:36:53 +00:00
parent a2edd9159a
commit d450056c78
7 changed files with 15 additions and 25 deletions

View File

@ -28,7 +28,6 @@ class DominatorTree;
class LoopInfo; class LoopInfo;
class Instruction; class Instruction;
class MDNode; class MDNode;
class Pass;
class ReturnInst; class ReturnInst;
class TargetLibraryInfo; class TargetLibraryInfo;
class TerminatorInst; class TerminatorInst;
@ -191,9 +190,9 @@ unsigned SplitAllCriticalEdges(Function &F,
const CriticalEdgeSplittingOptions &Options = const CriticalEdgeSplittingOptions &Options =
CriticalEdgeSplittingOptions()); CriticalEdgeSplittingOptions());
/// SplitEdge - Split the edge connecting specified block. Pass P must /// SplitEdge - Split the edge connecting specified block.
/// not be NULL. BasicBlock *SplitEdge(BasicBlock *From, BasicBlock *To,
BasicBlock *SplitEdge(BasicBlock *From, BasicBlock *To, Pass *P); DominatorTree *DT = nullptr, LoopInfo *LI = nullptr);
/// SplitBlock - Split the specified block at the specified instruction - every /// SplitBlock - Split the specified block at the specified instruction - every
/// thing before SplitPt stays in Old and everything starting with SplitPt moves /// thing before SplitPt stays in Old and everything starting with SplitPt moves

View File

@ -137,7 +137,7 @@ static bool replaceConstantExprOp(ConstantExpr *CE, Pass *P) {
if (PN->getIncomingValue(I) == CE) { if (PN->getIncomingValue(I) == CE) {
BasicBlock *PredBB = PN->getIncomingBlock(I); BasicBlock *PredBB = PN->getIncomingBlock(I);
if (PredBB->getTerminator()->getNumSuccessors() > 1) if (PredBB->getTerminator()->getNumSuccessors() > 1)
PredBB = SplitEdge(PredBB, PN->getParent(), P); PredBB = SplitEdge(PredBB, PN->getParent());
Instruction *InsertPos = PredBB->getTerminator(); Instruction *InsertPos = PredBB->getTerminator();
Instruction *NewInst = createReplacementInstr(CE, InsertPos); Instruction *NewInst = createReplacementInstr(CE, InsertPos);
PN->setOperand(I, NewInst); PN->setOperand(I, NewInst);

View File

@ -1532,7 +1532,7 @@ void DFSanVisitor::visitCallSite(CallSite CS) {
Next = II->getNormalDest()->begin(); Next = II->getNormalDest()->begin();
} else { } else {
BasicBlock *NewBB = BasicBlock *NewBB =
SplitEdge(II->getParent(), II->getNormalDest(), &DFSF.DFS); SplitEdge(II->getParent(), II->getNormalDest(), &DFSF.DT);
Next = NewBB->begin(); Next = NewBB->begin();
} }
} else { } else {

View File

@ -1575,7 +1575,7 @@ bool JumpThreading::DuplicateCondBranchOnPHIIntoPred(BasicBlock *BB,
BranchInst *OldPredBranch = dyn_cast<BranchInst>(PredBB->getTerminator()); BranchInst *OldPredBranch = dyn_cast<BranchInst>(PredBB->getTerminator());
if (!OldPredBranch || !OldPredBranch->isUnconditional()) { if (!OldPredBranch || !OldPredBranch->isUnconditional()) {
PredBB = SplitEdge(PredBB, BB, this); PredBB = SplitEdge(PredBB, BB);
OldPredBranch = cast<BranchInst>(PredBB->getTerminator()); OldPredBranch = cast<BranchInst>(PredBB->getTerminator());
} }

View File

@ -727,7 +727,7 @@ void LoopUnswitch::UnswitchTrivialCondition(Loop *L, Value *Cond,
// First step, split the preheader, so that we know that there is a safe place // First step, split the preheader, so that we know that there is a safe place
// to insert the conditional branch. We will change loopPreheader to have a // to insert the conditional branch. We will change loopPreheader to have a
// conditional branch on Cond. // conditional branch on Cond.
BasicBlock *NewPH = SplitEdge(loopPreheader, loopHeader, this); BasicBlock *NewPH = SplitEdge(loopPreheader, loopHeader, DT, LI);
// Now that we have a place to insert the conditional branch, create a place // Now that we have a place to insert the conditional branch, create a place
// to branch to: this is the exit block out of the loop that we should // to branch to: this is the exit block out of the loop that we should
@ -801,7 +801,7 @@ void LoopUnswitch::UnswitchNontrivialCondition(Value *LIC, Constant *Val,
// First step, split the preheader and exit blocks, and add these blocks to // First step, split the preheader and exit blocks, and add these blocks to
// the LoopBlocks list. // the LoopBlocks list.
BasicBlock *NewPreheader = SplitEdge(loopPreheader, loopHeader, this); BasicBlock *NewPreheader = SplitEdge(loopPreheader, loopHeader, DT, LI);
LoopBlocks.push_back(NewPreheader); LoopBlocks.push_back(NewPreheader);
// We want the loop to come after the preheader, but before the exit blocks. // We want the loop to come after the preheader, but before the exit blocks.
@ -1047,7 +1047,7 @@ void LoopUnswitch::RewriteLoopBodyWithConditionConstant(Loop *L, Value *LIC,
// and hooked up so as to preserve the loop structure, because // and hooked up so as to preserve the loop structure, because
// trying to update it is complicated. So instead we preserve the // trying to update it is complicated. So instead we preserve the
// loop structure and put the block on a dead code path. // loop structure and put the block on a dead code path.
SplitEdge(Switch, SISucc, this); SplitEdge(Switch, SISucc, DT, LI);
// Compute the successors instead of relying on the return value // Compute the successors instead of relying on the return value
// of SplitEdge, since it may have split the switch successor // of SplitEdge, since it may have split the switch successor
// after PHI nodes. // after PHI nodes.

View File

@ -231,22 +231,14 @@ void llvm::ReplaceInstWithInst(Instruction *From, Instruction *To) {
/// SplitEdge - Split the edge connecting specified block. Pass P must /// SplitEdge - Split the edge connecting specified block. Pass P must
/// not be NULL. /// not be NULL.
BasicBlock *llvm::SplitEdge(BasicBlock *BB, BasicBlock *Succ, Pass *P) { BasicBlock *llvm::SplitEdge(BasicBlock *BB, BasicBlock *Succ, DominatorTree *DT,
LoopInfo *LI) {
unsigned SuccNum = GetSuccessorNumber(BB, Succ); unsigned SuccNum = GetSuccessorNumber(BB, Succ);
auto *AA = P->getAnalysisIfAvailable<AliasAnalysis>();
auto *DTWP = P->getAnalysisIfAvailable<DominatorTreeWrapperPass>();
auto *DT = DTWP ? &DTWP->getDomTree() : nullptr;
auto *LIWP = P->getAnalysisIfAvailable<LoopInfoWrapperPass>();
auto *LI = LIWP ? &LIWP->getLoopInfo() : nullptr;
bool PreserveLCSSA = P->mustPreserveAnalysisID(LCSSAID);
auto Options = CriticalEdgeSplittingOptions(AA, DT, LI);
if (PreserveLCSSA)
Options.setPreserveLCSSA();
// If this is a critical edge, let SplitCriticalEdge do it. // If this is a critical edge, let SplitCriticalEdge do it.
TerminatorInst *LatchTerm = BB->getTerminator(); TerminatorInst *LatchTerm = BB->getTerminator();
if (SplitCriticalEdge(LatchTerm, SuccNum, Options)) if (SplitCriticalEdge(LatchTerm, SuccNum, CriticalEdgeSplittingOptions(DT, LI)
.setPreserveLCSSA()))
return LatchTerm->getSuccessor(SuccNum); return LatchTerm->getSuccessor(SuccNum);
// If the edge isn't critical, then BB has a single successor or Succ has a // If the edge isn't critical, then BB has a single successor or Succ has a

View File

@ -323,7 +323,6 @@ bool llvm::UnrollRuntimeLoopProlog(Loop *L, unsigned Count, LoopInfo *LI,
SE->forgetLoop(ParentLoop); SE->forgetLoop(ParentLoop);
// Grab analyses that we preserve. // Grab analyses that we preserve.
auto *AA = LPM->getAnalysisIfAvailable<AliasAnalysis>();
auto *DTWP = LPM->getAnalysisIfAvailable<DominatorTreeWrapperPass>(); auto *DTWP = LPM->getAnalysisIfAvailable<DominatorTreeWrapperPass>();
auto *DT = DTWP ? &DTWP->getDomTree() : nullptr; auto *DT = DTWP ? &DTWP->getDomTree() : nullptr;
@ -332,7 +331,7 @@ bool llvm::UnrollRuntimeLoopProlog(Loop *L, unsigned Count, LoopInfo *LI,
BasicBlock *Latch = L->getLoopLatch(); BasicBlock *Latch = L->getLoopLatch();
// It helps to splits the original preheader twice, one for the end of the // It helps to splits the original preheader twice, one for the end of the
// prolog code and one for a new loop preheader // prolog code and one for a new loop preheader
BasicBlock *PEnd = SplitEdge(PH, Header, LPM->getAsPass()); BasicBlock *PEnd = SplitEdge(PH, Header, DT, LI);
BasicBlock *NewPH = SplitBlock(PEnd, PEnd->getTerminator(), DT, LI); BasicBlock *NewPH = SplitBlock(PEnd, PEnd->getTerminator(), DT, LI);
BranchInst *PreHeaderBR = cast<BranchInst>(PH->getTerminator()); BranchInst *PreHeaderBR = cast<BranchInst>(PH->getTerminator());
@ -403,7 +402,7 @@ bool llvm::UnrollRuntimeLoopProlog(Loop *L, unsigned Count, LoopInfo *LI,
// PHI functions. // PHI functions.
BasicBlock *LastLoopBB = cast<BasicBlock>(VMap[Latch]); BasicBlock *LastLoopBB = cast<BasicBlock>(VMap[Latch]);
ConnectProlog(L, TripCount, Count, LastLoopBB, PEnd, PH, NewPH, VMap, ConnectProlog(L, TripCount, Count, LastLoopBB, PEnd, PH, NewPH, VMap,
AA, DT, LI, LPM->getAsPass()); /*AliasAnalysis*/ nullptr, DT, LI, LPM->getAsPass());
NumRuntimeUnrolled++; NumRuntimeUnrolled++;
return true; return true;
} }