From: Chris Lattner Date: Mon, 6 May 2002 22:08:29 +0000 (+0000) Subject: Finish up the updates to the language reference X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6536cfec4a8ddc25d4d34b6f806d3de9903db95f;p=oota-llvm.git Finish up the updates to the language reference git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2509 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/LangRef.html b/docs/LangRef.html index 86041a4d49f..926d8dca346 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -72,13 +72,14 @@
  • Other Operations
      +
    1. 'phi' Instruction
    2. 'cast .. to' Instruction
    3. 'call' Instruction -
    4. 'icall' Instruction -
    5. 'phi' Instruction
    + @@ -752,13 +753,15 @@ provided as part of the constant values type.

    to label <normal label> except label <exception label> -

    Overview:
    The 'invoke' instruction is used to cause control -flow to transfer to a specified function, with the possibility of control flow -transfer to either the 'normal label' label or the 'exception -label'. The 'call' instruction is closely -related, but guarantees that control flow either never returns from the called -function, or that it returns to the instruction succeeding the 'call' instruction.

    +

    Overview:
    + +The 'invoke' instruction is used to cause control flow to transfer to a +specified function, with the possibility of control flow transfer to either the +'normal label' label or the 'exception label'. The 'call' instruction is closely related, but guarantees +that control flow either never returns from the called function, or that it +returns to the instruction succeeding the 'call' +instruction.

    Arguments:
    @@ -774,7 +777,8 @@ an arbitrary pointer to function value.

    function to be invoked.

  • 'function args': argument list whose types match the function -signature argument types. +signature argument types. If the function signature indicates the function +accepts a variable number of arguments, the extra arguments can be specified.
  • 'normal label': the label reached when the called function executes a 'ret' instruction. @@ -826,7 +830,7 @@ There is only one unary operator: the 'not' instru The 'not' instruction returns the bitwise complement of its operand.

    Arguments:
    -The single argument to 'not' must be of of integral type.

    +The single argument to 'not' must be of of integral or bool type.

    Semantics:
    The 'not' instruction returns the bitwise @@ -980,7 +984,13 @@ The 'rem' instruction returns the remainder from the division of its t The two arguments to the 'rem' instruction must be either integral or floating point values. Both arguments must have identical types.

    Semantics:
    -TODO: remainder or modulus?

    + +This returns the remainder of a division (where the result has the same +sign as the divisor), not the modulus (where the result has the same sign +as the dividend) of a value. For more information about the difference, see: The Math +Forum.

    + ...

    Example:
    @@ -1002,24 +1012,37 @@ TODO: remainder or modulus?

    <result> = setge <ty> <var1>, <var2> ; yields {bool}:result -

    Overview:
    -The 'setcc' family of instructions returns a boolean value based on a comparison of their two operands.

    +

    Overview:
    The 'setcc' family of instructions returns a +boolean value based on a comparison of their two operands.

    Arguments:
    The two arguments to the 'setcc' instructions must be of first class or pointer type (it is not possible to compare 'label's, 'array's, 'structure' or 'void' -values). Both arguments must have identical types.

    +values, etc...). Both arguments must have identical types.

    -The 'setlt', 'setgt', 'setle', and 'setge' instructions do not operate on 'bool' typed arguments.

    +The 'setlt', 'setgt', 'setle', and 'setge' +instructions do not operate on 'bool' typed arguments.

    Semantics:
    -The 'seteq' instruction yields a true 'bool' value if both operands are equal.
    -The 'setne' instruction yields a true 'bool' value if both operands are unequal.
    -The 'setlt' instruction yields a true 'bool' value if the first operand is less than the second operand.
    -The 'setgt' instruction yields a true 'bool' value if the first operand is greater than the second operand.
    -The 'setle' instruction yields a true 'bool' value if the first operand is less than or equal to the second operand.
    -The 'setge' instruction yields a true 'bool' value if the first operand is greater than or equal to the second operand.

    + +The 'seteq' instruction yields a true 'bool' value if +both operands are equal.
    + +The 'setne' instruction yields a true 'bool' value if +both operands are unequal.
    + +The 'setlt' instruction yields a true 'bool' value if +the first operand is less than the second operand.
    + +The 'setgt' instruction yields a true 'bool' value if +the first operand is greater than the second operand.
    + +The 'setle' instruction yields a true 'bool' value if +the first operand is less than or equal to the second operand.
    + +The 'setge' instruction yields a true 'bool' value if +the first operand is greater than or equal to the second operand.

    Example:
    @@ -1057,7 +1080,10 @@ bitwise binary operators is always the same type as its first operand.

    The 'and' instruction returns the bitwise logical and of its two operands.

    Arguments:
    -The two arguments to the 'and' instruction must be either integral or bool values. Both arguments must have identical types.

    + +The two arguments to the 'and' instruction must be either integral or bool values. Both arguments must +have identical types.

    Semantics:
    @@ -1087,8 +1113,8 @@ inclusive or of its two operands.

    Arguments:
    The two arguments to the 'or' instruction must be either integral or bool values. -Both arguments must have identical types.

    +href="#t_integral">integral or bool values. Both arguments must +have identical types.

    Semantics:
    @@ -1119,8 +1145,8 @@ two operands.

    Arguments:
    The two arguments to the 'xor' instruction must be either integral or bool values. -Both arguments must have identical types.

    +href="#t_integral">integral or bool values. Both arguments must +have identical types.

    Semantics:
    @@ -1202,7 +1228,7 @@ The first argument to the 'shr' instruction must be an Memory Access Operations
      -Accessing memory in SSA form is, well, sticky at best. This section describes how to read and write memory in LLVM.

      +Accessing memory in SSA form is, well, sticky at best. This section describes how to read, write, allocate and free memory in LLVM.

      @@ -1255,12 +1281,13 @@ The 'free' instruction returns memory back to the unused memory heap, t

      Arguments:
      -'value' shall be a pointer value that points to a value that was allocated with the '
      malloc' instruction.

      +'value' shall be a pointer value that points to a value that was +allocated with the 'malloc' instruction.

      Semantics:
      -Memory is available for use after this point. The contents of the 'value' pointer are undefined after this instruction.

      +Access to the memory pointed to by the pointer is not longer defined after this instruction executes.

      Example:
      @@ -1379,11 +1406,7 @@ operand.

      Overview:
      The 'getelementptr' instruction is used to get the address of a -subelement of an aggregate data structure. In addition to being present as an -explicit instruction, the 'getelementptr' functionality is present in -both the 'load' and 'store' instructions to allow more compact specification -of common expressions.

      +subelement of an aggregate data structure.

      Arguments:
      @@ -1393,15 +1416,77 @@ 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.

      -TODO. +For example, lets consider a C code fragment and how it gets compiled to +LLVM:

      + +

      +struct RT {
      +  char A;
      +  int B[10][20];
      +  char C;
      +};
      +struct ST {
      +  int X;
      +  double Y;
      +  struct RT Z;
      +};
      +
      +int *foo(struct ST *s) {
      +  return &s[1].Z.B[5][13];
      +}
      +
      + +The LLVM code generated by the GCC frontend is: + +
      +%RT = type { sbyte, [10 x [20 x int]], sbyte }
      +%ST = type { int, double, %RT }
      +
      +int* "foo"(%ST* %s) {
      +  %reg = getelementptr %ST* %s, uint 1, ubyte 2, ubyte 1, uint 5, uint 13
      +  ret int* %reg
      +}
      +
      Semantics:
      +The index types specified for the 'getelementptr' instruction depend on +the pointer type that is being index into. Pointer and +array types require 'uint' values, and structure types require 'ubyte' +constants.

      + +In the example above, the first index is indexing into the '%ST*' type, +which is a pointer, yielding a '%ST' = '{ int, double, %RT }' +type, a structure. The second index indexes into the third element of the +structure, yielding a '%RT' = '{ sbyte, [10 x [20 x int]], sbyte +}' type, another structure. The third index indexes into the second +element of the structure, yielding a '[10 x [20 x int]]' type, an +array. The two dimensions of the array are subscripted into, yielding an +'int' type. The 'getelementptr' instruction return a pointer +to this element, thus yielding a 'int*' type.

      + +Note that it is perfectly legal to index partially through a structure, +returning a pointer to an inner element. Because of this, the LLVM code for the +given testcase is equivalent to:

      + +

      +int* "foo"(%ST* %s) {
      +  %t1 = getelementptr %ST* %s , uint 1                        ; yields %ST*:%t1
      +  %t2 = getelementptr %ST* %t1, uint 0, ubyte 2               ; yields %RT*:%t2
      +  %t3 = getelementptr %RT* %t2, uint 0, ubyte 1               ; yields [10 x [20 x int]]*:%t3
      +  %t4 = getelementptr [10 x [20 x int]]* %t3, uint 0, uint 5  ; yields [20 x int]*:%t4
      +  %t5 = getelementptr [20 x int]* %t4, uint 0, uint 13        ; yields int*:%t5
      +  ret int* %t5
      +}
      +
      + +
      Example:
      -  %aptr = getelementptr {int, [12 x ubyte]}* %sptr, 1   ; yields {[12 x ubyte]*}:aptr
      -  %ub   = load [12x ubyte]* %aptr, 4                    ;yields {ubyte}:ub
      +  ; yields {[12 x ubyte]*}:aptr
      +  %aptr = getelementptr {int, [12 x ubyte]}* %sptr, uint 0, ubyte 1
       
      @@ -1416,98 +1501,131 @@ The instructions in this catagory are the "miscellaneous" functions, that defy b -


    'cast .. to' Instruction


    'phi' Instruction


    'call' Instruction

      +


    'cast .. to' Instruction

      Syntax:
      -
      +  <result> = cast <ty> <value> to <ty2>             ; yields ty2
       
      Overview:
      +The 'cast' instruction is used as the primitive means to convert +integers to floating point, change data type sizes, and break type safety (by +casting pointers).

      Arguments:
      +The 'cast' instruction takes a value to case, which must be a first +class value, and a type to cast it to, which must also be a first class type.

      Semantics:
      +This instruction follows the C rules for explicit casts when determining how the +data being cast must change to fit in its new container.

      -

      Example:
      -
      -  %retval = call int %test(int %argc)
      -
      - - -


    'icall' Instruction

      - -Indirect calls are desperately needed to implement virtual function tables (C++, java) and function pointers (C, C++, ...).

      +When casting to bool, any value that would be considered true in the context of a C 'if' condition is converted to the boolean 'true' values, all else are 'false'.

      -A new instruction icall or similar should be introduced to represent an indirect call.

      - -Example: +

      Example:
      -  %retval = icall int %funcptr(int %arg1)          ; yields {int}:%retval
      +  %X = cast int 257 to ubyte              ; yields ubyte:1
      +  %Y = cast int 123 to bool               ; yields bool::true
       
      -


    'phi' Instruction

      +


    'call' Instruction

    + +
    Related Work


    Vectorized Architectures

    @@ -1573,7 +1697,7 @@ more...
    Chris Lattner
    -Last modified: Fri May 3 14:39:52 CDT 2002 +Last modified: Mon May 6 17:07:42 CDT 2002