Make getNumBackEdges more efficient
authorChris Lattner <sabre@nondot.org>
Sun, 12 Oct 2003 22:14:27 +0000 (22:14 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 12 Oct 2003 22:14:27 +0000 (22:14 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9063 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/LoopInfo.cpp

index 8c425623705404d1ef91f2f42fa195b7af518401..e92f10d49c3d6e555ae13ed9acda511d906bb3bc 100644 (file)
@@ -33,17 +33,16 @@ bool Loop::isLoopExit(const BasicBlock *BB) const {
   return false;
 }
 
+/// getNumBackEdges - Calculate the number of back edges to the loop header.
+///
 unsigned Loop::getNumBackEdges() const {
   unsigned NumBackEdges = 0;
   BasicBlock *H = getHeader();
 
-  for (std::vector<BasicBlock*>::const_iterator I = Blocks.begin(),
-         E = Blocks.end(); I != E; ++I)
-    for (succ_iterator SI = succ_begin(*I), SE = succ_end(*I);
-         SI != SE; ++SI)
-      if (*SI == H)
-       ++NumBackEdges;
-  
+  for (pred_iterator I = pred_begin(H), E = pred_end(H); I != E; ++I)
+    if (contains(*I))
+      ++NumBackEdges;
+
   return NumBackEdges;
 }