X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=docs%2FLangRef.html;h=5d3c7458c2d85d7ad1bafa8bd26d12a7c518afa3;hb=3bf15ced2b91661ac314911c1f28332da0e1c37c;hp=ec751504dab6a7c3007836e846e088a77e64732b;hpb=fbff0ec2c7ffcaebd2ab4029c6684d977f553065;p=oota-llvm.git diff --git a/docs/LangRef.html b/docs/LangRef.html index ec751504dab..5d3c7458c2d 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -35,7 +35,7 @@
  • 'extern_weak' Linkage
  • 'linkonce_odr' Linkage
  • 'weak_odr' Linkage
  • -
  • 'externally visible' Linkage
  • +
  • 'external' Linkage
  • 'dllimport' Linkage
  • 'dllexport' Linkage
  • @@ -54,6 +54,7 @@
  • Pointer Aliasing Rules
  • Volatile Memory Accesses
  • Memory Model for Concurrent Operations
  • +
  • Atomic Memory Ordering Constraints
  • Type System @@ -91,7 +92,7 @@
  • Complex Constants
  • Global Variable and Function Addresses
  • Undefined Values
  • -
  • Trap Values
  • +
  • Poison Values
  • Addresses of Basic Blocks
  • Constant Expressions
  • @@ -99,7 +100,17 @@
  • Other Values
    1. Inline Assembler Expressions
    2. -
    3. Metadata Nodes and Metadata Strings
    4. +
    5. Metadata Nodes and Metadata Strings +
        +
      1. 'tbaa' Metadata
      2. +
      3. 'fpaccuracy' Metadata
      4. +
      +
    6. +
    +
  • +
  • Module Flags Metadata +
      +
    1. Objective-C Garbage Collection Module Flags Metadata
  • Intrinsic Global Variables @@ -122,7 +133,7 @@
  • 'switch' Instruction
  • 'indirectbr' Instruction
  • 'invoke' Instruction
  • -
  • 'unwind' Instruction
  • +
  • 'resume' Instruction
  • 'unreachable' Instruction
  • @@ -167,9 +178,12 @@
  • Memory Access and Addressing Operations
      -
    1. 'alloca' Instruction
    2. -
    3. 'load' Instruction
    4. -
    5. 'store' Instruction
    6. +
    7. 'alloca' Instruction
    8. +
    9. 'load' Instruction
    10. +
    11. 'store' Instruction
    12. +
    13. 'fence' Instruction
    14. +
    15. 'cmpxchg' Instruction
    16. +
    17. 'atomicrmw' Instruction
    18. 'getelementptr' Instruction
  • @@ -197,6 +211,7 @@
  • 'select' Instruction
  • 'call' Instruction
  • 'va_arg' Instruction
  • +
  • 'landingpad' Instruction
  • @@ -269,34 +284,18 @@
  • Debugger intrinsics
  • Exception Handling intrinsics
  • -
  • Trampoline Intrinsic +
  • Trampoline Intrinsics
    1. 'llvm.init.trampoline' Intrinsic
    2. -
    -
  • -
  • Atomic intrinsics -
      -
    1. llvm.memory_barrier
    2. -
    3. llvm.atomic.cmp.swap
    4. -
    5. llvm.atomic.swap
    6. -
    7. llvm.atomic.load.add
    8. -
    9. llvm.atomic.load.sub
    10. -
    11. llvm.atomic.load.and
    12. -
    13. llvm.atomic.load.nand
    14. -
    15. llvm.atomic.load.or
    16. -
    17. llvm.atomic.load.xor
    18. -
    19. llvm.atomic.load.max
    20. -
    21. llvm.atomic.load.min
    22. -
    23. llvm.atomic.load.umax
    24. -
    25. llvm.atomic.load.umin
    26. +
    27. 'llvm.adjust.trampoline' Intrinsic
  • Memory Use Markers
      -
    1. llvm.lifetime.start
    2. -
    3. llvm.lifetime.end
    4. -
    5. llvm.invariant.start
    6. -
    7. llvm.invariant.end
    8. +
    9. 'llvm.lifetime.start' Intrinsic
    10. +
    11. 'llvm.lifetime.end' Intrinsic
    12. +
    13. 'llvm.invariant.start' Intrinsic
    14. +
    15. 'llvm.invariant.end' Intrinsic
  • General intrinsics @@ -311,6 +310,8 @@ 'llvm.stackprotector' Intrinsic
  • 'llvm.objectsize' Intrinsic
  • +
  • + 'llvm.expect' Intrinsic
  • @@ -640,7 +641,7 @@ define i32 @main() { ; i32()*   be merged with equivalent globals. These linkage types are otherwise the same as their non-odr versions. -
    externally visible:
    +
    external
    If none of the above identifiers are used, the global is externally visible, meaning that it participates in linkage and can be used to resolve external symbol references.
    @@ -673,8 +674,8 @@ define i32 @main() { ; i32()*   declarations), they are accessible outside of the current module.

    It is illegal for a function declaration to have any linkage type - other than "externally visible", dllimport - or extern_weak.

    + other than external, dllimport + or extern_weak.

    Aliases can have only external, internal, weak or weak_odr linkages.

    @@ -937,7 +938,7 @@ define i32 @main() { ; i32()*   alignments must be a power of 2.

    If the unnamed_addr attribute is given, the address is know to not - be significant and two identical functions can be merged

    . + be significant and two identical functions can be merged.

    Syntax:
    @@ -1146,6 +1147,10 @@ define void @f() optsize { ... }
     
    +
    address_safety
    +
    This attribute indicates that the address safety analysis + is enabled for this function.
    +
    alignstack(<n>)
    This attribute indicates that, when emitting the prologue and epilogue, the backend should forcibly align the stack pointer. Specify the @@ -1156,14 +1161,6 @@ define void @f() optsize { ... } function into callers whenever possible, ignoring any active inlining size threshold for this caller.
    -
    hotpatch
    -
    This attribute indicates that the function should be 'hotpatchable', - meaning the function can be patched and/or hooked even while it is - loaded into memory. On x86, the function prologue will be preceded - by six bytes of padding and will begin with a two-byte instruction. - Most of the functions in the Windows system DLLs in Windows XP SP2 or - higher were compiled in this fashion.
    -
    nonlazybind
    This attribute suppresses lazy symbol binding for the function. This may make calls to the function faster, at the cost of extra program @@ -1213,8 +1210,7 @@ define void @f() optsize { ... } It does not write through any pointer arguments (including byval arguments) and never changes any state visible to callers. This means that it cannot unwind - exceptions by calling the C++ exception throwing methods, but - could use the unwind instruction.
    + exceptions by calling the C++ exception throwing methods.
    readonly
    This attribute indicates that the function does not write through any @@ -1224,8 +1220,13 @@ define void @f() optsize { ... } and read state that may be set in the caller. A readonly function always returns the same value (or unwinds an exception identically) when called with the same set of arguments and global state. It cannot unwind an - exception by calling the C++ exception throwing methods, but may - use the unwind instruction.
    + exception by calling the C++ exception throwing methods. + +
    returns_twice
    +
    This attribute indicates that this function can return twice. The + C setjmp is an example of such a function. The compiler + disables some optimizations (like tail calls) in the caller of these + functions.
    ssp
    This attribute indicates that the function should emit a stack smashing @@ -1254,7 +1255,6 @@ define void @f() optsize { ... } show that no exceptions passes by it. This is normally the case for the ELF x86-64 abi, but it can be disabled for some compilation units.
    -
    @@ -1315,6 +1315,13 @@ target datalayout = "layout specification" the bits with the least significance have the lowest address location. +
    Ssize
    +
    Specifies the natural alignment of the stack in bits. Alignment promotion + of stack variables is limited to the natural stack alignment to avoid + dynamic stack realignment. The stack alignment must be a multiple of + 8-bits. If omitted, the natural stack alignment defaults to "unspecified", + which does not prevent any alignment promotions.
    +
    p:size:abi:pref
    This specifies the size of a pointer and its abi and preferred alignments. All sizes are in bits. Specifying @@ -1395,6 +1402,22 @@ target datalayout = "layout specification" implemented in terms of 64 <2 x double>, for example. +

    The function of the data layout string may not be what you expect. Notably, + this is not a specification from the frontend of what alignment the code + generator should use.

    + +

    Instead, if specified, the target data layout is required to match what the + ultimate code generator expects. This string is used by the + mid-level optimizers to + improve code, and this only works if it matches what the ultimate code + generator uses. If you would like to generate IR that does not embed this + target-specific detail into the IR, then you don't have to specify the + string. This will disable some optimizations that require precise layout + information, but this also prevents those optimizations from introducing + target specificity into the IR.

    + + + @@ -1491,6 +1514,9 @@ or to register signal handlers. Nonetheless, there are platform-specific ways to create them, and we define LLVM IR's behavior in their presence. This model is inspired by the C++0x memory model.

    +

    For a more informal introduction to this model, see the +LLVM Atomic Instructions and Concurrency Guide. +

    We define a happens-before partial order as the least partial order that

    Note that program order does not introduce happens-before edges @@ -1519,14 +1546,19 @@ any write to the same byte, except:

    write2, and write2 happens before Rbyte, then Rbyte does not see write1. -
  • If Rbyte happens before write3, - then Rbyte does not see - write3. +
  • If Rbyte happens before + write3, then Rbyte does not + see write3.

    Given that definition, Rbyte is defined as follows:

    @@ -1548,10 +1581,10 @@ emit more than one instruction to read the series of bytes.

    Note that in cases where none of the atomic intrinsics are used, this model places only one restriction on IR transformations on top of what is required for single-threaded execution: introducing a store to a byte which might not -otherwise be stored to can introduce undefined behavior. (Specifically, in -the case where another thread might write to and read from an address, -introducing a store can change a load that may see exactly one write into -a load that may see multiple writes.)

    +otherwise be stored is not allowed in general. (Specifically, in the case +where another thread might write to and read from an address, introducing a +store can change a load that may see exactly one write into a load that may +see multiple writes.)

    +

    + Atomic Memory Ordering Constraints +

    + +
    + +

    Atomic instructions (cmpxchg, +atomicrmw, +fence, +atomic load, and +atomic store) take an ordering parameter +that determines which other atomic instructions on the same address they +synchronize with. These semantics are borrowed from Java and C++0x, +but are somewhat more colloquial. If these descriptions aren't precise enough, +check those specs (see spec references in the +atomics guide). +fence instructions +treat these orderings somewhat differently since they don't take an address. +See that instruction's documentation for details.

    + +

    For a simpler introduction to the ordering constraints, see the +LLVM Atomic Instructions and Concurrency Guide.

    + +
    +
    unordered
    +
    The set of values that can be read is governed by the happens-before +partial order. A value cannot be read unless some operation wrote it. +This is intended to provide a guarantee strong enough to model Java's +non-volatile shared variables. This ordering cannot be specified for +read-modify-write operations; it is not strong enough to make them atomic +in any interesting way.
    +
    monotonic
    +
    In addition to the guarantees of unordered, there is a single +total order for modifications by monotonic operations on each +address. All modification orders must be compatible with the happens-before +order. There is no guarantee that the modification orders can be combined to +a global total order for the whole program (and this often will not be +possible). The read in an atomic read-modify-write operation +(cmpxchg and +atomicrmw) +reads the value in the modification order immediately before the value it +writes. If one atomic read happens before another atomic read of the same +address, the later read must see the same value or a later value in the +address's modification order. This disallows reordering of +monotonic (or stronger) operations on the same address. If an +address is written monotonically by one thread, and other threads +monotonically read that address repeatedly, the other threads must +eventually see the write. This corresponds to the C++0x/C1x +memory_order_relaxed.
    +
    acquire
    +
    In addition to the guarantees of monotonic, +a synchronizes-with edge may be formed with a release +operation. This is intended to model C++'s memory_order_acquire.
    +
    release
    +
    In addition to the guarantees of monotonic, if this operation +writes a value which is subsequently read by an acquire operation, +it synchronizes-with that operation. (This isn't a complete +description; see the C++0x definition of a release sequence.) This corresponds +to the C++0x/C1x memory_order_release.
    +
    acq_rel (acquire+release)
    Acts as both an +acquire and release operation on its address. +This corresponds to the C++0x/C1x memory_order_acq_rel.
    +
    seq_cst (sequentially consistent)
    +
    In addition to the guarantees of acq_rel +(acquire for an operation which only reads, release +for an operation which only writes), there is a global total order on all +sequentially-consistent operations on all addresses, which is consistent with +the happens-before partial order and with the modification orders of +all the affected addresses. Each sequentially-consistent read sees the last +preceding write to the same address in this global order. This corresponds +to the C++0x/C1x memory_order_seq_cst and Java volatile.
    +
    + +

    If an atomic operation is marked singlethread, +it only synchronizes with or participates in modification and seq_cst +total orderings with other operations running in the same thread (for example, +in signal handlers).

    + +
    + @@ -1601,7 +1715,7 @@ as if it writes to the relevant surrounding bytes. floating point - float, double, x86_fp80, fp128, ppc_fp128 + half, float, double, x86_fp80, fp128, ppc_fp128 first class @@ -1701,6 +1815,7 @@ as if it writes to the relevant surrounding bytes. + @@ -1797,9 +1912,6 @@ as if it writes to the relevant surrounding bytes. possible to have a two dimensional array, using an array as the element type of another array.

    - - -

    Aggregate Types @@ -1808,9 +1920,9 @@ as if it writes to the relevant surrounding bytes.

    Aggregate Types are a subset of derived types that can contain multiple - member types. Arrays, - structs, and vectors are - aggregate types.

    + member types. Arrays and + structs are aggregate types. + Vectors are not considered to be aggregate types.

    @@ -1949,20 +2061,22 @@ as if it writes to the relevant surrounding bytes.

    Structures may optionally be "packed" structures, which indicate that the alignment of the struct is one byte, and that there is no padding between - the elements. In non-packed structs, padding between field types is defined - by the target data string to match the underlying processor.

    - -

    Structures can either be "anonymous" or "named". An anonymous structure is - defined inline with other types (e.g. {i32, i32}*) and a named types - are always defined at the top level with a name. Anonmyous types are uniqued - by their contents and can never be recursive since there is no way to write - one. Named types can be recursive. + the elements. In non-packed structs, padding between field types is inserted + as defined by the TargetData string in the module, which is required to match + what the underlying code generator expects.

    + +

    Structures can either be "literal" or "identified". A literal structure is + defined inline with other types (e.g. {i32, i32}*) whereas identified + types are always defined at the top level with a name. Literal types are + uniqued by their contents and can never be recursive or opaque since there is + no way to write one. Identified types can be recursive, can be opaqued, and are + never uniqued.

    Syntax:
    -  %T1 = type { <type list> }     ; Named normal struct type
    -  %T2 = type <{ <type list> }>   ; Named packed struct type
    +  %T1 = type { <type list> }     ; Identified normal struct type
    +  %T2 = type <{ <type list> }>   ; Identified packed struct type
     
    Examples:
    @@ -2082,8 +2196,8 @@ as if it writes to the relevant surrounding bytes.

    The number of elements is a constant integer value larger than 0; elementtype - may be any integer or floating point type. Vectors of size zero are not - allowed, and pointers are not allowed as the element type.

    + may be any integer or floating point type, or a pointer to these types. + Vectors of size zero are not allowed.

    Examples:
    TypeDescription
    half16-bit floating point value
    float32-bit floating point value
    double64-bit floating point value
    fp128128-bit floating point value (112-bit mantissa)
    @@ -2099,10 +2213,18 @@ as if it writes to the relevant surrounding bytes. + + + +
    <2 x i64> Vector of 2 64-bit integer values.
    <4 x i64*>Vector of 4 pointers to 64-bit integer values.
    + + + +

    Constants

    @@ -2153,10 +2275,11 @@ as if it writes to the relevant surrounding bytes. represented in their IEEE hexadecimal format so that assembly and disassembly do not cause any bits to change in the constants.

    -

    When using the hexadecimal form, constants of types float and double are +

    When using the hexadecimal form, constants of types half, float, and double are represented using the 16-digit form shown above (which matches the IEEE754 - representation for double); float values must, however, be exactly - representable as IEE754 single precision. Hexadecimal format is always used + representation for double); half and float values must, however, be exactly + representable as IEE754 half and single precision, respectively. + Hexadecimal format is always used for long double, and there are three forms of long double. The 80-bit format used by x86 is represented as 0xK followed by 20 hexadecimal digits. The 128-bit format used by PowerPC (two adjacent doubles) is represented @@ -2391,22 +2514,21 @@ b: unreachable

    - Trap Values + Poison Values

    -

    Trap values are similar to undef values, however - instead of representing an unspecified bit pattern, they represent the - fact that an instruction or constant expression which cannot evoke side - effects has nevertheless detected a condition which results in undefined - behavior.

    +

    Poison values are similar to undef values, however + they also represent the fact that an instruction or constant expression which + cannot evoke side effects has nevertheless detected a condition which results + in undefined behavior.

    -

    There is currently no way of representing a trap value in the IR; they +

    There is currently no way of representing a poison value in the IR; they only exist when produced by operations such as add with the nsw flag.

    -

    Trap value behavior is defined in terms of value dependence:

    +

    Poison value behavior is defined in terms of value dependence:

    • Values other than phi nodes depend on @@ -2423,7 +2545,7 @@ b: unreachable control back to them.
    • Invoke instructions depend on the - ret, unwind, + ret, resume, or exception-throwing call instructions that dynamically transfer control back to them.
    • @@ -2457,62 +2579,61 @@ b: unreachable
    -

    Whenever a trap value is generated, all values which depend on it evaluate - to trap. If they have side effects, the evoke their side effects as if each - operand with a trap value were undef. If they have externally-visible side - effects, the behavior is undefined.

    +

    Poison Values have the same behavior as undef values, + with the additional affect that any instruction which has a dependence + on a poison value has undefined behavior.

    Here are some examples:

     entry:
    -  %trap = sub nuw i32 0, 1           ; Results in a trap value.
    -  %still_trap = and i32 %trap, 0     ; Whereas (and i32 undef, 0) would return 0.
    -  %trap_yet_again = getelementptr i32* @h, i32 %still_trap
    -  store i32 0, i32* %trap_yet_again  ; undefined behavior
    +  %poison = sub nuw i32 0, 1           ; Results in a poison value.
    +  %still_poison = and i32 %poison, 0   ; 0, but also poison.
    +  %poison_yet_again = getelementptr i32* @h, i32 %still_poison
    +  store i32 0, i32* %poison_yet_again  ; memory at @h[0] is poisoned
     
    -  store i32 %trap, i32* @g           ; Trap value conceptually stored to memory.
    -  %trap2 = load i32* @g              ; Returns a trap value, not just undef.
    +  store i32 %poison, i32* @g           ; Poison value stored to memory.
    +  %poison2 = load i32* @g              ; Poison value loaded back from memory.
     
    -  volatile store i32 %trap, i32* @g  ; External observation; undefined behavior.
    +  store volatile i32 %poison, i32* @g  ; External observation; undefined behavior.
     
       %narrowaddr = bitcast i32* @g to i16*
       %wideaddr = bitcast i32* @g to i64*
    -  %trap3 = load i16* %narrowaddr     ; Returns a trap value.
    -  %trap4 = load i64* %wideaddr       ; Returns a trap value.
    +  %poison3 = load i16* %narrowaddr     ; Returns a poison value.
    +  %poison4 = load i64* %wideaddr       ; Returns a poison value.
     
    -  %cmp = icmp slt i32 %trap, 0       ; Returns a trap value.
    -  br i1 %cmp, label %true, label %end ; Branch to either destination.
    +  %cmp = icmp slt i32 %poison, 0       ; Returns a poison value.
    +  br i1 %cmp, label %true, label %end  ; Branch to either destination.
     
     true:
    -  volatile store i32 0, i32* @g      ; This is control-dependent on %cmp, so
    -                                     ; it has undefined behavior.
    +  store volatile i32 0, i32* @g        ; This is control-dependent on %cmp, so
    +                                       ; it has undefined behavior.
       br label %end
     
     end:
       %p = phi i32 [ 0, %entry ], [ 1, %true ]
    -                                     ; Both edges into this PHI are
    -                                     ; control-dependent on %cmp, so this
    -                                     ; always results in a trap value.
    +                                       ; Both edges into this PHI are
    +                                       ; control-dependent on %cmp, so this
    +                                       ; always results in a poison value.
     
    -  volatile store i32 0, i32* @g      ; This would depend on the store in %true
    -                                     ; if %cmp is true, or the store in %entry
    -                                     ; otherwise, so this is undefined behavior.
    +  store volatile i32 0, i32* @g        ; This would depend on the store in %true
    +                                       ; if %cmp is true, or the store in %entry
    +                                       ; otherwise, so this is undefined behavior.
     
       br i1 %cmp, label %second_true, label %second_end
    -                                     ; The same branch again, but this time the
    -                                     ; true block doesn't have side effects.
    +                                       ; The same branch again, but this time the
    +                                       ; true block doesn't have side effects.
     
     second_true:
       ; No side effects!
       ret void
     
     second_end:
    -  volatile store i32 0, i32* @g      ; This time, the instruction always depends
    -                                     ; on the store in %end. Also, it is
    -                                     ; control-equivalent to %end, so this is
    -                                     ; well-defined (again, ignoring earlier
    -                                     ; undefined behavior in this example).
    +  store volatile i32 0, i32* @g        ; This time, the instruction always depends
    +                                       ; on the store in %end. Also, it is
    +                                       ; control-equivalent to %end, so this is
    +                                       ; well-defined (ignoring earlier undefined
    +                                       ; behavior in this example).
     
    @@ -2691,7 +2812,7 @@ second_end:

    LLVM supports inline assembler expressions (as opposed - to Module-Level Inline Assembly) through the use of + 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), a flag that indicates whether or not the inline asm @@ -2733,23 +2854,27 @@ call void asm alignstack "eieio", ""()

    If both keywords appear the 'sideeffect' keyword must come first.

    + +

    -Inline Asm Metadata + Inline Asm Metadata

    -

    The call instructions that wrap inline asm nodes may have a "!srcloc" MDNode - attached to it that contains a list of constant integers. If present, the - code generator will use the integer as the location cookie value when report - errors through the LLVMContext error reporting mechanisms. This allows a - front-end to correlate backend errors that occur with inline asm back to the - source code that produced it. For example:

    +

    The call instructions that wrap inline asm nodes may have a + "!srcloc" MDNode attached to it that contains a list of constant + integers. If present, the code generator will use the integer as the + location cookie value when report errors through the LLVMContext + error reporting mechanisms. This allows a front-end to correlate backend + errors that occur with inline asm back to the source code that produced it. + For example:

     call void asm sideeffect "something bad", ""(), !srcloc !42
    @@ -2758,7 +2883,7 @@ call void asm sideeffect "something bad", ""(), !srcloc !42
     

    It is up to the front-end to make sense of the magic numbers it places in the - IR. If the MDNode contains multiple constants, the code generator will use + IR. If the MDNode contains multiple constants, the code generator will use the one that corresponds to the line of the asm that the error occurs on.

    @@ -2780,20 +2905,33 @@ call void asm sideeffect "something bad", ""(), !srcloc !42 preceding exclamation point ('!').

    A metadata string is a string surrounded by double quotes. It can contain - any character by escaping non-printable characters with "\xx" where "xx" is - the two digit hex code. For example: "!"test\00"".

    + any character by escaping non-printable characters with "\xx" where + "xx" is the two digit hex code. For example: + "!"test\00"".

    Metadata nodes are represented with notation similar to structure constants (a comma separated list of elements, surrounded by braces and preceded by an - exclamation point). For example: "!{ metadata !"test\00", i32 - 10}". Metadata nodes can have any values as their operand.

    + exclamation point). Metadata nodes can have any values as their operand. For + example:

    + +
    +
    +!{ metadata !"test\00", i32 10}
    +
    +

    A named metadata is a collection of metadata nodes, which can be looked up in the module symbol table. For - example: "!foo = metadata !{!4, !3}". + example:

    + +
    +
    +!foo =  metadata !{!4, !3}
    +
    +

    Metadata can be used as function arguments. Here llvm.dbg.value - function is using two metadata arguments.

    + function is using two metadata arguments:

    @@ -2802,7 +2940,8 @@ call void @llvm.dbg.value(metadata !24, i64 0, metadata !25)
     

    Metadata can be attached with an instruction. Here metadata !21 is - attached with add instruction using !dbg identifier.

    + attached to the add instruction using the !dbg + identifier:

    @@ -2810,6 +2949,281 @@ call void @llvm.dbg.value(metadata !24, i64 0, metadata !25)
     
    +

    More information about specific metadata nodes recognized by the optimizers + and code generator is found below.

    + + +

    + 'tbaa' Metadata +

    + +
    + +

    In LLVM IR, memory does not have types, so LLVM's own type system is not + suitable for doing TBAA. Instead, metadata is added to the IR to describe + a type system of a higher level language. This can be used to implement + typical C/C++ TBAA, but it can also be used to implement custom alias + analysis behavior for other languages.

    + +

    The current metadata format is very simple. TBAA metadata nodes have up to + three fields, e.g.:

    + +
    +
    +!0 = metadata !{ metadata !"an example type tree" }
    +!1 = metadata !{ metadata !"int", metadata !0 }
    +!2 = metadata !{ metadata !"float", metadata !0 }
    +!3 = metadata !{ metadata !"const float", metadata !2, i64 1 }
    +
    +
    + +

    The first field is an identity field. It can be any value, usually + a metadata string, which uniquely identifies the type. The most important + name in the tree is the name of the root node. Two trees with + different root node names are entirely disjoint, even if they + have leaves with common names.

    + +

    The second field identifies the type's parent node in the tree, or + is null or omitted for a root node. A type is considered to alias + all of its descendants and all of its ancestors in the tree. Also, + a type is considered to alias all types in other trees, so that + bitcode produced from multiple front-ends is handled conservatively.

    + +

    If the third field is present, it's an integer which if equal to 1 + indicates that the type is "constant" (meaning + pointsToConstantMemory should return true; see + other useful + AliasAnalysis methods).

    + +
    + + +

    + 'fpaccuracy' Metadata +

    + +
    + +

    fpaccuracy metadata may be attached to any instruction of floating + point type. It expresses the maximum relative error of the result of + that instruction, in ULPs. ULP is defined as follows:

    + +
    + +

    If x is a real number that lies between two finite consecutive + floating-point numbers a and b, without being equal to one + of them, then ulp(x) = |b - a|, otherwise ulp(x) is the + distance between the two non-equal finite floating-point numbers nearest + x. Moreover, ulp(NaN) is NaN.

    + +
    + +

    The maximum relative error may be any rational number. The metadata node + shall consist of a pair of unsigned integers respectively representing + the numerator and denominator. For example, 2.5 ULP:

    + +
    +
    +!0 = metadata !{ i32 5, i32 2 }
    +
    +
    + +
    + +
    + + + + +

    + Module Flags Metadata +

    + + +
    + +

    Information about the module as a whole is difficult to convey to LLVM's + subsystems. The LLVM IR isn't sufficient to transmit this + information. The llvm.module.flags named metadata exists in order to + facilitate this. These flags are in the form of key / value pairs — + much like a dictionary — making it easy for any subsystem who cares + about a flag to look it up.

    + +

    The llvm.module.flags metadata contains a list of metadata + triplets. Each triplet has the following form:

    + +
      +
    • The first element is a behavior flag, which specifies the behavior + when two (or more) modules are merged together, and it encounters two (or + more) metadata with the same ID. The supported behaviors are described + below.
    • + +
    • The second element is a metadata string that is a unique ID for the + metadata. How each ID is interpreted is documented below.
    • + +
    • The third element is the value of the flag.
    • +
    + +

    When two (or more) modules are merged together, the resulting + llvm.module.flags metadata is the union of the + modules' llvm.module.flags metadata. The only exception being a flag + with the Override behavior, which may override another flag's value + (see below).

    + +

    The following behaviors are supported:

    + + + + + + + + + + + + + + + + + + + + + + + + +
    ValueBehavior
    1 +
    Error
    +
    Emits an error if two values disagree. It is an error to have an ID + with both an Error and a Warning behavior.
    +
    2 +
    Warning
    +
    Emits a warning if two values disagree.
    +
    3 +
    Require
    +
    Emits an error when the specified value is not present or doesn't + have the specified value. It is an error for two (or more) + llvm.module.flags with the same ID to have the Require + behavior but different values. There may be multiple Require flags + per ID.
    +
    4 +
    Override
    +
    Uses the specified value if the two values disagree. It is an error + for two (or more) llvm.module.flags with the same ID to + have the Override behavior but different values.
    +
    + +

    An example of module flags:

    + +
    +!0 = metadata !{ i32 1, metadata !"foo", i32 1 }
    +!1 = metadata !{ i32 4, metadata !"bar", i32 37 }
    +!2 = metadata !{ i32 2, metadata !"qux", i32 42 }
    +!3 = metadata !{ i32 3, metadata !"qux",
    +  metadata !{
    +    metadata !"foo", i32 1
    +  }
    +}
    +!llvm.module.flags = !{ !0, !1, !2, !3 }
    +
    + +
      +
    • Metadata !0 has the ID !"foo" and the value '1'. The + behavior if two or more !"foo" flags are seen is to emit an + error if their values are not equal.

    • + +
    • Metadata !1 has the ID !"bar" and the value '37'. The + behavior if two or more !"bar" flags are seen is to use the + value '37' if their values are not equal.

    • + +
    • Metadata !2 has the ID !"qux" and the value '42'. The + behavior if two or more !"qux" flags are seen is to emit a + warning if their values are not equal.

    • + +
    • Metadata !3 has the ID !"qux" and the value:

      + +
      +metadata !{ metadata !"foo", i32 1 }
      +
      + +

      The behavior is to emit an error if the llvm.module.flags does + not contain a flag with the ID !"foo" that has the value + '1'. If two or more !"qux" flags exist, then they must have + the same value or an error will be issued.

    • +
    + + + +

    +Objective-C Garbage Collection Module Flags Metadata +

    + +
    + +

    On the Mach-O platform, Objective-C stores metadata about garbage collection + in a special section called "image info". The metadata consists of a version + number and a bitmask specifying what types of garbage collection are + supported (if any) by the file. If two or more modules are linked together + their garbage collection metadata needs to be merged rather than appended + together.

    + +

    The Objective-C garbage collection module flags metadata consists of the + following key-value pairs:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    KeyValue
    Objective-C Version[Required] — The Objective-C ABI + version. Valid values are 1 and 2.
    Objective-C Image Info Version[Required] — The version of the image info + section. Currently always 0.
    Objective-C Image Info Section[Required] — The section to place the + metadata. Valid values are "__OBJC, __image_info, regular" for + Objective-C ABI version 1, and "__DATA,__objc_imageinfo, regular, + no_dead_strip" for Objective-C ABI version 2.
    Objective-C Garbage Collection[Required] — Specifies whether garbage + collection is supported or not. Valid values are 0, for no garbage + collection, and 2, for garbage collection supported.
    Objective-C GC Only[Optional] — Specifies that only garbage + collection is supported. If present, its value must be 6. This flag + requires that the Objective-C Garbage Collection flag have the + value 2.
    + +

    Some important flag interactions:

    + +
      +
    • If a module with Objective-C Garbage Collection set to 0 is + merged with a module with Objective-C Garbage Collection set to + 2, then the resulting module has the Objective-C Garbage + Collection flag set to 0.
    • + +
    • A module with Objective-C Garbage Collection set to 0 cannot be + merged with a module with Objective-C GC Only set to 6.
    • +
    +
    @@ -2838,26 +3252,29 @@ href="#linkage_appending">appending linkage. This array contains a list of pointers to global variables and functions which may optionally have a pointer cast formed of bitcast or getelementptr. For example, a legal use of it is:

    +
    -  @X = global i8 4
    -  @Y = global i32 123
    +@X = global i8 4
    +@Y = global i32 123
     
    -  @llvm.used = appending global [2 x i8*] [
    -     i8* @X,
    -     i8* bitcast (i32* @Y to i8*)
    -  ], section "llvm.metadata"
    +@llvm.used = appending global [2 x i8*] [
    +   i8* @X,
    +   i8* bitcast (i32* @Y to i8*)
    +], section "llvm.metadata"
     
    +

    If a global variable appears in the @llvm.used list, then the -compiler, assembler, and linker are required to treat the symbol as if there is -a reference to the global that it cannot see. For example, if a variable has -internal linkage and no references other than that from the @llvm.used -list, it cannot be deleted. This is commonly used to represent references from -inline asms and other things the compiler cannot "see", and corresponds to -"attribute((used))" in GNU C.

    + compiler, assembler, and linker are required to treat the symbol as if there + is a reference to the global that it cannot see. For example, if a variable + has internal linkage and no references other than that from + the @llvm.used list, it cannot be deleted. This is commonly used to + represent references from inline asms and other things the compiler cannot + "see", and corresponds to "attribute((used))" in GNU C.

    On some targets, the code generator must emit a directive to the assembler or -object file to prevent the assembler and linker from molesting the symbol.

    + object file to prevent the assembler and linker from molesting the + symbol.

    @@ -2871,13 +3288,13 @@ object file to prevent the assembler and linker from molesting the symbol.

    The @llvm.compiler.used directive is the same as the -@llvm.used directive, except that it only prevents the compiler from -touching the symbol. On targets that support it, this allows an intelligent -linker to optimize references to the symbol without being impeded as it would be -by @llvm.used.

    + @llvm.used directive, except that it only prevents the compiler from + touching the symbol. On targets that support it, this allows an intelligent + linker to optimize references to the symbol without being impeded as it would + be by @llvm.used.

    This is a rare construct that should only be used in rare circumstances, and -should not be exposed to source languages.

    + should not be exposed to source languages.

    @@ -2887,12 +3304,19 @@ should not be exposed to source languages.

    + +
     %0 = type { i32, void ()* }
     @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @ctor }]
     
    -

    The @llvm.global_ctors array contains a list of constructor functions and associated priorities. The functions referenced by this array will be called in ascending order of priority (i.e. lowest first) when the module is loaded. The order of functions with the same priority is not defined. -

    +
    + +

    The @llvm.global_ctors array contains a list of constructor + functions and associated priorities. The functions referenced by this array + will be called in ascending order of priority (i.e. lowest first) when the + module is loaded. The order of functions with the same priority is not + defined.

    @@ -2902,13 +3326,18 @@ should not be exposed to source languages.

    + +
     %0 = type { i32, void ()* }
     @llvm.global_dtors = appending global [1 x %0] [%0 { i32 65535, void ()* @dtor }]
     
    +
    -

    The @llvm.global_dtors array contains a list of destructor functions and associated priorities. The functions referenced by this array will be called in descending order of priority (i.e. highest first) when the module is loaded. The order of functions with the same priority is not defined. -

    +

    The @llvm.global_dtors array contains a list of destructor functions + and associated priorities. The functions referenced by this array will be + called in descending order of priority (i.e. highest first) when the module + is loaded. The order of functions with the same priority is not defined.

    @@ -2941,14 +3370,14 @@ should not be exposed to source languages.

    control flow, not values (the one exception being the 'invoke' instruction).

    -

    There are seven different terminator instructions: the - 'ret' instruction, the - 'br' instruction, the - 'switch' instruction, the - ''indirectbr' Instruction, the - 'invoke' instruction, the - 'unwind' instruction, and the - 'unreachable' instruction.

    +

    The terminator instructions are: + 'ret', + 'br', + 'switch', + 'indirectbr', + 'invoke', + 'resume', and + 'unreachable'.

    @@ -3009,7 +3438,8 @@ should not be exposed to source languages.

    Syntax:
    -  br i1 <cond>, label <iftrue>, label <iffalse>
    br label <dest> ; Unconditional branch + br i1 <cond>, label <iftrue>, label <iffalse> + br label <dest> ; Unconditional branch
    Overview:
    @@ -3165,9 +3595,20 @@ IfUnequal: 'normal' label or the 'exception' label. If the callee function returns with the "ret" instruction, control flow will return to the "normal" label. If the callee (or any - indirect callees) returns with the "unwind" - instruction, control is interrupted and continued at the dynamically nearest - "exception" label.

    + indirect callees) returns via the "resume" + instruction or other exception handling mechanism, control is interrupted and + continued at the dynamically nearest "exception" label.

    + +

    The 'exception' label is a + landing pad for the + exception. As such, 'exception' label is required to have the + "landingpad" instruction, which contains + the information about the behavior of the program after unwinding + happens, as its first non-PHI instruction. The restrictions on the + "landingpad" instruction's tightly couples it to the + "invoke" instruction, so that the important information contained + within the "landingpad" instruction can't be lost through normal + code motion.

    Arguments:

    This instruction requires several arguments:

    @@ -3198,8 +3639,9 @@ IfUnequal:
  • 'normal label': the label reached when the called function executes a 'ret' instruction.
  • -
  • 'exception label': the label reached when a callee returns with - the unwind instruction.
  • +
  • 'exception label': the label reached when a callee returns via + the resume instruction or other exception + handling mechanism.
  • The optional function attributes list. Only 'noreturn', 'nounwind', 'readonly' and @@ -3222,9 +3664,6 @@ IfUnequal: block to the "normal" label. If the callee unwinds then no return value is available.

    -

    Note that the code generator does not yet completely support unwind, and -that the invoke/unwind semantics are likely to change in future versions.

    -
    Example:
       %retval = invoke i32 @Test(i32 15) to label %Continue
    @@ -3235,35 +3674,37 @@ that the invoke/unwind semantics are likely to change in future versions.

    - - + +

    - 'unwind' Instruction + 'resume' Instruction

    Syntax:
    -  unwind
    +  resume <type> <value>
     
    Overview:
    -

    The 'unwind' instruction unwinds the stack, continuing control flow - at the first callee in the dynamic call stack which used - an invoke instruction to perform the call. - This is primarily used to implement exception handling.

    +

    The 'resume' instruction is a terminator instruction that has no + successors.

    + +
    Arguments:
    +

    The 'resume' instruction requires one argument, which must have the + same type as the result of any 'landingpad' instruction in the same + function.

    Semantics:
    -

    The 'unwind' instruction causes execution of the current function to - immediately halt. The dynamic call stack is then searched for the - first invoke instruction on the call stack. - Once found, execution continues at the "exceptional" destination block - specified by the invoke instruction. If there is no invoke - instruction in the dynamic call chain, undefined behavior results.

    +

    The 'resume' instruction resumes propagation of an existing + (in-flight) exception whose unwinding was interrupted with + a landingpad instruction.

    -

    Note that the code generator does not yet completely support unwind, and -that the invoke/unwind semantics are likely to change in future versions.

    +
    Example:
    +
    +  resume { i8*, i32 } %exn
    +
    @@ -3343,7 +3784,7 @@ that the invoke/unwind semantics are likely to change in future versions.

    nuw and nsw stand for "No Unsigned Wrap" and "No Signed Wrap", respectively. If the nuw and/or nsw keywords are present, the result value of the add - is a trap value if unsigned and/or signed overflow, + is a poison value if unsigned and/or signed overflow, respectively, occurs.

    Example:
    @@ -3424,7 +3865,7 @@ that the invoke/unwind semantics are likely to change in future versions.

    nuw and nsw stand for "No Unsigned Wrap" and "No Signed Wrap", respectively. If the nuw and/or nsw keywords are present, the result value of the sub - is a trap value if unsigned and/or signed overflow, + is a poison value if unsigned and/or signed overflow, respectively, occurs.

    Example:
    @@ -3511,7 +3952,7 @@ that the invoke/unwind semantics are likely to change in future versions.

    nuw and nsw stand for "No Unsigned Wrap" and "No Signed Wrap", respectively. If the nuw and/or nsw keywords are present, the result value of the mul - is a trap value if unsigned and/or signed overflow, + is a poison value if unsigned and/or signed overflow, respectively, occurs.

    Example:
    @@ -3581,7 +4022,7 @@ that the invoke/unwind semantics are likely to change in future versions.

    Division by zero leads to undefined behavior.

    If the exact keyword is present, the result value of the - udiv is a trap value if %op1 is not a + udiv is a poison value if %op1 is not a multiple of %op2 (as such, "((a udiv exact b) mul b) == a").

    @@ -3625,7 +4066,7 @@ that the invoke/unwind semantics are likely to change in future versions.

    a 32-bit division of -2147483648 by -1.

    If the exact keyword is present, the result value of the - sdiv is a trap value if the result would + sdiv is a poison value if the result would be rounded.

    Example:
    @@ -3834,9 +4275,9 @@ that the invoke/unwind semantics are likely to change in future versions.

    shift amount in op2.

    If the nuw keyword is present, then the shift produces a - trap value if it shifts out any non-zero bits. If + poison value if it shifts out any non-zero bits. If the nsw keyword is present, then the shift produces a - trap value if it shifts out any bits that disagree + poison value if it shifts out any bits that disagree with the resultant sign bit. As such, NUW/NSW have the same semantics as they would if the shift were expressed as a mul instruction with the same nsw/nuw bits in (mul %op1, (shl 1, %op2)).

    @@ -3883,7 +4324,7 @@ that the invoke/unwind semantics are likely to change in future versions.

    shift amount in op2.

    If the exact keyword is present, the result value of the - lshr is a trap value if any of the bits + lshr is a poison value if any of the bits shifted out are non-zero.

    @@ -3931,7 +4372,7 @@ that the invoke/unwind semantics are likely to change in future versions.

    the corresponding shift amount in op2.

    If the exact keyword is present, the result value of the - ashr is a trap value if any of the bits + ashr is a poison value if any of the bits shifted out are non-zero.

    Example:
    @@ -3973,9 +4414,9 @@ that the invoke/unwind semantics are likely to change in future versions.

    - - - + + + @@ -4034,9 +4475,9 @@ that the invoke/unwind semantics are likely to change in future versions.

    In0In1OutIn0In1Out
    0
    - - - + + + @@ -4098,9 +4539,9 @@ that the invoke/unwind semantics are likely to change in future versions.

    In0In1OutIn0In1Out
    0
    - - - + + + @@ -4334,7 +4775,7 @@ that the invoke/unwind semantics are likely to change in future versions.

    Syntax:
    -  <result> = insertvalue <aggregate type> <val>, <ty> <elt>, <idx>{, }*    ; yields <aggregate type>
    +  <result> = insertvalue <aggregate type> <val>, <ty> <elt>, <idx>{, <idx>}*    ; yields <aggregate type>
     
    Overview:
    @@ -4417,7 +4858,7 @@ that the invoke/unwind semantics are likely to change in future versions.

    '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 + or resume instructions), the memory is reclaimed. Allocating zero bytes is legal, but the result is undefined.

    Example:
    @@ -4439,8 +4880,8 @@ that the invoke/unwind semantics are likely to change in future versions.

    Syntax:
    -  <result> = load <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>]
    -  <result> = volatile load <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>]
    +  <result> = load [volatile] <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>][, !invariant.load !<index>]
    +  <result> = load atomic [volatile] <ty>* <pointer> [singlethread] <ordering>, align <alignment>
       !<index> = !{ i32 1 }
     
    @@ -4455,6 +4896,19 @@ that the invoke/unwind semantics are likely to change in future versions.

    number or order of execution of this load with other volatile operations.

    +

    If the load is marked as atomic, it takes an extra + ordering and optional singlethread + argument. The release and acq_rel orderings are + not valid on load instructions. Atomic loads produce defined results when they may see multiple atomic + stores. The type of the pointee must be an integer type whose bit width + is a power of two greater than or equal to eight and less than or equal + to a target-specific size limit. align must be explicitly + specified on atomic loads, and the load has undefined behavior if the + alignment is not set to a value which is at least the size in bytes of + the pointee. !nontemporal does not have any defined semantics + for atomic loads.

    +

    The optional constant align argument specifies the alignment of the operation (that is, the alignment of the memory address). A value of 0 or an omitted align argument means that the operation has the preferential @@ -4471,6 +4925,14 @@ that the invoke/unwind semantics are likely to change in future versions.

    The code generator may select special instructions to save cache bandwidth, such as the MOVNT instruction on x86.

    +

    The optional !invariant.load metadata must reference a single + metatadata name <index> corresponding to a metadata node with no + entries. The existence of the !invariant.load metatadata on the + instruction tells the optimizer and code generator that this load address + points to memory which does not change value during program execution. + The optimizer may then move this load around, for example, by hoisting it + out of loops using loop invariant code motion.

    +
    Semantics:

    The location of memory pointed to is loaded. If the value being loaded is of scalar type then the number of bytes read does not exceed the minimum number @@ -4498,8 +4960,8 @@ that the invoke/unwind semantics are likely to change in future versions.

    Syntax:
    -  store <ty> <value>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>]                   ; yields {void}
    -  volatile store <ty> <value>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>]          ; yields {void}
    +  store [volatile] <ty> <value>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>]        ; yields {void}
    +  store atomic [volatile] <ty> <value>, <ty>* <pointer> [singlethread] <ordering>, align <alignment>  ; yields {void}
     
    Overview:
    @@ -4515,6 +4977,19 @@ that the invoke/unwind semantics are likely to change in future versions.

    order of execution of this store with other volatile operations.

    +

    If the store is marked as atomic, it takes an extra + ordering and optional singlethread + argument. The acquire and acq_rel orderings aren't + valid on store instructions. Atomic loads produce defined results when they may see multiple atomic + stores. The type of the pointee must be an integer type whose bit width + is a power of two greater than or equal to eight and less than or equal + to a target-specific size limit. align must be explicitly + specified on atomic stores, and the store has undefined behavior if the + alignment is not set to a value which is at least the size in bytes of + the pointee. !nontemporal does not have any defined semantics + for atomic stores.

    +

    The optional constant "align" argument specifies the alignment of the operation (that is, the alignment of the memory address). A value of 0 or an omitted "align" argument means that the operation has the preferential @@ -4553,117 +5028,333 @@ that the invoke/unwind semantics are likely to change in future versions.

    - 'getelementptr' Instruction +'fence' Instruction

    Syntax:
    -  <result> = getelementptr <pty>* <ptrval>{, <ty> <idx>}*
    -  <result> = getelementptr inbounds <pty>* <ptrval>{, <ty> <idx>}*
    +  fence [singlethread] <ordering>                   ; yields {void}
     
    Overview:
    -

    The 'getelementptr' instruction is used to get the address of a - subelement of an aggregate data structure. - It performs address calculation only and does not access memory.

    - -
    Arguments:
    -

    The first argument is always a pointer, and forms the basis of the - calculation. The remaining arguments are indices that indicate which of the - elements of the aggregate object are indexed. The interpretation of each - index is dependent on the type being indexed into. The first index always - indexes the pointer value given as the first argument, the second index - indexes a value of the type pointed to (not necessarily the value directly - pointed to, since the first index can be non-zero), etc. The first type - indexed into must be a pointer value, subsequent types can be arrays, - vectors, and structs. Note that subsequent types being indexed into - can never be pointers, since that would require loading the pointer before - continuing calculation.

    - -

    The type of each index argument depends on the type it is indexing into. - When indexing into a (optionally packed) structure, only i32 - integer constants are allowed. When indexing into an array, pointer - or vector, integers of any width are allowed, and they are not required to be - constant.

    +

    The 'fence' instruction is used to introduce happens-before edges +between operations.

    -

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

    +
    Arguments:

    'fence' instructions take an ordering argument which defines what +synchronizes-with edges they add. They can only be given +acquire, release, acq_rel, and +seq_cst orderings.

    -
    -struct RT {
    -  char A;
    -  int B[10][20];
    -  char C;
    -};
    -struct ST {
    -  int X;
    -  double Y;
    -  struct RT Z;
    -};
    +
    Semantics:
    +

    A fence A which has (at least) release ordering +semantics synchronizes with a fence B with (at least) +acquire ordering semantics if and only if there exist atomic +operations X and Y, both operating on some atomic object +M, such that A is sequenced before X, +X modifies M (either directly or through some side effect +of a sequence headed by X), Y is sequenced before +B, and Y observes M. This provides a +happens-before dependency between A and B. Rather +than an explicit fence, one (but not both) of the atomic operations +X or Y might provide a release or +acquire (resp.) ordering constraint and still +synchronize-with the explicit fence and establish the +happens-before edge.

    + +

    A fence which has seq_cst ordering, in addition to +having both acquire and release semantics specified +above, participates in the global program order of other seq_cst +operations and/or fences.

    + +

    The optional "singlethread" argument +specifies that the fence only synchronizes with other fences in the same +thread. (This is useful for interacting with signal handlers.)

    -int *foo(struct ST *s) { - return &s[1].Z.B[5][13]; -} +
    Example:
    +
    +  fence acquire                          ; yields {void}
    +  fence singlethread seq_cst             ; yields {void}
     
    -

    The LLVM code generated by the GCC frontend is:

    +
    -
    -%RT = type { i8 , [10 x [20 x i32]], i8  }
    -%ST = type { i32, double, %RT }
    +
    +

    +'cmpxchg' Instruction +

    -define i32* @foo(%ST* %s) { -entry: - %reg = getelementptr %ST* %s, i32 1, i32 2, i32 1, i32 5, i32 13 - ret i32* %reg -} +
    + +
    Syntax:
    +
    +  cmpxchg [volatile] <ty>* <pointer>, <ty> <cmp>, <ty> <new> [singlethread] <ordering>  ; yields {ty}
     
    -
    Semantics:
    -

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

    +
    Overview:
    +

    The 'cmpxchg' instruction is used to atomically modify memory. +It loads a value in memory and compares it to a given value. If they are +equal, it stores a new value into the memory.

    + +
    Arguments:
    +

    There are three arguments to the 'cmpxchg' instruction: an +address to operate on, a value to compare to the value currently be at that +address, and a new value to place at that address if the compared values are +equal. The type of '<cmp>' must be an integer type whose +bit width is a power of two greater than or equal to eight and less than +or equal to a target-specific size limit. '<cmp>' and +'<new>' must have the same type, and the type of +'<pointer>' must be a pointer to that type. If the +cmpxchg is marked as volatile, then the +optimizer is not allowed to modify the number or order of execution +of this cmpxchg with other volatile +operations.

    + + + +

    The ordering argument specifies how this +cmpxchg synchronizes with other atomic operations.

    + +

    The optional "singlethread" argument declares that the +cmpxchg is only atomic with respect to code (usually signal +handlers) running in the same thread as the cmpxchg. Otherwise the +cmpxchg is atomic with respect to all other code in the system.

    + +

    The pointer passed into cmpxchg must have alignment greater than or equal to +the size in memory of the operand. + +

    Semantics:
    +

    The contents of memory at the location specified by the +'<pointer>' operand is read and compared to +'<cmp>'; if the read value is the equal, +'<new>' is written. The original value at the location +is returned. + +

    A successful cmpxchg is a read-modify-write instruction for the +purpose of identifying release sequences. A +failed cmpxchg is equivalent to an atomic load with an ordering +parameter determined by dropping any release part of the +cmpxchg's ordering.

    + + + +
    Example:
    +
    +entry:
    +  %orig = atomic load i32* %ptr unordered                   ; yields {i32}
    +  br label %loop
    +
    +loop:
    +  %cmp = phi i32 [ %orig, %entry ], [%old, %loop]
    +  %squared = mul i32 %cmp, %cmp
    +  %old = cmpxchg i32* %ptr, i32 %cmp, i32 %squared          ; yields {i32}
    +  %success = icmp eq i32 %cmp, %old
    +  br i1 %success, label %done, label %loop
    +
    +done:
    +  ...
    +
    + +
    + + +

    +'atomicrmw' Instruction +

    + +
    + +
    Syntax:
    +
    +  atomicrmw [volatile] <operation> <ty>* <pointer>, <ty> <value> [singlethread] <ordering>                   ; yields {ty}
    +
    + +
    Overview:
    +

    The 'atomicrmw' instruction is used to atomically modify memory.

    + +
    Arguments:
    +

    There are three arguments to the 'atomicrmw' instruction: an +operation to apply, an address whose value to modify, an argument to the +operation. The operation must be one of the following keywords:

    +
      +
    • xchg
    • +
    • add
    • +
    • sub
    • +
    • and
    • +
    • nand
    • +
    • or
    • +
    • xor
    • +
    • max
    • +
    • min
    • +
    • umax
    • +
    • umin
    • +
    + +

    The type of '<value>' must be an integer type whose +bit width is a power of two greater than or equal to eight and less than +or equal to a target-specific size limit. The type of the +'<pointer>' operand must be a pointer to that type. +If the atomicrmw is marked as volatile, then the +optimizer is not allowed to modify the number or order of execution of this +atomicrmw with other volatile + operations.

    + + + +
    Semantics:
    +

    The contents of memory at the location specified by the +'<pointer>' operand are atomically read, modified, and written +back. The original value at the location is returned. The modification is +specified by the operation argument:

    + +
      +
    • xchg: *ptr = val
    • +
    • add: *ptr = *ptr + val
    • +
    • sub: *ptr = *ptr - val
    • +
    • and: *ptr = *ptr & val
    • +
    • nand: *ptr = ~(*ptr & val)
    • +
    • or: *ptr = *ptr | val
    • +
    • xor: *ptr = *ptr ^ val
    • +
    • max: *ptr = *ptr > val ? *ptr : val (using a signed comparison)
    • +
    • min: *ptr = *ptr < val ? *ptr : val (using a signed comparison)
    • +
    • umax: *ptr = *ptr > val ? *ptr : val (using an unsigned comparison)
    • +
    • umin: *ptr = *ptr < val ? *ptr : val (using an unsigned comparison)
    • +
    + +
    Example:
    +
    +  %old = atomicrmw add i32* %ptr, i32 1 acquire                        ; yields {i32}
    +
    + +
    + + +

    + 'getelementptr' Instruction +

    + +
    + +
    Syntax:
    +
    +  <result> = getelementptr <pty>* <ptrval>{, <ty> <idx>}*
    +  <result> = getelementptr inbounds <pty>* <ptrval>{, <ty> <idx>}*
    +  <result> = getelementptr <ptr vector> ptrval, <vector index type> idx 
    +
    + +
    Overview:
    +

    The 'getelementptr' instruction is used to get the address of a + subelement of an aggregate data structure. + It performs address calculation only and does not access memory.

    + +
    Arguments:
    +

    The first argument is always a pointer or a vector of pointers, + and forms the basis of the + calculation. The remaining arguments are indices that indicate which of the + elements of the aggregate object are indexed. The interpretation of each + index is dependent on the type being indexed into. The first index always + indexes the pointer value given as the first argument, the second index + indexes a value of the type pointed to (not necessarily the value directly + pointed to, since the first index can be non-zero), etc. The first type + indexed into must be a pointer value, subsequent types can be arrays, + vectors, and structs. Note that subsequent types being indexed into + can never be pointers, since that would require loading the pointer before + continuing calculation.

    + +

    The type of each index argument depends on the type it is indexing into. + When indexing into a (optionally packed) structure, only i32 + integer constants are allowed. When indexing into an array, pointer + or vector, integers of any width are allowed, and they are not required to be + constant. These integers are treated as signed values where relevant.

    + +

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

    + +
    +struct RT {
    +  char A;
    +  int B[10][20];
    +  char C;
    +};
    +struct ST {
    +  int X;
    +  double Y;
    +  struct RT Z;
    +};
    +
    +int *foo(struct ST *s) {
    +  return &s[1].Z.B[5][13];
    +}
    +
    + +

    The LLVM code generated by Clang is:

    + +
    +%struct.RT = type { i8, [10 x [20 x i32]], i8 }
    +%struct.ST = type { i32, double, %struct.RT }
    +
    +define i32* @foo(%struct.ST* %s) nounwind uwtable readnone optsize ssp {
    +entry:
    +  %arrayidx = getelementptr inbounds %struct.ST* %s, i64 1, i32 2, i32 1, i64 5, i64 13
    +  ret i32* %arrayidx
    +}
    +
    + +
    Semantics:
    +

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

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

    -
    -  define i32* @foo(%ST* %s) {
    -    %t1 = getelementptr %ST* %s, i32 1                        ; yields %ST*:%t1
    -    %t2 = getelementptr %ST* %t1, i32 0, i32 2                ; yields %RT*:%t2
    -    %t3 = getelementptr %RT* %t2, i32 0, i32 1                ; yields [10 x [20 x i32]]*:%t3
    -    %t4 = getelementptr [10 x [20 x i32]]* %t3, i32 0, i32 5  ; yields [20 x i32]*:%t4
    -    %t5 = getelementptr [20 x i32]* %t4, i32 0, i32 13        ; yields i32*:%t5
    -    ret i32* %t5
    -  }
    +
    +define i32* @foo(%struct.ST* %s) {
    +  %t1 = getelementptr %struct.ST* %s, i32 1                 ; yields %struct.ST*:%t1
    +  %t2 = getelementptr %struct.ST* %t1, i32 0, i32 2         ; yields %struct.RT*:%t2
    +  %t3 = getelementptr %struct.RT* %t2, i32 0, i32 1         ; yields [10 x [20 x i32]]*:%t3
    +  %t4 = getelementptr [10 x [20 x i32]]* %t3, i32 0, i32 5  ; yields [20 x i32]*:%t4
    +  %t5 = getelementptr [20 x i32]* %t4, i32 0, i32 13        ; yields i32*:%t5
    +  ret i32* %t5
    +}
     

    If the inbounds keyword is present, the result value of the - getelementptr is a trap value if the + getelementptr is a poison value if the base pointer is not an in bounds address of an allocated object, or if any of the addresses that would be formed by successive addition of the offsets implied by the indices to the base address with infinitely - precise arithmetic are not an in bounds address of that allocated - object. The in bounds addresses for an allocated object are all - the addresses that point into the object, plus the address one byte past - the end.

    + precise signed arithmetic are not an in bounds address of that + allocated object. The in bounds addresses for an allocated object + are all the addresses that point into the object, plus the address one + byte past the end. + In cases where the base is a vector of pointers the inbounds keyword + applies to each of the computations element-wise.

    If the inbounds keyword is not present, the offsets are added to - the base address with silently-wrapping two's complement arithmetic, and - the result value of the getelementptr may be outside the object - pointed to by the base pointer. The result value may not necessarily be - used to access memory though, even if it happens to point into allocated - storage. See the Pointer Aliasing Rules - section for more information.

    + the base address with silently-wrapping two's complement arithmetic. If the + offsets have a different width from the pointer, they are sign-extended or + truncated to the width of the pointer. The result value of the + getelementptr may be outside the object pointed to by the base + pointer. The result value may not necessarily be used to access memory + though, even if it happens to point into allocated storage. See the + Pointer Aliasing Rules section for more + information.

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

    @@ -4680,6 +5371,13 @@ entry: %iptr = getelementptr [10 x i32]* @arr, i16 0, i16 0
    +

    In cases where the pointer argument is a vector of pointers, only a + single index may be used, and the number of vector elements has to be + the same. For example:

    +
    + %A = getelementptr <4 x i8*> %ptrs, <4 x i64> %offsets,
    +
    +
    @@ -5052,13 +5750,16 @@ entry:
    Overview:
    -

    The 'ptrtoint' instruction converts the pointer value to - the integer type ty2.

    +

    The 'ptrtoint' instruction converts the pointer or a vector of + pointers value to + the integer (or vector of integers) type ty2.

    Arguments:

    The 'ptrtoint' instruction takes a value to cast, which - must be a pointer value, and a type to cast it to - ty2, which must be an integer type.

    + must be a a value of type pointer or a vector of + pointers, and a type to cast it to + ty2, which must be an integer or a vector + of integers type.

    Semantics:

    The 'ptrtoint' instruction converts value to integer type @@ -5071,8 +5772,9 @@ entry:

    Example:
    -  %X = ptrtoint i32* %X to i8           ; yields truncation on 32-bit architecture
    -  %Y = ptrtoint i32* %x to i64          ; yields zero extension on 32-bit architecture
    +  %X = ptrtoint i32* %P to i8                         ; yields truncation on 32-bit architecture
    +  %Y = ptrtoint i32* %P to i64                        ; yields zero extension on 32-bit architecture
    +  %Z = ptrtoint <4 x i32*> %P to <4 x i64>; yields vector zero extension for a vector of addresses on 32-bit architecture
     
    @@ -5111,6 +5813,7 @@ entry: %X = inttoptr i32 255 to i32* ; yields zero extension on 64-bit architecture %Y = inttoptr i32 255 to i32* ; yields no-op on 32-bit architecture %Z = inttoptr i64 0 to i32* ; yields truncation on 32-bit architecture + %Z = inttoptr <4 x i32> %G to <4 x i8*>; yields truncation of vector G to four pointers @@ -5145,8 +5848,9 @@ entry:

    The 'bitcast' instruction converts value to type ty2. It is always a no-op cast because no bits change with this conversion. The conversion is done as if the value had been - stored to memory and read back as type ty2. Pointer types may only - be converted to other pointer types with this instruction. To convert + stored to memory and read back as type ty2. + Pointer (or vector of pointers) types may only be converted to other pointer + (or vector of pointers) types with this instruction. To convert pointers to other types, use the inttoptr or ptrtoint instructions first.

    @@ -5154,7 +5858,8 @@ entry:
       %X = bitcast i8 255 to i8              ; yields i8 :-1
       %Y = bitcast i32* %x to sint*          ; yields sint*:%x
    -  %Z = bitcast <2 x int> %V to i64;      ; yields i64: %V
    +  %Z = bitcast <2 x int> %V to i64;        ; yields i64: %V
    +  %Z = bitcast <2 x i32*> %V to <2 x i64*> ; yields <2 x i64*>
     
    @@ -5185,8 +5890,8 @@ entry:
    Overview:

    The 'icmp' instruction returns a boolean value or a vector of - boolean values based on comparison of its two integer, integer vector, or - pointer operands.

    + boolean values based on comparison of its two integer, integer vector, + pointer, or pointer vector operands.

    Arguments:

    The 'icmp' instruction takes three operands. The first operand is @@ -5481,9 +6186,6 @@ Loop: ; Infinite loop that counts from 0 on up... %X = select i1 true, i8 17, i8 42 ; yields i8:17 -

    Note that the code generator does not yet support conditions - with vector type.

    - @@ -5641,6 +6343,91 @@ freestanding environments and non-C-based languages.

    + +

    + 'landingpad' Instruction +

    + +
    + +
    Syntax:
    +
    +  <resultval> = landingpad <resultty> personality <type> <pers_fn> <clause>+
    +  <resultval> = landingpad <resultty> personality <type> <pers_fn> cleanup <clause>*
    +
    +  <clause> := catch <type> <value>
    +  <clause> := filter <array constant type> <array constant>
    +
    + +
    Overview:
    +

    The 'landingpad' instruction is used by + LLVM's exception handling + system to specify that a basic block is a landing pad — one where + the exception lands, and corresponds to the code found in the + catch portion of a try/catch sequence. It + defines values supplied by the personality function (pers_fn) upon + re-entry to the function. The resultval has the + type resultty.

    + +
    Arguments:
    +

    This instruction takes a pers_fn value. This is the personality + function associated with the unwinding mechanism. The optional + cleanup flag indicates that the landing pad block is a cleanup.

    + +

    A clause begins with the clause type — catch + or filter — and contains the global variable representing the + "type" that may be caught or filtered respectively. Unlike the + catch clause, the filter clause takes an array constant as + its argument. Use "[0 x i8**] undef" for a filter which cannot + throw. The 'landingpad' instruction must contain at least + one clause or the cleanup flag.

    + +
    Semantics:
    +

    The 'landingpad' instruction defines the values which are set by the + personality function (pers_fn) upon re-entry to the function, and + therefore the "result type" of the landingpad instruction. As with + calling conventions, how the personality function results are represented in + LLVM IR is target specific.

    + +

    The clauses are applied in order from top to bottom. If two + landingpad instructions are merged together through inlining, the + clauses from the calling function are appended to the list of clauses. + When the call stack is being unwound due to an exception being thrown, the + exception is compared against each clause in turn. If it doesn't + match any of the clauses, and the cleanup flag is not set, then + unwinding continues further up the call stack.

    + +

    The landingpad instruction has several restrictions:

    + +
      +
    • A landing pad block is a basic block which is the unwind destination of an + 'invoke' instruction.
    • +
    • A landing pad block must have a 'landingpad' instruction as its + first non-PHI instruction.
    • +
    • There can be only one 'landingpad' instruction within the landing + pad block.
    • +
    • A basic block that is not a landing pad block may not include a + 'landingpad' instruction.
    • +
    • All 'landingpad' instructions in a function must have the same + personality function.
    • +
    + +
    Example:
    +
    +  ;; A landing pad which can catch an integer.
    +  %res = landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
    +           catch i8** @_ZTIi
    +  ;; A landing pad that is a cleanup.
    +  %res = landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
    +           cleanup
    +  ;; A landing pad which can catch an integer and can only throw a double.
    +  %res = landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
    +           catch i8** @_ZTIi
    +           filter [1 x i8**] [@_ZTId]
    +
    + +
    + @@ -6529,8 +7316,6 @@ LLVM.

    - -

    'llvm.exp.*' Intrinsic @@ -6595,6 +7380,9 @@ LLVM.

    This function returns the same values as the libm log functions would, and handles error conditions in the same way.

    + + +

    'llvm.fma.*' Intrinsic

    @@ -6628,6 +7416,8 @@ LLVM.

    + +

    Bit Manipulation Intrinsics @@ -6722,12 +7512,12 @@ LLVM.

    targets support all bit widths or vector types, however.

    -  declare i8 @llvm.ctlz.i8 (i8  <src>)
    -  declare i16 @llvm.ctlz.i16(i16 <src>)
    -  declare i32 @llvm.ctlz.i32(i32 <src>)
    -  declare i64 @llvm.ctlz.i64(i64 <src>)
    -  declare i256 @llvm.ctlz.i256(i256 <src>)
    -  declare <2 x i32> @llvm.ctlz.v2i32(<2 x i32> <src;gt)
    +  declare i8   @llvm.ctlz.i8  (i8   <src>, i1 <is_zero_undef>)
    +  declare i16  @llvm.ctlz.i16 (i16  <src>, i1 <is_zero_undef>)
    +  declare i32  @llvm.ctlz.i32 (i32  <src>, i1 <is_zero_undef>)
    +  declare i64  @llvm.ctlz.i64 (i64  <src>, i1 <is_zero_undef>)
    +  declare i256 @llvm.ctlz.i256(i256 <src>, i1 <is_zero_undef>)
    +  declase <2 x i32> @llvm.ctlz.v2i32(<2 x i32> <src>, i1 <is_zero_undef>)
     

    Overview:
    @@ -6735,15 +7525,22 @@ LLVM.

    leading zeros in a variable.

    Arguments:
    -

    The only argument is the value to be counted. The argument may be of any - integer type, or any vector type with integer element type. - The return type must match the argument type.

    +

    The first argument is the value to be counted. This argument may be of any + integer type, or a vectory with integer element type. The return type + must match the first argument type.

    + +

    The second argument must be a constant and is a flag to indicate whether the + intrinsic should ensure that a zero as the first argument produces a defined + result. Historically some architectures did not provide a defined result for + zero values as efficiently, and many algorithms are now predicated on + avoiding zero-value inputs.

    Semantics:

    The 'llvm.ctlz' intrinsic counts the leading (most significant) - zeros in a variable, or within each element of the vector if the operation - is of vector type. If the src == 0 then the result is the size in bits of - the type of src. For example, llvm.ctlz(i32 2) = 30.

    + zeros in a variable, or within each element of the vector. + If src == 0 then the result is the size in bits of the type of + src if is_zero_undef == 0 and undef otherwise. + For example, llvm.ctlz(i32 2) = 30.

    @@ -6760,12 +7557,12 @@ LLVM.

    support all bit widths or vector types, however.

    -  declare i8 @llvm.cttz.i8 (i8  <src>)
    -  declare i16 @llvm.cttz.i16(i16 <src>)
    -  declare i32 @llvm.cttz.i32(i32 <src>)
    -  declare i64 @llvm.cttz.i64(i64 <src>)
    -  declare i256 @llvm.cttz.i256(i256 <src>)
    -  declase <2 x i32> @llvm.cttz.v2i32(<2 x i32> <src>)
    +  declare i8   @llvm.cttz.i8  (i8   <src>, i1 <is_zero_undef>)
    +  declare i16  @llvm.cttz.i16 (i16  <src>, i1 <is_zero_undef>)
    +  declare i32  @llvm.cttz.i32 (i32  <src>, i1 <is_zero_undef>)
    +  declare i64  @llvm.cttz.i64 (i64  <src>, i1 <is_zero_undef>)
    +  declare i256 @llvm.cttz.i256(i256 <src>, i1 <is_zero_undef>)
    +  declase <2 x i32> @llvm.cttz.v2i32(<2 x i32> <src>, i1 <is_zero_undef>)
     
    Overview:
    @@ -6773,15 +7570,22 @@ LLVM.

    trailing zeros.

    Arguments:
    -

    The only argument is the value to be counted. The argument may be of any - integer type, or a vectory with integer element type.. The return type - must match the argument type.

    +

    The first argument is the value to be counted. This argument may be of any + integer type, or a vectory with integer element type. The return type + must match the first argument type.

    + +

    The second argument must be a constant and is a flag to indicate whether the + intrinsic should ensure that a zero as the first argument produces a defined + result. Historically some architectures did not provide a defined result for + zero values as efficiently, and many algorithms are now predicated on + avoiding zero-value inputs.

    Semantics:

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

    + If src == 0 then the result is the size in bits of the type of + src if is_zero_undef == 0 and undef otherwise. + For example, llvm.cttz(2) = 1.

    @@ -7212,12 +8016,12 @@ LLVM.

    - Trampoline Intrinsic + Trampoline Intrinsics

    -

    This intrinsic makes it possible to excise one parameter, marked with +

    These intrinsics make it possible to excise one parameter, marked with the nest attribute, from a function. The result is a callable function pointer lacking the nest parameter - the caller does not need to @@ -7234,7 +8038,8 @@ LLVM.

       %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86
       %tramp1 = getelementptr [10 x i8]* %tramp, i32 0, i32 0
    -  %p = call i8* @llvm.init.trampoline(i8* %tramp1, i8* bitcast (i32 (i8* nest , i32, i32)* @f to i8*), i8* %nval)
    +  call i8* @llvm.init.trampoline(i8* %tramp1, i8* bitcast (i32 (i8*, i32, i32)* @f to i8*), i8* %nval)
    +  %p = call i8* @llvm.adjust.trampoline(i8* %tramp1)
       %fp = bitcast i8* %p to i32 (i32, i32)*
     
    @@ -7252,12 +8057,12 @@ LLVM.

    Syntax:
    -  declare i8* @llvm.init.trampoline(i8* <tramp>, i8* <func>, i8* <nval>)
    +  declare void @llvm.init.trampoline(i8* <tramp>, i8* <func>, i8* <nval>)
     
    Overview:
    -

    This fills the memory pointed to by tramp with code and returns a - function pointer suitable for executing it.

    +

    This fills the memory pointed to by tramp with executable code, + turning it into a trampoline.

    Arguments:

    The llvm.init.trampoline intrinsic takes three arguments, all @@ -7271,514 +8076,50 @@ LLVM.

    Semantics:

    The block of memory pointed to by tramp is filled with target - dependent code, turning it into a function. A pointer to this function is - returned, but needs to be bitcast to an appropriate - function pointer type before being called. The new function's signature - is the same as that of func with any arguments marked with - the nest attribute removed. At most one such nest argument - is allowed, and it must be of pointer type. Calling the new function is - equivalent to calling func with the same argument list, but - with nval used for the missing nest argument. If, after - calling llvm.init.trampoline, the memory pointed to - by tramp is modified, then the effect of any later call to the - returned function pointer is undefined.

    - -
    - - - - -

    - Atomic Operations and Synchronization Intrinsics -

    - -
    - -

    These intrinsic functions expand the "universal IR" of LLVM to represent - hardware constructs for atomic operations and memory synchronization. This - provides an interface to the hardware, not an interface to the programmer. It - is aimed at a low enough level to allow any programming models or APIs - (Application Programming Interfaces) which need atomic behaviors to map - cleanly onto it. It is also modeled primarily on hardware behavior. Just as - hardware provides a "universal IR" for source languages, it also provides a - starting point for developing a "universal" atomic operation and - synchronization IR.

    - -

    These do not form an API such as high-level threading libraries, - software transaction memory systems, atomic primitives, and intrinsic - functions as found in BSD, GNU libc, atomic_ops, APR, and other system and - application libraries. The hardware interface provided by LLVM should allow - a clean implementation of all of these APIs and parallel programming models. - No one model or paradigm should be selected above others unless the hardware - itself ubiquitously does so.

    - - -

    - 'llvm.memory.barrier' Intrinsic -

    - -
    -
    Syntax:
    -
    -  declare void @llvm.memory.barrier(i1 <ll>, i1 <ls>, i1 <sl>, i1 <ss>, i1 <device>)
    -
    - -
    Overview:
    -

    The llvm.memory.barrier intrinsic guarantees ordering between - specific pairs of memory access types.

    - -
    Arguments:
    -

    The llvm.memory.barrier intrinsic requires five boolean arguments. - The first four arguments enables a specific barrier as listed below. The - fifth argument specifies that the barrier applies to io or device or uncached - memory.

    - -
      -
    • ll: load-load barrier
    • -
    • ls: load-store barrier
    • -
    • sl: store-load barrier
    • -
    • ss: store-store barrier
    • -
    • device: barrier applies to device and uncached memory also.
    • -
    - -
    Semantics:
    -

    This intrinsic causes the system to enforce some ordering constraints upon - the loads and stores of the program. This barrier does not - indicate when any events will occur, it only enforces - an order in which they occur. For any of the specified pairs of load - and store operations (f.ex. load-load, or store-load), all of the first - operations preceding the barrier will complete before any of the second - operations succeeding the barrier begin. Specifically the semantics for each - pairing is as follows:

    - -
      -
    • ll: All loads before the barrier must complete before any load - after the barrier begins.
    • -
    • ls: All loads before the barrier must complete before any - store after the barrier begins.
    • -
    • ss: All stores before the barrier must complete before any - store after the barrier begins.
    • -
    • sl: All stores before the barrier must complete before any - load after the barrier begins.
    • -
    - -

    These semantics are applied with a logical "and" behavior when more than one - is enabled in a single memory barrier intrinsic.

    - -

    Backends may implement stronger barriers than those requested when they do - not support as fine grained a barrier as requested. Some architectures do - not need all types of barriers and on such architectures, these become - noops.

    - -
    Example:
    -
    -%mallocP  = tail call i8* @malloc(i32 ptrtoint (i32* getelementptr (i32* null, i32 1) to i32))
    -%ptr      = bitcast i8* %mallocP to i32*
    -            store i32 4, %ptr
    -
    -%result1  = load i32* %ptr      ; yields {i32}:result1 = 4
    -            call void @llvm.memory.barrier(i1 false, i1 true, i1 false, i1 false, i1 true)
    -                                ; guarantee the above finishes
    -            store i32 8, %ptr   ; before this begins
    -
    - -
    - - -

    - 'llvm.atomic.cmp.swap.*' Intrinsic -

    - -
    - -
    Syntax:
    -

    This is an overloaded intrinsic. You can use llvm.atomic.cmp.swap on - any integer bit width and for different address spaces. Not all targets - support all bit widths however.

    - -
    -  declare i8 @llvm.atomic.cmp.swap.i8.p0i8(i8* <ptr>, i8 <cmp>, i8 <val>)
    -  declare i16 @llvm.atomic.cmp.swap.i16.p0i16(i16* <ptr>, i16 <cmp>, i16 <val>)
    -  declare i32 @llvm.atomic.cmp.swap.i32.p0i32(i32* <ptr>, i32 <cmp>, i32 <val>)
    -  declare i64 @llvm.atomic.cmp.swap.i64.p0i64(i64* <ptr>, i64 <cmp>, i64 <val>)
    -
    - -
    Overview:
    -

    This loads a value in memory and compares it to a given value. If they are - equal, it stores a new value into the memory.

    - -
    Arguments:
    -

    The llvm.atomic.cmp.swap intrinsic takes three arguments. The result - as well as both cmp and val must be integer values with the - same bit width. The ptr argument must be a pointer to a value of - this integer type. While any bit width integer may be used, targets may only - lower representations they support in hardware.

    - -
    Semantics:
    -

    This entire intrinsic must be executed atomically. It first loads the value - in memory pointed to by ptr and compares it with the - value cmp. If they are equal, val is stored into the - memory. The loaded value is yielded in all cases. This provides the - equivalent of an atomic compare-and-swap operation within the SSA - framework.

    - -
    Examples:
    -
    -%mallocP  = tail call i8* @malloc(i32 ptrtoint (i32* getelementptr (i32* null, i32 1) to i32))
    -%ptr      = bitcast i8* %mallocP to i32*
    -            store i32 4, %ptr
    -
    -%val1     = add i32 4, 4
    -%result1  = call i32 @llvm.atomic.cmp.swap.i32.p0i32(i32* %ptr, i32 4, %val1)
    -                                          ; yields {i32}:result1 = 4
    -%stored1  = icmp eq i32 %result1, 4       ; yields {i1}:stored1 = true
    -%memval1  = load i32* %ptr                ; yields {i32}:memval1 = 8
    -
    -%val2     = add i32 1, 1
    -%result2  = call i32 @llvm.atomic.cmp.swap.i32.p0i32(i32* %ptr, i32 5, %val2)
    -                                          ; yields {i32}:result2 = 8
    -%stored2  = icmp eq i32 %result2, 5       ; yields {i1}:stored2 = false
    -
    -%memval2  = load i32* %ptr                ; yields {i32}:memval2 = 8
    -
    - + dependent code, turning it into a function. Then tramp needs to be + passed to llvm.adjust.trampoline to get a pointer + which can be bitcast (to a new function) and + called. The new function's signature is the same as that of + func with any arguments marked with the nest attribute + removed. At most one such nest argument is allowed, and it must be of + pointer type. Calling the new function is equivalent to calling func + with the same argument list, but with nval used for the missing + nest argument. If, after calling llvm.init.trampoline, the + memory pointed to by tramp is modified, then the effect of any later call + to the returned function pointer is undefined.

    - 'llvm.atomic.swap.*' Intrinsic -

    - -
    -
    Syntax:
    - -

    This is an overloaded intrinsic. You can use llvm.atomic.swap on any - integer bit width. Not all targets support all bit widths however.

    - -
    -  declare i8 @llvm.atomic.swap.i8.p0i8(i8* <ptr>, i8 <val>)
    -  declare i16 @llvm.atomic.swap.i16.p0i16(i16* <ptr>, i16 <val>)
    -  declare i32 @llvm.atomic.swap.i32.p0i32(i32* <ptr>, i32 <val>)
    -  declare i64 @llvm.atomic.swap.i64.p0i64(i64* <ptr>, i64 <val>)
    -
    - -
    Overview:
    -

    This intrinsic loads the value stored in memory at ptr and yields - the value from memory. It then stores the value in val in the memory - at ptr.

    - -
    Arguments:
    -

    The llvm.atomic.swap intrinsic takes two arguments. Both - the val argument and the result must be integers of the same bit - width. The first argument, ptr, must be a pointer to a value of this - integer type. The targets may only lower integer representations they - support.

    - -
    Semantics:
    -

    This intrinsic loads the value pointed to by ptr, yields it, and - stores val back into ptr atomically. This provides the - equivalent of an atomic swap operation within the SSA framework.

    - -
    Examples:
    -
    -%mallocP  = tail call i8* @malloc(i32 ptrtoint (i32* getelementptr (i32* null, i32 1) to i32))
    -%ptr      = bitcast i8* %mallocP to i32*
    -            store i32 4, %ptr
    -
    -%val1     = add i32 4, 4
    -%result1  = call i32 @llvm.atomic.swap.i32.p0i32(i32* %ptr, i32 %val1)
    -                                        ; yields {i32}:result1 = 4
    -%stored1  = icmp eq i32 %result1, 4     ; yields {i1}:stored1 = true
    -%memval1  = load i32* %ptr              ; yields {i32}:memval1 = 8
    -
    -%val2     = add i32 1, 1
    -%result2  = call i32 @llvm.atomic.swap.i32.p0i32(i32* %ptr, i32 %val2)
    -                                        ; yields {i32}:result2 = 8
    -
    -%stored2  = icmp eq i32 %result2, 8     ; yields {i1}:stored2 = true
    -%memval2  = load i32* %ptr              ; yields {i32}:memval2 = 2
    -
    - -
    - - -

    - 'llvm.atomic.load.add.*' Intrinsic -

    - -
    - -
    Syntax:
    -

    This is an overloaded intrinsic. You can use llvm.atomic.load.add on - any integer bit width. Not all targets support all bit widths however.

    - -
    -  declare i8 @llvm.atomic.load.add.i8.p0i8(i8* <ptr>, i8 <delta>)
    -  declare i16 @llvm.atomic.load.add.i16.p0i16(i16* <ptr>, i16 <delta>)
    -  declare i32 @llvm.atomic.load.add.i32.p0i32(i32* <ptr>, i32 <delta>)
    -  declare i64 @llvm.atomic.load.add.i64.p0i64(i64* <ptr>, i64 <delta>)
    -
    - -
    Overview:
    -

    This intrinsic adds delta to the value stored in memory - at ptr. It yields the original value at ptr.

    - -
    Arguments:
    -

    The intrinsic takes two arguments, the first a pointer to an integer value - and the second an integer value. The result is also an integer value. These - integer types can have any bit width, but they must all have the same bit - width. The targets may only lower integer representations they support.

    - -
    Semantics:
    -

    This intrinsic does a series of operations atomically. It first loads the - value stored at ptr. It then adds delta, stores the result - to ptr. It yields the original value stored at ptr.

    - -
    Examples:
    -
    -%mallocP  = tail call i8* @malloc(i32 ptrtoint (i32* getelementptr (i32* null, i32 1) to i32))
    -%ptr      = bitcast i8* %mallocP to i32*
    -            store i32 4, %ptr
    -%result1  = call i32 @llvm.atomic.load.add.i32.p0i32(i32* %ptr, i32 4)
    -                                ; yields {i32}:result1 = 4
    -%result2  = call i32 @llvm.atomic.load.add.i32.p0i32(i32* %ptr, i32 2)
    -                                ; yields {i32}:result2 = 8
    -%result3  = call i32 @llvm.atomic.load.add.i32.p0i32(i32* %ptr, i32 5)
    -                                ; yields {i32}:result3 = 10
    -%memval1  = load i32* %ptr      ; yields {i32}:memval1 = 15
    -
    - -
    - - -

    - 'llvm.atomic.load.sub.*' Intrinsic -

    - -
    - -
    Syntax:
    -

    This is an overloaded intrinsic. You can use llvm.atomic.load.sub on - any integer bit width and for different address spaces. Not all targets - support all bit widths however.

    - -
    -  declare i8 @llvm.atomic.load.sub.i8.p0i32(i8* <ptr>, i8 <delta>)
    -  declare i16 @llvm.atomic.load.sub.i16.p0i32(i16* <ptr>, i16 <delta>)
    -  declare i32 @llvm.atomic.load.sub.i32.p0i32(i32* <ptr>, i32 <delta>)
    -  declare i64 @llvm.atomic.load.sub.i64.p0i32(i64* <ptr>, i64 <delta>)
    -
    - -
    Overview:
    -

    This intrinsic subtracts delta to the value stored in memory at - ptr. It yields the original value at ptr.

    - -
    Arguments:
    -

    The intrinsic takes two arguments, the first a pointer to an integer value - and the second an integer value. The result is also an integer value. These - integer types can have any bit width, but they must all have the same bit - width. The targets may only lower integer representations they support.

    - -
    Semantics:
    -

    This intrinsic does a series of operations atomically. It first loads the - value stored at ptr. It then subtracts delta, stores the - result to ptr. It yields the original value stored - at ptr.

    - -
    Examples:
    -
    -%mallocP  = tail call i8* @malloc(i32 ptrtoint (i32* getelementptr (i32* null, i32 1) to i32))
    -%ptr      = bitcast i8* %mallocP to i32*
    -            store i32 8, %ptr
    -%result1  = call i32 @llvm.atomic.load.sub.i32.p0i32(i32* %ptr, i32 4)
    -                                ; yields {i32}:result1 = 8
    -%result2  = call i32 @llvm.atomic.load.sub.i32.p0i32(i32* %ptr, i32 2)
    -                                ; yields {i32}:result2 = 4
    -%result3  = call i32 @llvm.atomic.load.sub.i32.p0i32(i32* %ptr, i32 5)
    -                                ; yields {i32}:result3 = 2
    -%memval1  = load i32* %ptr      ; yields {i32}:memval1 = -3
    -
    - -
    - - -

    - - 'llvm.atomic.load.and.*' Intrinsic - -
    - - 'llvm.atomic.load.nand.*' Intrinsic - -
    - - 'llvm.atomic.load.or.*' Intrinsic - -
    - - 'llvm.atomic.load.xor.*' Intrinsic - -

    - -
    - -
    Syntax:
    -

    These are overloaded intrinsics. You can - use llvm.atomic.load_and, llvm.atomic.load_nand, - llvm.atomic.load_or, and llvm.atomic.load_xor on any integer - bit width and for different address spaces. Not all targets support all bit - widths however.

    - -
    -  declare i8 @llvm.atomic.load.and.i8.p0i8(i8* <ptr>, i8 <delta>)
    -  declare i16 @llvm.atomic.load.and.i16.p0i16(i16* <ptr>, i16 <delta>)
    -  declare i32 @llvm.atomic.load.and.i32.p0i32(i32* <ptr>, i32 <delta>)
    -  declare i64 @llvm.atomic.load.and.i64.p0i64(i64* <ptr>, i64 <delta>)
    -
    - -
    -  declare i8 @llvm.atomic.load.or.i8.p0i8(i8* <ptr>, i8 <delta>)
    -  declare i16 @llvm.atomic.load.or.i16.p0i16(i16* <ptr>, i16 <delta>)
    -  declare i32 @llvm.atomic.load.or.i32.p0i32(i32* <ptr>, i32 <delta>)
    -  declare i64 @llvm.atomic.load.or.i64.p0i64(i64* <ptr>, i64 <delta>)
    -
    - -
    -  declare i8 @llvm.atomic.load.nand.i8.p0i32(i8* <ptr>, i8 <delta>)
    -  declare i16 @llvm.atomic.load.nand.i16.p0i32(i16* <ptr>, i16 <delta>)
    -  declare i32 @llvm.atomic.load.nand.i32.p0i32(i32* <ptr>, i32 <delta>)
    -  declare i64 @llvm.atomic.load.nand.i64.p0i32(i64* <ptr>, i64 <delta>)
    -
    - -
    -  declare i8 @llvm.atomic.load.xor.i8.p0i32(i8* <ptr>, i8 <delta>)
    -  declare i16 @llvm.atomic.load.xor.i16.p0i32(i16* <ptr>, i16 <delta>)
    -  declare i32 @llvm.atomic.load.xor.i32.p0i32(i32* <ptr>, i32 <delta>)
    -  declare i64 @llvm.atomic.load.xor.i64.p0i32(i64* <ptr>, i64 <delta>)
    -
    - -
    Overview:
    -

    These intrinsics bitwise the operation (and, nand, or, xor) delta to - the value stored in memory at ptr. It yields the original value - at ptr.

    - -
    Arguments:
    -

    These intrinsics take two arguments, the first a pointer to an integer value - and the second an integer value. The result is also an integer value. These - integer types can have any bit width, but they must all have the same bit - width. The targets may only lower integer representations they support.

    - -
    Semantics:
    -

    These intrinsics does a series of operations atomically. They first load the - value stored at ptr. They then do the bitwise - operation delta, store the result to ptr. They yield the - original value stored at ptr.

    - -
    Examples:
    -
    -%mallocP  = tail call i8* @malloc(i32 ptrtoint (i32* getelementptr (i32* null, i32 1) to i32))
    -%ptr      = bitcast i8* %mallocP to i32*
    -            store i32 0x0F0F, %ptr
    -%result0  = call i32 @llvm.atomic.load.nand.i32.p0i32(i32* %ptr, i32 0xFF)
    -                                ; yields {i32}:result0 = 0x0F0F
    -%result1  = call i32 @llvm.atomic.load.and.i32.p0i32(i32* %ptr, i32 0xFF)
    -                                ; yields {i32}:result1 = 0xFFFFFFF0
    -%result2  = call i32 @llvm.atomic.load.or.i32.p0i32(i32* %ptr, i32 0F)
    -                                ; yields {i32}:result2 = 0xF0
    -%result3  = call i32 @llvm.atomic.load.xor.i32.p0i32(i32* %ptr, i32 0F)
    -                                ; yields {i32}:result3 = FF
    -%memval1  = load i32* %ptr      ; yields {i32}:memval1 = F0
    -
    - -
    - - -

    - - 'llvm.atomic.load.max.*' Intrinsic - -
    - - 'llvm.atomic.load.min.*' Intrinsic - -
    - - 'llvm.atomic.load.umax.*' Intrinsic - -
    - - 'llvm.atomic.load.umin.*' Intrinsic + + 'llvm.adjust.trampoline' Intrinsic

    Syntax:
    -

    These are overloaded intrinsics. You can use llvm.atomic.load_max, - llvm.atomic.load_min, llvm.atomic.load_umax, and - llvm.atomic.load_umin on any integer bit width and for different - address spaces. Not all targets support all bit widths however.

    -
    -  declare i8 @llvm.atomic.load.max.i8.p0i8(i8* <ptr>, i8 <delta>)
    -  declare i16 @llvm.atomic.load.max.i16.p0i16(i16* <ptr>, i16 <delta>)
    -  declare i32 @llvm.atomic.load.max.i32.p0i32(i32* <ptr>, i32 <delta>)
    -  declare i64 @llvm.atomic.load.max.i64.p0i64(i64* <ptr>, i64 <delta>)
    -
    - -
    -  declare i8 @llvm.atomic.load.min.i8.p0i8(i8* <ptr>, i8 <delta>)
    -  declare i16 @llvm.atomic.load.min.i16.p0i16(i16* <ptr>, i16 <delta>)
    -  declare i32 @llvm.atomic.load.min.i32.p0i32(i32* <ptr>, i32 <delta>)
    -  declare i64 @llvm.atomic.load.min.i64.p0i64(i64* <ptr>, i64 <delta>)
    -
    - -
    -  declare i8 @llvm.atomic.load.umax.i8.p0i8(i8* <ptr>, i8 <delta>)
    -  declare i16 @llvm.atomic.load.umax.i16.p0i16(i16* <ptr>, i16 <delta>)
    -  declare i32 @llvm.atomic.load.umax.i32.p0i32(i32* <ptr>, i32 <delta>)
    -  declare i64 @llvm.atomic.load.umax.i64.p0i64(i64* <ptr>, i64 <delta>)
    -
    - -
    -  declare i8 @llvm.atomic.load.umin.i8.p0i8(i8* <ptr>, i8 <delta>)
    -  declare i16 @llvm.atomic.load.umin.i16.p0i16(i16* <ptr>, i16 <delta>)
    -  declare i32 @llvm.atomic.load.umin.i32.p0i32(i32* <ptr>, i32 <delta>)
    -  declare i64 @llvm.atomic.load.umin.i64.p0i64(i64* <ptr>, i64 <delta>)
    +  declare i8* @llvm.adjust.trampoline(i8* <tramp>)
     
    Overview:
    -

    These intrinsics takes the signed or unsigned minimum or maximum of - delta and the value stored in memory at ptr. It yields the - original value at ptr.

    +

    This performs any required machine-specific adjustment to the address of a + trampoline (passed as tramp).

    Arguments:
    -

    These intrinsics take two arguments, the first a pointer to an integer value - and the second an integer value. The result is also an integer value. These - integer types can have any bit width, but they must all have the same bit - width. The targets may only lower integer representations they support.

    +

    tramp must point to a block of memory which already has trampoline code + filled in by a previous call to llvm.init.trampoline + .

    Semantics:
    -

    These intrinsics does a series of operations atomically. They first load the - value stored at ptr. They then do the signed or unsigned min or - max delta and the value, store the result to ptr. They - yield the original value stored at ptr.

    - -
    Examples:
    -
    -%mallocP  = tail call i8* @malloc(i32 ptrtoint (i32* getelementptr (i32* null, i32 1) to i32))
    -%ptr      = bitcast i8* %mallocP to i32*
    -            store i32 7, %ptr
    -%result0  = call i32 @llvm.atomic.load.min.i32.p0i32(i32* %ptr, i32 -2)
    -                                ; yields {i32}:result0 = 7
    -%result1  = call i32 @llvm.atomic.load.max.i32.p0i32(i32* %ptr, i32 8)
    -                                ; yields {i32}:result1 = -2
    -%result2  = call i32 @llvm.atomic.load.umin.i32.p0i32(i32* %ptr, i32 10)
    -                                ; yields {i32}:result2 = 8
    -%result3  = call i32 @llvm.atomic.load.umax.i32.p0i32(i32* %ptr, i32 30)
    -                                ; yields {i32}:result3 = 8
    -%memval1  = load i32* %ptr      ; yields {i32}:memval1 = 30
    -
    +

    On some architectures the address of the code to be executed needs to be + different to the address where the trampoline is actually stored. This + intrinsic returns the executable address corresponding to tramp + after performing the required machine specific adjustments. + The pointer returned can then be bitcast and + executed. +

    @@ -7943,7 +8284,7 @@ LLVM.

    Semantics:

    This intrinsic allows annotation of local variables with arbitrary strings. This can be useful for special purpose optimizations that want to look for - these annotations. These have no other defined use, they are ignored by code + these annotations. These have no other defined use; they are ignored by code generation and optimization.

    @@ -7979,7 +8320,7 @@ LLVM.

    Semantics:

    This intrinsic allows annotations to be put on arbitrary expressions with arbitrary strings. This can be useful for special purpose optimizations that - want to look for these annotations. These have no other defined use, they + want to look for these annotations. These have no other defined use; they are ignored by code generation and optimization.

    @@ -8077,11 +8418,35 @@ LLVM.

    compile time.

    + +

    + 'llvm.expect' Intrinsic +

    + +
    + +
    Syntax:
    +
    +  declare i32 @llvm.expect.i32(i32 <val>, i32 <expected_val>)
    +  declare i64 @llvm.expect.i64(i64 <val>, i64 <expected_val>)
    +
    +
    Overview:
    +

    The llvm.expect intrinsic provides information about expected (the + most probable) value of val, which can be used by optimizers.

    + +
    Arguments:
    +

    The llvm.expect intrinsic takes two arguments. The first + argument is a value. The second argument is an expected value, this needs to + be a constant value, variables are not allowed.

    + +
    Semantics:
    +

    This intrinsic is lowered to the val.

    +
    In0In1OutIn0In1Out
    0