Cloning a MachineInstr

I’m trying to clone a MachineInstr in the AsmPrinter::EmitInstruction, Here is the code:

void EsenciaAsmPrinter::EmitInstruction(const MachineInstr *MI) {
const MachineFunction *MF = MI->getParent()->getParent();
MachineInstr *CloneMI = MF->CloneMachineInstr(MI);


}

The problem is that MF is a const and CloneMachineInstr expects a non-const. Does anybody know if there is a way to create a copy of a given MachineInstr?

Any help is appreciated.

There is a getParent() function in MachineBasicBlock that returns non-const MachineFunction.

Patrick

The problem is that in
void EscalaAsmPrinter::EmitInstruction(const MachineInstr *MI), MI is a
const. So whenever I call MI->getParent()->getParent() I get a const
method. Is there a different way to clone a MachineInstr?

What are you trying to achieve in the end?

What are you trying to achieve in the end?


Mehdi

I need to insert extra NOP instructions into the bundle or at least
generate a few extra ones during the assembly generation.

You shouldn’t need to modify the the MachineFunction to do that. Just emit the extra MCInst directly. The ARM backend does things analogous to this for some of its MC level pseudo-instructions that might prove useful as examples you could adapt.

You shouldn’t need to modify the the MachineFunction to do that. Just emit
the extra MCInst directly. The ARM backend does things analogous to this
for some of its MC level pseudo-instructions that might prove useful as
examples you could adapt.

After looking at multiple options this was exactly my conclusion. Do you
mind pointing me to the code in ARM that does that?

There’s a giant switch statement in ARMAsmPrinter::EmitInstruction() that does a lot of it. The ARM::BMOVPCRX_CALL case does multiple instruction expansion from a single MachineInstr.