From 0eae112009967cfb4ffa441e62c89fb8c38331bd Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Mon, 19 Jan 2015 03:03:39 +0000 Subject: [PATCH] [PM] Lift the analyses into the interface for SplitLandingPadPredecessors and remove the Pass argument from its interface. Another step to the utilities being usable with both old and new pass managers. llvm-svn: 226426 --- llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h | 9 +++++++-- llvm/lib/Transforms/IPO/LoopExtractor.cpp | 2 +- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp | 3 ++- llvm/lib/Transforms/Scalar/LoopUnswitch.cpp | 3 ++- llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | 14 ++++---------- llvm/lib/Transforms/Utils/LoopSimplify.cpp | 7 +++---- llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp | 3 ++- 7 files changed, 21 insertions(+), 20 deletions(-) diff --git a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h index a9b6b39..da1988c 100644 --- a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h +++ b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h @@ -188,9 +188,14 @@ BasicBlock *SplitBlockPredecessors(BasicBlock *BB, ArrayRef Preds, /// case where one of the edges being split is an exit of a loop with other /// exits). /// -void SplitLandingPadPredecessors(BasicBlock *OrigBB,ArrayRef Preds, +void SplitLandingPadPredecessors(BasicBlock *OrigBB, + ArrayRef Preds, const char *Suffix, const char *Suffix2, - Pass *P, SmallVectorImpl &NewBBs); + SmallVectorImpl &NewBBs, + AliasAnalysis *AA = nullptr, + DominatorTree *DT = nullptr, + LoopInfo *LI = nullptr, + bool PreserveLCSSA = false); /// FoldReturnIntoUncondBranch - This method duplicates the specified return /// instruction into a predecessor which ends in an unconditional branch. If diff --git a/llvm/lib/Transforms/IPO/LoopExtractor.cpp b/llvm/lib/Transforms/IPO/LoopExtractor.cpp index 20414aa..41334ca 100644 --- a/llvm/lib/Transforms/IPO/LoopExtractor.cpp +++ b/llvm/lib/Transforms/IPO/LoopExtractor.cpp @@ -242,7 +242,7 @@ void BlockExtractorPass::SplitLandingPadPreds(Function *F) { if (!Split) continue; SmallVector NewBBs; - SplitLandingPadPredecessors(LPad, Parent, ".1", ".2", nullptr, NewBBs); + SplitLandingPadPredecessors(LPad, Parent, ".1", ".2", NewBBs); } } diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 250185c..629b0a2 100644 --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -4733,7 +4733,8 @@ void LSRInstance::RewriteForPHI(PHINode *PN, /*DontDeleteUselessPhis=*/true); } else { SmallVector NewBBs; - SplitLandingPadPredecessors(Parent, BB, "", "", P, NewBBs); + SplitLandingPadPredecessors(Parent, BB, "", "", NewBBs, + /*AliasAnalysis*/ nullptr, &DT, &LI); NewBB = NewBBs[0]; } // If NewBB==NULL, then SplitCriticalEdge refused to split because all diff --git a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp index cf80244..30d6d51 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -775,7 +775,8 @@ void LoopUnswitch::SplitExitEdges(Loop *L, } else { SmallVector NewBBs; SplitLandingPadPredecessors(ExitBlock, Preds, ".us-lcssa", ".us-lcssa", - this, NewBBs); + NewBBs, /*AliasAnalysis*/ nullptr, DT, LI, + /*PreserveLCSSA*/ true); } } } diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp index c680788..c2304d7 100644 --- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -523,10 +523,11 @@ BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB, /// exits). /// void llvm::SplitLandingPadPredecessors(BasicBlock *OrigBB, - ArrayRef Preds, + ArrayRef Preds, const char *Suffix1, const char *Suffix2, - Pass *P, - SmallVectorImpl &NewBBs) { + SmallVectorImpl &NewBBs, + AliasAnalysis *AA, DominatorTree *DT, + LoopInfo *LI, bool PreserveLCSSA) { assert(OrigBB->isLandingPad() && "Trying to split a non-landing pad!"); // Create a new basic block for OrigBB's predecessors listed in Preds. Insert @@ -549,18 +550,11 @@ void llvm::SplitLandingPadPredecessors(BasicBlock *OrigBB, Preds[i]->getTerminator()->replaceUsesOfWith(OrigBB, NewBB1); } - // Update DominatorTree, LoopInfo, and LCCSA analysis information. - auto *DTWP = P->getAnalysisIfAvailable(); - auto *DT = DTWP ? &DTWP->getDomTree() : nullptr; - auto *LIWP = P->getAnalysisIfAvailable(); - auto *LI = LIWP ? &LIWP->getLoopInfo() : nullptr; - bool PreserveLCSSA = P->mustPreserveAnalysisID(LCSSAID); bool HasLoopExit = false; UpdateAnalysisInformation(OrigBB, NewBB1, Preds, DT, LI, PreserveLCSSA, HasLoopExit); // Update the PHI nodes in OrigBB with the values coming from NewBB1. - AliasAnalysis *AA = P ? P->getAnalysisIfAvailable() : nullptr; UpdatePHINodes(OrigBB, NewBB1, Preds, BI1, AA, HasLoopExit); // Move the remaining edges from OrigBB to point to NewBB2. diff --git a/llvm/lib/Transforms/Utils/LoopSimplify.cpp b/llvm/lib/Transforms/Utils/LoopSimplify.cpp index 926c3a7..725188d 100644 --- a/llvm/lib/Transforms/Utils/LoopSimplify.cpp +++ b/llvm/lib/Transforms/Utils/LoopSimplify.cpp @@ -145,7 +145,7 @@ BasicBlock *llvm::InsertPreheaderForLoop(Loop *L, Pass *PP) { } else { SmallVector NewBBs; SplitLandingPadPredecessors(Header, OutsideBlocks, ".preheader", - ".split-lp", PP, NewBBs); + ".split-lp", NewBBs, AA, DT, LI, PreserveLCSSA); PreheaderBB = NewBBs[0]; } @@ -186,9 +186,8 @@ static BasicBlock *rewriteLoopExitBlock(Loop *L, BasicBlock *Exit, if (Exit->isLandingPad()) { SmallVector NewBBs; - SplitLandingPadPredecessors(Exit, LoopBlocks, - ".loopexit", ".nonloopexit", - PP, NewBBs); + SplitLandingPadPredecessors(Exit, LoopBlocks, ".loopexit", ".nonloopexit", + NewBBs, AA, DT, LI, PreserveLCSSA); NewExitBB = NewBBs[0]; } else { NewExitBB = SplitBlockPredecessors(Exit, LoopBlocks, ".loopexit", AA, DT, diff --git a/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp b/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp index 82b4f09..2a8c20d 100644 --- a/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp +++ b/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp @@ -125,7 +125,8 @@ static void ConnectProlog(Loop *L, Value *TripCount, unsigned Count, } else { SmallVector NewBBs; SplitLandingPadPredecessors(Exit, Preds, ".unr1-lcssa", ".unr2-lcssa", - P, NewBBs); + NewBBs, AA, DT, LI, + P->mustPreserveAnalysisID(LCSSAID)); } // Add the branch to the exit block (around the unrolled loop) BranchInst::Create(Exit, NewPH, BrLoopExit, InsertPt); -- 2.7.4