[llvm-commits] CVS: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp LICM.cpp LoopSimplify.cpp

Chris Lattner lattner at cs.uiuc.edu
Wed Jan 7 18:10:00 PST 2004


Changes in directory llvm/lib/Transforms/Scalar:

IndVarSimplify.cpp updated: 1.51 -> 1.52
LICM.cpp updated: 1.54 -> 1.55
LoopSimplify.cpp updated: 1.29 -> 1.30

---
Log message:

Improve encapsulation in the Loop and LoopInfo classes by eliminating the
getSubLoops/getTopLevelLoops methods, replacing them with iterator-based 
accessors.


---
Diffs of the changes:  (+24 -26)

Index: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
diff -u llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.51 llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.52
--- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.51	Tue Dec 23 01:47:09 2003
+++ llvm/lib/Transforms/Scalar/IndVarSimplify.cpp	Wed Jan  7 18:09:44 2004
@@ -43,8 +43,8 @@
       Changed = false;
 
       // Induction Variables live in the header nodes of loops
-      for (unsigned i = 0, e = Loops->getTopLevelLoops().size(); i != e; ++i)
-        runOnLoop(Loops->getTopLevelLoops()[i]);
+      for (LoopInfo::iterator I = Loops->begin(), E = Loops->end(); I != E; ++I)
+        runOnLoop(*I);
       return Changed;
     }
 
@@ -77,8 +77,8 @@
 
 void IndVarSimplify::runOnLoop(Loop *Loop) {
   // Transform all subloops before this loop...
-  for (unsigned i = 0, e = Loop->getSubLoops().size(); i != e; ++i)
-    runOnLoop(Loop->getSubLoops()[i]);
+  for (LoopInfo::iterator I = Loop->begin(), E = Loop->end(); I != E; ++I)
+    runOnLoop(*I);
 
   // Get the header node for this loop.  All of the phi nodes that could be
   // induction variables must live in this basic block.


Index: llvm/lib/Transforms/Scalar/LICM.cpp
diff -u llvm/lib/Transforms/Scalar/LICM.cpp:1.54 llvm/lib/Transforms/Scalar/LICM.cpp:1.55
--- llvm/lib/Transforms/Scalar/LICM.cpp:1.54	Fri Dec 19 02:18:16 2003
+++ llvm/lib/Transforms/Scalar/LICM.cpp	Wed Jan  7 18:09:44 2004
@@ -113,8 +113,8 @@
     ///
     bool inSubLoop(BasicBlock *BB) {
       assert(CurLoop->contains(BB) && "Only valid if BB is IN the loop");
-      for (unsigned i = 0, e = CurLoop->getSubLoops().size(); i != e; ++i)
-        if (CurLoop->getSubLoops()[i]->contains(BB))
+      for (Loop::iterator I = CurLoop->begin(), E = CurLoop->end(); I != E; ++I)
+        if ((*I)->contains(BB))
           return true;  // A subloop actually contains this block!
       return false;
     }
@@ -221,9 +221,7 @@
   DT = &getAnalysis<DominatorTree>();
 
   // Hoist expressions out of all of the top-level loops.
-  const std::vector<Loop*> &TopLevelLoops = LI->getTopLevelLoops();
-  for (std::vector<Loop*>::const_iterator I = TopLevelLoops.begin(),
-         E = TopLevelLoops.end(); I != E; ++I) {
+  for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I) {
     AliasSetTracker AST(*AA);
     visitLoop(*I, AST);
   }
@@ -235,8 +233,7 @@
 ///
 void LICM::visitLoop(Loop *L, AliasSetTracker &AST) {
   // Recurse through all subloops before we process this loop...
-  for (std::vector<Loop*>::const_iterator I = L->getSubLoops().begin(),
-         E = L->getSubLoops().end(); I != E; ++I) {
+  for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I) {
     AliasSetTracker SubAST(*AA);
     visitLoop(*I, SubAST);
 


Index: llvm/lib/Transforms/Scalar/LoopSimplify.cpp
diff -u llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.29 llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.30
--- llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.29	Fri Dec 19 00:27:08 2003
+++ llvm/lib/Transforms/Scalar/LoopSimplify.cpp	Wed Jan  7 18:09:44 2004
@@ -91,8 +91,8 @@
   bool Changed = false;
   LoopInfo &LI = getAnalysis<LoopInfo>();
 
-  for (unsigned i = 0, e = LI.getTopLevelLoops().size(); i != e; ++i)
-    Changed |= ProcessLoop(LI.getTopLevelLoops()[i]);
+  for (LoopInfo::iterator I = LI.begin(), E = LI.end(); I != E; ++I)
+    Changed |= ProcessLoop(*I);
 
   return Changed;
 }
@@ -136,9 +136,8 @@
     Changed = true;
   }
 
-  const std::vector<Loop*> &SubLoops = L->getSubLoops();
-  for (unsigned i = 0, e = SubLoops.size(); i != e; ++i)
-    Changed |= ProcessLoop(SubLoops[i]);
+  for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I)
+    Changed |= ProcessLoop(*I);
   return Changed;
 }
 
@@ -227,9 +226,8 @@
 static void ChangeExitBlock(Loop *L, BasicBlock *OldExit, BasicBlock *NewExit) {
   if (L->hasExitBlock(OldExit)) {
     L->changeExitBlock(OldExit, NewExit);
-    const std::vector<Loop*> &SubLoops = L->getSubLoops();
-    for (unsigned i = 0, e = SubLoops.size(); i != e; ++i)
-      ChangeExitBlock(SubLoops[i], OldExit, NewExit);
+    for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I)
+      ChangeExitBlock(*I, OldExit, NewExit);
   }
 }
 
@@ -266,16 +264,19 @@
   // is a sibling loop, ie, one with the same parent loop, or one if it's
   // children.
   //
-  const std::vector<Loop*> *ParentSubLoops;
-  if (Loop *Parent = L->getParentLoop())
-    ParentSubLoops = &Parent->getSubLoops();
-  else       // Must check top-level loops...
-    ParentSubLoops = &getAnalysis<LoopInfo>().getTopLevelLoops();
+  LoopInfo::iterator ParentLoops, ParentLoopsE;
+  if (Loop *Parent = L->getParentLoop()) {
+    ParentLoops = Parent->begin();
+    ParentLoopsE = Parent->end();
+  } else {      // Must check top-level loops...
+    ParentLoops = getAnalysis<LoopInfo>().begin();
+    ParentLoopsE = getAnalysis<LoopInfo>().end();
+  }
 
   // Loop over all sibling loops, performing the substitution (recursively to
   // include child loops)...
-  for (unsigned i = 0, e = ParentSubLoops->size(); i != e; ++i)
-    ChangeExitBlock((*ParentSubLoops)[i], Header, NewBB);
+  for (; ParentLoops != ParentLoopsE; ++ParentLoops)
+    ChangeExitBlock(*ParentLoops, Header, NewBB);
   
   DominatorSet &DS = getAnalysis<DominatorSet>();  // Update dominator info
   {





More information about the llvm-commits mailing list