[llvm-commits] [llvm] r48320 - /llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
Nick Lewycky
nicholas at mxc.ca
Wed Mar 12 19:42:41 PDT 2008
Author: nicholas
Date: Wed Mar 12 21:42:41 2008
New Revision: 48320
URL: http://llvm.org/viewvc/llvm-project?rev=48320&view=rev
Log:
Update -mem2reg to use succ_iterator instead of iterating across TerminatorInst
successors. This makes it support nounwind.
Modified:
llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
Modified: llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp?rev=48320&r1=48319&r2=48320&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp Wed Mar 12 21:42:41 2008
@@ -884,12 +884,10 @@
// 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 @@
}
// '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;
}
More information about the llvm-commits
mailing list