<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 8/11/15 5:36 PM, Ethan J. Johnson
via llvm-dev wrote:<br>
</div>
<blockquote
cite="mid:00f301d0d486$3c61c150$b52543f0$@cs.rochester.edu"
type="cite">
<meta http-equiv="Context-Type" content="text/html;
charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<div class="WordSection1">
<p class="MsoNormal">Hi all,</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">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.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">I see in the Doxygen that for a
MachineOperand, I can call <span>isReg()</span> and<span>
getReg()</span> 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.</p>
</div>
</blockquote>
<br>
I believe that the enum values X86::<reg> correspond to the
integers that you're seeing. For example, X86::RAX is %rax,
X86::RBX is %rbx, etc.<br>
<br>
<blockquote
cite="mid:00f301d0d486$3c61c150$b52543f0$@cs.rochester.edu"
type="cite">
<div class="WordSection1">
<p class="MsoNormal"> </p>
<p class="MsoNormal">Also, I will need to identify definitions
and uses of registers in instructions. I see that
MachineOperand has methods such as <span>isUse()</span>, <span>isDef()</span>,
and <span>isKill()</span>, 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! :-)</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">To summarize, my questions are as follows:</p>
<p class="MsoListParagraph"><span>1.<span> </span></span>How
can I determine the actual X86 register that a MachineOperand
corresponds to?</p>
<p class="MsoListParagraph"><span>2.<span> </span></span>What
is the best/most straightforward way to determine whether a
MachineInstr defines and/or uses a particular register?</p>
</div>
</blockquote>
<br>
I'm not sure if LLVM provides what you need, but I think it probably
does: I believe the Tablegen files contain information on which
registers are killed by each instruction so that the register
allocator can do its work. You should look at the LLVM register
allocator code and Quentin's code and see what it does and what APIs
LLVM provides for getting this information.<br>
<br>
In the unlikely event that LLVM does not provide the information you
need, your code will need to understand the semantics of the X86
instructions and determine which are read and written itself.
However, if you go that route, all is not lost; your code can
initially make conservative assumptions about instructions that it
does not recognize.<br>
<br>
Regards,<br>
<br>
John Criswell<br>
<blockquote
cite="mid:00f301d0d486$3c61c150$b52543f0$@cs.rochester.edu"
type="cite">
<div class="WordSection1">
<p class="MsoNormal"> </p>
<p class="MsoNormal">Thanks,</p>
<p class="MsoNormal">Ethan Johnson</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"><i>Ethan J. Johnson</i></p>
<p class="MsoNormal"><i>Computer Science PhD student, Systems
group, University of Rochester</i></p>
<p class="MsoNormal"><a moz-do-not-send="true"
href="mailto:ejohns48@cs.rochester.edu"><i><span>ejohns48@cs.rochester.edu</span></i></a></p>
<p class="MsoNormal"><a moz-do-not-send="true"
href="mailto:ethanjohnson@acm.org"><i><span>ethanjohnson@acm.org</span></i></a></p>
<p class="MsoNormal"><i>PGP pubkey available from public
directory or on request</i></p>
<p class="MsoNormal"> </p>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a> <a class="moz-txt-link-freetext" href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a class="moz-txt-link-freetext" href="http://www.cs.rochester.edu/u/criswell">http://www.cs.rochester.edu/u/criswell</a></pre>
</body>
</html>