diff options
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/IPO/InlineSimple.cpp | 9 | ||||
-rw-r--r-- | lib/Transforms/Scalar/ConstantProp.cpp | 17 | ||||
-rw-r--r-- | lib/Transforms/Scalar/DCE.cpp | 2 | ||||
-rw-r--r-- | lib/Transforms/Scalar/SCCP.cpp | 8 |
4 files changed, 17 insertions, 19 deletions
diff --git a/lib/Transforms/IPO/InlineSimple.cpp b/lib/Transforms/IPO/InlineSimple.cpp index d85b33dffd..de76dcd52d 100644 --- a/lib/Transforms/IPO/InlineSimple.cpp +++ b/lib/Transforms/IPO/InlineSimple.cpp @@ -37,7 +37,8 @@ using namespace opt; static inline void RemapInstruction(Instruction *I, map<const Value *, Value*> &ValueMap) { - for (unsigned op = 0; const Value *Op = I->getOperand(op); ++op) { + for (unsigned op = 0, E = I->getNumOperands(); op != E; ++op) { + const Value *Op = I->getOperand(op); Value *V = ValueMap[Op]; if (!V && Op->isMethod()) continue; // Methods don't get relocated @@ -115,11 +116,9 @@ bool opt::InlineMethod(BasicBlock::iterator CIIt) { // Method::ArgumentListType::const_iterator PTI = CalledMeth->getArgumentList().begin(); - for (unsigned a = 1; Value *Operand = CI->getOperand(a); ++a, ++PTI) { - ValueMap[*PTI] = Operand; - } + for (unsigned a = 1, E = CI->getNumOperands(); a != E; ++a, ++PTI) + ValueMap[*PTI] = CI->getOperand(a); - ValueMap[NewBB] = NewBB; // Returns get converted to reference NewBB // Loop over all of the basic blocks in the method, inlining them as 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 diff --git a/lib/Transforms/Scalar/DCE.cpp b/lib/Transforms/Scalar/DCE.cpp index 8e37279178..fa2c9c7221 100644 --- a/lib/Transforms/Scalar/DCE.cpp +++ b/lib/Transforms/Scalar/DCE.cpp @@ -91,7 +91,7 @@ static bool RemoveSingularPHIs(BasicBlock *BB) { do { PHINode *PN = (PHINode*)I; - assert(PN->getOperand(2) == 0 && "PHI node should only have one value!"); + assert(PN->getNumOperands() == 2 && "PHI node should only have one value!"); Value *V = PN->getOperand(0); PN->replaceAllUsesWith(V); // Replace PHI node with its single value. diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index 8b59e19c1c..5bb75c7008 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -408,10 +408,10 @@ void SCCP::UpdateInstruction(Instruction *I) { markExecutable(Succ); } else if (SCValue.isConstant()) { ConstPoolVal *CPV = SCValue.getConstant(); - for (SwitchInst::dest_iterator I = SI->dest_begin(), E = SI->dest_end(); - I != E; ++I) { - if (I->first->equals(CPV)) { // Found the right branch... - markExecutable(I->second); + // Make sure to skip the "default value" which isn't a value + for (unsigned i = 1, E = SI->getNumSuccessors(); i != E; ++i) { + if (SI->getSuccessorValue(i)->equals(CPV)) {// Found the right branch... + markExecutable(SI->getSuccessor(i)); return; } } |