<div dir="ltr"><div><div><div>Hi John,<br><br></div>Thank you so much for the comments! I will do it as suggested.<br><br></div>Thanks!<br></div>Ruiling<br><div><div><div><div><div class="gmail_extra"><br><div class="gmail_quote">2014-11-24 13:12 GMT+08:00 John Criswell <span dir="ltr"><<a href="mailto:jtcriswel@gmail.com" target="_blank">jtcriswel@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"><div><div class="h5">
<div>On 11/19/14, 3:54 AM, Ruiling Song
wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div>
<div>
<div>
<div>Hi,<br>
<br>
</div>
</div>
I want to get the information where the address of
load/store comes from, <br>
like below load instruction, %152 may come from a
getelementpr, or comes from some
gep+ptrtoint+add+inttoptr... instructions. what's the
recommended way to find the original memory pointer?<br>
<br>
%153 = load <2 x i16> addrspace(1)* %152, align 2<br>
<br>
</div>
going through the use-def chain seems not easy, because the
'add' operation contains two operands, one come from a
pointer, the other is an integer offset. I could not know
which is at operand 0 and which is at operand 1.<br>
</div>
</div>
</blockquote>
<br></div></div>
To find the source of the pointer for the LoadInst, you'll need to
climb up the def-use chain. In the case of an add instruction, you
will have to search back through both operands to figure out which
one originates from a pointer. You will also have to handle
phi-nodes, so you'll probably need a list of processed phi-nodes to
ensure that you don't iterate indefinitely.<br>
<br>
The only other way to do it is find all the definitions that you
consider to be pointer "origins" (e.g., function arguments, the
results of load instructions, etc.) and iterate through their uses
until you find the load instruction that uses the pointer (in this
case, %153). In other words, instead of starting at a use and
searching for the definition, you start at all possible definitions
and look for the use. If you're searching for a lot of pointers,
this may end up being more efficient as you won't be traversing the
same definitions over and over again.<br>
<br>
In short, you're attacking the problem in the right way, and I don't
think there's really any better way of doing it.<br>
<br>
Regards,<br>
<br>
John Criswell<br>
<br>
<br>
<br>
<blockquote type="cite">
<div dir="ltr">
<div><br>
</div>
Thanks!<br>
Ruiling<br>
<div>
<div><br>
</div>
</div>
</div><span class="">
<br>
<fieldset></fieldset>
<br>
<pre>_______________________________________________
LLVM Developers mailing list
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</pre>
</span></blockquote><span class="HOEnZb"><font color="#888888">
<br>
<br>
<pre cols="72">--
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a href="http://www.cs.rochester.edu/u/criswell" target="_blank">http://www.cs.rochester.edu/u/criswell</a></pre>
</font></span></div>
</blockquote></div><br></div></div></div></div></div></div>