Radhika via llvm-dev
2017-Feb-04 22:19 UTC
[llvm-dev] How to get assembly opcode mnemonic(s) corresponding to a MachineInstr?
Hi, 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 (http://lists.llvm.org/pipermail/llvm-dev/2012-October/054818.html) and I understand I need to modify the AsmPrinter or InstPrinter in some way, but am not sure how. Thank you for your help! Radhika
David Chisnall via llvm-dev
2017-Feb-05 01:21 UTC
[llvm-dev] How to get assembly opcode mnemonic(s) corresponding to a MachineInstr?
On 4 Feb 2017, at 14:19, Radhika via llvm-dev <llvm-dev at lists.llvm.org> wrote:> > Hi, > > 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 > (http://lists.llvm.org/pipermail/llvm-dev/2012-October/054818.html) > and I understand I need to modify the AsmPrinter or InstPrinter in > some way, but am not sure how.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). David
Radhika via llvm-dev
2017-Feb-05 12:52 UTC
[llvm-dev] How to get assembly opcode mnemonic(s) corresponding to a MachineInstr?
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>GenAsmMatcher.inc (AVRGenAsmMatcher.inc 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 MnemonicTable). 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! Radhika [1]: http://www.atmel.com/images/Atmel-0856-AVR-Instruction-Set-Manual.pdf#page=22 On Sun, Feb 5, 2017 at 6:51 AM, David Chisnall <David.Chisnall at cl.cam.ac.uk> wrote:> On 4 Feb 2017, at 14:19, Radhika via llvm-dev <llvm-dev at lists.llvm.org> wrote: >> >> Hi, >> >> 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 >> (http://lists.llvm.org/pipermail/llvm-dev/2012-October/054818.html) >> and I understand I need to modify the AsmPrinter or InstPrinter in >> some way, but am not sure how. > > 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). > > David >