aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/SCCP.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-02-12 21:07:25 +0000
committerChris Lattner <sabre@nondot.org>2002-02-12 21:07:25 +0000
commit221d688a5ef21a22c2368c9fff0e92d7966c95e5 (patch)
treed2dc21b19341a39bdc0a47f4736d76839d9ad73b /lib/Transforms/Scalar/SCCP.cpp
parent3c34a46c7e51ab290b208248461542eb83c469b0 (diff)
Method.h no longer includes BasicBlock.h
Method::inst_* is now in llvm/Support/InstIterator.h GraphTraits specializations for BasicBlock and Methods are now in llvm/Support/CFG.h git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1746 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/SCCP.cpp')
-rw-r--r--lib/Transforms/Scalar/SCCP.cpp61
1 files changed, 29 insertions, 32 deletions
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp
index d6b7c40f34..ada670deb8 100644
--- a/lib/Transforms/Scalar/SCCP.cpp
+++ b/lib/Transforms/Scalar/SCCP.cpp
@@ -244,39 +244,36 @@ bool SCCP::doSCCP() {
// constants if we have found them to be of constant values.
//
bool MadeChanges = false;
- for (Method::inst_iterator II = M->inst_begin(); II != M->inst_end(); ) {
- Instruction *Inst = *II;
- InstVal &IV = ValueState[Inst];
- if (IV.isConstant()) {
- Constant *Const = IV.getConstant();
- // cerr << "Constant: " << Inst << " is: " << Const;
-
- // Replaces all of the uses of a variable with uses of the constant.
- Inst->replaceAllUsesWith(Const);
-
- // Remove the operator from the list of definitions...
- Inst->getParent()->getInstList().remove(II.getInstructionIterator());
-
- // The new constant inherits the old name of the operator...
- if (Inst->hasName() && !Const->hasName())
- Const->setName(Inst->getName(), M->getSymbolTableSure());
-
- // Delete the operator now...
- delete Inst;
-
- // Incrementing the iterator in an unchecked manner could mess up the
- // internals of 'II'. To make sure everything is happy, tell it we might
- // have broken it.
- II.resyncInstructionIterator();
-
- // Hey, we just changed something!
- MadeChanges = true;
- continue; // Skip the ++II at the end of the loop here...
- } else if (Inst->isTerminator()) {
- MadeChanges |= ConstantFoldTerminator(cast<TerminatorInst>(Inst));
- }
+ for (Method::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
+ BasicBlock *BB = *MI;
+ for (BasicBlock::iterator BI = BB->begin(); BI != BB->end();) {
+ Instruction *Inst = *BI;
+ InstVal &IV = ValueState[Inst];
+ if (IV.isConstant()) {
+ Constant *Const = IV.getConstant();
+ // cerr << "Constant: " << Inst << " is: " << Const;
+
+ // Replaces all of the uses of a variable with uses of the constant.
+ Inst->replaceAllUsesWith(Const);
+
+ // Remove the operator from the list of definitions...
+ BB->getInstList().remove(BI);
+
+ // The new constant inherits the old name of the operator...
+ if (Inst->hasName() && !Const->hasName())
+ Const->setName(Inst->getName(), M->getSymbolTableSure());
+
+ // Delete the operator now...
+ delete Inst;
+
+ // Hey, we just changed something!
+ MadeChanges = true;
+ } else if (TerminatorInst *TI = dyn_cast<TerminatorInst>(Inst)) {
+ MadeChanges |= ConstantFoldTerminator(TI);
+ }
- ++II;
+ ++BI;
+ }
}
// Merge identical constants last: this is important because we may have just