[llvm-dev] Working with X86 registers in MachineInstr
Quentin Colombet via llvm-dev
llvm-dev at lists.llvm.org
Tue Aug 11 15:42:57 PDT 2015
> On Aug 11, 2015, at 3:36 PM, Ethan J. Johnson via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 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.
There is an implementation of such algorithm in AArch64CollectLOH.cpp. I suggest you have a look there.
If the algorithm is of general use, we may want to move it into some generic place.
Let me know if you need more information.
> 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?
> Ethan Johnson
> Ethan J. Johnson
> Computer Science PhD student, Systems group, University of Rochester
> ejohns48 at cs.rochester.edu <mailto:ejohns48 at cs.rochester.edu>
> ethanjohnson at acm.org <mailto:ethanjohnson at acm.org>
> PGP pubkey available from public directory or on request
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org> http://llvm.cs.uiuc.edu <http://llvm.cs.uiuc.edu/>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev <http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev