[LLVMdev] Inspecting target-specific opcodes in machine function pass

Tim Northover t.p.northover at gmail.com
Sun Mar 8 13:21:45 PDT 2015


Hi,

> As the comment suggests I want to inspect the target-specific opcode of each
> instruction. By opcode I mean the actual machine code (=encoding of that in
> struction as an array of bytes), not the integer descriptor returned by
> I->getOpcode().

That's not generally possible. The best you might be able to do would
be to lower each MachineInstr to an MCInst and emit its encoding via
an MCCodeEmitter. But that has quite a few problems:

  + There's virtually no hope before register allocation. You'd
probably get an assertion if you're lucky.
  + Many targets don't have really separate "opcode" and "operand"
bytes. Just 32-bit (say) instructions that have
  + A MachineInstr can become 0, 1, or many real target .instructions
  + What you get back may or may not be what's emitted finally anyway.
  + It's slow and redundant work.

What are you trying to do with the opcode? There may be a better way.

Cheers.

Tim.



More information about the llvm-dev mailing list