diff options
author | Chris Lattner <sabre@nondot.org> | 2004-04-18 05:38:37 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-04-18 05:38:37 +0000 |
commit | 9c2cc4626b157ca2a7363edd0581783b5e5eb12d (patch) | |
tree | a81633fc754a0b72e9912ca9c7e14d6701ea3d3b /lib/Transforms/Scalar/LoopUnroll.cpp | |
parent | 24199db80ebd43398318b21d3e8d13e9bf72981d (diff) |
Fix a bug: this does not preserve the CFG!
While we're at it, add support for updating loop information correctly.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13033 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/LoopUnroll.cpp')
-rw-r--r-- | lib/Transforms/Scalar/LoopUnroll.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/Transforms/Scalar/LoopUnroll.cpp b/lib/Transforms/Scalar/LoopUnroll.cpp index d337a43132..8b296cb768 100644 --- a/lib/Transforms/Scalar/LoopUnroll.cpp +++ b/lib/Transforms/Scalar/LoopUnroll.cpp @@ -47,9 +47,9 @@ namespace { /// loop preheaders be inserted into the CFG... /// virtual void getAnalysisUsage(AnalysisUsage &AU) const { - AU.setPreservesCFG(); AU.addRequiredID(LoopSimplifyID); AU.addRequired<LoopInfo>(); + AU.addPreserved<LoopInfo>(); } }; RegisterOpt<LoopUnroll> X("loop-unroll", "Unroll loops"); @@ -61,8 +61,11 @@ bool LoopUnroll::runOnFunction(Function &F) { bool Changed = false; LI = &getAnalysis<LoopInfo>(); - for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I) - Changed |= visitLoop(*I); + // Transform all the top-level loops. Copy the loop list so that the child + // can update the loop tree if it needs to delete the loop. + std::vector<Loop*> SubLoops(LI->begin(), LI->end()); + for (unsigned i = 0, e = SubLoops.size(); i != e; ++i) + Changed |= visitLoop(SubLoops[i]); return Changed; } @@ -238,7 +241,20 @@ bool LoopUnroll::visitLoop(Loop *L) { } } - // FIXME: Should update analyses + // Update the loop information for this loop. + Loop *Parent = L->getParentLoop(); + + // Move all of the basic blocks in the loop into the parent loop. + LI->changeLoopFor(BB, Parent); + + // Remove the loop from the parent. + if (Parent) + delete Parent->removeChildLoop(std::find(Parent->begin(), Parent->end(),L)); + else + delete LI->removeLoop(std::find(LI->begin(), LI->end(), L)); + + + // FIXME: Should update dominator analyses // FIXME: Should fold into preheader and exit block |