Now LoopUnroll is a LoopPass.
authorDevang Patel <dpatel@apple.com>
Wed, 7 Mar 2007 01:38:05 +0000 (01:38 +0000)
committerDevang Patel <dpatel@apple.com>
Wed, 7 Mar 2007 01:38:05 +0000 (01:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34996 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Transforms/Scalar.h
lib/Transforms/Scalar/LoopUnroll.cpp

index 1d6445c64e3671287f9b0b94934bf4850762ed9a..01063f9136de52d1cbd3570fa8bf0d4adfc301b1 100644 (file)
@@ -133,7 +133,7 @@ LoopPass *createLoopUnswitchPass();
 //
 // LoopUnroll - This pass is a simple loop unrolling pass.
 //
-FunctionPass *createLoopUnrollPass();
+LoopPass *createLoopUnrollPass();
 
 //===----------------------------------------------------------------------===//
 //
index b0db806a495786e72733814b67912cccac900b78..eff35e4f142cb5d40665d8e6ed2951687f5cc9b8 100644 (file)
@@ -24,6 +24,7 @@
 #include "llvm/Instructions.h"
 #include "llvm/Analysis/ConstantFolding.h"
 #include "llvm/Analysis/LoopInfo.h"
+#include "llvm/Analysis/LoopPass.h"
 #include "llvm/Transforms/Utils/Cloning.h"
 #include "llvm/Transforms/Utils/Local.h"
 #include "llvm/Support/CFG.h"
@@ -45,11 +46,10 @@ namespace {
   UnrollThreshold("unroll-threshold", cl::init(100), cl::Hidden,
                   cl::desc("The cut-off point for loop unrolling"));
 
-  class VISIBILITY_HIDDEN LoopUnroll : public FunctionPass {
+  class VISIBILITY_HIDDEN LoopUnroll : public LoopPass {
     LoopInfo *LI;  // The current loop information
   public:
-    virtual bool runOnFunction(Function &F);
-    bool visitLoop(Loop *L);
+    bool runOnLoop(Loop *L, LPPassManager &LPM);
     BasicBlock* FoldBlockIntoPredecessor(BasicBlock* BB);
 
     /// This transformation requires natural loop information & requires that
@@ -66,20 +66,7 @@ namespace {
   RegisterPass<LoopUnroll> X("loop-unroll", "Unroll loops");
 }
 
-FunctionPass *llvm::createLoopUnrollPass() { return new LoopUnroll(); }
-
-bool LoopUnroll::runOnFunction(Function &F) {
-  bool Changed = false;
-  LI = &getAnalysis<LoopInfo>();
-
-  // 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;
-}
+LoopPass *llvm::createLoopUnrollPass() { return new LoopUnroll(); }
 
 /// ApproximateLoopSize - Approximate the size of the loop after it has been
 /// unrolled.
@@ -171,15 +158,9 @@ BasicBlock* LoopUnroll::FoldBlockIntoPredecessor(BasicBlock* BB) {
   return OnlyPred;
 }
 
-bool LoopUnroll::visitLoop(Loop *L) {
+bool LoopUnroll::runOnLoop(Loop *L, LPPassManager &LPM) {
   bool Changed = false;
-
-  // Recurse through all subloops before we process this loop.  Copy the loop
-  // list so that the child can update the loop tree if it needs to delete the
-  // loop.
-  std::vector<Loop*> SubLoops(L->begin(), L->end());
-  for (unsigned i = 0, e = SubLoops.size(); i != e; ++i)
-    Changed |= visitLoop(SubLoops[i]);
+  LI = &getAnalysis<LoopInfo>();
 
   BasicBlock* Header = L->getHeader();
   BasicBlock* LatchBlock = L->getLoopLatch();
@@ -367,18 +348,8 @@ bool LoopUnroll::visitLoop(Loop *L) {
     }
 
   // Update the loop information for this loop.
-  Loop *Parent = L->getParentLoop();
-
-  // Move all of the basic blocks in the loop into the parent loop.
-  for (std::vector<BasicBlock*>::const_iterator BB = NewLoopBlocks.begin(),
-       E = NewLoopBlocks.end(); BB != E; ++BB)
-    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));
+  LPM.deleteLoopFromQueue(L);
 
   ++NumUnrolled;
   return true;