X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=docs%2FLangRef.html;h=05de0bd4cfbb032ddfebb061c5badc6f4eb953b6;hb=22e4686974c01a7df8fa237ee541d0d514a1462e;hp=caba8f0ad8437cfee810b957a2ec01bd50794b3d;hpb=d816bcfe40295e2e4234ee7308d795b597d91a5d;p=oota-llvm.git diff --git a/docs/LangRef.html b/docs/LangRef.html index caba8f0ad84..05de0bd4cfb 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -1,1705 +1,1688 @@ - -llvm Assembly Language Reference Manual - - - - -
  llvm Assembly Language Reference Manual
- + + + + LLVM Assembly Language Reference Manual + + + +
LLVM Language Reference Manual
    -
  1. Abstract -
  2. Introduction -
  3. Identifiers +
  4. Abstract
  5. +
  6. Introduction
  7. +
  8. Identifiers
  9. Type System
      -
    1. Primitive Types -
        -
      1. Type Classifications +
      2. Primitive Types +
          +
        1. Type Classifications
        +
      3. Derived Types
          -
        1. Array Type -
        2. Function Type -
        3. Pointer Type -
        4. Structure Type - +
        5. Array Type
        6. +
        7. Function Type
        8. +
        9. Pointer Type
        10. +
        11. Structure Type
        12. +
        +
      +
    2. High Level Structure
        -
      1. Module Structure -
      2. Global Variables -
      3. Function Structure +
      4. Module Structure
      5. +
      6. Global Variables
      7. +
      8. Function Structure
      +
    3. Instruction Reference
      1. Terminator Instructions
          -
        1. 'ret' Instruction -
        2. 'br' Instruction -
        3. 'switch' Instruction -
        4. 'invoke' Instruction +
        5. 'ret' Instruction
        6. +
        7. 'br' Instruction
        8. +
        9. 'switch' Instruction
        10. +
        11. 'invoke' Instruction
        12. +
        13. 'unwind' Instruction
        +
      2. Binary Operations
          -
        1. 'add' Instruction -
        2. 'sub' Instruction -
        3. 'mul' Instruction -
        4. 'div' Instruction -
        5. 'rem' Instruction -
        6. 'setcc' Instructions +
        7. 'add' Instruction
        8. +
        9. 'sub' Instruction
        10. +
        11. 'mul' Instruction
        12. +
        13. 'div' Instruction
        14. +
        15. 'rem' Instruction
        16. +
        17. 'setcc' Instructions
        +
      3. Bitwise Binary Operations
          -
        1. 'and' Instruction -
        2. 'or' Instruction -
        3. 'xor' Instruction -
        4. 'shl' Instruction -
        5. 'shr' Instruction +
        6. 'and' Instruction
        7. +
        8. 'or' Instruction
        9. +
        10. 'xor' Instruction
        11. +
        12. 'shl' Instruction
        13. +
        14. 'shr' Instruction
        +
      4. Memory Access Operations
          -
        1. 'malloc' Instruction -
        2. 'free' Instruction -
        3. 'alloca' Instruction -
        4. 'load' Instruction -
        5. 'store' Instruction -
        6. 'getelementptr' Instruction +
        7. 'malloc' Instruction
        8. +
        9. 'free' Instruction
        10. +
        11. 'alloca' Instruction
        12. +
        13. 'load' Instruction
        14. +
        15. 'store' Instruction
        16. +
        17. 'getelementptr' Instruction
        +
      5. Other Operations
          -
        1. 'phi' Instruction -
        2. 'cast .. to' Instruction -
        3. 'call' Instruction +
        4. 'phi' Instruction
        5. +
        6. 'cast .. to' Instruction
        7. +
        8. 'call' Instruction
        9. +
        10. 'vanext' Instruction
        11. +
        12. 'vaarg' Instruction
        +
      - - -

      Written by Chris Lattner and Vikram Adve

      - - +

    4. +
    5. Intrinsic Functions +
        +
      1. Variable Argument Handling Intrinsics +
          +
        1. 'llvm.va_start' Intrinsic
        2. +
        3. 'llvm.va_end' Intrinsic
        4. +
        5. 'llvm.va_copy' Intrinsic
        6. +
        +
      2. +
      +
    - - +
    +

    Written by Chris Lattner +and Vikram Adve

    +

    +
    -

    -
    -Abstract -

    -
    -Introduction -


    Well Formedness

    -
    -Identifiers -
+

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 start with a '%' character.

+

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

+

The easy way:

+
  %result = mul uint %X, 8
+

After strength reduction:

+
  %result = shl uint %X, ubyte 3
+

And the hard way:

+
  add uint %X, %X           ; yields {uint}:%0
+  add uint %0, %0           ; yields {uint}:%1
+  %result = add uint %1, %1
+

This last way of multiplying %X by 8 illustrates several +important lexical features of LLVM:

    -
  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 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.

