//===- DeadStoreElimination.cpp - Dead Store Elimination ------------------===//
-//
+//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
+//
//===----------------------------------------------------------------------===//
//
// This file implements a trivial dead store elimination that only considers
Changed |= runOnBasicBlock(*I);
return Changed;
}
-
+
bool runOnBasicBlock(BasicBlock &BB);
-
+
void DeleteDeadInstructionChains(Instruction *I,
SetVector<Instruction*> &DeadInsts);
unsigned Size = ~0U;
if (!AI->isArrayAllocation() &&
AI->getType()->getElementType()->isSized())
- Size = TD.getTypeSize(AI->getType()->getElementType());
+ Size = (unsigned)TD.getTypeSize(AI->getType()->getElementType());
KillLocs.add(AI, Size);
}
}
bool MadeChange = false;
for (BasicBlock::iterator BBI = BB.end(); BBI != BB.begin(); ) {
Instruction *I = --BBI; // Keep moving iterator backwards
-
+
// If this is a free instruction, it makes the free'd location dead!
if (FreeInst *FI = dyn_cast<FreeInst>(I)) {
// Free instructions make any stores to the free'd location dead.
// the stored location is already in the tracker, then this is a dead
// store. We can just delete it here, but while we're at it, we also
// delete any trivially dead expression chains.
- unsigned ValSize = TD.getTypeSize(I->getOperand(0)->getType());
+ unsigned ValSize = (unsigned)TD.getTypeSize(I->getOperand(0)->getType());
Value *Ptr = I->getOperand(1);
if (AliasSet *AS = KillLocs.getAliasSetForPointerIfExists(Ptr, ValSize))
// See if this made any operands dead. We do it this way in case the
// instruction uses the same operand twice. We don't want to delete a
// value then reference it.
- while (unsigned NumOps = I->getNumOperands()) {
- Instruction *Op = dyn_cast<Instruction>(I->getOperand(NumOps-1));
- I->op_erase(I->op_end()-1); // Drop from the operand list.
-
- if (Op) DeadInsts.insert(Op); // Attempt to nuke it later.
+ for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) {
+ if (Instruction *Op = dyn_cast<Instruction>(I->getOperand(i)))
+ DeadInsts.insert(Op); // Attempt to nuke it later.
+ I->setOperand(i, 0); // Drop from the operand list.
}
-
- I->getParent()->getInstList().erase(I);
+
+ I->eraseFromParent();
++NumOther;
}