[llvm-commits] CVS: llvm/lib/Analysis/LoopInfo.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Sep 12 10:04:07 PDT 2005



Changes in directory llvm/lib/Analysis:

LoopInfo.cpp updated: 1.64 -> 1.65
---
Log message:

Add a new getLoopLatch() method.



---
Diffs of the changes:  (+25 -1)

 LoopInfo.cpp |   26 +++++++++++++++++++++++++-
 1 files changed, 25 insertions(+), 1 deletion(-)


Index: llvm/lib/Analysis/LoopInfo.cpp
diff -u llvm/lib/Analysis/LoopInfo.cpp:1.64 llvm/lib/Analysis/LoopInfo.cpp:1.65
--- llvm/lib/Analysis/LoopInfo.cpp:1.64	Thu May  5 18:43:47 2005
+++ llvm/lib/Analysis/LoopInfo.cpp	Mon Sep 12 12:03:55 2005
@@ -373,12 +373,36 @@
   if (SI != succ_end(Out))
     return 0;  // Multiple exits from the block, must not be a preheader.
 
-
   // If there is exactly one preheader, return it.  If there was zero, then Out
   // is still null.
   return Out;
 }
 
+/// getLoopLatch - If there is a latch block for this loop, return it.  A
+/// latch block is the canonical backedge for a loop.  A loop header in normal
+/// form has two edges into it: one from a preheader and one from a latch
+/// block.
+BasicBlock *Loop::getLoopLatch() const {
+  BasicBlock *Header = getHeader();
+  pred_iterator PI = pred_begin(Header), PE = pred_end(Header);
+  if (PI == PE) return 0;  // no preds?
+  
+  BasicBlock *Latch = 0;
+  if (contains(*PI))
+    Latch = *PI;
+  ++PI;
+  if (PI == PE) return 0;  // only one pred?
+  
+  if (contains(*PI)) {
+    if (Latch) return 0;  // multiple backedges
+    Latch = *PI;
+  }
+  ++PI;
+  if (PI != PE) return 0;  // more than two preds
+  
+  return Latch;  
+}
+
 /// getCanonicalInductionVariable - Check to see if the loop has a canonical
 /// induction variable: an integer recurrence that starts at 0 and increments by
 /// one each time through the loop.  If so, return the phi node that corresponds






More information about the llvm-commits mailing list