[LLVMdev] GetElementPtr
John Criswell
criswell at illinois.edu
Mon Dec 12 17:15:03 PST 2011
On 12/12/11 7:00 PM, Ryan Taylor wrote:
> 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?
I believe pointers and arrays are indexed using i64 (or some integer
size matching the pointer size) and structure elements are indexed using
i32.
-- John T.
>
>
> On Mon, Dec 12, 2011 at 4:58 PM, Ryan Taylor <ryta1203 at gmail.com
> <mailto:ryta1203 at gmail.com>> wrote:
>
>
>
> ---------- Forwarded message ----------
> From: *Ryan Taylor* <ryta1203 at gmail.com <mailto: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
> <mailto: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 <mailto:eli.friedman at gmail.com>> wrote:
>
> On Mon, Dec 12, 2011 at 4:46 PM, Ryan Taylor
> <ryta1203 at gmail.com <mailto: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 <mailto:eli.friedman at gmail.com>>
> > wrote:
> >>
> >> On Mon, Dec 12, 2011 at 4:38 PM, Ryan Taylor
> <ryta1203 at gmail.com <mailto: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
> >
> >
>
>
>
>
>
>
> _______________________________________________
> 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/20111212/6f7f240a/attachment.html>
More information about the llvm-dev
mailing list