[llvm-dev] Working with X86 registers in MachineInstr

Ethan J. Johnson via llvm-dev llvm-dev at lists.llvm.org
Tue Aug 11 15:36:53 PDT 2015


Hi all,

 

I am attempting to implement the "reaching definitions" data-flow algorithm
on (X86) MachineBasicBlocks for an analysis pass. To do this, I need to
compute gen/kill sets for machine basic blocks. To start with, I am only
considering the general-purpose registers, RAX-R15 and their sub-registers.
Thus, I need to examine each MachineInstr to determine which register(s) it
defines and/or uses.

 

I see in the Doxygen that for a MachineOperand, I can call isReg() and
getReg() to figure out which X86 register the operand corresponds to. These
return an unsigned int "register number"; but I'm not sure how to identify
which register actually corresponds to that number.

 

Also, I will need to identify definitions and uses of registers in
instructions. I see that MachineOperand has methods such as isUse(),
isDef(), and isKill(), which sound like they might be relevant to what I'm
doing; but neither the Doxygen nor the source are particularly helpful as to
what they actually do. From the MachineInstr documentation, I gathered that
instructions which define a value are always written so that the value being
defined is the first operand; but since X86 has instructions that use more
than one register as output (multiplication, for instance), I would need to
manually account for the semantics of each instruction. Since X86 has a
great many instructions to account for, many of them obscure, I would very
much prefer not to go this route if LLVM already provides it! :-)

 

To summarize, my questions are as follows:

1.       How can I determine the actual X86 register that a MachineOperand
corresponds to?

2.       What is the best/most straightforward way to determine whether a
MachineInstr defines and/or uses a particular register?

 

Thanks,

Ethan Johnson

 

Ethan J. Johnson

Computer Science PhD student, Systems group, University of Rochester

 <mailto:ejohns48 at cs.rochester.edu> ejohns48 at cs.rochester.edu

 <mailto:ethanjohnson at acm.org> ethanjohnson at acm.org

PGP pubkey available from public directory or on request

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150811/edcae83a/attachment.html>


More information about the llvm-dev mailing list