}
}
+ /// Wrapper Method to do all the necessary work when an Instruction is
+ /// deleted.
+ /// Optimizations should use this to make sure that deleted instructions
+ /// are always accounted for.
+ void deleteInstr(MachineInstr* MI) {
+ ErasedInstrs.insert(MI);
+ LIS->RemoveMachineInstrFromMaps(*MI);
+ MI->eraseFromParent();
+ }
+
public:
static char ID; ///< Class identification, replacement for typeinfo
RegisterCoalescer() : MachineFunctionPass(ID) {
S.MergeValueNumberInto(SubDVNI, SubBValNo);
}
- ErasedInstrs.insert(UseMI);
- LIS->RemoveMachineInstrFromMaps(*UseMI);
- UseMI->eraseFromParent();
+ deleteInstr(UseMI);
}
// Extend BValNo by merging in IntA live segments of AValNo. Val# definition
// Note: This is fine to remove the copy before updating the live-ranges.
// While updating the live-ranges, we only look at slot indices and
// never go back to the instruction.
- LIS->RemoveMachineInstrFromMaps(CopyMI);
// Mark instructions as deleted.
- ErasedInstrs.insert(&CopyMI);
- CopyMI.eraseFromParent();
+ deleteInstr(&CopyMI);
// Update the liveness.
SmallVector<SlotIndex, 8> EndPoints;
// Eliminate undefs.
if (!CP.isPhys() && eliminateUndefCopy(CopyMI)) {
- LIS->RemoveMachineInstrFromMaps(*CopyMI);
- CopyMI->eraseFromParent();
+ deleteInstr(CopyMI);
return false; // Not coalescable.
}
}
DEBUG(dbgs() << "\tMerged values: " << LI << '\n');
}
- LIS->RemoveMachineInstrFromMaps(*CopyMI);
- CopyMI->eraseFromParent();
+ deleteInstr(CopyMI);
return true;
}
if (!CP.isPartial() && !CP.isPhys()) {
if (adjustCopiesBackFrom(CP, CopyMI) ||
removeCopyByCommutingDef(CP, CopyMI)) {
- LIS->RemoveMachineInstrFromMaps(*CopyMI);
- CopyMI->eraseFromParent();
+ deleteInstr(CopyMI);
DEBUG(dbgs() << "\tTrivial!\n");
return true;
}
}
}
- LIS->RemoveMachineInstrFromMaps(*CopyMI);
- CopyMI->eraseFromParent();
+ deleteInstr(CopyMI);
// We don't track kills for reserved registers.
MRI->clearKillFlags(CP.getSrcReg());