diff options
author | Chris Lattner <sabre@nondot.org> | 2003-12-10 17:20:35 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-12-10 17:20:35 +0000 |
commit | 66ea98e85c5f9c03aac139563d7874e93dc345c6 (patch) | |
tree | 3125e41c8ea5d769ba5cb6c6d62734597e38b615 /lib/Transforms/Utils/LoopSimplify.cpp | |
parent | baf9d2ea62c82574d2e14565d99165bf071e49b4 (diff) |
Finegrainify namespacification
Fix bug: LoopSimplify/2003-12-10-ExitBlocksProblem.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10373 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/LoopSimplify.cpp')
-rw-r--r-- | lib/Transforms/Utils/LoopSimplify.cpp | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp index 2618b73409..64b0a7cc70 100644 --- a/lib/Transforms/Utils/LoopSimplify.cpp +++ b/lib/Transforms/Utils/LoopSimplify.cpp @@ -17,8 +17,9 @@ // // Loop exit-block insertion guarantees that all exit blocks from the loop // (blocks which are outside of the loop that have predecessors inside of the -// loop) are dominated by the loop header. This simplifies transformations such -// as store-sinking that are built into LICM. +// loop) only have predecessors from inside of the loop (and are thus dominated +// by the loop header). This simplifies transformations such as store-sinking +// that are built into LICM. // // This pass also guarantees that loops will have exactly one backedge. // @@ -42,12 +43,11 @@ #include "Support/SetOperations.h" #include "Support/Statistic.h" #include "Support/DepthFirstIterator.h" - -namespace llvm { +using namespace llvm; namespace { Statistic<> - NumInserted("loopsimplify", "Number of pre-header blocks inserted"); + NumInserted("loopsimplify", "Number of pre-header or exit blocks inserted"); struct LoopSimplify : public FunctionPass { virtual bool runOnFunction(Function &F); @@ -81,8 +81,8 @@ namespace { } // Publically exposed interface to pass... -const PassInfo *LoopSimplifyID = X.getPassInfo(); -Pass *createLoopSimplifyPass() { return new LoopSimplify(); } +const PassInfo *llvm::LoopSimplifyID = X.getPassInfo(); +Pass *llvm::createLoopSimplifyPass() { return new LoopSimplify(); } /// runOnFunction - Run down all loops in the CFG (recursively, but we could do /// it in any convenient order) inserting preheaders... @@ -111,18 +111,20 @@ bool LoopSimplify::ProcessLoop(Loop *L) { Changed = true; } - // Regardless of whether or not we added a preheader to the loop we must - // guarantee that the preheader dominates all exit nodes. If there are any - // exit nodes not dominated, split them now. - DominatorSet &DS = getAnalysis<DominatorSet>(); - BasicBlock *Header = L->getHeader(); - for (unsigned i = 0, e = L->getExitBlocks().size(); i != e; ++i) - if (!DS.dominates(Header, L->getExitBlocks()[i])) { - RewriteLoopExitBlock(L, L->getExitBlocks()[i]); - assert(DS.dominates(Header, L->getExitBlocks()[i]) && - "RewriteLoopExitBlock failed?"); - NumInserted++; - Changed = true; + // Next, check to make sure that all exit nodes of the loop only have + // predecessors that are inside of the loop. This check guarantees that the + // loop preheader/header will dominate the exit blocks. If the exit block has + // predecessors from outside of the loop, split the edge now. + for (unsigned i = 0, e = L->getExitBlocks().size(); i != e; ++i) { + BasicBlock *ExitBlock = L->getExitBlocks()[i]; + for (pred_iterator PI = pred_begin(ExitBlock), PE = pred_end(ExitBlock); + PI != PE; ++PI) + if (!L->contains(*PI)) { + RewriteLoopExitBlock(L, ExitBlock); + NumInserted++; + Changed = true; + break; + } } // The preheader may have more than two predecessors at this point (from the @@ -342,8 +344,6 @@ void LoopSimplify::InsertPreheaderForLoop(Loop *L) { void LoopSimplify::RewriteLoopExitBlock(Loop *L, BasicBlock *Exit) { DominatorSet &DS = getAnalysis<DominatorSet>(); - assert(!DS.dominates(L->getHeader(), Exit) && - "Loop already dominates exit block??"); assert(std::find(L->getExitBlocks().begin(), L->getExitBlocks().end(), Exit) != L->getExitBlocks().end() && "Not a current exit block!"); @@ -576,4 +576,3 @@ void LoopSimplify::UpdateDomInfoForRevectoredPreds(BasicBlock *NewBB, } } -} // End llvm namespace |