aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/ConstantProp.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-05-06 17:54:10 +0000
committerChris Lattner <sabre@nondot.org>2002-05-06 17:54:10 +0000
commitf51825e3fb74db0e6c85583a9a662000eb1e8388 (patch)
tree8bd6711607efbe1978778fc46a5eed5996e87bd3 /lib/Transforms/Scalar/ConstantProp.cpp
parentdb93124d41ff5e50425982ef3ade15d6b8096d1b (diff)
* Use simplified interface to constant propogation stuff.
* Remove dead PHI case (which could not work due to getNumOperands rather than getNumIncomingValues. This really belongs in InstCombine, anyway so we'll move it there. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2497 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/ConstantProp.cpp')
-rw-r--r--lib/Transforms/Scalar/ConstantProp.cpp43
1 files changed, 8 insertions, 35 deletions
diff --git a/lib/Transforms/Scalar/ConstantProp.cpp b/lib/Transforms/Scalar/ConstantProp.cpp
index 9e519e7cf7..aa46f2bb49 100644
--- a/lib/Transforms/Scalar/ConstantProp.cpp
+++ b/lib/Transforms/Scalar/ConstantProp.cpp
@@ -179,43 +179,16 @@ bool ConstantFoldTerminator(BasicBlock *BB, BasicBlock::iterator &II,
//
bool doConstantPropogation(BasicBlock *BB, BasicBlock::iterator &II) {
Instruction *Inst = *II;
- if (BinaryOperator *BO = dyn_cast<BinaryOperator>(Inst)) {
- Constant *D1 = dyn_cast<Constant>(BO->getOperand(0));
- Constant *D2 = dyn_cast<Constant>(BO->getOperand(1));
-
- if (D1 && D2)
- return ConstantFoldBinaryInst(BB, II, BO, D1, D2);
-
- } else if (CastInst *CI = dyn_cast<CastInst>(Inst)) {
- Constant *D = dyn_cast<Constant>(CI->getOperand(0));
- if (D) return ConstantFoldCast(BB, II, CI, D);
-
- } else if (UnaryOperator *UInst = dyn_cast<UnaryOperator>(Inst)) {
- Constant *D = dyn_cast<Constant>(UInst->getOperand(0));
- if (D) return ConstantFoldUnaryInst(BB, II, UInst, D);
- } else if (TerminatorInst *TInst = dyn_cast<TerminatorInst>(Inst)) {
+ if (TerminatorInst *TInst = dyn_cast<TerminatorInst>(Inst)) {
return ConstantFoldTerminator(BB, II, TInst);
+ } else if (Constant *C = ConstantFoldInstruction(Inst)) {
+ // Replaces all of the uses of a variable with uses of the constant.
+ Inst->replaceAllUsesWith(C);
+
+ // Remove the instruction from the basic block...
+ delete BB->getInstList().remove(II);
+ return true;
- } else if (PHINode *PN = dyn_cast<PHINode>(Inst)) {
- // If it's a PHI node and only has one operand
- // Then replace it directly with that operand.
- assert(PN->getNumOperands() && "PHI Node must have at least one 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
- PN->getParent()->getInstList().remove(II);
- if (PN->hasName()) // Inherit PHINode name
- V->setName(PN->getName(), BB->getParent()->getSymbolTableSure());
- delete PN; // Finally, delete the node...
- return true;
- }
- } else if (ShiftInst *SI = dyn_cast<ShiftInst>(Inst)) {
- Constant *D1 = dyn_cast<Constant>(SI->getOperand(0));
- Constant *D2 = dyn_cast<Constant>(SI->getOperand(1));
-
- if (D1 && D2)
- return ConstantFoldShiftInst(BB, II, SI, D1, D2);
}
return false;