/// which has the same signature (i.e., def operands in the same place) but
/// a modified instruction type, flags, or otherwise. An example: X86 moves
/// are sometimes transformed into equivalent LEAs.
- void substituteDebugValuesForInst(const MachineInstr &Old, MachineInstr &New);
+ /// If the two instructions are not the same opcode, limit which operands to
+ /// examine for substitutions to the first N operands by setting
+ /// \p MaxOperand.
+ void substituteDebugValuesForInst(const MachineInstr &Old, MachineInstr &New,
+ unsigned MaxOperand = UINT_MAX);
MachineFunction(Function &F, const LLVMTargetMachine &Target,
const TargetSubtargetInfo &STI, unsigned FunctionNum,
}
void MachineFunction::substituteDebugValuesForInst(const MachineInstr &Old,
- MachineInstr &New) {
+ MachineInstr &New,
+ unsigned MaxOperand) {
// If the Old instruction wasn't tracked at all, there is no work to do.
unsigned OldInstrNum = Old.peekDebugInstrNum();
if (!OldInstrNum)
// Avoid creating new instr numbers unless we create a new substitution.
// While this has no functional effect, it risks confusing someone reading
// MIR output.
+ // Examine all the operands, or the first N specified by the caller.
+ MaxOperand = std::min(MaxOperand, Old.getNumOperands());
for (unsigned int I = 0; I < Old.getNumOperands(); ++I) {
const auto &OldMO = Old.getOperand(I);
+ auto &NewMO = New.getOperand(I);
+ (void)NewMO;
if (!OldMO.isReg() || !OldMO.isDef())
continue;
- assert(Old.getOperand(I).isDef());
+ assert(NewMO.isDef());
unsigned NewInstrNum = New.getDebugInstrNum();
makeDebugValueSubstitution(std::make_pair(OldInstrNum, I),