Start using the new function cloning header
[oota-llvm.git] / lib / Analysis / LoopInfo.cpp
index 1c3d5ee5658a1ec4137d77026aeb870b07e5ce74..002e55362452a7da852adfee2137af56decbf606 100644 (file)
@@ -24,6 +24,30 @@ bool Loop::contains(const BasicBlock *BB) const {
   return find(Blocks.begin(), Blocks.end(), BB) != Blocks.end();
 }
 
+bool Loop::isLoopExit(const BasicBlock *BB) const {
+  for (BasicBlock::succ_const_iterator SI = succ_begin(BB), SE = succ_end(BB);
+       SI != SE; ++SI) {
+    if (! contains(*SI))
+      return true;
+  }
+  return false;
+}
+
+unsigned Loop::getNumBackEdges() const {
+  unsigned numBackEdges = 0;
+  BasicBlock *header = Blocks.front();
+
+  for (std::vector<BasicBlock*>::const_iterator i = Blocks.begin(), e = Blocks.end();
+       i != e; ++i) {
+    for (BasicBlock::succ_iterator Successor = succ_begin(*i), SEnd = succ_end(*i);
+        Successor != SEnd; ++Successor) {
+      if (header == *Successor)
+       ++numBackEdges;
+    }
+  }
+  return numBackEdges;
+}
+
 void Loop::print(std::ostream &OS) const {
   OS << std::string(getLoopDepth()*2, ' ') << "Loop Containing: ";
 
@@ -147,8 +171,9 @@ BasicBlock *Loop::getLoopPreheader() const {
   BasicBlock *Header = getHeader();
   for (pred_iterator PI = pred_begin(Header), PE = pred_end(Header);
        PI != PE; ++PI)
-    if (!contains(*PI)) { // If the block is not in the loop...
-      if (Out) return 0;  // Multiple predecessors outside the loop
+    if (!contains(*PI)) {     // If the block is not in the loop...
+      if (Out && Out != *PI)
+        return 0;             // Multiple predecessors outside the loop
       Out = *PI;
     }