[LLVMdev] question about GetElementPtr Instruction

Vikram S. Adve vadve at cs.uiuc.edu
Thu Sep 26 09:20:01 PDT 2002

You are correct, ubyte 2 simply means 3rd element of the structure.  This
quantity is always constant (it specifies the field number), so we could
have used any signed or unsigned integer type for it instead of ubyte.
UByte means we are limited to at most 256 structure fields but it also makes
the bytecode representation more compact.  (To remove this restriction, we
may migrate to UInt in the future and use some kind of Zipf encoding to
avoid increasing bytecode size in the common case.)

There is a routine TargetData::GetIndexedOffset to convert any ptr + index
list to the actual byte  offset for a particular target machine.  See


> -----Original Message-----
> From: llvmdev-admin at cs.uiuc.edu [mailto:llvmdev-admin at cs.uiuc.edu]On
> Behalf Of Brian R. Gaeke
> Sent: Thursday, September 26, 2002 1:55 AM
> To: llvmdev at cs.uiuc.edu
> Subject: Re: [LLVMdev] question about GetElementPtr Instruction
> Dear LLVMdev,
> As far as I can tell, what the "ubyte 2" value really means is the
> 2+1'th member of the structure...regardless of whether that structure's
> 3rd element actually starts at (pointer to structure) + 3*sizeof(ubyte)
> or not.  So, is there any semantic connection between "ubyte" as
> used in structure accesses and what getelementptr actually interprets
> it as?  Or is it just called ubyte for fun?
> -"Confused in Urbana", Brian
> > I have a question about GetElementPtr.
> >
> > Suppose I have an GetElementPtr Instruction GI:
> >
> > %reg = getelementptr %ST* %s, uint 1, ubyte 2, ubyte 1, uint
> > 5, uint 13
> --
> gaeke at uiuc.edu
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev

More information about the llvm-dev mailing list