[LLVMdev] GetElementPtr

Ryan Taylor ryta1203 at gmail.com
Mon Dec 12 17:00:19 PST 2011


So in this example:

%idx = getelementptr { float*, i32 }* %MyStruct, i64 0, i32 1

Why is it picking i64 for the index but i32 for the offset?



On Mon, Dec 12, 2011 at 4:58 PM, Ryan Taylor <ryta1203 at gmail.com> wrote:

>
>
> ---------- Forwarded message ----------
> From: Ryan Taylor <ryta1203 at gmail.com>
> Date: Mon, Dec 12, 2011 at 4:58 PM
> Subject: Re: [LLVMdev] GetElementPtr
> To: Eli Friedman <eli.friedman at gmail.com>
>
>
> Sorry,
>
>   So what I'm trying to ask is are the widths given (32, 64) for the index
> and the offset the widths of the index and offset values or the width of
> the type they are offsetting and indexing or both?
>
>   I apologize if you already answered this and I didn't get it.
>
>
> On Mon, Dec 12, 2011 at 4:50 PM, Eli Friedman <eli.friedman at gmail.com>wrote:
>
>> On Mon, Dec 12, 2011 at 4:46 PM, Ryan Taylor <ryta1203 at gmail.com> wrote:
>> > So in the second example I gave, why is the pointer type 32 but the
>> index
>> > type is 64?
>>
>> Because that's what the frontend chose the generate?  I'm not sure
>> what you're trying to ask.
>>
>> -Eli
>>
>> > On Mon, Dec 12, 2011 at 4:43 PM, Eli Friedman <eli.friedman at gmail.com>
>> > wrote:
>> >>
>> >> On Mon, Dec 12, 2011 at 4:38 PM, Ryan Taylor <ryta1203 at gmail.com>
>> wrote:
>> >> > By LLVM do you mean the backend? I'm not using the backend, so is
>> that
>> >> > i32
>> >> > on the 0 index the type of the index value or the type of the value
>> to
>> >> > which
>> >> > exists at that index?
>> >> >
>> >> > it seems the pointer itself has no width, it's arbitrary and is
>> handled
>> >> > in
>> >> > the lowering and is target dependent on the bus width.
>> >> >
>> >> > Basically, when I am computing offset I need to know the sizes for
>> add.
>> >> > The
>> >> > size of the pointer (dedicated by bus width) and the size of the
>> index.
>> >>
>> >> The size of the index is simply its type.  You would normally
>> >> sign-extend or truncate to the width of a pointer to do arithmetic,
>> >> though.
>> >>
>> >> You can grab the pointer size from TargetData::getPointerSizeInBits().
>> >>
>> >> -Eli
>> >
>> >
>>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111212/3ba0f844/attachment.html>


More information about the llvm-dev mailing list