<html><head><meta http-equiv="Content-Type" content="text/html charset=GB2312"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi Weixue,<div><br><div><div>On Sep 12, 2013, at 6:48 PM, weixuegong <<a href="mailto:weixuegong@gmail.com">weixuegong@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">
<meta http-equiv="content-type" content="text/html; charset=GB2312">
<div bgcolor="#FFFFFF" text="#000000">
Hi, all<br>
<br>
When I read the document of IR on <a href="http://llvm.org">llvm.org</a>,<br>
I found two instructions, "ptrtoint" and load.<br>
<br>
Load, I think, is : when after allocating some<br>
bytes in memory and storing some data into it, we could<br>
use load to get the data, like this:<br>
<font color="#009900"><br>
%0 = alloca i32<br>
store i32 5, i32* %0<br>
%1 = load i32* %0</font><br>
so, the type of %1 is i32, and the value is 5, right?<br>
<br>
And "ptrtoint" is:we cast it from ptr to int?</div></blockquote><blockquote type="cite"><div bgcolor="#FFFFFF" text="#000000">Just like<br>
"&" in c++ ?</div></blockquote>More or less yes. More specifically, we convert the pointer to the defined type.</div><div><br><blockquote type="cite"></blockquote><blockquote type="cite"><div bgcolor="#FFFFFF" text="#000000">When we are doing like this:<br>
<font color="#009900"><br>
%0 = alloca i32<br>
store i32 5, i32* %0<br>
%1 = ptrtoint i32* %0 to i32</font><br>
No doubt, the type of %1 is i32. But what is the value of %1?<br></div></blockquote>%1 contains the address of the alloca converted to i32.</div><div>The exact value depends on the architecture. For instance on x86-64, addresses are 64-bits, thus here you will truncate the address to a 32-bits value.</div><div><br></div><div>Does it make sense?</div><div><br><blockquote type="cite"><div bgcolor="#FFFFFF" text="#000000">
Is it just like "load", loading the value stored, or becoming a
"var"<br>
to store the address(not the real value stored in memory)?<br>
<br>
If I want to get the value stored in memory, I should use load,<br>
and if I want to get the addr of the ptr, use ptrtoint, am I right?<br></div></blockquote>Basically, yes :).<br><blockquote type="cite"><div bgcolor="#FFFFFF" text="#000000">
<br>
Could anyone tell me the difference between them clearly?<br></div></blockquote>Hope it helps.</div><div><br></div><div>-Quentin<br><blockquote type="cite"><div bgcolor="#FFFFFF" text="#000000">
<br>
Best Regards<br>
<br>
Weixue<br>
</div>
_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br></blockquote></div><br></div></body></html>