aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/ConstantProp.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-07-07 08:36:50 +0000
committerChris Lattner <sabre@nondot.org>2001-07-07 08:36:50 +0000
commitc8b25d40cbec063b1ca99cc1adf794399c6d05c0 (patch)
tree8ad1468cb632eb9770206b1bd4bdd45d4e037898 /lib/Transforms/Scalar/ConstantProp.cpp
parentf0d0e9c262b668cf362fbaa8111bb6cc15268909 (diff)
Changed the fundemental architecture of Operands for Instructions. Now
Operands are maintained as a vector<Use> in the User class, and operator iterators are provided as before. Getting an operand no longer requires a virtual function call. WARNING: getOperand(x) where x >= getNumOperands() will now assert instead of returning null! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/ConstantProp.cpp')
-rw-r--r--lib/Transforms/Scalar/ConstantProp.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/Transforms/Scalar/ConstantProp.cpp b/lib/Transforms/Scalar/ConstantProp.cpp
index 7a0254bca7..91a21c3c6b 100644
--- a/lib/Transforms/Scalar/ConstantProp.cpp
+++ b/lib/Transforms/Scalar/ConstantProp.cpp
@@ -132,9 +132,9 @@ bool opt::ConstantFoldTerminator(TerminatorInst *T) {
BasicBlock *Dest1 = BI->getOperand(0)->castBasicBlockAsserting();
BasicBlock *Dest2 = BI->getOperand(1)->castBasicBlockAsserting();
- if (BI->getOperand(2)->isConstant()) { // Are we branching on constant?
+ if (BI->getCondition()->isConstant()) { // Are we branching on constant?
// YES. Change to unconditional branch...
- ConstPoolBool *Cond = (ConstPoolBool*)BI->getOperand(2);
+ ConstPoolBool *Cond = (ConstPoolBool*)BI->getCondition();
BasicBlock *Destination = Cond->getValue() ? Dest1 : Dest2;
BasicBlock *OldDest = Cond->getValue() ? Dest2 : Dest1;
@@ -147,9 +147,9 @@ bool opt::ConstantFoldTerminator(TerminatorInst *T) {
assert(BI->getParent() && "Terminator not inserted in block!");
OldDest->removePredecessor(BI->getParent());
- BI->setOperand(0, Destination); // Set the unconditional destination
- BI->setOperand(1, 0); // Clear the conditional destination
- BI->setOperand(2, 0); // Clear the condition...
+ // Set the unconditional destination, and change the insn to be an
+ // unconditional branch.
+ BI->setUnconditionalDest(Destination);
return true;
} else if (Dest2 == Dest1) { // Conditional branch to same location?
// This branch matches something like this:
@@ -160,9 +160,8 @@ bool opt::ConstantFoldTerminator(TerminatorInst *T) {
assert(BI->getParent() && "Terminator not inserted in block!");
Dest1->removePredecessor(BI->getParent());
- // Nuke the second destination, and the use of the condition variable
- BI->setOperand(1, 0); // Clear the conditional destination
- BI->setOperand(2, 0); // Clear the condition...
+ // Change a conditional branch to unconditional.
+ BI->setUnconditionalDest(Dest1);
return true;
}
}
@@ -192,7 +191,7 @@ ConstantFoldInstruction(Method *M, Method::inst_iterator &II) {
PHINode *PN = (PHINode*)Inst; // If it's a PHI node and only has one operand
// Then replace it directly with that operand.
assert(PN->getOperand(0) && "PHI Node must have at least one operand!");
- if (PN->getOperand(1) == 0) { // If the PHI Node has exactly 1 operand
+ if (PN->getNumOperands() == 1) { // If the PHI Node has exactly 1 operand
Value *V = PN->getOperand(0);
PN->replaceAllUsesWith(V); // Replace all uses of this PHI
// Unlink from basic block