aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Analysis/LoopInfo.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-09-12 17:03:55 +0000
committerChris Lattner <sabre@nondot.org>2005-09-12 17:03:55 +0000
commitb6a69e70e00857a60861b584ed88cb57eae58175 (patch)
tree4938304265a5b1fb80c67ea00ec3878fd388bf6f /lib/Analysis/LoopInfo.cpp
parent331a1833e12b6229986f63f0a156062affbf3142 (diff)
downloadexternal_llvm-b6a69e70e00857a60861b584ed88cb57eae58175.zip
external_llvm-b6a69e70e00857a60861b584ed88cb57eae58175.tar.gz
external_llvm-b6a69e70e00857a60861b584ed88cb57eae58175.tar.bz2
Add a new getLoopLatch() method.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23315 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/LoopInfo.cpp')
-rw-r--r--lib/Analysis/LoopInfo.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/Analysis/LoopInfo.cpp b/lib/Analysis/LoopInfo.cpp
index e12d317..b8315ac 100644
--- a/lib/Analysis/LoopInfo.cpp
+++ b/lib/Analysis/LoopInfo.cpp
@@ -373,12 +373,36 @@ BasicBlock *Loop::getLoopPreheader() const {
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