aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/LoopSimplify.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-09-08 15:45:00 +0000
committerDan Gohman <gohman@apple.com>2009-09-08 15:45:00 +0000
commit5c89b5240c90eb8171f999e5f06f815502d0321c (patch)
treef34aa8c5b5b7783f84d985d44c086360683dc226 /lib/Transforms/Utils/LoopSimplify.cpp
parent6ca0b9e7220911a6d1fccf34e532e69c7e37cd2f (diff)
Re-apply r80926, with fixes: keep the domtree informed of new blocks
that get created during loop unswitching, and fix SplitBlockPredecessors' LCSSA updating code to create new PHIs instead of trying to just move existing ones. Also, optimize Loop::verifyLoop, since it gets called a lot. Use searches on a sorted list of blocks instead of calling the "contains" function, as is done in other places in the Loop class, since "contains" does a linear search. Also, don't call verifyLoop from LoopSimplify or LCSSA, as the PassManager is already calling verifyLoop as part of LoopInfo's verifyAnalysis. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81221 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/LoopSimplify.cpp')
-rw-r--r--lib/Transforms/Utils/LoopSimplify.cpp40
1 files changed, 11 insertions, 29 deletions
diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp
index 56e5a46cb7..2ff9f8be4b 100644
--- a/lib/Transforms/Utils/LoopSimplify.cpp
+++ b/lib/Transforms/Utils/LoopSimplify.cpp
@@ -69,8 +69,8 @@ namespace {
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
// We need loop information to identify the loops...
- AU.addRequired<LoopInfo>();
- AU.addRequired<DominatorTree>();
+ AU.addRequiredTransitive<LoopInfo>();
+ AU.addRequiredTransitive<DominatorTree>();
AU.addPreserved<LoopInfo>();
AU.addPreserved<DominatorTree>();
@@ -83,9 +83,11 @@ namespace {
void verifyAnalysis() const {
#ifndef NDEBUG
LoopInfo *NLI = &getAnalysis<LoopInfo>();
- for (LoopInfo::iterator I = NLI->begin(), E = NLI->end(); I != E; ++I)
- (*I)->verifyLoop();
-#endif
+ for (LoopInfo::iterator I = NLI->begin(), E = NLI->end(); I != E; ++I) {
+ // Check the special guarantees that LoopSimplify makes.
+ assert((*I)->isLoopSimplifyForm());
+ }
+#endif
}
private:
@@ -346,15 +348,6 @@ BasicBlock *LoopSimplify::InsertPreheaderForLoop(Loop *L) {
BasicBlock *NewBB =
SplitBlockPredecessors(Header, &OutsideBlocks[0], OutsideBlocks.size(),
".preheader", this);
-
-
- //===--------------------------------------------------------------------===//
- // Update analysis results now that we have performed the transformation
- //
-
- // We know that we have loop information to update... update it now.
- if (Loop *Parent = L->getParentLoop())
- Parent->addBasicBlockToLoop(NewBB, LI->getBase());
// Make sure that NewBB is put someplace intelligent, which doesn't mess up
// code layout too horribly.
@@ -377,17 +370,6 @@ BasicBlock *LoopSimplify::RewriteLoopExitBlock(Loop *L, BasicBlock *Exit) {
LoopBlocks.size(), ".loopexit",
this);
- // Update Loop Information - we know that the new block will be in whichever
- // loop the Exit block is in. Note that it may not be in that immediate loop,
- // if the successor is some other loop header. In that case, we continue
- // walking up the loop tree to find a loop that contains both the successor
- // block and the predecessor block.
- Loop *SuccLoop = LI->getLoopFor(Exit);
- while (SuccLoop && !SuccLoop->contains(L->getHeader()))
- SuccLoop = SuccLoop->getParentLoop();
- if (SuccLoop)
- SuccLoop->addBasicBlockToLoop(NewBB, LI->getBase());
-
return NewBB;
}
@@ -521,10 +503,6 @@ Loop *LoopSimplify::SeparateNestedLoop(Loop *L) {
else
LI->changeTopLevelLoop(L, NewOuter);
- // This block is going to be our new header block: add it to this loop and all
- // parent loops.
- NewOuter->addBasicBlockToLoop(NewBB, LI->getBase());
-
// L is now a subloop of our outer loop.
NewOuter->addChildLoop(L);
@@ -532,6 +510,10 @@ Loop *LoopSimplify::SeparateNestedLoop(Loop *L) {
I != E; ++I)
NewOuter->addBlockEntry(*I);
+ // Now reset the header in L, which had been moved by
+ // SplitBlockPredecessors for the outer loop.
+ L->moveToHeader(Header);
+
// Determine which blocks should stay in L and which should be moved out to
// the Outer loop now.
std::set<BasicBlock*> BlocksInL;