diff --git a/docs/LangRef.html b/docs/LangRef.html index 026b6e794f9..cf514490a8a 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -19,7 +19,7 @@
  • Derived Types
    1. Array Type -
    2. Method Type +
    3. Function Type
    4. Pointer Type
    5. Structure Type
    6. Packed Type @@ -28,16 +28,16 @@
    7. High Level Structure
      1. Module Structure -
      2. Method Structure +
      3. Function Structure
    8. Instruction Reference
      1. Terminator Instructions
          -
        1. 'ret' Instruction -
        2. 'br' Instruction -
        3. 'switch' Instruction -
        4. 'call .. with' Instruction +
        5. 'ret' Instruction +
        6. 'br' Instruction +
        7. 'switch' Instruction +
        8. 'invoke' Instruction
      2. Unary Operations
          @@ -65,9 +65,9 @@
        1. 'malloc' Instruction
        2. 'free' Instruction
        3. 'alloca' Instruction +
        4. 'getelementptr' Instruction
        5. 'load' Instruction
        6. 'store' Instruction -
        7. 'getelementptr' Instruction
      3. Other Operations
          @@ -100,10 +100,10 @@
          - This document describes the LLVM assembly language IR/VM. LLVM is an SSA - based representation that attempts to be a useful midlevel IR by providing - type safety, low level operations, flexibility, and the capability to - represent 'all' high level languages cleanly. + This document describes the LLVM assembly language. LLVM is an SSA based + representation that is a useful midlevel IR, providing type safety, low level + operations, flexibility, and the capability to represent 'all' high level + languages cleanly.
          @@ -115,22 +115,44 @@
            -The LLVM is designed to exhibit a dual nature: on one hand, it is a useful compiler IR, on the other hand, it is a bytecode representation for dynamic compilation. We contend that this is a natural and good thing, making LLVM a natural form of communication between different compiler phases, and also between a static and dynamic compiler.

            +The LLVM code representation is designed to be used in three different forms: as +an in-memory compiler IR, as an on-disk bytecode representation, suitable for +fast loading by a dynamic compiler, and as a human readable assembly language +representation. This allows LLVM to provide a powerful intermediate +representation for efficient compiler transformations and analysis, while +providing a natural means to debug and visualize the transformations. The three +different forms of LLVM are all equivalent. This document describes the human +readable representation and notation.

            -This dual nature leads to three different representations of LLVM (the human readable assembly representation, the compact bytecode representation, and the in memory, pointer based, representation). This document describes the human readable representation and notation.

            - -The LLVM representation aims to be a light weight and low level while being expressive, type safe, and extensible at the same time. It aims to be a "universal IR" of sorts, by being at a low enough level that high level ideas may be cleanly mapped to it. By providing type safety, LLVM can be used as the target of optimizations: for example, through pointer analysis, it can be proven that a C automatic variable is never accessed outside of the current function... allowing it to be promoted to a simple SSA value instead of a memory location.

            +The LLVM representation aims to be a light weight and low level while being +expressive, type safe, and extensible at the same time. It aims to be a +"universal IR" of sorts, by being at a low enough level that high level ideas +may be cleanly mapped to it (similar to how microprocessors are "universal +IR's", allowing many source languages to be mapped to them). By providing type +safety, LLVM can be used as the target of optimizations: for example, through +pointer analysis, it can be proven that a C automatic variable is never accessed +outside of the current function... allowing it to be promoted to a simple SSA +value instead of a memory location.


          Well Formedness

        -LLVM requires the values start with a '%' sign for two reasons: Compilers don't need to worry about name clashes with reserved words, and the set of reserved words may be expanded in the future without penalty. Additionally, unnamed identifiers allow a compiler to quickly come up with a temporary variable without having to avoid symbol table conflicts.

        +LLVM requires the values start with a '%' sign for two reasons: Compilers don't +need to worry about name clashes with reserved words, and the set of reserved +words may be expanded in the future without penalty. Additionally, unnamed +identifiers allow a compiler to quickly come up with a temporary variable +without having to avoid symbol table conflicts.

        -Reserved words in LLVM are very similar to reserved words in other languages. There are keywords for different opcodes ('add', 'cast', 'ret', etc...), for primitive type names ('void', 'uint', etc...), and others. These reserved words cannot conflict with variable names, because none of them may start with a '%' character.

        +Reserved words in LLVM are very similar to reserved words in other languages. +There are keywords for different opcodes ('add', +'cast', 'ret', +etc...), for primitive type names ('void', +'uint', etc...), and others. These reserved +words cannot conflict with variable names, because none of them start with a '%' +character.

        -Here is an example of LLVM code to multiply the integer variable '%X' by 8:

        +Here is an example of LLVM code to multiply the integer variable '%X' +by 8:

        The easy way:

        @@ -177,11 +210,15 @@ This last way of multiplying %X by 8 illustrates several important lexi
         
         
        1. Comments are delimited with a ';' and go until the end of line. -
        2. Unnamed temporaries are created when the result of a computation is not assigned to a named value. +
        3. Unnamed temporaries are created when the result of a computation is not + assigned to a named value.
        4. Unnamed temporaries are numbered sequentially

        -...and it also show a convention that we follow in this document. When demonstrating instructions, we will follow an instruction with a comment that defines the type and name of value produced. Comments are shown in italic text.

        +...and it also show a convention that we follow in this document. When +demonstrating instructions, we will follow an instruction with a comment that +defines the type and name of value produced. Comments are shown in italic +text.

        @@ -191,9 +228,15 @@ This last way of multiplying %X by 8 illustrates several important lexi

        Overview:
        -The 'br' instruction is used to cause control flow to transfer to a different basic block in the current method. There are two forms of this instruction, corresponding to a conditional branch and an unconditional branch. The 'br' instruction is a (useful) special case 'switch' instruction.

        + +The 'br' instruction is used to cause control flow to transfer to a +different basic block in the current function. There are two forms of this +instruction, corresponding to a conditional branch and an unconditional +branch.

        Arguments:
        -The conditional branch form of the 'br' instruction shall take a single 'bool' value and two 'label' values. The unconditional form of the 'br' instruction takes a single 'label' value as a target.

        +The conditional branch form of the 'br' instruction takes a single +'bool' value and two 'label' values. The unconditional form +of the 'br' instruction takes a single 'label' value as a +target.

        Semantics:
        -Upon execution of a conditional 'br' instruction, the 'bool' argument is evaluated. If the value is true, control flows to the 'iftrue' 'label' argument. If "cond" is false, control flows to the 'iffalse' 'label' argument.

        +Upon execution of a conditional 'br' instruction, the 'bool' +argument is evaluated. If the value is true, control flows to the +'iftrue' 'label' argument. If "cond" is false, +control flows to the 'iffalse' 'label' argument.

        Example:
        @@ -472,23 +600,44 @@ IfUnequal:
         
        Overview:
        -The 'switch' instruction is used to transfer control flow to one of several different places. It is a simple generalization of the 'br' instruction, and supports a strict superset of its functionality.

        -The 'switch' statement supports two different styles of indirect branching: lookup branching and indexed branching. Lookup branching is generally useful if the values to switch on are spread far appart, where index branching is useful if the values to switch on are generally dense.

        +The 'switch' instruction is used to transfer control flow to one of +several different places. It is a generalization of the 'br' +instruction, allowing a branch to occur to one of many possible destinations.

        -The two different forms of the 'switch' statement are simple hints to the underlying virtual machine implementation. For example, a virtual machine may choose to implement a small indirect branch table as a series of predicated comparisons: if it is faster for the target architecture.

        +The 'switch' statement supports two different styles of indirect +branching: lookup branching and indexed branching. Lookup branching is +generally useful if the values to switch on are spread far appart, where index +branching is useful if the values to switch on are generally dense.

        + +The two different forms of the 'switch' statement are simple hints to +the underlying virtual machine implementation. For example, a virtual machine +may choose to implement a small indirect branch table as a series of predicated +comparisons: if it is faster for the target architecture.

        Arguments:
        -The lookup form of the 'switch' instruction uses three parameters: a 'uint' comparison value 'value', a default 'label' destination, and a sized array of pairs of comparison value constants and 'label's. The sized array must be a constant value.

        -The indexed form of the 'switch' instruction uses three parameters: an 'uint' index value, a default 'label' and a sized array of 'label's. The 'dests' array must be a constant array. +The lookup form of the 'switch' instruction uses three parameters: a +'uint' comparison value 'value', a default 'label' +destination, and an array of pairs of comparison value constants and +'label's. The sized array must be a constant value.

        + +The indexed form of the 'switch' instruction uses three parameters: an +'uint' index value, a default 'label' and a sized array of +'label's. The 'dests' array must be a constant array.

        Semantics:
        -The lookup style switch statement specifies a table of values and destinations. When the 'switch' instruction is executed, this table is searched for the given value. If the value is found, the corresponding destination is branched to.

        -The index branch form simply looks up a label element directly in a table and branches to it.

        +The lookup style switch statement specifies a table of values and destinations. +When the 'switch' instruction is executed, this table is searched for +the given value. If the value is found, the corresponding destination is +branched to.

        -In either case, the compiler knows the static size of the array, because it is provided as part of the constant values type.

        +The index branch form simply looks up a label element directly in a table and +branches to it.

        + +In either case, the compiler knows the static size of the array, because it is +provided as part of the constant values type.

        Example:
        @@ -502,11 +651,11 @@ In either case, the compiler knows the static size of the array, because it is p
           ; Implement a jump table using the constant pool:
           void "testmeth"(int %arg0)
             %switchdests = [3 x label] [ label %onzero, label %onone, label %ontwo ]
        -  {
        +  begin
           ...
             switch uint %val, label %otherwise, [3 x label] %switchdests...
           ...
        -  }
        +  end
         
           ; Implement the equivilent jump table directly:
           switch uint %val, label %otherwise, [3 x label] [ label %onzero, 
        @@ -518,37 +667,54 @@ In either case, the compiler knows the static size of the array, because it is p
         
         
         
        -


        'call .. with' Instruction

          +


        'invoke' Instruction

          Syntax:
          -  <result> = call <method ty> %<method name>(<method args>) with label <break label>
          +  <result> = invoke <ptr to function ty> %<function ptr val>(<function args>)
          +                 to label <normal label> except label <exception label>
           
          -
          Overview:
          -The 'call .. with' instruction is used to cause control flow to transfer to a specified method, with the possibility of control flow transfer to the 'break label' label, in addition to the possibility of fallthrough to the next basic block. The '
          call' instruction is closely related, but does guarantees that control flow either never returns from the invoked method, or that it returns to the instruction succeeding the 'call' instruction.

          - -TODO: icall .. with needs to be defined as well for an indirect call.

          +

          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:
          This instruction requires several arguments:

            -
          1. 'method ty': shall be the signature of the named method being invoked. This must be a method type. -
          2. 'method name': method name to be invoked. -
          3. 'method args': argument list whose types match the method signature argument types. -
          4. 'break label': a label that specifies the break label associated with this call. + +
          5. 'ptr to function ty': shall be the signature of the pointer to +function value being invoked. In most cases, this is a direct method +invocation, but indirect invoke's are just as possible, branching off +an arbitrary pointer to function value.

            + +

          6. 'function ptr val': An LLVM value containing a pointer to a +function to be invoked. + +
          7. 'function args': argument list whose types match the function +signature argument types. + +
          8. 'normal label': the label reached when the called function executes +a 'ret' instruction. + +
          9. 'exception label': the label reached when an exception is thrown.
          Semantics:
          -This instruction is designed to operate as a standard 'call' instruction in most regards. The primary difference is that it assiciates a label with the method invocation that may be accessed via the runtime library provided by the execution environment. This instruction is used in languages with destructors to ensure that proper cleanup is performed in the case of either a longjmp or a thrown exception. Additionally, this is important for implementation of 'catch' clauses in high-level languages that support them.

          +This instruction is designed to operate as a standard 'call' instruction in most regards. The primary difference is that it assiciates a label with the function invocation that may be accessed via the runtime library provided by the execution environment. This instruction is used in languages with destructors to ensure that proper cleanup is performed in the case of either a longjmp or a thrown exception. Additionally, this is important for implementation of 'catch' clauses in high-level languages that support them.

          -For a more comprehensive explanation of this instruction look in the llvm/docs/2001-05-18-ExceptionHandling.txt document. +For a more comprehensive explanation of this instruction look in the llvm/docs/2001-05-18-ExceptionHandling.txt document.

          Example:
          -  %retval = call int (int) %Test(int 15) with label %TestCleanup     ; {int}:retval set
          +  %retval = invoke int %Test(int 15)
          +              to label %Continue except label %TestCleanup     ; {int}:retval set
           
          @@ -560,7 +726,7 @@ For a more comprehensive explanation of this instruction look in the llvm/docs/2 Unary operators are used to do a simple operation to a single value.

          -There is only one unary operators: the 'not' instruction.

          +There is only one unary operator: the 'not' instruction.

          @@ -581,8 +747,6 @@ The single argument to 'not' must be of of integr

          Semantics:
          The 'not' instruction returns the logical inverse of an integral type.

          -Note that the 'not' instruction is is not defined over to 'bool' type. To invert a boolean value, the recommended method is to use:

          -

             <result> = xor bool true, <var> ; yields {bool}:result
           
          @@ -600,7 +764,10 @@ Note that the 'not' instruction is is not defined over to 'boolBinary Operations
            -Binary operators are used to do most of the computation in a program. They require two operands, execute an operation on them, and produce a single value. The result value of a binary operator is not neccesarily the same type as its operands.

            +Binary operators are used to do most of the computation in a program. They +require two operands, execute an operation on them, and produce a single value. +The result value of a binary operator is not neccesarily the same type as its +operands.

            There are several different binary operators:

            @@ -637,12 +804,17 @@ The two arguments to the 'add' instruction must be either integral or floating point values. Both arguments must have identical types.

            + +The two arguments to the 'sub' instruction must be either integral or floating point +values. Both arguments must have identical types.

            Semantics:
            ...

            @@ -669,7 +841,9 @@ The two arguments to the 'mul' instruction must be either integral or floating point values. Both arguments must have identical types.

            + +The two arguments to the 'div' instruction must be either integral or floating point +values. Both arguments must have identical types.

            Semantics:
            ...

            @@ -741,8 +919,11 @@ TODO: remainder or modulus?

            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 derived type (it is not possible to compare 'label's or 'void' values). Both arguments must have identical types.

            +

            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.

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

            @@ -809,11 +990,14 @@ 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 'or' instruction must be either integral or bool values. +Both arguments must have identical types.

            Semantics:
            @@ -837,10 +1021,15 @@ The two arguments to the 'or' instruction must be either integral or bool values. Both arguments must have identical types.

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

            Semantics:
            @@ -864,10 +1053,15 @@ The two arguments to the 'xor' instruction must be either integral type. The second argument must be an 'ubyte' type.

            + +The first argument to the 'shl' instruction must be an integral type. The second argument must be an +'ubyte' type.

            Semantics:
            ... 0 bits are shifted into the emptied bit positions...

            @@ -924,8 +1118,8 @@ Accessing memory in SSA form is, well, sticky at best. This section describes h

            Syntax:
            -  <result> = malloc  <type>                        ; yields { type  *}:result
            -  <result> = malloc [<type>], uint <NumElements>   ; yields {[type] *}:result
            +  <result> = malloc <type>, uint <NumElements>     ; yields {type*}:result
            +  <result> = malloc <type>                         ; yields {type*}:result
             
            Overview:
            @@ -933,9 +1127,13 @@ The 'malloc' instruction allocates memory from the system heap and retu
            Arguments:
            -There are two forms of the 'malloc' instruction, one for allocating a variable of a fixed type, and one for allocating an array. The array form is used to allocate an array, where the upper bound is not known until run time. If the upper bound is known at compile time, it is recommended that the first form be used with a sized array type.

            +The the 'malloc' instruction allocates +sizeof(<type>)*NumElements bytes of memory from the operating +system, and returns a pointer of the appropriate type to the program. The +second form of the instruction is a shorter version of the first instruction +that defaults to allocating one element.

            -'type' may be any type except for a unsized array type.

            +'type' must be a sized type

            Semantics:
            Memory is allocated, a pointer is returned.

            @@ -945,8 +1143,8 @@ Memory is allocated, a pointer is returned.

            %array = malloc [4 x ubyte ] ; yields {[%4 x ubyte]*}:array %size = add uint 2, 2 ; yields {uint}:size = uint 4 - %array1 = malloc [ubyte], uint 4 ; yields {[ubyte]*}:array1 - %array2 = malloc [ubyte], uint %size ; yields {[ubyte]*}:array2 + %array1 = malloc ubyte, uint 4 ; yields {ubyte*}:array1 + %array2 = malloc [12 x ubyte], uint %size ; yields {[12 x ubyte]*}:array2

        @@ -984,40 +1182,84 @@ Memory is available for use after this point. The contents of the 'valueSyntax:
        -  <result> = alloca  <type>                       ; yields {type*}:result
        -  <result> = alloca [<type>], uint <NumElements>  ; yields {[type] *}:result
        +  <result> = alloca <type>, uint <NumElements>  ; yields {type*}:result
        +  <result> = alloca <type>                      ; yields {type*}:result
         
        Overview:
        -The 'alloca' instruction allocates memory on the current stack frame of the procedure that is live as long as the method does not return.

        +The 'alloca' instruction allocates memory on the current stack frame of +the procedure that is live until the current function returns to its caller.

        Arguments:
        -There are two forms of the 'alloca' instruction, one for allocating a variable of a fixed type, and one for allocating an array. The array form is used to allocate an array, where the upper bound is not known until run time. If the upper bound is known at compile time, it is recommended that the first form be used with a sized array type.

        -'type' may be any type except for a unsized array type.

        - -Note that a virtual machine may generate more efficient native code for a method if all of the fixed size 'alloca' instructions live in the first basic block of that method. +The the 'alloca' instruction allocates +sizeof(<type>)*NumElements bytes of memory on the runtime stack, +returning a pointer of the appropriate type to the program. The second form of +the instruction is a shorter version of the first that defaults to allocating +one element.

        +'type' may be any sized type.

        Semantics:
        -Memory is allocated, a pointer is returned. 'alloca'd memory is automatically released when the method returns. The 'alloca' utility is how variable spills shall be implemented.

        + +Memory is allocated, a pointer is returned. 'alloca'd memory is +automatically released when the function returns. The 'alloca' +instruction is commonly used to represent automatic variables that must have an +address available, as well as spilled variables.

        Example:
           %ptr = alloca int                              ; yields {int*}:ptr
        -  %ptr = alloca [int], uint 4                    ; yields {[int]*}:ptr
        +  %ptr = alloca int, uint 4                      ; yields {int*}:ptr
         
        + +


        'getelementptr' Instruction


        'load' Instruction


        'getelementptr' Instruction

           Other Operations @@ -1215,7 +1430,7 @@ Example: Notice: Preliminary idea!

        -Builtin functions are very similar to normal functions, except they are defined by the implementation. Invocations of these functions are very similar to method invocations, except that the syntax is a little less verbose.

        +Builtin functions are very similar to normal functions, except they are defined by the implementation. Invocations of these functions are very similar to function invocations, except that the syntax is a little less verbose.

        Builtin functions are useful to implement semi-high level ideas like a 'min' or 'max' operation that can have important properties when doing program analysis. For example: @@ -1223,10 +1438,10 @@ Builtin functions are useful to implement semi-high level ideas like a 'min<

      4. Some optimizations can make use of identities defined over the functions, for example a parrallelizing compiler could make use of 'min' identities to parrellelize a loop. -
      5. Builtin functions would have polymorphic types, where normal method calls +
      6. Builtin functions would have polymorphic types, where normal function calls may only have a single type.
      7. Builtin functions would be known to not have side effects, simplifying - analysis over straight method calls. + analysis over straight function calls.
      8. The syntax of the builtin are cleaner than the syntax of the 'call' instruction (very minor point). @@ -1236,7 +1451,7 @@ Because these invocations are explicit in the representation, the runtime can ch
        • Inlining the code directly into the invocation
        • Implementing the functions in some sort of Runtime class, convert invocation - to a standard method call. + to a standard function call.
        • Implementing the functions in some sort of Runtime class, and perform standard inlining optimizations on it.
        @@ -1245,7 +1460,7 @@ Note that these builtins do not use quoted identifiers: the name of the builtin Example:
        -  ; Example of a normal method call
        +  ; Example of a normal function call
           %maximum = call int %maximum(int %arg1, int %arg2)   ; yields {int}:%maximum
         
           ; Examples of potential builtin functions
        @@ -1259,7 +1474,7 @@ Example:
           %cos = cos(float %arg)                               ; yields {float}:%cos
         
        -The 'maximum' vs 'max' example illustrates the difference in calling semantics between a 'call' instruction and a builtin function invocation. Notice that the 'maximum' example assumes that the method is defined local to the caller.

        +The 'maximum' vs 'max' example illustrates the difference in calling semantics between a 'call' instruction and a builtin function invocation. Notice that the 'maximum' example assumes that the function is defined local to the caller.

        @@ -1301,7 +1516,7 @@ In order to represent programs written in languages like C, we need to be able t


        Explicit Parrellelism

          -With the rise of massively parrellel architectures (like the IA64 architecture, multithreaded CPU cores, and SIMD data sets) it is becoming increasingly more important to extract all of the ILP from a code stream possible. It would be interesting to research encoding methods that can explicitly represent this. One straightforward way to do this would be to introduce a "stop" instruction that is equilivent to the IA64 stop bit.

          +With the rise of massively parrellel architectures (like the IA64 architecture, multithreaded CPU cores, and SIMD data sets) it is becoming increasingly more important to extract all of the ILP from a code stream possible. It would be interesting to research encoding functions that can explicitly represent this. One straightforward way to do this would be to introduce a "stop" instruction that is equilivent to the IA64 stop bit.

          @@ -1375,7 +1590,7 @@ more...

          Chris Lattner
          -Last modified: Sun Jul 8 19:25:56 CDT 2001 +Last modified: Sun Apr 14 01:12:55 CDT 2002