I’m writing a machine function pass that very simply iterates over instructions and in a certain case replaces the opcode of one instruction with another opcode I’ve introduced. Ideally I’d like to change the opcode of the machine instruction object I’m iterating over, but this doesn’t seem possible with the API, so instead I’m creating a new instruction before the existing one with
BuildMI and then erasing the original. I’m using the following code to do this and wanted to make sure this actually achieves what I want:
MachineInstr &NewMI = BuildMI(MBB, MI, DL, TII->get(NewOpcode)); NewMI.copyImplicitOps(MF, MI); NewMI.cloneMemRefs(MF, MI); NewMI.cloneInstrSymbols(MF, MI); MI.eraseFromParent();
I’m hoping this will give the
NewMI all the same operands and properties of
MI but with a different opcode. For instance,
copyImplicitOps seems to do what I want, but I’m unsure what ‘implicit’ means here - will any be left out that I’d have to copy over manually? And do I need
cloneInstrSymbols? Lastly are there any other properties I need to copy over?