- -The one unintuitive notation for constants is the optional hexidecimal form of -floating point constants. For example, the form 'double +

  • Comments are delimited with a ';' and go until the end +of line.
  • +
  • Unnamed temporaries are created when the result of a computation +is not assigned to a named value.
  • +
  • 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.

    +

    The one non-intuitive notation for constants is the optional +hexidecimal form of floating point constants. For example, the form 'double 0x432ff973cafa8000' is equivalent to (but harder to read than) 'double -4.5e+15' which is also supported by the parser. The only time hexadecimal -floating point constants are useful (and the only time that they are generated -by the disassembler) is when an FP constant has to be emitted that is not -representable as a decimal floating point number exactly. For example, NaN's, -infinities, and other special cases are represented in their IEEE hexadecimal -format so that assembly and disassembly do not cause any bits to change in the -constants.

    - - +4.5e+15' which is also supported by the parser. The only time +hexadecimal floating point constants are useful (and the only time that +they are generated by the disassembler) is when an FP constant has to +be emitted that is not representable as a decimal floating point number +exactly. For example, NaN's, infinities, and other special cases are +represented in their IEEE hexadecimal format so that assembly and +disassembly do not cause any bits to change in the constants.

    + - -
    -Type System -
    -
       -Primitive Types -


    Type Classifications

       -Derived Types -


    Array Type


    Function Type


    Structure Type


    Pointer Type

    -
    -High Level Structure -
    -
       -Module Structure -
    -
       -Global Variables -
    -
       -Function Structure -
    -
    -Instruction Reference -
    -
       -Terminator Instructions -


    'ret' Instruction


    'br' Instruction


    'switch' Instruction


    'invoke' Instruction

       -Binary Operations -


    'add' Instruction


    'sub' Instruction


    'mul' Instruction


    'div' Instruction


    'rem' Instruction


    'setcc' Instructions

    -
       -Bitwise Binary Operations -


    'and' Instruction


    'or' Instruction


    'xor' Instruction


    'shl' Instruction


    'shr' Instruction

    -
       -Memory Access Operations -


    'malloc' Instruction


    'free' Instruction


    'alloca' Instruction


    'load' Instruction


    'store' Instruction


    'getelementptr' Instruction

    -
       -Other Operations -


    'phi' Instruction


    'cast .. to' Instruction


    'call' Instruction

    +
    Intrinsic Functions
    + +
    +

    LLVM supports the notion of an "intrinsic function". These +functions have well known names and semantics, and are required to +follow certain restrictions. Overall, these instructions represent an +extension mechanism for the LLVM language that does not require +changing all of the transformations in LLVM to add to the language (or +the bytecode reader/writer, the parser, etc...).

    +

    Intrinsic function names must all start with an "llvm." +prefix, this prefix is reserved in LLVM for intrinsic names, thus +functions may not be named this. Intrinsic functions must always be +external functions: you cannot define the body of intrinsic functions. +Intrinsic functions may only be used in call or invoke instructions: it +is illegal to take the address of an intrinsic function. Additionally, +because intrinsic functions are part of the LLVM language, it is +required that they all be documented here if any are added.

    +

    Unless an intrinsic function is target-specific, there must be a +lowering pass to eliminate the intrinsic or all backends must support +the intrinsic function.

    +
    + +
    Variable Argument +Handling Intrinsics
    +
    +

    Variable argument support is defined in LLVM with the vanext instruction and these three +intrinsic functions. These functions are related to the similarly +named macros defined in the <stdarg.h> header file.

    +

    All of these functions operate on arguments that use a +target-specific value type "va_list". The LLVM assembly +language reference manual does not define what this type is, so all +transformations should be prepared to handle intrinsics with any type +used.

    +

    This example shows how the vanext +instruction and the variable argument handling intrinsic functions are +used.

    +
    int %test(int %X, ...) {
    ; Initialize variable argument processing
    %ap = call sbyte*()* %llvm.va_start()

    ; Read a single integer argument
    %tmp = vaarg sbyte* %ap, int

    ; Advance to the next argument
    %ap2 = vanext sbyte* %ap, int

    ; Demonstrate usage of llvm.va_copy and llvm.va_end
    %aq = call sbyte* (sbyte*)* %llvm.va_copy(sbyte* %ap2)
    call void %llvm.va_end(sbyte* %aq)

    ; Stop processing of arguments.
    call void %llvm.va_end(sbyte* %ap2)
    ret int %tmp
    }
    +
    + +
    'llvm.va_start' +Intrinsic
    +
    +
    Syntax:
    +
      call va_list ()* %llvm.va_start()
    +
    Overview:
    +

    The 'llvm.va_start' intrinsic returns a new <arglist> +for subsequent use by the variable argument intrinsics.

    +
    Semantics:
    +

    The 'llvm.va_start' intrinsic works just like the va_start +macro available in C. In a target-dependent way, it initializes and +returns a va_list element, so that the next vaarg +will produce the first variable argument passed to the function. Unlike +the C va_start macro, this intrinsic does not need to know the +last argument of the function, the compiler can figure that out.

    +

    Note that this intrinsic function is only legal to be called from +within the body of a variable argument function.

    +
    + +
    'llvm.va_end' +Intrinsic
    +
    +
    Syntax:
    +
      call void (va_list)* %llvm.va_end(va_list <arglist>)
    +
    Overview:
    +

    The 'llvm.va_end' intrinsic destroys <arglist> +which has been initialized previously with llvm.va_start +or llvm.va_copy.

    +
    Arguments:
    +

    The argument is a va_list to destroy.

    +
    Semantics:
    +

    The 'llvm.va_end' intrinsic works just like the va_end +macro available in C. In a target-dependent way, it destroys the va_list. +Calls to llvm.va_start and llvm.va_copy must be matched exactly +with calls to llvm.va_end.

    +
    + +
    'llvm.va_copy' +Intrinsic
    +
    +
    Syntax:
    +
      call va_list (va_list)* %llvm.va_copy(va_list <destarglist>)
    +
    Overview:
    +

    The 'llvm.va_copy' intrinsic copies the current argument +position from the source argument list to the destination argument list.

    +
    Arguments:
    +

    The argument is the va_list to copy.

    +
    Semantics:
    +

    The 'llvm.va_copy' intrinsic works just like the va_copy +macro available in C. In a target-dependent way, it copies the source va_list +element into the returned list. This intrinsic is necessary because the llvm.va_start intrinsic may be arbitrarily +complex and require memory allocation, for example.

    +
    - -
    - + + +