[llvm-commits] [llvm] r137926 - /llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp
Chris Lattner
clattner at apple.com
Wed Aug 17 23:07:32 PDT 2011
On Aug 17, 2011, at 10:25 PM, Bill Wendling wrote:
> Author: void
> Date: Thu Aug 18 00:25:23 2011
> New Revision: 137926
>
> URL: http://llvm.org/viewvc/llvm-project?rev=137926&view=rev
> Log:
> Split out the analysis updating code into a helper function. No intended
> functionality change.
Hi Bill,
Please use static for functions, not anonymous namespaces.
http://llvm.org/docs/CodingStandards.html#micro_anonns
-Chris
>
> Modified:
> llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp
>
> Modified: llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp?rev=137926&r1=137925&r2=137926&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp (original)
> +++ llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp Thu Aug 18 00:25:23 2011
> @@ -314,6 +314,79 @@
> return New;
> }
>
> +namespace {
> +
> +/// UpdateAnalysisInformation - Update DominatorTree, LoopInfo, and LCCSA
> +/// analysis information.
> +void UpdateAnalysisInformation(BasicBlock *OldBB, BasicBlock *NewBB,
> + BasicBlock *const *Preds,
> + unsigned NumPreds, Pass *P, bool &HasLoopExit) {
> + if (!P) return;
> +
> + LoopInfo *LI = P->getAnalysisIfAvailable<LoopInfo>();
> + Loop *L = LI ? LI->getLoopFor(OldBB) : 0;
> + bool PreserveLCSSA = P->mustPreserveAnalysisID(LCSSAID);
> +
> + // If we need to preserve loop analyses, collect some information about how
> + // this split will affect loops.
> + bool IsLoopEntry = !!L;
> + bool SplitMakesNewLoopHeader = false;
> + if (LI) {
> + for (unsigned i = 0; i != NumPreds; ++i) {
> + // If we need to preserve LCSSA, determine if any of the preds is a loop
> + // exit.
> + if (PreserveLCSSA)
> + if (Loop *PL = LI->getLoopFor(Preds[i]))
> + if (!PL->contains(OldBB))
> + HasLoopExit = true;
> +
> + // If we need to preserve LoopInfo, note whether any of the preds crosses
> + // an interesting loop boundary.
> + if (!L) continue;
> + if (L->contains(Preds[i]))
> + IsLoopEntry = false;
> + else
> + SplitMakesNewLoopHeader = true;
> + }
> + }
> +
> + // Update dominator tree if available.
> + DominatorTree *DT = P->getAnalysisIfAvailable<DominatorTree>();
> + if (DT)
> + DT->splitBlock(NewBB);
> +
> + if (!L) return;
> +
> + if (IsLoopEntry) {
> + // Add the new block to the nearest enclosing loop (and not an adjacent
> + // loop). To find this, examine each of the predecessors and determine which
> + // loops enclose them, and select the most-nested loop which contains the
> + // loop containing the block being split.
> + Loop *InnermostPredLoop = 0;
> + for (unsigned i = 0; i != NumPreds; ++i)
> + if (Loop *PredLoop = LI->getLoopFor(Preds[i])) {
> + // Seek a loop which actually contains the block being split (to avoid
> + // adjacent loops).
> + while (PredLoop && !PredLoop->contains(OldBB))
> + PredLoop = PredLoop->getParentLoop();
> +
> + // Select the most-nested of these loops which contains the block.
> + if (PredLoop && PredLoop->contains(OldBB) &&
> + (!InnermostPredLoop ||
> + InnermostPredLoop->getLoopDepth() < PredLoop->getLoopDepth()))
> + InnermostPredLoop = PredLoop;
> + }
> +
> + if (InnermostPredLoop)
> + InnermostPredLoop->addBasicBlockToLoop(NewBB, LI->getBase());
> + } else {
> + L->addBasicBlockToLoop(NewBB, LI->getBase());
> + if (SplitMakesNewLoopHeader)
> + L->moveToHeader(NewBB);
> + }
> +}
> +
> +} // end anonymous namespace
>
> /// SplitBlockPredecessors - This method transforms BB by introducing a new
> /// basic block into the function, and moving some of the predecessors of BB to
> @@ -337,48 +410,16 @@
> // The new block unconditionally branches to the old block.
> BranchInst *BI = BranchInst::Create(BB, NewBB);
>
> - LoopInfo *LI = P ? P->getAnalysisIfAvailable<LoopInfo>() : 0;
> - Loop *L = LI ? LI->getLoopFor(BB) : 0;
> - bool PreserveLCSSA = P->mustPreserveAnalysisID(LCSSAID);
> -
> // Move the edges from Preds to point to NewBB instead of BB.
> - // While here, if we need to preserve loop analyses, collect
> - // some information about how this split will affect loops.
> - bool HasLoopExit = false;
> - bool IsLoopEntry = !!L;
> - bool SplitMakesNewLoopHeader = false;
> for (unsigned i = 0; i != NumPreds; ++i) {
> // This is slightly more strict than necessary; the minimum requirement
> // is that there be no more than one indirectbr branching to BB. And
> // all BlockAddress uses would need to be updated.
> assert(!isa<IndirectBrInst>(Preds[i]->getTerminator()) &&
> "Cannot split an edge from an IndirectBrInst");
> -
> Preds[i]->getTerminator()->replaceUsesOfWith(BB, NewBB);
> -
> - if (LI) {
> - // If we need to preserve LCSSA, determine if any of
> - // the preds is a loop exit.
> - if (PreserveLCSSA)
> - if (Loop *PL = LI->getLoopFor(Preds[i]))
> - if (!PL->contains(BB))
> - HasLoopExit = true;
> - // If we need to preserve LoopInfo, note whether any of the
> - // preds crosses an interesting loop boundary.
> - if (L) {
> - if (L->contains(Preds[i]))
> - IsLoopEntry = false;
> - else
> - SplitMakesNewLoopHeader = true;
> - }
> - }
> }
>
> - // Update dominator tree if available.
> - DominatorTree *DT = P ? P->getAnalysisIfAvailable<DominatorTree>() : 0;
> - if (DT)
> - DT->splitBlock(NewBB);
> -
> // Insert a new PHI node into NewBB for every PHI node in BB and that new PHI
> // node becomes an incoming value for BB's phi node. However, if the Preds
> // list is empty, we need to insert dummy entries into the PHI nodes in BB to
> @@ -390,38 +431,12 @@
> return NewBB;
> }
>
> - AliasAnalysis *AA = P ? P->getAnalysisIfAvailable<AliasAnalysis>() : 0;
> + // Update DominatorTree, LoopInfo, and LCCSA analysis information.
> + bool HasLoopExit = false;
> + UpdateAnalysisInformation(BB, NewBB, Preds, NumPreds, P, HasLoopExit);
>
> - if (L) {
> - if (IsLoopEntry) {
> - // Add the new block to the nearest enclosing loop (and not an
> - // adjacent loop). To find this, examine each of the predecessors and
> - // determine which loops enclose them, and select the most-nested loop
> - // which contains the loop containing the block being split.
> - Loop *InnermostPredLoop = 0;
> - for (unsigned i = 0; i != NumPreds; ++i)
> - if (Loop *PredLoop = LI->getLoopFor(Preds[i])) {
> - // Seek a loop which actually contains the block being split (to
> - // avoid adjacent loops).
> - while (PredLoop && !PredLoop->contains(BB))
> - PredLoop = PredLoop->getParentLoop();
> - // Select the most-nested of these loops which contains the block.
> - if (PredLoop &&
> - PredLoop->contains(BB) &&
> - (!InnermostPredLoop ||
> - InnermostPredLoop->getLoopDepth() < PredLoop->getLoopDepth()))
> - InnermostPredLoop = PredLoop;
> - }
> - if (InnermostPredLoop)
> - InnermostPredLoop->addBasicBlockToLoop(NewBB, LI->getBase());
> - } else {
> - L->addBasicBlockToLoop(NewBB, LI->getBase());
> - if (SplitMakesNewLoopHeader)
> - L->moveToHeader(NewBB);
> - }
> - }
> -
> // Otherwise, create a new PHI node in NewBB for each PHI node in BB.
> + AliasAnalysis *AA = P ? P->getAnalysisIfAvailable<AliasAnalysis>() : 0;
> for (BasicBlock::iterator I = BB->begin(); isa<PHINode>(I); ) {
> PHINode *PN = cast<PHINode>(I++);
>
> @@ -462,7 +477,7 @@
> // edge.
> PN->addIncoming(InVal, NewBB);
> }
> -
> +
> return NewBB;
> }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list