Update -mem2reg to use succ_iterator instead of iterating across TerminatorInst
authorNick Lewycky <nicholas@mxc.ca>
Thu, 13 Mar 2008 02:42:41 +0000 (02:42 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Thu, 13 Mar 2008 02:42:41 +0000 (02:42 +0000)
successors. This makes it support nounwind.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48320 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/PromoteMemoryToRegister.cpp

index 7d08a7cfd1d996b2b179935a07ee6c5a76459547..3d25dee1e8a86a448ea73a058f1f0bb7c2b5ab92 100644 (file)
@@ -884,12 +884,10 @@ NextIteration:
       // operands so far.  Remember this count.
       unsigned NewPHINumOperands = APN->getNumOperands();
       
-      TerminatorInst *PredTerm = Pred->getTerminator();
       unsigned NumEdges = 0;
-      for (unsigned i = 0, e = PredTerm->getNumSuccessors(); i != e; ++i) {
-        if (PredTerm->getSuccessor(i) == BB)
+      for (succ_iterator I = succ_begin(Pred), E = succ_end(Pred); I != E; ++I)
+        if (*I == BB)
           ++NumEdges;
-      }
       assert(NumEdges && "Must be at least one edge from Pred to BB!");
       
       // Add entries for all the phis.
@@ -952,18 +950,17 @@ NextIteration:
   }
 
   // 'Recurse' to our successors.
-  TerminatorInst *TI = BB->getTerminator();
-  unsigned NumSuccs = TI->getNumSuccessors();
-  if (NumSuccs == 0) return;
-  
-  // Add all-but-one successor to the worklist.
-  for (unsigned i = 0; i != NumSuccs-1; i++)
-    Worklist.push_back(RenamePassData(TI->getSuccessor(i), BB, IncomingVals));
-  
+  succ_iterator I = succ_begin(BB), E = succ_end(BB);
+  if (I == E) return;
+
   // Handle the last successor without using the worklist.  This allows us to
   // handle unconditional branches directly, for example.
+  --E;
+  for (; I != E; ++I)
+    Worklist.push_back(RenamePassData(*I, BB, IncomingVals));
+
   Pred = BB;
-  BB = TI->getSuccessor(NumSuccs-1);
+  BB = *I;
   goto NextIteration;
 }