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. A less confusing example (for me) might be this: %idx2 = getelementptr i32* %MyVar, i64 1 The pointer type size is 32 bits (let's say int pointer), why is the index of size 64? On Mon, Dec 12, 2011 at 3:58 PM, Eli Friedman <eli.friedman at gmail.com>wrote:> On Mon, Dec 12, 2011 at 3:54 PM, Ryan Taylor <ryta1203 at gmail.com> wrote: > > For the gep: > > > > %idx1 = getelementptr i32* %MyVar, i32 0 > > > > i32* is the type that MyVar is pointing to and i32 is the type of the > offset > > value, or what? If it's the type of offset value, then > > the size of the pointer shouldn't be less than i32, correct? > > > > > > The index is 0, so in this example, the address computation is idx1 > > &MyVar+0. > > > > What I want to know is the size in bits of the values above, it looks > like 0 > > is 32 bits in size, which would make the pointer size also 32? > > LLVM will sign-extend or truncate the index to the size of the > pointer; the pointer type could have any width. > > -Eli >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111212/991fd06f/attachment.html>
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
---------- Forwarded message ---------- From: Ryan Taylor <ryta1203 at gmail.com> Date: Mon, Dec 12, 2011 at 4:46 PM Subject: Re: [LLVMdev] GetElementPtr To: Eli Friedman <eli.friedman at gmail.com> So in the second example I gave, why is the pointer type 32 but the index type is 64? 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/cf6edecb/attachment.html>
---------- 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/70275bfc/attachment.html>
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>
On Dec 12, 2011, at 5:15 PM, John Criswell wrote:> 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.This. Frontends generally emit non-struct indexes as appropriately-sized integers to avoid (possibly) unwanted problems with extension. In this case, since that index is constant 0, it's unimportant, but you can imagine cases where it would. Struct indexes, on the other hand, must be constant and non-negative, so the choice of index width doesn't matter. John. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111212/03fb2ba0/attachment.html>
Ok, thanks. I'm just curious since when I'm doing the calculations, I need to make sure all operands are of the same size. So I suppose I will simply pick the largest width. On Mon, Dec 12, 2011 at 5:25 PM, John McCall <rjmccall at apple.com> wrote:> On Dec 12, 2011, at 5:15 PM, John Criswell wrote: > > 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. > > > This. Frontends generally emit non-struct indexes as appropriately-sized > integers to avoid (possibly) unwanted problems with extension. In this > case, since that index is constant 0, it's unimportant, but you can imagine > cases where it would. Struct indexes, on the other hand, must be constant > and non-negative, so the choice of index width doesn't matter. > > John. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111212/b9f1ebbc/attachment.html>