From: Matthijs Kooijman Date: Mon, 13 Oct 2008 13:44:15 +0000 (+0000) Subject: Improve the description on the getelementptr instruction. It should now better X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=e49d0bc946a3f658da0e82e207bc87f59a2aa587;p=oota-llvm.git Improve the description on the getelementptr instruction. It should now better define what the instruction does. This also makes it clear that getelementptr can index into a vector type. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57440 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/LangRef.html b/docs/LangRef.html index 523abfaeefa..99eb163f8ca 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -3316,25 +3316,34 @@ at the location specified by the '<pointer>' operand.

Syntax:
-  <result> = getelementptr <ty>* <ptrval>{, <ty> <idx>}*
+  <result> = getelementptr <pty>* <ptrval>{, <ty> <idx>}*
 
Overview:

The 'getelementptr' instruction is used to get the address of a -subelement of an aggregate data structure.

+subelement of an aggregate data structure. It performs address calculation only +and does not access memory.

Arguments:
-

This instruction takes a list of integer operands that indicate what -elements of the aggregate object to index to. The actual types of the arguments -provided depend on the type of the first pointer argument. The -'getelementptr' instruction is used to index down through the type -levels of a structure or to a specific index in an array. When indexing into a -structure, only i32 integer constants are allowed. When indexing -into an array or pointer, only integers of 32 or 64 bits are allowed; 32-bit -values will be sign extended to 64-bits if required.

+

The first argument is always a pointer, and forms the basis of the +calculation. The remaining arguments are indices, that indicate which of the +elements of the aggregate object are indexed. The interpretation of each index +is dependent on the type being indexed into. The first index always indexes the +pointer value given as the first argument, the second index indexes a value of +the type pointed to (not necessarily the value directly pointed to, since the +first index can be non-zero), etc. The first type indexed into must be a pointer +value, subsequent types can be arrays, vectors and structs. Note that subsequent +types being indexed into can never be pointers, since that would require loading +the pointer before continuing calculation.

+ +

The type of each index argument depends on the type it is indexing into. +When indexing into a (packed) structure, only i32 integer +constants are allowed. When indexing into an array, pointer or vector, +only integers of 32 or 64 bits are allowed (also non-constants). 32-bit values +will be sign extended to 64-bits if required.

For example, let's consider a C code fragment and how it gets compiled to LLVM:

@@ -3375,13 +3384,6 @@ entry:
Semantics:
-

The index types specified for the 'getelementptr' instruction depend -on the pointer type that is being indexed into. Pointer -and array types can use a 32-bit or 64-bit -integer type but the value will always be sign extended -to 64-bits. Structure and packed -structure types require i32 constants.

-

In the example above, the first index is indexing into the '%ST*' type, which is a pointer, yielding a '%ST' = '{ i32, double, %RT }' type, a structure. The second index indexes into the third element of @@ -3421,7 +3423,11 @@ FAQ.

     ; yields [12 x i8]*:aptr
-    %aptr = getelementptr {i32, [12 x i8]}* %sptr, i64 0, i32 1
+    %aptr = getelementptr {i32, [12 x i8]}* %saptr, i64 0, i32 1
+    ; yields i8*:vptr
+    %vptr = getelementptr {i32, <2 x i8>}* %svptr, i64 0, i32 1, i32 1
+    ; yields i8*:eptr
+    %eptr = getelementptr [12 x i8]* %aptr, i64 0, i32 1