Hi Weixue,
On Sep 12, 2013, at 6:48 PM, weixuegong <weixuegong at gmail.com> wrote:
> Hi, all
>
> When I read the document of IR on llvm.org,
> I found two instructions, "ptrtoint" and load.
>
> Load, I think, is : when after allocating some
> bytes in memory and storing some data into it, we could
> use load to get the data, like this:
>
> %0 = alloca i32
> store i32 5, i32* %0
> %1 = load i32* %0
> so, the type of %1 is i32, and the value is 5, right?
>
> And "ptrtoint" is:we cast it from ptr to int?
> Just like
> "&" in c++ ?
More or less yes. More specifically, we convert the pointer to the defined type.
> When we are doing like this:
>
> %0 = alloca i32
> store i32 5, i32* %0
> %1 = ptrtoint i32* %0 to i32
> No doubt, the type of %1 is i32. But what is the value of %1?
%1 contains the address of the alloca converted to i32.
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.
Does it make sense?
> Is it just like "load", loading the value stored, or becoming a
"var"
> to store the address(not the real value stored in memory)?
>
> If I want to get the value stored in memory, I should use load,
> and if I want to get the addr of the ptr, use ptrtoint, am I right?
Basically, yes :).>
> Could anyone tell me the difference between them clearly?
Hope it helps.
-Quentin>
> Best Regards
>
> Weixue
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20130912/1825c9c8/attachment.html>