Index: llvm/trunk/docs/GetElementPtr.rst =================================================================== --- llvm/trunk/docs/GetElementPtr.rst +++ llvm/trunk/docs/GetElementPtr.rst @@ -27,7 +27,7 @@ What is the first index of the GEP instruction? ----------------------------------------------- -Quick answer: The index stepping through the first operand. +Quick answer: The index stepping through the second operand. The confusion with the first index usually arises from thinking about the GetElementPtr instruction as if it was a C index operator. They aren't the @@ -59,7 +59,7 @@ won't be dereferenced?* The answer is simply because memory does not have to be accessed to perform the -computation. The first operand to the GEP instruction must be a value of a +computation. The second operand to the GEP instruction must be a value of a pointer type. The value of the pointer is provided directly to the GEP instruction as an operand without any need for accessing memory. It must, therefore be indexed and requires an index operand. Consider this example: @@ -80,8 +80,8 @@ In this "C" example, the front end compiler (Clang) will generate three GEP instructions for the three indices through "P" in the assignment statement. The -function argument ``P`` will be the first operand of each of these GEP -instructions. The second operand indexes through that pointer. The third +function argument ``P`` will be the second operand of each of these GEP +instructions. The third operand indexes through that pointer. The fourth operand will be the field offset into the ``struct munger_struct`` type, for either the ``f1`` or ``f2`` field. So, in LLVM assembly the ``munge`` function looks like: @@ -100,8 +100,8 @@ ret void } -In each case the first operand is the pointer through which the GEP instruction -starts. The same is true whether the first operand is an argument, allocated +In each case the second operand is the pointer through which the GEP instruction +starts. The same is true whether the second operand is an argument, allocated memory, or a global variable. To make this clear, let's consider a more obtuse example: @@ -159,11 +159,11 @@ i32 }*``. That is, ``%MyStruct`` is a pointer to a structure containing a pointer to a ``float`` and an ``i32``. -#. Point #1 is evidenced by noticing the type of the first operand of the GEP +#. Point #1 is evidenced by noticing the type of the second operand of the GEP instruction (``%MyStruct``) which is ``{ float*, i32 }*``. #. The first index, ``i64 0`` is required to step over the global variable - ``%MyStruct``. Since the first argument to the GEP instruction must always + ``%MyStruct``. Since the second argument to the GEP instruction must always be a value of pointer type, the first index steps through that pointer. A value of 0 means 0 elements offset from that pointer. @@ -267,7 +267,7 @@ What effect do address spaces have on GEPs? ------------------------------------------- -None, except that the address space qualifier on the first operand pointer type +None, except that the address space qualifier on the second operand pointer type always matches the address space qualifier on the result type. How is GEP different from ``ptrtoint``, arithmetic, and ``inttoptr``? @@ -526,7 +526,7 @@ #. The GEP instruction never accesses memory, it only provides pointer computations. -#. The first operand to the GEP instruction is always a pointer and it must be +#. The second operand to the GEP instruction is always a pointer and it must be indexed. #. There are no superfluous indices for the GEP instruction. Index: llvm/trunk/docs/LangRef.rst =================================================================== --- llvm/trunk/docs/LangRef.rst +++ llvm/trunk/docs/LangRef.rst @@ -1989,7 +1989,7 @@ following rules: - A pointer value formed from a ``getelementptr`` operation is *based* - on the first value operand of the ``getelementptr``. + on the second value operand of the ``getelementptr``. - The result value of a ``bitcast`` is *based* on the operand of the ``bitcast``. - A pointer value formed by an ``inttoptr`` is *based* on all pointer @@ -3166,7 +3166,7 @@ ``getelementptr (TY, CSTPTR, IDX0, IDX1, ...)``, ``getelementptr inbounds (TY, CSTPTR, IDX0, IDX1, ...)`` Perform the :ref:`getelementptr operation ` on constants. As with the :ref:`getelementptr ` - instruction, the index list may have zero or more indexes, which are + instruction, the index list may have one or more indexes, which are required to make sense for the type of "pointer to TY". ``select (COND, VAL1, VAL2)`` Perform the :ref:`select operation ` on constants. @@ -7805,7 +7805,7 @@ 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 +second 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