//
struct VISIBILITY_HIDDEN DeadInstElimination : public BasicBlockPass {
static char ID; // Pass identification, replacement for typeid
- DeadInstElimination() : BasicBlockPass(intptr_t(&ID)) {}
+ DeadInstElimination() : BasicBlockPass(&ID) {}
virtual bool runOnBasicBlock(BasicBlock &BB) {
bool Changed = false;
- for (BasicBlock::iterator DI = BB.begin(); DI != BB.end(); )
- if (dceInstruction(DI)) {
+ for (BasicBlock::iterator DI = BB.begin(); DI != BB.end(); ) {
+ Instruction *Inst = DI++;
+ if (isInstructionTriviallyDead(Inst)) {
+ Inst->eraseFromParent();
Changed = true;
++DIEEliminated;
- } else
- ++DI;
+ }
+ }
return Changed;
}