How to get assembly opcode mnemonic(s) corresponding to a MachineInstr?


I'd like to modify MachineBasicBlock contents within a
MachineFunctionPass on the basis of how many CPU cycles the assembly
instructions corresponding to the MBB take. I'm using the AVR backend
and the number of CPU cycles every AVR assembly operation takes is
openly available.

Is there any straightforward way of getting the opcode mnemonics
corresponding to a MachineInstr? I've gone through this thread
and I understand I need to modify the AsmPrinter or InstPrinter in
some way, but am not sure how.

Thank you for your help!


I think that you actually want to do the opposite of what you’re asking: identify the opcode of a MCInstrDesc that corresponds to a particular mnemonic. Unfortunately, there is no way of doing this other than looking in the backend’s instruction definitions. Attempting to print the instruction using the AsmPrinter and then parse the mnemonic is almost certainly not the right way of doing anything (though it would help if you explained what you are trying to do).


I have a table which maps each AVR mnemonic to the number of CPU
cycles it takes (eg. `add` takes 1 cycle, `adiw` takes 2 cycles, etc;
source: [1]) and I'd like to find out how many CPU cycles does the
particular MachineBasicBlock take and accordingly make modifications.

I read up and found that each MachineInstr descriptor defines the
opcode mnemonic as well, but I can't seem to find any function which
returns the mnemonic corresponding to the MCInstrDesc (the closest
function I can find is getOpcode()).

However I see that in <Target> (
for me), there's a MnemonicTable char array which contains all the
mnemonics of the <Target> and a MatchTable array which matches
MachineInstr opcodes to MnemonicTable indices (like AVR::ADCRdRr
matches to 0; 0 being the starting index of the string `adc` in

Apologies for the verbosity, I assume there are the tables required
for my purpose. Thank you very much for your pointer to the backend
instruction definitions!