X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=docs%2FLangRef.html;h=de19222c52b16f9c501967d08435a2fc83cd387f;hb=15a6c3e97629c61c8407b57289be53de9237b554;hp=df1ab479af2cd862a11d2667b6847770106e5075;hpb=dae2e9383b31cb3ff64b3a5c1b6fcd298ce7dff9;p=oota-llvm.git diff --git a/docs/LangRef.html b/docs/LangRef.html index df1ab479af2..de19222c52b 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -23,12 +23,13 @@
  • Linkage Types
  • Calling Conventions
  • Global Variables
  • -
  • Function Structure
  • +
  • Functions
  • +
  • Module-Level Inline Assembly
  • Type System
      -
    1. Primitive Types +
    2. Primitive Types
      1. Type Classifications
      @@ -54,6 +55,11 @@
    3. Constant Expressions
  • +
  • Other Values +
      +
    1. Inline Assembler Expressions +
    +
  • Instruction Reference
    1. Terminator Instructions @@ -85,14 +91,24 @@
    2. 'shr' Instruction
  • -
  • Memory Access Operations +
  • Vector Operations +
      +
    1. 'extractelement' Instruction
    2. +
    3. 'insertelement' Instruction
    4. +
    5. 'shufflevector' Instruction
    6. +
    7. 'vsetint' Instruction
    8. +
    9. 'vsetfp' Instruction
    10. +
    11. 'vselect' Instruction
    12. +
    +
  • +
  • Memory Access and Addressing Operations
    1. 'malloc' Instruction
    2. 'free' Instruction
    3. 'alloca' Instruction
    4. -
    5. 'load' Instruction
    6. -
    7. 'store' Instruction
    8. -
    9. 'getelementptr' Instruction
    10. +
    11. 'load' Instruction
    12. +
    13. 'store' Instruction
    14. +
    15. 'getelementptr' Instruction
  • Other Operations @@ -101,8 +117,7 @@
  • 'cast .. to' Instruction
  • 'select' Instruction
  • 'call' Instruction
  • -
  • 'vanext' Instruction
  • -
  • 'vaarg' Instruction
  • +
  • 'va_arg' Instruction
  • @@ -127,30 +142,29 @@
    1. 'llvm.returnaddress' Intrinsic
    2. 'llvm.frameaddress' Intrinsic
    3. +
    4. 'llvm.stacksave' Intrinsic
    5. +
    6. 'llvm.stackrestore' Intrinsic
    7. 'llvm.prefetch' Intrinsic
    8. 'llvm.pcmarker' Intrinsic
    9. +
    10. llvm.readcyclecounter' Intrinsic
    -
  • Operating System Intrinsics -
      -
    1. 'llvm.readport' Intrinsic
    2. -
    3. 'llvm.writeport' Intrinsic
    4. -
    5. 'llvm.readio' Intrinsic
    6. -
    7. 'llvm.writeio' Intrinsic
    8. -
  • Standard C Library Intrinsics
      -
    1. 'llvm.memcpy' Intrinsic
    2. -
    3. 'llvm.memmove' Intrinsic
    4. -
    5. 'llvm.memset' Intrinsic
    6. -
    7. 'llvm.isunordered' Intrinsic
    8. +
    9. 'llvm.memcpy.*' Intrinsic
    10. +
    11. 'llvm.memmove.*' Intrinsic
    12. +
    13. 'llvm.memset.*' Intrinsic
    14. +
    15. 'llvm.isunordered.*' Intrinsic
    16. +
    17. 'llvm.sqrt.*' Intrinsic
    18. +
    19. 'llvm.powi.*' Intrinsic
  • -
  • Bit counting Intrinsics +
  • Bit Manipulation Intrinsics
      -
    1. 'llvm.ctpop' Intrinsic
    2. -
    3. 'llvm.cttz' Intrinsic
    4. -
    5. 'llvm.ctlz' Intrinsic
    6. +
    7. 'llvm.bswap.*' Intrinsics
    8. +
    9. 'llvm.ctpop.*' Intrinsic
    10. +
    11. 'llvm.ctlz.*' Intrinsic
    12. +
    13. 'llvm.cttz.*' Intrinsic
  • Debugger intrinsics
  • @@ -192,7 +206,7 @@ to debug and visualize the transformations. The three different forms of LLVM are all equivalent. This document describes the human readable representation and notation.

    -

    The LLVM representation aims to be a light-weight and low-level +

    The LLVM representation aims to be light-weight and low-level while being expressive, typed, 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 @@ -222,7 +236,7 @@ following instruction is syntactically okay, but not well formed:

    ...because the definition of %x does not dominate all of its uses. The LLVM infrastructure provides a verification pass that may be used to verify that an LLVM module is well formed. This pass is -automatically run by the parser after parsing input assembly, and by +automatically run by the parser after parsing input assembly and by the optimizer before it outputs bytecode. The violations pointed out by the verifier pass indicate bugs in transformation passes or input to the parser.

    @@ -336,6 +350,9 @@ symbol table entries. Here is an example of the "hello world" module:

    ; External declaration of the puts function declare int %puts(sbyte*) ; int(sbyte*)* +; Global variable / Function body section separator +implementation + ; Definition of main function int %main() { ; int()* ; Convert [13x sbyte]* to sbyte *... @@ -359,6 +376,13 @@ represented by a pointer to a memory location (in this case, a pointer to an array of char, and a pointer to a function), and have one of the following linkage types.

    +

    Due to a limitation in the current LLVM assembly parser (it is limited by +one-token lookahead), modules are split into two pieces by the "implementation" +keyword. Global variable prototypes and definitions must occur before the +keyword, and function definitions must occur after it. Function prototypes may +occur either before or after it. In the future, the implementation keyword may +become a noop, if the parser gets smarter.

    + @@ -415,6 +439,35 @@ All Global Variables and Functions have one of the following types of linkage: visible, meaning that it participates in linkage and can be used to resolve external symbol references. + +
    extern_weak:
    + +
    "extern_weak" TBD +
    + +

    + The next two types of linkage are targeted for Microsoft Windows platform + only. They are designed to support importing (exporting) symbols from (to) + DLLs. +

    + +
    dllimport:
    + +
    "dllimport" linkage causes the compiler to reference a function + or variable via a global pointer to a pointer that is set up by the DLL + exporting the symbol. On Microsoft Windows targets, the pointer name is + formed by combining _imp__ and the function or variable name. +
    + +
    dllexport:
    + +
    "dllexport" linkage causes the compiler to provide a global + pointer to a pointer in a DLL, so that it can be referenced with the + dllimport attribute. On Microsoft Windows targets, the pointer + name is formed by combining _imp__ and the function or variable + name. +
    +

    For example, since the ".LC0" @@ -450,6 +503,19 @@ the future:

    prototype and implemented declaration of the function (as does normal C). +
    "csretcc" - The C struct return calling convention:
    + +
    This calling convention matches the target C calling conventions, except + that functions with this convention are required to take a pointer as their + first argument, and the return type of the function must be void. This is + used for C functions that return aggregates by-value. In this case, the + function has been transformed to take a pointer to the struct as the first + argument to the function. For targets where the ABI specifies specific + behavior for structure-return calls, the calling convention can be used to + distinguish between struct return functions and other functions that take a + pointer to a struct as the first argument. +
    +
    "fastcc" - The fast calling convention:
    This calling convention attempts to make calls as fast as possible @@ -493,12 +559,14 @@ convention.

    Global variables define regions of memory allocated at compilation time -instead of run-time. Global variables may optionally be initialized. A -variable may be defined as a global "constant", which indicates that the +instead of run-time. Global variables may optionally be initialized, may have +an explicit section to be placed in, and may +have an optional explicit alignment specified. A +variable may be defined as a global "constant," which indicates that the contents of the variable will never be modified (enabling better optimization, allowing the global data to be placed in the read-only section of an executable, etc). Note that variables that need runtime initialization -cannot be marked "constant", as there is a store to the variable.

    +cannot be marked "constant" as there is a store to the variable.

    LLVM explicitly allows declarations of global variables to be marked @@ -515,6 +583,15 @@ variables always define a pointer to their "content" type because they describe a region of memory, and all memory objects in LLVM are accessed through pointers.

    +

    LLVM allows an explicit section to be specified for globals. If the target +supports it, it will emit globals to the section specified.

    + +

    An explicit alignment may be specified for a global. If not present, or if +the alignment is set to zero, the alignment of the global is set by the target +to whatever it feels convenient. If an explicit alignment is specified, the +global is forced to have at least that much alignment. All alignments must be +a power of 2.

    +
    @@ -527,11 +604,12 @@ accessed through pointers.

    LLVM function definitions consist of an optional linkage type, an optional calling convention, a return -type, a function name, a (possibly empty) argument list, an opening curly brace, +type, a function name, a (possibly empty) argument list, an optional section, +an optional alignment, an opening curly brace, a list of basic blocks, and a closing curly brace. LLVM function declarations are defined with the "declare" keyword, an optional calling convention, a return type, a function name, and -a possibly empty list of arguments.

    +href="#callingconv">calling convention, a return type, a function name, +a possibly empty list of arguments, and an optional alignment.

    A function definition contains a list of basic blocks, forming the CFG for the function. Each basic block may optionally start with a label (giving the @@ -550,8 +628,45 @@ functions with the same name but different parameter lists or return values are considered different functions, and LLVM will resolve references to each appropriately.

    +

    LLVM allows an explicit section to be specified for functions. If the target +supports it, it will emit functions to the section specified.

    + +

    An explicit alignment may be specified for a function. If not present, or if +the alignment is set to zero, the alignment of the function is set by the target +to whatever it feels convenient. If an explicit alignment is specified, the +function is forced to have at least that much alignment. All alignments must be +a power of 2.

    + + + + +
    + Module-Level Inline Assembly
    +
    +

    +Modules may contain "module-level inline asm" blocks, which corresponds to the +GCC "file scope inline asm" blocks. These blocks are internally concatenated by +LLVM and treated as a single unit, but may be separated in the .ll file if +desired. The syntax is very simple: +

    + +
    +  module asm "inline asm code goes here"
    +  module asm "more can go here"
    +
    + +

    The strings can contain any character by escaping non-printable characters. + The escape sequence used is simply "\xx" where "xx" is the two digit hex code + for the number. +

    + +

    + The inline asm code is simply printed to the machine code .s file when + assembly code is generated. +

    +
    @@ -712,12 +827,20 @@ be any type with a size.

    [2 x [3 x [4 x uint]]]
    - 3x4 array integer values.
    + 3x4 array of integer values.
    12x10 array of single precision floating point values.
    2x3x4 array of unsigned integer values.
    + +

    Note that 'variable sized arrays' can be implemented in LLVM with a zero +length array. Normally, accesses past the end of an array are undefined in +LLVM (e.g. it is illegal to access the 5th element of a 3 element array). +As a special case, however, zero length arrays are recognized to be variable +length. This allows implementation of 'pascal style arrays' with the LLVM +type "{ int, [0 x float]}", for example.

    + @@ -734,7 +857,7 @@ The return type of a function type cannot be an aggregate type.

    Syntax:
      <returntype> (<parameter list>)
    -

    Where '<parameter list>' is a comma-separated list of type +

    ...where '<parameter list>' is a comma-separated list of type specifiers. Optionally, the parameter list may include a type ..., which indicates that the function takes a variable number of arguments. Variable argument functions can access their arguments with the of elements. Packed types are used when multiple primitive data are operated in parallel using a single instruction (SIMD). A packed type requires a size (number of -elements) and an underlying primitive data type. Packed types are +elements) and an underlying primitive data type. Vectors must have a power +of two length (1, 2, 4, 8, 16 ...). Packed types are considered first class.

    Syntax:
    @@ -836,7 +960,7 @@ considered first class.

    < <# elements> x <elementtype> > -

    The number of elements is a constant integer value, elementtype may +

    The number of elements is a constant integer value; elementtype may be any integral or floating point type.

    Examples:
    @@ -923,7 +1047,6 @@ them all and their syntax.

    Floating point constants use standard decimal notation (e.g. 123.421), exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal - notation. Floating point constants have an optional hexadecimal notation (see below). Floating point constants must have a floating point type.
    @@ -989,7 +1112,7 @@ and smaller aggregate constants.

    The string 'zeroinitializer' can be used to zero initialize a value to zero of any type, including scalar and aggregate types. This is often used to avoid having to print large zero initializers (e.g. for - large arrays), and is always exactly equivalent to using explicit zero + large arrays) and is always exactly equivalent to using explicit zero initializers.
    @@ -1022,7 +1145,7 @@ file:

    Undefined Values

    The string 'undef' is recognized as a type-less constant that has - no specific value. Undefined values may be of any type, and be used anywhere + no specific value. Undefined values may be of any type and be used anywhere a constant is permitted.

    Undefined values indicate to the compiler that the program is well defined @@ -1038,7 +1161,7 @@ file:

    Constant expressions are used to allow expressions involving other constants to be used as constants. Constant expressions may be of any first class type, and may involve any LLVM operation +href="#t_firstclass">first class type and may involve any LLVM operation that does not have side effects (e.g. load and call are not supported). The following is the syntax for constant expressions:

    @@ -1054,6 +1177,27 @@ following is the syntax for constant expressions:

    instruction, the index list may have zero or more indexes, which are required to make sense for the type of "CSTPTR". +
    select ( COND, VAL1, VAL2 )
    + +
    Perform the select operation on + constants. + +
    extractelement ( VAL, IDX )
    + +
    Perform the extractelement + operation on constants. + +
    insertelement ( VAL, ELT, IDX )
    + +
    Perform the insertelement + operation on constants. + + +
    shufflevector ( VEC1, VEC2, IDXMASK )
    + +
    Perform the shufflevector + operation on constants. +
    OPCODE ( LHS, RHS )
    Perform the specified operation of the LHS and RHS constants. OPCODE may @@ -1064,6 +1208,56 @@ following is the syntax for constant expressions:

    + +
    Other Values
    + + + +
    +Inline Assembler Expressions +
    + +
    + +

    +LLVM supports inline assembler expressions (as opposed to +Module-Level Inline Assembly) through the use of a special value. This +value represents the inline assembler as a string (containing the instructions +to emit), a list of operand constraints (stored as a string), and a flag that +indicates whether or not the inline asm expression has side effects. An example +inline assembler expression is: +

    + +
    +  int(int) asm "bswap $0", "=r,r"
    +
    + +

    +Inline assembler expressions may only be used as the callee operand of +a call instruction. Thus, typically we have: +

    + +
    +  %X = call int asm "bswap $0", "=r,r"(int %Y)
    +
    + +

    +Inline asms with side effects not visible in the constraint list must be marked +as having side effects. This is done through the use of the +'sideeffect' keyword, like so: +

    + +
    +  call void asm sideeffect "eieio", ""()
    +
    + +

    TODO: The format of the asm and constraints string still need to be +documented here. Constraints on what can be done (e.g. duplication, moving, etc +need to be documented). +

    + +
    +
    Instruction Reference
    @@ -1072,7 +1266,8 @@ following is the syntax for constant expressions:

    The LLVM instruction set consists of several different classifications of instructions: terminator -instructions, binary instructions, , binary instructions, +bitwise binary instructions, memory instructions, and other instructions.

    @@ -1109,7 +1304,7 @@ Instruction
    Overview:

    The 'ret' instruction is used to return control flow (and a -value) from a function, back to the caller.

    +value) from a function back to the caller.

    There are two forms of the 'ret' instruction: one that returns a value and then causes control flow, and one that just causes control flow to occur.

    @@ -1228,7 +1423,7 @@ branches or with a lookup table.

       <result> = invoke [cconv] <ptr to function ty> %<function ptr val>(<function args>) 
    -                to label <normal label> except label <exception label>
    +                to label <normal label> unwind label <exception label>
     
    Overview:
    @@ -1248,7 +1443,7 @@ continued at the dynamically nearest "exception" label.

    1. -

      The optional "cconv" marker indicates which calling + The optional "cconv" marker indicates which calling convention the call should use. If none is specified, the call defaults to using C calling conventions.

    2. @@ -1289,9 +1484,9 @@ exception. Additionally, this is important for implementation of
      Example:
         %retval = invoke int %Test(int 15)             to label %Continue
      -              except label %TestCleanup     ; {int}:retval set
      +              unwind label %TestCleanup     ; {int}:retval set
         %retval = invoke coldcc int %Test(int 15)             to label %Continue
      -              except label %TestCleanup     ; {int}:retval set
      +              unwind label %TestCleanup     ; {int}:retval set
       
      @@ -1477,12 +1672,13 @@ Both arguments must have identical types.

      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:
        <result> = rem int 4, %var          ; yields {int}:result = 4 % %var
       
      +
      'setcc' @@ -1528,6 +1724,7 @@ operand.

      <result> = setge sbyte 4, 5 ; yields {bool}:result = false
      +
      Bitwise Binary Operations
      @@ -1752,163 +1949,572 @@ positions.

      <result> = shr sbyte -2, ubyte 1 ; yields {sbyte}:result = -1 + -
      Memory Access -Operations
      +
      + Vector Operations +
      +
      -

      A key design point of an SSA-based representation is how it -represents memory. In LLVM, no memory locations are in SSA form, which -makes things very simple. This section describes how to read, write, -allocate, and free memory in LLVM.

      + +

      LLVM supports several instructions to represent vector operations in a +target-independent manner. This instructions cover the element-access and +vector-specific operations needed to process vectors effectively. While LLVM +does directly support these vector operations, many sophisticated algorithms +will want to use target-specific intrinsics to take full advantage of a specific +target.

      +
      + -
      'malloc' -Instruction
      +
      + 'extractelement' Instruction +
      +
      +
      Syntax:
      -
        <result> = malloc <type>, uint <NumElements>     ; yields {type*}:result
      -  <result> = malloc <type>                         ; yields {type*}:result
      +
      +
      +  <result> = extractelement <n x <ty>> <val>, uint <idx>    ; yields <ty>
       
      +
      Overview:
      -

      The 'malloc' instruction allocates memory from the system -heap and returns a pointer to it.

      + +

      +The 'extractelement' instruction extracts a single scalar +element from a packed vector at a specified index. +

      + +
      Arguments:
      -

      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' must be a sized type.

      + +

      +The first operand of an 'extractelement' instruction is a +value of packed type. The second operand is +an index indicating the position from which to extract the element. +The index may be a variable.

      +
      Semantics:
      -

      Memory is allocated using the system "malloc" function, and -a pointer is returned.

      + +

      +The result is a scalar of the same type as the element type of +val. Its value is the value at position idx of +val. If idx exceeds the length of val, the +results are undefined. +

      +
      Example:
      -
        %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 [12 x ubyte], uint %size        ; yields {[12 x ubyte]*}:array2
      +
      +  %result = extractelement <4 x int> %vec, uint 0    ; yields int
       
      + + -
      'free' -Instruction
      +
      + 'insertelement' Instruction +
      +
      +
      Syntax:
      -
        free <type> <value>                              ; yields {void}
      +
      +
      +  <result> = insertelement <n x <ty>> <val>, <ty> <elt>, uint <idx>    ; yields <n x <ty>>
       
      +
      Overview:
      -

      The 'free' instruction returns memory back to the unused -memory heap, to be reallocated in the future.

      -

      + +

      +The 'insertelement' instruction inserts a scalar +element into a packed vector at a specified index. +

      + +
      Arguments:
      -

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

      + +

      +The first operand of an 'insertelement' instruction is a +value of packed type. The second operand is a +scalar value whose type must equal the element type of the first +operand. The third operand is an index indicating the position at +which to insert the value. The index may be a variable.

      +
      Semantics:
      -

      Access to the memory pointed to by the pointer is no longer defined -after this instruction executes.

      + +

      +The result is a packed vector of the same type as val. Its +element values are those of val except at position +idx, where it gets the value elt. If idx +exceeds the length of val, the results are undefined. +

      +
      Example:
      -
        %array  = malloc [4 x ubyte]                    ; yields {[4 x ubyte]*}:array
      -            free   [4 x ubyte]* %array
      +
      +
      +  %result = insertelement <4 x int> %vec, int 1, uint 0    ; yields <4 x int>
       
      + -
      'alloca' -Instruction
      +
      + 'shufflevector' Instruction +
      +
      +
      Syntax:
      -
        <result> = alloca <type>, uint <NumElements>  ; yields {type*}:result
      -  <result> = alloca <type>                      ; yields {type*}:result
      +
      +
      +  <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <n x uint> <mask>    ; yields <n x <ty>>
       
      +
      Overview:
      -

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

      + +

      +The 'shufflevector' instruction constructs a permutation of elements +from two input vectors, returning a vector of the same type. +

      +
      Arguments:
      -

      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.

      + +

      +The first two operands of a 'shufflevector' instruction are vectors +with types that match each other and types that match the result of the +instruction. The third argument is a shuffle mask, which has the same number +of elements as the other vector type, but whose element type is always 'uint'. +

      + +

      +The shuffle mask operand is required to be a constant vector with either +constant integer or undef values. +

      +
      Semantics:
      -

      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. When the function returns (either with the ret or unwind -instructions), the memory is reclaimed.

      + +

      +The elements of the two input vectors are numbered from left to right across +both of the vectors. The shuffle mask operand specifies, for each element of +the result vector, which element of the two input registers the result element +gets. The element selector may be undef (meaning "don't care") and the second +operand may be undef if performing a shuffle from only one vector. +

      +
      Example:
      -
        %ptr = alloca int                              ; yields {int*}:ptr
      -  %ptr = alloca int, uint 4                      ; yields {int*}:ptr
      +
      +
      +  %result = shufflevector <4 x int> %v1, <4 x int> %v2, 
      +                          <4 x uint> <uint 0, uint 4, uint 1, uint 5>    ; yields <4 x int>
      +  %result = shufflevector <4 x int> %v1, <4 x int> undef, 
      +                          <4 x uint> <uint 0, uint 1, uint 2, uint 3>  ; yields <4 x int> - Identity shuffle.
       
      + + -
      'load' +
      Syntax:
      -
        <result> = load <ty>* <pointer>
      <result> = volatile load <ty>* <pointer>
      -
      Overview:
      -

      The 'load' instruction is used to read from memory.

      -
      Arguments:
      -

      The argument to the 'load' instruction specifies the memory -address to load from. The pointer must point to a first class type. If the load is -marked as volatile then the optimizer is not allowed to modify -the number or order of execution of this load with other -volatile load and store -instructions.

      -
      Semantics:
      -

      The location of memory pointed to is loaded.

      -
      Examples:
      -
        %ptr = alloca int                               ; yields {int*}:ptr
      -  store int 3, int* %ptr                          ; yields {void}
      -  %val = load int* %ptr                           ; yields {int}:val = int 3
      -
      -
      - - -
      Syntax:
      -
        store <ty> <value>, <ty>* <pointer>                   ; yields {void}
      -  volatile store <ty> <value>, <ty>* <pointer>                   ; yields {void}
      +
      <result> = vsetint <op>, <n x <ty>> <var1>, <var2>   ; yields <n x bool>
       
      +
      Overview:
      -

      The 'store' instruction is used to write to memory.

      + +

      The 'vsetint' instruction takes two integer vectors and +returns a vector of boolean values representing, at each position, the +result of the comparison between the values at that position in the +two operands.

      +
      Arguments:
      -

      There are two arguments to the 'store' instruction: a value -to store and an address to store it into. The type of the '<pointer>' -operand must be a pointer to the type of the '<value>' -operand. If the store is marked as volatile then the -optimizer is not allowed to modify the number or order of execution of -this store with other volatile load and store instructions.

      + +

      The arguments to a 'vsetint' instruction are a comparison +operation and two value arguments. The value arguments must be of integral packed type, +and they must have identical types. The operation argument must be +one of eq, ne, slt, sgt, +sle, sge, ult, ugt, ule, +uge, true, and false. The result is a +packed bool value with the same length as each operand.

      +
      Semantics:
      -

      The contents of memory are updated to contain '<value>' -at the location specified by the '<pointer>' operand.

      + +

      The following table shows the semantics of 'vsetint'. For +each position of the result, the comparison is done on the +corresponding positions of the two value arguments. Note that the +signedness of the comparison depends on the comparison opcode and +not on the signedness of the value operands. E.g., vsetint +slt <4 x unsigned> %x, %y does an elementwise signed +comparison of %x and %y.

      + + + + + + + + + + + + + + + + + +
      OperationResult is true iffComparison is
      eqvar1 == var2--
      nevar1 != var2--
      sltvar1 < var2signed
      sgtvar1 > var2signed
      slevar1 <= var2signed
      sgevar1 >= var2signed
      ultvar1 < var2unsigned
      ugtvar1 > var2unsigned
      ulevar1 <= var2unsigned
      ugevar1 >= var2unsigned
      truealways--
      falsenever--
      +
      Example:
      -
        %ptr = alloca int                               ; yields {int*}:ptr
      -  store int 3, int* %ptr                          ; yields {void}
      -  %val = load int* %ptr                           ; yields {int}:val = int 3
      +
        <result> = vsetint eq <2 x int> <int 0, int 1>, <int 1, int 0>      ; yields {<2 x bool>}:result = false, false
      +  <result> = vsetint ne <2 x int> <int 0, int 1>, <int 1, int 0>      ; yields {<2 x bool>}:result = true, true
      +  <result> = vsetint slt <2 x int> <int 0, int 1>, <int 1, int 0>      ; yields {<2 x bool>}:result = true, false
      +  <result> = vsetint sgt <2 x int> <int 0, int 1>, <int 1, int 0>      ; yields {<2 x bool>}:result = false, true
      +  <result> = vsetint sle <2 x int> <int 0, int 1>, <int 1, int 0>      ; yields {<2 x bool>}:result = true, false
      +  <result> = vsetint sge <2 x int> <int 0, int 1>, <int 1, int 0>      ; yields {<2 x bool>}:result = false, true
       
      - - + +
      Syntax:
      -
      -  <result> = getelementptr <ty>* <ptrval>{, <ty> <idx>}*
      +
      <result> = vsetfp <op>, <n x <ty>> <var1>, <var2>   ; yields <n x bool>
       
      Overview:
      -

      +

      The 'vsetfp' instruction takes two floating point vector +arguments and returns a vector of boolean values representing, at each +position, the result of the comparison between the values at that +position in the two operands.

      + +
      Arguments:
      + +

      The arguments to a 'vsetfp' instruction are a comparison +operation and two value arguments. The value arguments must be of floating point packed +type, and they must have identical types. The operation argument must +be one of eq, ne, lt, gt, +le, ge, oeq, one, olt, +ogt, ole, oge, ueq, une, +ult, ugt, ule, uge, o, +u, true, and false. The result is a packed +bool value with the same length as each operand.

      + +
      Semantics:
      + +

      The following table shows the semantics of 'vsetfp' for +floating point types. If either operand is a floating point Not a +Number (NaN) value, the operation is unordered, and the value in the +first column below is produced at that position. Otherwise, the +operation is ordered, and the value in the second column is +produced.

      + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      OperationIf unorderedOtherwise true iff
      equndefinedvar1 == var2
      neundefinedvar1 != var2
      ltundefinedvar1 < var2
      gtundefinedvar1 > var2
      leundefinedvar1 <= var2
      geundefinedvar1 >= var2
      oeqfalsevar1 == var2
      onefalsevar1 != var2
      oltfalsevar1 < var2
      ogtfalsevar1 > var2
      olefalsevar1 <= var2
      ogefalsevar1 >= var2
      ueqtruevar1 == var2
      unetruevar1 != var2
      ulttruevar1 < var2
      ugttruevar1 > var2
      uletruevar1 <= var2
      ugetruevar1 >= var2
      ofalsealways
      utruenever
      truetruealways
      falsefalsenever
      + +
      Example:
      +
        <result> = vsetfp eq <2 x float> <float 0.0, float 1.0>, <float 1.0, float 0.0>      ; yields {<2 x bool>}:result = false, false
      +  <result> = vsetfp ne <2 x float> <float 0.0, float 1.0>, <float 1.0, float 0.0>      ; yields {<2 x bool>}:result = true, true
      +  <result> = vsetfp lt <2 x float> <float 0.0, float 1.0>, <float 1.0, float 0.0>      ; yields {<2 x bool>}:result = true, false
      +  <result> = vsetfp gt <2 x float> <float 0.0, float 1.0>, <float 1.0, float 0.0>      ; yields {<2 x bool>}:result = false, true
      +  <result> = vsetfp le <2 x float> <float 0.0, float 1.0>, <float 1.0, float 0.0>      ; yields {<2 x bool>}:result = true, false
      +  <result> = vsetfp ge <2 x float> <float 0.0, float 1.0>, <float 1.0, float 0.0>      ; yields {<2 x bool>}:result = false, true
      +
      +
      + + + + +
      + +
      Syntax:
      + +
      +  <result> = vselect <n x bool> <cond>, <n x <ty>> <val1>, <n x <ty>> <val2> ; yields <n x <ty>>
      +
      + +
      Overview:
      + +

      +The 'vselect' instruction chooses one value at each position +of a vector based on a condition. +

      + + +
      Arguments:
      + +

      +The 'vselect' instruction requires a packed bool value indicating the +condition at each vector position, and two values of the same packed +type. All three operands must have the same length. The type of the +result is the same as the type of the two value operands.

      + +
      Semantics:
      + +

      +At each position where the bool vector is true, that position +of the result gets its value from the first value argument; otherwise, +it gets its value from the second value argument. +

      + +
      Example:
      + +
      +  %X = vselect bool <2 x bool> <bool true, bool false>, <2 x ubyte> <ubyte 17, ubyte 17>, 
      +    <2 x ubyte> <ubyte 42, ubyte 42>      ; yields <2 x ubyte>:17, 42
      +
      +
      + + + + + + +
      + +

      A key design point of an SSA-based representation is how it +represents memory. In LLVM, no memory locations are in SSA form, which +makes things very simple. This section describes how to read, write, +allocate, and free memory in LLVM.

      + +
      + + + + +
      + +
      Syntax:
      + +
      +  <result> = malloc <type>[, uint <NumElements>][, align <alignment>]     ; yields {type*}:result
      +
      + +
      Overview:
      + +

      The 'malloc' instruction allocates memory from the system +heap and returns a pointer to it.

      + +
      Arguments:
      + +

      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. If "NumElements" is specified, it is the +number of elements allocated. If an alignment is specified, the value result +of the allocation is guaranteed to be aligned to at least that boundary. If +not specified, or if zero, the target can choose to align the allocation on any +convenient boundary.

      + +

      'type' must be a sized type.

      + +
      Semantics:
      + +

      Memory is allocated using the system "malloc" function, and +a pointer is returned.

      + +
      Example:
      + +
      +  %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 [12 x ubyte], uint %size        ; yields {[12 x ubyte]*}:array2
      +  %array3 = malloc int, uint 4, align 1024         ; yields {int*}:array3
      +  %array4 = malloc int, align 1024                 ; yields {int*}:array4
      +
      +
      + + + + +
      + +
      Syntax:
      + +
      +  free <type> <value>                              ; yields {void}
      +
      + +
      Overview:
      + +

      The 'free' instruction returns memory back to the unused +memory heap to be reallocated in the future.

      + +
      Arguments:
      + +

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

      + +
      Semantics:
      + +

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

      + +
      Example:
      + +
      +  %array  = malloc [4 x ubyte]                    ; yields {[4 x ubyte]*}:array
      +            free   [4 x ubyte]* %array
      +
      +
      + + + + +
      + +
      Syntax:
      + +
      +  <result> = alloca <type>[, uint <NumElements>][, align <alignment>]     ; yields {type*}:result
      +
      + +
      Overview:
      + +

      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:
      + +

      The 'alloca' instruction allocates sizeof(<type>)*NumElements +bytes of memory on the runtime stack, returning a pointer of the +appropriate type to the program. If "NumElements" is specified, it is the +number of elements allocated. If an alignment is specified, the value result +of the allocation is guaranteed to be aligned to at least that boundary. If +not specified, or if zero, the target can choose to align the allocation on any +convenient boundary.

      + +

      'type' may be any sized type.

      + +
      Semantics:
      + +

      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. When the function returns (either with the ret or unwind +instructions), the memory is reclaimed.

      + +
      Example:
      + +
      +  %ptr = alloca int                              ; yields {int*}:ptr
      +  %ptr = alloca int, uint 4                      ; yields {int*}:ptr
      +  %ptr = alloca int, uint 4, align 1024          ; yields {int*}:ptr
      +  %ptr = alloca int, align 1024                  ; yields {int*}:ptr
      +
      +
      + + + +
      +
      Syntax:
      +
        <result> = load <ty>* <pointer>
      <result> = volatile load <ty>* <pointer>
      +
      Overview:
      +

      The 'load' instruction is used to read from memory.

      +
      Arguments:
      +

      The argument to the 'load' instruction specifies the memory +address from which to load. The pointer must point to a first class type. If the load is +marked as volatile, then the optimizer is not allowed to modify +the number or order of execution of this load with other +volatile load and store +instructions.

      +
      Semantics:
      +

      The location of memory pointed to is loaded.

      +
      Examples:
      +
        %ptr = alloca int                               ; yields {int*}:ptr
      +  store int 3, int* %ptr                          ; yields {void}
      +  %val = load int* %ptr                           ; yields {int}:val = int 3
      +
      +
      + + +
      Syntax:
      +
        store <ty> <value>, <ty>* <pointer>                   ; yields {void}
      +  volatile store <ty> <value>, <ty>* <pointer>                   ; yields {void}
      +
      +
      Overview:
      +

      The 'store' instruction is used to write to memory.

      +
      Arguments:
      +

      There are two arguments to the 'store' instruction: a value +to store and an address in which to store it. The type of the '<pointer>' +operand must be a pointer to the type of the '<value>' +operand. If the store is marked as volatile, then the +optimizer is not allowed to modify the number or order of execution of +this store with other volatile load and store instructions.

      +
      Semantics:
      +

      The contents of memory are updated to contain '<value>' +at the location specified by the '<pointer>' operand.

      +
      Example:
      +
        %ptr = alloca int                               ; yields {int*}:ptr
      +  store int 3, int* %ptr                          ; yields {void}
      +  %val = load int* %ptr                           ; yields {int}:val = int 3
      +
      + + + +
      +
      Syntax:
      +
      +  <result> = getelementptr <ty>* <ptrval>{, <ty> <idx>}*
      +
      + +
      Overview:
      + +

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

      @@ -1918,8 +2524,9 @@ subelement of an aggregate data structure.

      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. When indexing into a structure, only uint -integer constants are allowed. When indexing into an array or pointer +levels of a structure or to a specific index in an array. When indexing into a +structure, only uint +integer constants are allowed. When indexing into an array or pointer, int and long indexes are allowed of any sign.

      For example, let's consider a C code fragment and how it gets @@ -1960,7 +2567,7 @@ compiled to LLVM:

      Semantics:

      The index types specified for the 'getelementptr' instruction depend -on the pointer type that is being index into. Pointer +on the pointer type that is being indexed into. Pointer and array types require uint, int, ulong, or long values, and structure types require uint constants.

      @@ -1972,7 +2579,7 @@ 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 +'int' type. The 'getelementptr' instruction returns a pointer to this element, thus computing a value of 'int*' type.

      Note that it is perfectly legal to index partially through a @@ -1989,7 +2596,19 @@ the LLVM code for the given testcase is equivalent to:

      ret int* %t5 }
      + +

      Note that it is undefined to access an array out of bounds: array and +pointer indexes must always be within the defined bounds of the array type. +The one exception for this rules is zero length arrays. These arrays are +defined to be accessible as variable length arrays, which requires access +beyond the zero'th element.

      + +

      The getelementptr instruction is often confusing. For some more insight +into how it works, see the getelementptr +FAQ.

      +
      Example:
      +
           ; yields [12 x ubyte]*:aptr
           %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
      @@ -2119,7 +2738,7 @@ The 'select' instruction requires a boolean value indicating the condit
       
       

      If the boolean condition evaluates to true, the instruction returns the first -value argument, otherwise it returns the second value argument. +value argument; otherwise, it returns the second value argument.

      Example:
      @@ -2130,9 +2749,6 @@ value argument, otherwise it returns the second value argument.
      - - -
      'call' Instruction @@ -2169,13 +2785,14 @@ value argument, otherwise it returns the second value argument.
    3. 'ty': shall be the signature of the pointer to function value being invoked. The argument types must match the types implied by this - signature.

      + signature. This type can be omitted if the function is not varargs and + if the function type does not return a pointer to a function.

    4. 'fnptrval': An LLVM value containing a pointer to a function to be invoked. In most cases, this is a direct function invocation, but indirect calls are just as possible, calling an arbitrary pointer - to function values.

      + to function value.

    5. 'function args': argument list whose types match the @@ -2209,59 +2826,7 @@ the invoke instruction.

      - -
      - -
      Syntax:
      - -
      -  <resultarglist> = vanext <va_list> <arglist>, <argty>
      -
      - -
      Overview:
      - -

      The 'vanext' instruction is used to access arguments passed -through the "variable argument" area of a function call. It is used to -implement the va_arg macro in C.

      - -
      Arguments:
      - -

      This instruction takes a va_list value and the type of the -argument. It returns another va_list. The actual type of -va_list may be defined differently for different targets. Most targets -use a va_list type of sbyte* or some other pointer type.

      - -
      Semantics:
      - -

      The 'vanext' instruction advances the specified va_list -past an argument of the specified type. In conjunction with the vaarg instruction, it is used to implement -the va_arg macro available in C. For more information, see -the variable argument handling Intrinsic -Functions.

      - -

      It is legal for this instruction to be called in a function which -does not take a variable number of arguments, for example, the vfprintf -function.

      - -

      vanext is an LLVM instruction instead of an intrinsic function because it takes a type as an -argument. The type refers to the current argument in the va_list, it -tells the compiler how far on the stack it needs to advance to find the next -argument

      - -
      Example:
      - -

      See the variable argument processing -section.

      - -
      - - -
      @@ -2269,35 +2834,36 @@ section.

      Syntax:
      -  <resultval> = vaarg <va_list> <arglist>, <argty>
      +  <resultval> = va_arg <va_list*> <arglist>, <argty>
       
      Overview:
      -

      The 'vaarg' instruction is used to access arguments passed through +

      The 'va_arg' instruction is used to access arguments passed through the "variable argument" area of a function call. It is used to implement the va_arg macro in C.

      Arguments:
      -

      This instruction takes a va_list value and the type of the -argument. It returns a value of the specified argument type. Again, the actual -type of va_list is target specific.

      +

      This instruction takes a va_list* value and the type of +the argument. It returns a value of the specified argument type and +increments the va_list to point to the next argument. Again, the +actual type of va_list is target specific.

      Semantics:
      -

      The 'vaarg' instruction loads an argument of the specified type from -the specified va_list. In conjunction with the vanext instruction, it is used to implement the -va_arg macro available in C. For more information, see the variable -argument handling Intrinsic Functions.

      +

      The 'va_arg' instruction loads an argument of the specified +type from the specified va_list and causes the +va_list to point to the next argument. For more information, +see the variable argument handling Intrinsic +Functions.

      It is legal for this instruction to be called in a function which does not take a variable number of arguments, for example, the vfprintf function.

      -

      vaarg is an LLVM instruction instead of an intrinsic function because it takes an type as an +

      va_arg is an LLVM instruction instead of an intrinsic function because it takes a type as an argument.

      Example:
      @@ -2313,14 +2879,14 @@ argument.

      LLVM supports the notion of an "intrinsic function". These functions have -well known names and semantics, and are required to follow certain +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 +

      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 @@ -2328,7 +2894,7 @@ function. Additionally, because intrinsic functions are part of the LLVM language, it is required that they all be documented here if any are added.

      -

      To learn how to add an intrinsics, please see the To learn how to add an intrinsic function, please see the Extending LLVM Guide.

      @@ -2342,7 +2908,7 @@ href="ExtendingLLVM.html">Extending LLVM Guide.

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

      @@ -2352,27 +2918,26 @@ 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 +

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

       int %test(int %X, ...) {
         ; Initialize variable argument processing
      -  %ap = call sbyte* %llvm.va_start()
      +  %ap = alloca sbyte*
      +  call void %llvm.va_start(sbyte** %ap)
       
         ; Read a single integer argument
      -  %tmp = vaarg sbyte* %ap, int
      -
      -  ; Advance to the next argument
      -  %ap2 = vanext sbyte* %ap, int
      +  %tmp = va_arg sbyte** %ap, int
       
         ; Demonstrate usage of llvm.va_copy and llvm.va_end
      -  %aq = call sbyte* %llvm.va_copy(sbyte* %ap2)
      -  call void %llvm.va_end(sbyte* %aq)
      +  %aq = alloca sbyte*
      +  call void %llvm.va_copy(sbyte** %aq, sbyte** %ap)
      +  call void %llvm.va_end(sbyte** %aq)
       
         ; Stop processing of arguments.
      -  call void %llvm.va_end(sbyte* %ap2)
      +  call void %llvm.va_end(sbyte** %ap)
         ret int %tmp
       }
       
      @@ -2386,19 +2951,25 @@ int %test(int %X, ...) {
      Syntax:
      -
        declare <va_list> %llvm.va_start()
      +
        declare void %llvm.va_start(<va_list>* <arglist>)
      Overview:
      -

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

      +

      The 'llvm.va_start' intrinsic initializes +*<arglist> for subsequent use by va_arg.

      + +
      Arguments:
      + +

      The argument is a pointer to a va_list element to initialize.

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

      The 'llvm.va_start' intrinsic works just like the va_start +macro available in C. In a target-dependent way, it initializes the +va_list element the argument points to, so that the next call to +va_arg 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.

      +
      @@ -2408,7 +2979,7 @@ within the body of a variable argument function.

      Syntax:
      -
        declare void %llvm.va_end(<va_list> <arglist>)
      +
        declare void %llvm.va_end(<va_list*> <arglist>)
      Overview:

      The 'llvm.va_end' intrinsic destroys <arglist> which has been initialized previously with llvm.va_start @@ -2433,24 +3004,27 @@ with calls to llvm.va_end.

      Syntax:
      -  declare <va_list> %llvm.va_copy(<va_list> <destarglist>)
      +  declare void %llvm.va_copy(<va_list>* <destarglist>,
      +                                          <va_list>* <srcarglist>)
       
      Overview:
      -

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

      +

      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.

      +

      The first argument is a pointer to a va_list element to initialize. +The second argument is a pointer to a va_list element to copy from.

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

      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 destination list. This intrinsic is necessary +because the llvm.va_begin intrinsic may be arbitrarily complex and require memory allocation, for example.

      @@ -2518,7 +3092,7 @@ the runtime to find the pointer at GC safe points.
      Syntax:
      -  declare sbyte* %llvm.gcread(sbyte** %Ptr)
      +  declare sbyte* %llvm.gcread(sbyte* %ObjPtr, sbyte** %Ptr)
       
      Overview:
      @@ -2529,8 +3103,10 @@ barriers.

      Arguments:
      -

      The argument is the address to read from, which should be an address -allocated from the garbage collector.

      +

      The second argument is the address to read from, which should be an address +allocated from the garbage collector. The first object is a pointer to the +start of the referenced object, if needed by the language runtime (otherwise +null).

      Semantics:
      @@ -2551,7 +3127,7 @@ garbage collector runtime, as needed.

      Syntax:
      -  declare void %llvm.gcwrite(sbyte* %P1, sbyte** %P2)
      +  declare void %llvm.gcwrite(sbyte* %P1, sbyte* %Obj, sbyte** %P2)
       
      Overview:
      @@ -2562,8 +3138,10 @@ barriers (such as generational or reference counting collectors).

      Arguments:
      -

      The first argument is the reference to store, and the second is the heap -location to store to.

      +

      The first argument is the reference to store, the second is the start of the +object to store it to, and the third is the address of the field of Obj to +store to. If the runtime does not require a pointer to the object, Obj may be +null.

      Semantics:
      @@ -2597,14 +3175,15 @@ be implemented with code generator support.
      Syntax:
      -  declare void* %llvm.returnaddress(uint <level>)
      +  declare sbyte *%llvm.returnaddress(uint <level>)
       
      Overview:

      -The 'llvm.returnaddress' intrinsic returns a target-specific value -indicating the return address of the current function or one of its callers. +The 'llvm.returnaddress' intrinsic attempts to compute a +target-specific value indicating the return address of the current function +or one of its callers.

      Arguments:
      @@ -2641,14 +3220,14 @@ source-language caller.
      Syntax:
      -  declare void* %llvm.frameaddress(uint <level>)
      +  declare sbyte *%llvm.frameaddress(uint <level>)
       
      Overview:

      -The 'llvm.frameaddress' intrinsic returns the target-specific frame -pointer value for the specified stack frame. +The 'llvm.frameaddress' intrinsic attempts to return the +target-specific frame pointer value for the specified stack frame.

      Arguments:
      @@ -2677,277 +3256,185 @@ source-language caller.
      Syntax:
      -  declare void %llvm.prefetch(sbyte * <address>,
      -                                uint <rw>, uint <locality>)
      +  declare sbyte *%llvm.stacksave()
       
      Overview:
      -

      -The 'llvm.prefetch' intrinsic is a hint to the code generator to insert -a prefetch instruction if supported, otherwise it is a noop. Prefetches have no -effect on the behavior of the program, but can change its performance -characteristics. -

      - -
      Arguments:
      - -

      -address is the address to be prefetched, rw is the specifier -determining if the fetch should be for a read (0) or write (1), and -locality is a temporal locality specifier ranging from (0) - no -locality, to (3) - extremely local keep in cache. The rw and -locality arguments must be constant integers. +The 'llvm.stacksave' intrinsic is used to remember the current state of +the function stack, for use with +llvm.stackrestore. This is useful for implementing language +features like scoped automatic variable sized arrays in C99.

      Semantics:

      -This intrinsic does not modify the behavior of the program. In particular, -prefetches cannot trap and do not produce a value. On targets that support this -intrinsic, the prefetch can provide hints to the processor cache for better -performance. +This intrinsic returns a opaque pointer value that can be passed to llvm.stackrestore. When an +llvm.stackrestore intrinsic is executed with a value saved from +llvm.stacksave, it effectively restores the state of the stack to the +state it was in when the llvm.stacksave intrinsic executed. In +practice, this pops any alloca blocks from the stack +that were allocated after the llvm.stacksave was executed.

      Syntax:
      -  declare void %llvm.pcmarker( uint <id> )
      +  declare void %llvm.stackrestore(sbyte* %ptr)
       
      Overview:
      -

      -The 'llvm.pcmarker' intrinsic is a method to export a PC in a region of -code to simulators and other tools. The method is target specific, but it is -expected that the marker will use exported symbols to transmit the PC of the marker. -The marker makes no guaranties that it will remain with any specific instruction -after optimizations. It is possible that the presense of a marker will inhibit -optimizations. The intended use is to be inserted after optmizations to allow -corrolations of simulation runs. -

      - -
      Arguments:
      - -

      -id is a numerical id identifying the marker. +The 'llvm.stackrestore' intrinsic is used to restore the state of +the function stack to the state it was in when the corresponding llvm.stacksave intrinsic executed. This is +useful for implementing language features like scoped automatic variable sized +arrays in C99.

      Semantics:

      -This intrinsic does not modify the behavior of the program. Backends that do not -support this intrinisic may ignore it. +See the description for llvm.stacksave.

      - - - -
      -

      -These intrinsics are provided by LLVM to support the implementation of -operating system level code. -

      - -
      -
      Syntax:
      -  declare <integer type> %llvm.readport (<integer type> <address>)
      +  declare void %llvm.prefetch(sbyte * <address>,
      +                                uint <rw>, uint <locality>)
       
      Overview:
      -

      -The 'llvm.readport' intrinsic reads data from the specified hardware -I/O port. -

      - -
      Arguments:
      - -

      -The argument to this intrinsic indicates the hardware I/O address from which -to read the data. The address is in the hardware I/O address namespace (as -opposed to being a memory location for memory mapped I/O). -

      - -
      Semantics:
      - -

      -The 'llvm.readport' intrinsic reads data from the hardware I/O port -specified by address and returns the value. The address and return -value must be integers, but the size is dependent upon the platform upon which -the program is code generated. For example, on x86, the address must be an -unsigned 16-bit value, and the return value must be 8, 16, or 32 bits. -

      - -
      - - - - -
      - -
      Syntax:
      -
      -  call void (<integer type>, <integer type>)*
      -            %llvm.writeport (<integer type> <value>,
      -                             <integer type> <address>)
      -
      - -
      Overview:

      -The 'llvm.writeport' intrinsic writes data to the specified hardware -I/O port. +The 'llvm.prefetch' intrinsic is a hint to the code generator to insert +a prefetch instruction if supported; otherwise, it is a noop. Prefetches have +no +effect on the behavior of the program but can change its performance +characteristics.

      Arguments:

      -The first argument is the value to write to the I/O port. -

      - -

      -The second argument indicates the hardware I/O address to which data should be -written. The address is in the hardware I/O address namespace (as opposed to -being a memory location for memory mapped I/O). +address is the address to be prefetched, rw is the specifier +determining if the fetch should be for a read (0) or write (1), and +locality is a temporal locality specifier ranging from (0) - no +locality, to (3) - extremely local keep in cache. The rw and +locality arguments must be constant integers.

      Semantics:

      -The 'llvm.writeport' intrinsic writes value to the I/O port -specified by address. The address and value must be integers, but the -size is dependent upon the platform upon which the program is code generated. -For example, on x86, the address must be an unsigned 16-bit value, and the -value written must be 8, 16, or 32 bits in length. +This intrinsic does not modify the behavior of the program. In particular, +prefetches cannot trap and do not produce a value. On targets that support this +intrinsic, the prefetch can provide hints to the processor cache for better +performance.

      Syntax:
      -  declare <result> %llvm.readio (<ty> * <pointer>)
      +  declare void %llvm.pcmarker( uint <id> )
       
      Overview:
      +

      -The 'llvm.readio' intrinsic reads data from a memory mapped I/O -address. +The 'llvm.pcmarker' intrinsic is a method to export a Program Counter +(PC) in a region of +code to simulators and other tools. The method is target specific, but it is +expected that the marker will use exported symbols to transmit the PC of the marker. +The marker makes no guarantees that it will remain with any specific instruction +after optimizations. It is possible that the presence of a marker will inhibit +optimizations. The intended use is to be inserted after optimizations to allow +correlations of simulation runs.

      Arguments:

      -The argument to this intrinsic is a pointer indicating the memory address from -which to read the data. The data must be a -first class type. +id is a numerical id identifying the marker.

      Semantics:

      -The 'llvm.readio' intrinsic reads data from a memory mapped I/O -location specified by pointer and returns the value. The argument must -be a pointer, and the return value must be a -first class type. However, certain architectures -may not support I/O on all first class types. For example, 32-bit processors -may only support I/O on data types that are 32 bits or less. -

      - -

      -This intrinsic enforces an in-order memory model for llvm.readio and -llvm.writeio calls on machines that use dynamic scheduling. Dynamically -scheduled processors may execute loads and stores out of order, re-ordering at -run time accesses to memory mapped I/O registers. Using these intrinsics -ensures that accesses to memory mapped I/O registers occur in program order. +This intrinsic does not modify the behavior of the program. Backends that do not +support this intrinisic may ignore it.

      Syntax:
      -  declare void %llvm.writeio (<ty1> <value>, <ty2> * <pointer>)
      +  declare ulong %llvm.readcyclecounter( )
       
      Overview:
      -

      -The 'llvm.writeio' intrinsic writes data to the specified memory -mapped I/O address. -

      - -
      Arguments:

      -The first argument is the value to write to the memory mapped I/O location. -The second argument is a pointer indicating the memory address to which the -data should be written. +The 'llvm.readcyclecounter' intrinsic provides access to the cycle +counter register (or similar low latency, high accuracy clocks) on those targets +that support it. On X86, it should map to RDTSC. On Alpha, it should map to RPCC. +As the backing counters overflow quickly (on the order of 9 seconds on alpha), this +should only be used for small timings.

      Semantics:

      -The 'llvm.writeio' intrinsic writes value to the memory mapped -I/O address specified by pointer. The value must be a -first class type. However, certain architectures -may not support I/O on all first class types. For example, 32-bit processors -may only support I/O on data types that are 32 bits or less. -

      - -

      -This intrinsic enforces an in-order memory model for llvm.readio and -llvm.writeio calls on machines that use dynamic scheduling. Dynamically -scheduled processors may execute loads and stores out of order, re-ordering at -run time accesses to memory mapped I/O registers. Using these intrinsics -ensures that accesses to memory mapped I/O registers occur in program order. +When directly supported, reading the cycle counter should not modify any memory. +Implementations are allowed to either return a application specific value or a +system wide value. On backends without support, this is lowered to a constant 0.

      @@ -2976,41 +3463,43 @@ for more efficient code generation.
      Syntax:
      -  declare void %llvm.memcpy(sbyte* <dest>, sbyte* <src>,
      -                            uint <len>, uint <align>)
      +  declare void %llvm.memcpy.i32(sbyte* <dest>, sbyte* <src>,
      +                                uint <len>, uint <align>)
      +  declare void %llvm.memcpy.i64(sbyte* <dest>, sbyte* <src>,
      +                                ulong <len>, uint <align>)
       
      Overview:

      -The 'llvm.memcpy' intrinsic copies a block of memory from the source +The 'llvm.memcpy.*' intrinsics copy a block of memory from the source location to the destination location.

      -Note that, unlike the standard libc function, the llvm.memcpy intrinsic -does not return a value, and takes an extra alignment argument. +Note that, unlike the standard libc function, the llvm.memcpy.* +intrinsics do not return a value, and takes an extra alignment argument.

      Arguments:

      The first argument is a pointer to the destination, the second is a pointer to -the source. The third argument is an (arbitrarily sized) integer argument +the source. The third argument is an integer argument specifying the number of bytes to copy, and the fourth argument is the alignment of the source and destination locations.

      If the call to this intrinisic has an alignment value that is not 0 or 1, then -the caller guarantees that the size of the copy is a multiple of the alignment -and that both the source and destination pointers are aligned to that boundary. +the caller guarantees that both the source and destination pointers are aligned +to that boundary.

      Semantics:

      -The 'llvm.memcpy' intrinsic copies a block of memory from the source +The 'llvm.memcpy.*' intrinsics copy a block of memory from the source location to the destination location, which are not allowed to overlap. It copies "len" bytes of memory over. If the argument is known to be aligned to some boundary, this can be specified as the fourth argument, otherwise it should @@ -3028,42 +3517,44 @@ be set to 0 or 1.

      Syntax:
      -  declare void %llvm.memmove(sbyte* <dest>, sbyte* <src>,
      -                             uint <len>, uint <align>)
      +  declare void %llvm.memmove.i32(sbyte* <dest>, sbyte* <src>,
      +                                 uint <len>, uint <align>)
      +  declare void %llvm.memmove.i64(sbyte* <dest>, sbyte* <src>,
      +                                 ulong <len>, uint <align>)
       
      Overview:

      -The 'llvm.memmove' intrinsic moves a block of memory from the source -location to the destination location. It is similar to the 'llvm.memcpy' -intrinsic but allows the two memory locations to overlap. +The 'llvm.memmove.*' intrinsics move a block of memory from the source +location to the destination location. It is similar to the +'llvm.memcmp' intrinsic but allows the two memory locations to overlap.

      -Note that, unlike the standard libc function, the llvm.memmove intrinsic -does not return a value, and takes an extra alignment argument. +Note that, unlike the standard libc function, the llvm.memmove.* +intrinsics do not return a value, and takes an extra alignment argument.

      Arguments:

      The first argument is a pointer to the destination, the second is a pointer to -the source. The third argument is an (arbitrarily sized) integer argument +the source. The third argument is an integer argument specifying the number of bytes to copy, and the fourth argument is the alignment of the source and destination locations.

      If the call to this intrinisic has an alignment value that is not 0 or 1, then -the caller guarantees that the size of the copy is a multiple of the alignment -and that both the source and destination pointers are aligned to that boundary. +the caller guarantees that the source and destination pointers are aligned to +that boundary.

      Semantics:

      -The 'llvm.memmove' intrinsic copies a block of memory from the source +The 'llvm.memmove.*' intrinsics copy a block of memory from the source location to the destination location, which may overlap. It copies "len" bytes of memory over. If the argument is known to be aligned to some boundary, this can be specified as the fourth argument, otherwise it should @@ -3074,21 +3565,23 @@ be set to 0 or 1.

      Syntax:
      -  declare void %llvm.memset(sbyte* <dest>, ubyte <val>,
      -                            uint <len>, uint <align>)
      +  declare void %llvm.memset.i32(sbyte* <dest>, ubyte <val>,
      +                                uint <len>, uint <align>)
      +  declare void %llvm.memset.i64(sbyte* <dest>, ubyte <val>,
      +                                ulong <len>, uint <align>)
       
      Overview:

      -The 'llvm.memset' intrinsic fills a block of memory with a particular +The 'llvm.memset.*' intrinsics fill a block of memory with a particular byte value.

      @@ -3101,21 +3594,21 @@ does not return a value, and takes an extra alignment argument.

      The first argument is a pointer to the destination to fill, the second is the -byte value to fill it with, the third argument is an (arbitrarily sized) integer +byte value to fill it with, the third argument is an integer argument specifying the number of bytes to fill, and the fourth argument is the known alignment of destination location.

      If the call to this intrinisic has an alignment value that is not 0 or 1, then -the caller guarantees that the size of the copy is a multiple of the alignment -and that the destination pointer is aligned to that boundary. +the caller guarantees that the destination pointer is aligned to that boundary.

      Semantics:

      -The 'llvm.memset' intrinsic fills "len" bytes of memory starting at the +The 'llvm.memset.*' intrinsics fill "len" bytes of memory starting at +the destination location. If the argument is known to be aligned to some boundary, this can be specified as the fourth argument, otherwise it should be set to 0 or 1. @@ -3125,20 +3618,21 @@ this can be specified as the fourth argument, otherwise it should be set to 0 or

      Syntax:
      -  declare bool %llvm.isunordered(<float or double> Val1, <float or double> Val2)
      +  declare bool %llvm.isunordered.f32(float Val1, float  Val2)
      +  declare bool %llvm.isunordered.f64(double Val1, double Val2)
       
      Overview:

      -The 'llvm.isunordered' intrinsic returns true if either or both of the +The 'llvm.isunordered' intrinsics return true if either or both of the specified floating point values is a NAN.

      @@ -3157,14 +3651,86 @@ false.
      + + + +
      + +
      Syntax:
      +
      +  declare float %llvm.sqrt.f32(float %Val)
      +  declare double %llvm.sqrt.f64(double %Val)
      +
      + +
      Overview:
      + +

      +The 'llvm.sqrt' intrinsics return the sqrt of the specified operand, +returning the same value as the libm 'sqrt' function would. Unlike +sqrt in libm, however, llvm.sqrt has undefined behavior for +negative numbers (which allows for better optimization). +

      + +
      Arguments:
      + +

      +The argument and return value are floating point numbers of the same type. +

      + +
      Semantics:
      + +

      +This function returns the sqrt of the specified operand if it is a positive +floating point number. +

      +
      + + + + +
      + +
      Syntax:
      +
      +  declare float  %llvm.powi.f32(float  %Val, int %power)
      +  declare double %llvm.powi.f64(double %Val, int %power)
      +
      + +
      Overview:
      + +

      +The 'llvm.powi.*' intrinsics return the first operand raised to the +specified (positive or negative) power. The order of evaluation of +multiplications is not defined. +

      + +
      Arguments:
      + +

      +The second argument is an integer power, and the first is a value to raise to +that power. +

      + +
      Semantics:
      + +

      +This function returns the first value raised to the second power with an +unspecified sequence of rounding operations.

      +
      + +

      -LLVM provides intrinsics for a few important bit counting operations. +LLVM provides intrinsics for a few important bit manipulation operations. These allow efficient code generation for some algorithms.

      @@ -3172,28 +3738,66 @@ These allow efficient code generation for some algorithms.
      Syntax:
      -  declare int %llvm.ctpop(int <src>)
      +  declare ushort %llvm.bswap.i16(ushort <id>)
      +  declare uint   %llvm.bswap.i32(uint <id>)
      +  declare ulong  %llvm.bswap.i64(ulong <id>)
      +
      + +
      Overview:
      + +

      +The 'llvm.bwsap' family of intrinsics is used to byteswap a 16, 32 or +64 bit quantity. These are useful for performing operations on data that is not +in the target's native byte order. +

      + +
      Semantics:
      + +

      +The llvm.bswap.16 intrinsic returns a ushort value that has the high and low +byte of the input ushort swapped. Similarly, the llvm.bswap.i32 intrinsic +returns a uint value that has the four bytes of the input uint swapped, so that +if the input bytes are numbered 0, 1, 2, 3 then the returned uint will have its +bytes in 3, 2, 1, 0 order. The llvm.bswap.i64 intrinsic extends this concept +to 64 bits. +

      + +
      + + + + +
      +
      Syntax:
      +
      +  declare ubyte  %llvm.ctpop.i8 (ubyte <src>)
      +  declare ushort %llvm.ctpop.i16(ushort <src>)
      +  declare uint   %llvm.ctpop.i32(uint <src>)
      +  declare ulong  %llvm.ctpop.i64(ulong <src>)
       
      Overview:

      -The 'llvm.ctpop' intrinsic counts the number of ones in a variable. +The 'llvm.ctpop' family of intrinsics counts the number of bits set in a +value.

      Arguments:

      The only argument is the value to be counted. The argument may be of any -integer type. The return type must match the argument type. +unsigned integer type. The return type must match the argument type.

      Semantics:
      @@ -3205,74 +3809,82 @@ The 'llvm.ctpop' intrinsic counts the 1's in a variable.
      Syntax:
      -  declare int %llvm.cttz(int <src>)
      -
      +  declare ubyte  %llvm.ctlz.i8 (ubyte <src>)
      +  declare ushort %llvm.ctlz.i16(ushort <src>)
      +  declare uint   %llvm.ctlz.i32(uint <src>)
      +  declare ulong  %llvm.ctlz.i64(ulong <src>)
       
      Overview:

      -The 'llvm.cttz' intrinsic counts the number of trailing zeros. +The 'llvm.ctlz' family of intrinsic functions counts the number of +leading zeros in a variable.

      Arguments:

      The only argument is the value to be counted. The argument may be of any -integer type. The return type must match the argument type. +unsigned integer type. The return type must match the argument type.

      Semantics:

      -The 'llvm.cttz' intrinsic counts the trailing zeros in a variable. If -the src == 0 then the result is the size in bits of the type of src. +The 'llvm.ctlz' intrinsic counts the leading (most significant) zeros +in a variable. If the src == 0 then the result is the size in bits of the type +of src. For example, llvm.ctlz(int 2) = 30.

      + +
      Syntax:
      -  declare int %llvm.ctlz(int <src>)
      -
      +  declare ubyte  %llvm.cttz.i8 (ubyte <src>)
      +  declare ushort %llvm.cttz.i16(ushort <src>)
      +  declare uint   %llvm.cttz.i32(uint <src>)
      +  declare ulong  %llvm.cttz.i64(ulong <src>)
       
      Overview:

      -The 'llvm.ctlz' intrinsic counts the number of leading zeros in a -variable. +The 'llvm.cttz' family of intrinsic functions counts the number of +trailing zeros.

      Arguments:

      The only argument is the value to be counted. The argument may be of any -integer type. The return type must match the argument type. +unsigned integer type. The return type must match the argument type.

      Semantics:

      -The 'llvm.ctlz' intrinsic counts the leading zeros in a variable. If -the src == 0 then the result is the size in bits of the type of src. +The 'llvm.cttz' intrinsic counts the trailing (least significant) zeros +in a variable. If the src == 0 then the result is the size in bits of the type +of src. For example, llvm.cttz(2) = 1.

      -
      Debugger Intrinsics @@ -3297,7 +3909,7 @@ Debugging document. src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /> Chris Lattner
      - The LLVM Compiler Infrastructure
      + The LLVM Compiler Infrastructure
      Last modified: $Date$