[llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopUnroll.cpp

Devang Patel dpatel at apple.com
Tue Mar 6 17:38:27 PST 2007



Changes in directory llvm/lib/Transforms/Scalar:

LoopUnroll.cpp updated: 1.37 -> 1.38
---
Log message:

Now LoopUnroll is a LoopPass.


---
Diffs of the changes:  (+7 -36)

 LoopUnroll.cpp |   43 +++++++------------------------------------
 1 files changed, 7 insertions(+), 36 deletions(-)


Index: llvm/lib/Transforms/Scalar/LoopUnroll.cpp
diff -u llvm/lib/Transforms/Scalar/LoopUnroll.cpp:1.37 llvm/lib/Transforms/Scalar/LoopUnroll.cpp:1.38
--- llvm/lib/Transforms/Scalar/LoopUnroll.cpp:1.37	Fri Mar  2 17:31:34 2007
+++ llvm/lib/Transforms/Scalar/LoopUnroll.cpp	Tue Mar  6 19:38:05 2007
@@ -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 @@
   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 @@
   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 @@
   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 @@
     }
 
   // 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;






More information about the llvm-commits mailing list