X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=docs%2FLangRef.html;h=96d4fa1086869383e65b85e926b1bec74120b1e2;hb=9030d384c404ef2d28e2464cddcfbea268a12109;hp=1504a807625b500eaf4eb307179f94a2afc7cd40;hpb=9dee3acd91d474dd2dd85efe1498ca2f65975d33;p=oota-llvm.git diff --git a/docs/LangRef.html b/docs/LangRef.html index 1504a807625..96d4fa10868 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -24,7 +24,10 @@
...because the definition of %x does not dominate all of its uses. The LLVM infrastructure provides a verification pass that may @@ -256,6 +271,7 @@ automatically run by the parser after parsing input assembly and by the optimizer before it outputs bytecode. The violations pointed out by the verifier pass indicate bugs in transformation passes or input to the parser.
+ @@ -273,7 +289,7 @@ purposes: For example, %foo, %DivisionByZero, %a.really.long.identifier. The actual regular expression used is '%[a-zA-Z$._][a-zA-Z$._0-9]*'. Identifiers which require other characters in their names can be surrounded - with quotes. In this way, anything except a " character can be used + with quotes. In this way, anything except a " character can be used in a name.Reserved words in LLVM are very similar to reserved words in other -languages. There are keywords for different opcodes ('add', 'cast', 'ret', etc...), for primitive type names ('void', 'uint', etc...), +languages. There are keywords for different opcodes +('add', + 'bitcast', + 'ret', etc...), for primitive type names ('void', 'i32', etc...), and others. These reserved words cannot conflict with variable names, because none of them start with a '%' character.
@@ -302,23 +319,29 @@ none of them start with a '%' character.The easy way:
+After strength reduction:
+And the hard way:
+- add uint %X, %X ; yields {uint}:%0 - add uint %0, %0 ; yields {uint}:%1 - %result = add uint %1, %1 +add i32 %X, %X ; yields {i32}:%0 +add i32 %0, %0 ; yields {i32}:%1 +%result = add i32 %1, %1+
This last way of multiplying %X by 8 illustrates several important lexical features of LLVM:
@@ -359,27 +382,27 @@ combined together with the LLVM linker, which merges function (and global variable) definitions, resolves forward declarations, and merges symbol table entries. Here is an example of the "hello world" module: +; Declare the string constant as a global constant... -%.LC0 = internal constant [13 x sbyte] c"hello world\0A\00" ; [13 x sbyte]* +@.LC0 = internal constant [13 x i8] c"hello world\0A\00" ; [13 x i8]* ; External declaration of the puts function -declare int %puts(sbyte*) ; int(sbyte*)* - -; Global variable / Function body section separator -implementation +declare i32 @puts(i8 *) ; i32(i8 *)* ; Definition of main function -int %main() { ; int()* - ; Convert [13x sbyte]* to sbyte *... +define i32 @main() { ; i32()* + ; Convert [13x i8 ]* to i8 *... %cast210 = getelementptr [13 x sbyte]* %.LC0, long 0, long 0 ; sbyte* + href="#i_getelementptr">getelementptr [13 x i8 ]* @.LC0, i64 0, i64 0 ; i8 * ; Call puts function to write out the string to stdout... call int %puts(sbyte* %cast210) ; int + href="#i_call">call i32 @puts(i8 * %cast210) ; i32 ret int 0+ href="#i_ret">ret i32 0
}
This example is made up of a global variable named ".LC0", an external declaration of the "puts" @@ -392,13 +415,6 @@ represented by a pointer to a memory location (in this case, a pointer to an array of char, and a pointer to a function), and have one of the following linkage types.
-Due to a limitation in the current LLVM assembly parser (it is limited by -one-token lookahead), modules are split into two pieces by the "implementation" -keyword. Global variable prototypes and definitions must occur before the -keyword, and function definitions must occur after it. Function prototypes may -occur either before or after it. In the future, the implementation keyword may -become a noop, if the parser gets smarter.
- @@ -421,23 +437,26 @@ All Global Variables and Functions have one of the following types of linkage: an internal global value may cause the internal to be renamed as necessary to avoid collisions. Because the symbol is internal to the module, all references can be updated. This corresponds to the notion of the - 'static' keyword in C, or the idea of "anonymous namespaces" in C++. + 'static' keyword in C.The next two types of linkage are targeted for Microsoft Windows platform @@ -467,6 +488,7 @@ All Global Variables and Functions have one of the following types of linkage: DLLs.
+For example, since the ".LC0"
+ For example, since the ".LC0"
variable is defined to be internal, if another module defined a ".LC0"
variable and was linked with this one, one of the two would be renamed,
preventing a collision. Since "main" and "puts" are
external (i.e., lacking any linkage 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".
It is illegal for a function declaration +to have any linkage type other than "externally visible", dllimport, +or extern_weak.
+Aliases can have only external, internal and weak +linkages. @@ -516,20 +541,7 @@ the future:
+All Global Variables and Functions have one of the following visibility styles: +
+ +Global variables define regions of memory allocated at compilation time instead of run-time. Global variables may optionally be initialized, may have -an explicit section to be placed in, and may -have an optional explicit alignment specified. A -variable may be defined as a global "constant," which indicates that the -contents of the variable will never be modified (enabling better +an explicit section to be placed in, and may have an optional explicit alignment +specified. A variable may be defined as "thread_local", which means that it +will not be shared by threads (each thread will have a separated copy of the +variable). A variable may be defined as a global "constant," which indicates +that the contents of the variable will never be modified (enabling better optimization, allowing the global data to be placed in the read-only section of an executable, etc). Note that variables that need runtime initialization cannot be marked "constant" as there is a store to the variable.
@@ -608,6 +662,15 @@ to whatever it feels convenient. If an explicit alignment is specified, the global is forced to have at least that much alignment. All alignments must be a power of 2. +For example, the following defines a global with an initializer, section, + and alignment:
+ ++%G = constant float 1.0, section "foo", align 4 ++
LLVM function definitions consist of an optional linkage -type, an optional calling convention, a return -type, a function name, a (possibly empty) argument list, an optional section, -an optional alignment, an opening curly brace, -a list of basic blocks, and a closing curly brace. LLVM function declarations -are defined with the "declare" keyword, an optional calling convention, a return type, a function name, -a possibly empty list of arguments, and an optional alignment.
+LLVM function definitions consist of the "define" keyord, +an optional linkage type, an optional +visibility style, an optional +calling convention, a return type, an optional +parameter attribute for the return type, a function +name, a (possibly empty) argument list (each with optional +parameter attributes), an optional section, an +optional alignment, an opening curly brace, a list of basic blocks, and a +closing curly brace. + +LLVM function declarations consist of the "declare" keyword, an +optional linkage type, an optional +visibility style, an optional +calling convention, a return type, an optional +parameter attribute for the return type, a function +name, a possibly empty list of arguments, and an optional alignment.
A function definition contains a list of basic blocks, forming the CFG for the function. Each basic block may optionally start with a label (giving the @@ -633,7 +704,7 @@ basic block a symbol table entry), contains a list of instructions, and ends with a terminator instruction (such as a branch or function return).
-The first basic block in a program is special in two ways: it is immediately +
The first basic block in a function is special in two ways: it is immediately executed on entrance to the function, and it is not allowed to have predecessor basic blocks (i.e. there can not be any branches to the entry block of a function). Because the block can have no predecessors, it also cannot have any @@ -655,6 +726,85 @@ a power of 2.
Aliases act as "second name" for the aliasee value (which can be either + function or global variable or bitcast of global value). Aliases may have an + optional linkage type, and an + optional visibility style.
+ ++@<Name> = [Linkage] [Visibility] alias <AliaseeTy> @<Aliasee> ++
The return type and each parameter of a function type may have a set of + parameter attributes associated with them. Parameter attributes are + used to communicate additional information about the result or parameters of + a function. Parameter attributes are considered to be part of the function + type so two functions types that differ only by the parameter attributes + are different function types.
+ +Parameter attributes are simple keywords that follow the type specified. If + multiple parameter attributes are needed, they are space separated. For + example:
+ ++%someFunc = i16 (i8 sext %someParam) zext +%someFunc = i16 (i8 zext %someParam) zext ++
Note that the two function types above are unique because the parameter has + a different attribute (sext in the first one, zext in the second). Also note + that the attribute for the function result (zext) comes immediately after the + argument list.
+ +Currently, only the following parameter attributes are defined:
+- module asm "inline asm code goes here" - module asm "more can go here" -
+module asm "inline asm code goes here" +module asm "more can go here" ++
The strings can contain any character by escaping non-printable characters. The escape sequence used is simply "\xx" where "xx" is the two digit hex code @@ -684,6 +836,81 @@ desired. The syntax is very simple:
A module may specify a target specific data layout string that specifies how +data is to be laid out in memory. The syntax for the data layout is simply:
+target datalayout = "layout specification"+
The layout specification consists of a list of specifications +separated by the minus sign character ('-'). Each specification starts with a +letter and may include other information after the letter to define some +aspect of the data layout. The specifications accepted are as follows:
+When constructing the data layout for a given target, LLVM starts with a +default set of specifications which are then (possibly) overriden by the +specifications in the datalayout keyword. The default specifications +are given in this list:
+When llvm is determining the alignment for a given type, it uses the +following rules: +
Type | Description |
---|---|
void | No value |
ubyte | Unsigned 8-bit value |
ushort | Unsigned 16-bit value |
uint | Unsigned 32-bit value |
ulong | Unsigned 64-bit value |
float | 32-bit floating point value |
void | No value |
label | Branch destination |
Type | Description |
---|---|
bool | True or False value |
sbyte | Signed 8-bit value |
short | Signed 16-bit value |
int | Signed 32-bit value |
long | Signed 64-bit value |
double | 64-bit floating point value |
float | 32-bit floating point value |
double | 64-bit floating point value |
Classification | Types | |
---|---|---|
signed | -sbyte, short, int, long, float, double | -|
unsigned | -ubyte, ushort, uint, ulong | -|
integer | -ubyte, sbyte, ushort, short, uint, int, ulong, long | -|
integral | -bool, ubyte, sbyte, ushort, short, uint, int, ulong, long - | +i1, i2, i3, ... i8, ... i16, ... i32, ... i64, ... |
floating point | @@ -773,9 +978,9 @@ classifications:||
first class | -bool, ubyte, sbyte, ushort, short, uint, int, ulong, long, - float, double, pointer, - packed |
+ i1, ..., float, double, + pointer,vector + |
The integer type is a very simple derived type that simply specifies an +arbitrary bit width for the integer type desired. Any bit width from 1 bit to +2^23-1 (about 8 million) can be specified.
+ ++ iN ++ +
The number of bits the integer will occupy is specified by the N +value.
+ +
+ i1 + i4 + i8 + i16 + i32 + i42 + i64 + i1942652 + |
+
+ A boolean integer of 1 bit + A nibble sized integer of 4 bits. + A byte sized integer of 8 bits. + A half word sized integer of 16 bits. + A word sized integer of 32 bits. + An integer whose bit width is the answer. + A double word sized integer of 64 bits. + A really big integer of over 1 million bits. + |
+
- [40 x int ] - [41 x int ] - [40 x uint] + [40 x i32 ] + [41 x i32 ] + [40 x i8] |
- Array of 40 integer values. - Array of 41 integer values. - Array of 40 unsigned integer values. + Array of 40 32-bit integer values. + Array of 41 32-bit integer values. + Array of 40 8-bit integer values. |
- [3 x [4 x int]] + [3 x [4 x i32]] [12 x [10 x float]] - [2 x [3 x [4 x uint]]] + [2 x [3 x [4 x i16]]] |
- 3x4 array of integer values. + 3x4 array of 32-bit integer values. 12x10 array of single precision floating point values. - 2x3x4 array of unsigned integer values. + 2x3x4 array of 16-bit integer values. |
- int (int) - float (int, int *) * - int (sbyte *, ...) + | i32 (i32) | +function taking an i32, returning an i32 | -
- function taking an int, returning an int - Pointer to a function that takes an - int and a pointer to int, - returning float. - A vararg function that takes at least one pointer - to sbyte (signed char in C), which returns an integer. This is - the signature for printf in LLVM. + |
float (i16 sext, i32 *) * + | +Pointer to a function that takes + an i16 that should be sign extended and a + pointer to i32, returning + float. + | +||
i32 (i8*, ...) | +A vararg function that takes at least one + pointer to i8 (char in C), + which returns an integer. This is the signature for printf in + LLVM. |
- { int, int, int } - { float, int (int) * } - |
-
- a triple of three int values - A pair, where the first element is a float and the second element - is a pointer to a function - that takes an int, returning an int. - |
+ { i32, i32, i32 } | +A triple of three i32 values | +
{ float, i32 (i32) * } | +A pair, where the first element is a float and the + second element is a pointer to a + function that takes an i32, returning + an i32. | +
The packed structure type is used to represent a collection of data members +together in memory. There is no padding between fields. Further, the alignment +of a packed structure is 1 byte. The elements of a packed structure may +be any type that has a size.
+Structures are accessed using 'load +and 'store' by getting a pointer to a +field with the 'getelementptr' +instruction.
+< { <type list> } >+
< { i32, i32, i32 } > | +A triple of three i32 values | +
< { float, i32 (i32) * } > | +A pair, where the first element is a float and the + second element is a pointer to a + function that takes an i32, returning + an i32. |
- [4x int]* - int (int *) * + [4x i32]* + i32 (i32 *) * |
A pointer to array of
- four int values + four i32 values A pointer to a function that takes an int*, returning an - int. + href="#t_function">function that takes an i32*, returning an + i32. |
A packed type is a simple derived type that represents a vector -of elements. Packed types are used when multiple primitive data +
A vector type is a simple derived type that represents a vector +of elements. Vector types are used when multiple primitive data are operated in parallel using a single instruction (SIMD). -A packed type requires a size (number of +A vector type requires a size (number of elements) and an underlying primitive data type. Vectors must have a power -of two length (1, 2, 4, 8, 16 ...). Packed types are +of two length (1, 2, 4, 8, 16 ...). Vector types are considered first class.
The number of elements is a constant integer value; elementtype may -be any integral or floating point type.
+be any integer or floating point type.
- <4 x int> + <4 x i32> <8 x float> - <2 x uint> + <2 x i64> |
- Packed vector of 4 integer values. - Packed vector of 8 floating-point values. - Packed vector of 2 unsigned integer values. + Vector of 4 32-bit integer values. + Vector of 8 floating-point values. + Vector of 2 64-bit integer values. |
- %X = global int 17 - %Y = global int 42 - %Z = global [2 x int*] [ int* %X, int* %Y ] +@X = global i32 17 +@Y = global i32 42 +@Z = global [2 x i32*] [ i32* @X, i32* @Y ]+
- int(int) asm "bswap $0", "=r,r" +i32 (i32) asm "bswap $0", "=r,r"+
Inline assembler expressions may only be used as the callee operand of a call instruction. Thus, typically we have:
+Inline asms with side effects not visible in the constraint list must be marked @@ -1308,9 +1615,11 @@ as having side effects. This is done through the use of the 'sideeffect' keyword, like so:
+- call void asm sideeffect "eieio", ""() +call void asm sideeffect "eieio", ""()+
TODO: The format of the asm and constraints string still need to be documented here. Constraints on what can be done (e.g. duplication, moving, etc @@ -1385,7 +1694,7 @@ at the beginning of the "normal" destination block. If the instruction returns a value, that value shall set the call or invoke instruction's return value.
ret int 5 ; Return an integer value of 5 +ret i32 5 ; Return an integer value of 5 ret void ; Return from a void function@@ -1393,7 +1702,7 @@ return value.Syntax:
-br bool <cond>, label <iftrue>, label <iffalse>
br label <dest> ; Unconditional branch +br i1 <cond>, label <iftrue>, label <iffalse>
br label <dest> ; Unconditional branchOverview:
The 'br' instruction is used to cause control flow to @@ -1402,17 +1711,17 @@ two forms of this instruction, corresponding to a conditional branch and an unconditional branch.
Arguments:
The conditional branch form of the 'br' instruction takes a -single 'bool' value and two 'label' values. The -unconditional form of the 'br' instruction takes a single 'label' -value as a target.
+single 'i1' value and two 'label' values. The +unconditional form of the 'br' instruction takes a single +'label' value as a target.Semantics:
-Upon execution of a conditional 'br' instruction, the 'bool' +
Upon execution of a conditional 'br' instruction, the 'i1' argument is evaluated. If the value is true, control flows to the 'iftrue' label argument. If "cond" is false, control flows to the 'iffalse' label argument.
Example:
-Test:+
%cond = seteq int %a, %b
br bool %cond, label %IfEqual, label %IfUnequal
IfEqual:
ret int 1
IfUnequal:
ret int 0Test:
%cond = icmp eq, i32 %a, %b
br i1 %cond, label %IfEqual, label %IfUnequal
IfEqual:
ret i32 1
IfUnequal:
ret i32 0@@ -1460,16 +1769,16 @@ branches or with a lookup table.@@ -1504,7 +1813,7 @@ continued at the dynamically nearest "exception" label.; Emulate a conditional br instruction - %Val = zext bool %value to int - switch int %Val, label %truedest [int 0, label %falsedest ] + %Val = zext i1 %value to i32 + switch i32 %Val, label %truedest [i32 0, label %falsedest ] ; Emulate an unconditional br instruction - switch uint 0, label %dest [ ] + switch i32 0, label %dest [ ] ; Implement a jump table: - switch uint %val, label %otherwise [ uint 0, label %onzero - uint 1, label %onone - uint 2, label %ontwo ] + switch i32 %val, label %otherwise [ i32 0, label %onzero + i32 1, label %onone + i32 2, label %ontwo ]
- - The optional "cconv" marker indicates which calling + The optional "cconv" marker indicates which calling convention the call should use. If none is specified, the call defaults to using C calling conventions.
@@ -1544,10 +1853,10 @@ exception. Additionally, this is important for implementation ofExample:
- %retval = invoke int %Test(int 15) to label %Continue - unwind label %TestCleanup ; {int}:retval set - %retval = invoke coldcc int %Test(int 15) to label %Continue - unwind label %TestCleanup ; {int}:retval set + %retval = invoke i32 %Test(i32 15) to label %Continue + unwind label %TestCleanup ; {i32}:retval set + %retval = invoke coldcc i32 %Test(i32 15) to label %Continue + unwind label %TestCleanup ; {i32}:retval set@@ -1613,7 +1922,7 @@ no-return function cannot be reached, and other facts.Binary operators are used to do most of the computation in a program. They require two operands, execute an operation on them, and produce a single value. The operands might represent -multiple data, as is the case with the packed data type. +multiple data, as is the case with the vector data type. The result value of a binary operator is not necessarily the same type as its operands.
There are several different binary operators:
@@ -1630,13 +1939,13 @@ InstructionArguments:
The two arguments to the 'add' instruction must be either integer or floating point values. - This instruction can also take packed versions of the values. + This instruction can also take vector versions of the values. Both arguments must have identical types.
Semantics:
The value produced is the integer or floating point sum of the two operands.
Example:
-<result> = add int 4, %var ; yields {int}:result = 4 + %var +<result> = add i32 4, %var ; yields {i32}:result = 4 + %var@@ -1655,14 +1964,15 @@ instruction present in most other intermediate representations.The two arguments to the 'sub' instruction must be either integer or floating point values. -This instruction can also take packed versions of the values. +This instruction can also take vector versions of the values. Both arguments must have identical types.
Semantics:
The value produced is the integer or floating point difference of the two operands.
Example:
-<result> = sub int 4, %var ; yields {int}:result = 4 - %var - <result> = sub int 0, %val ; yields {int}:result = -%var ++ <result> = sub i32 4, %var ; yields {i32}:result = 4 - %var + <result> = sub i32 0, %val ; yields {i32}:result = -%var@@ -1679,15 +1989,16 @@ operands.The two arguments to the 'mul' instruction must be either integer or floating point values. -This instruction can also take packed versions of the values. +This instruction can also take vector versions of the values. Both arguments must have identical types.
Semantics:
The value produced is the integer or floating point product of the two operands.
-There is no signed vs unsigned multiplication. The appropriate -action is taken based on the type of the operand.
+Because the operands are the same width, the result of an integer +multiplication is the same whether the operands should be deemed unsigned or +signed.
Example:
-<result> = mul int 4, %var ; yields {int}:result = 4 * %var +<result> = mul i32 4, %var ; yields {i32}:result = 4 * %var@@ -1703,14 +2014,14 @@ operands.Arguments:
The two arguments to the 'udiv' instruction must be integer values. Both arguments must have identical -types. This instruction can also take packed versions +types. This instruction can also take vector versions of the values in which case the elements must be integers.
Semantics:
The value produced is the unsigned integer quotient of the two operands. This instruction always performs an unsigned division operation, regardless of whether the arguments are unsigned or not.
Example:
-<result> = udiv uint 4, %var ; yields {uint}:result = 4 / %var +<result> = udiv i32 4, %var ; yields {i32}:result = 4 / %var@@ -1726,14 +2037,14 @@ operands.Arguments:
The two arguments to the 'sdiv' instruction must be integer values. Both arguments must have identical -types. This instruction can also take packed versions +types. This instruction can also take vector versions of the values in which case the elements must be integers.
Semantics:
The value produced is the signed integer quotient of the two operands. This instruction always performs a signed division operation, regardless of whether the arguments are signed or not.
Example:
-<result> = sdiv int 4, %var ; yields {int}:result = 4 / %var +<result> = sdiv i32 4, %var ; yields {i32}:result = 4 / %var@@ -1747,10 +2058,10 @@ InstructionThe 'fdiv' instruction returns the quotient of its two operands.
Arguments:
-The two arguments to the 'div' instruction must be +
The two arguments to the 'fdiv' instruction must be floating point values. Both arguments must have -identical types. This instruction can also take packed -versions of the values in which case the elements must be floating point.
+identical types. This instruction can also take vector +versions of floating point values.Semantics:
The value produced is the floating point quotient of the two operands.
Example:
@@ -1776,7 +2087,7 @@ types. This instruction always performs an unsigned division to get the remainder, regardless of whether the arguments are unsigned or not.Example:
-<result> = urem uint 4, %var ; yields {uint}:result = 4 % %var +<result> = urem i32 4, %var ; yields {i32}:result = 4 % %var@@ -1796,13 +2107,15 @@ signed division of its two operands. types.Semantics:
This instruction returns the remainder of a division (where the result -has the same sign as the divisor), not the modulus (where the -result has the same sign as the dividend) of a value. For more -information about the difference, see var1), not the modulo +operator (where the result has the same sign as the divisor, var2) of +a value. For more information about the difference, see The -Math Forum.
+Math Forum. For a table of how this is implemented in various languages, +please see +Wikipedia: modulo operation.Example:
-<result> = srem int 4, %var ; yields {int}:result = 4 % %var +<result> = srem i32 4, %var ; yields {i32}:result = 4 % %var@@ -1825,64 +2138,102 @@ identical types.Example:
<result> = frem float 4.0, %var ; yields {float}:result = 4.0 % %var+ + + + +++ + +Bitwise binary operators are used to do various forms of +bit-twiddling in a program. They are generally very efficient +instructions and can commonly be strength reduced from other +instructions. They require two operands, execute an operation on them, +and produce a single value. The resulting value of the bitwise binary +operators is always the same type as its first operand.
++- +Syntax:
+<result> = shl <ty> <var1>, <var2> ; yields {ty}:result ++Overview:
+The 'shl' instruction returns the first operand shifted to +the left a specified number of bits.
+Arguments:
+Both arguments to the 'shl' instruction must be the same integer type.
+Semantics:
+The value produced is var1 * 2var2.
+Example:
+ <result> = shl i32 4, %var ; yields {i32}: 4 << %var + <result> = shl i32 4, 2 ; yields {i32}: 16 + <result> = shl i32 1, 10 ; yields {i32}: 1024 +- - + +Syntax:
-<result> = seteq <ty> <var1>, <var2> ; yields {bool}:result - <result> = setne <ty> <var1>, <var2> ; yields {bool}:result - <result> = setlt <ty> <var1>, <var2> ; yields {bool}:result - <result> = setgt <ty> <var1>, <var2> ; yields {bool}:result - <result> = setle <ty> <var1>, <var2> ; yields {bool}:result - <result> = setge <ty> <var1>, <var2> ; yields {bool}:result +<result> = lshr <ty> <var1>, <var2> ; yields {ty}:result+Overview:
-The 'setcc' family of instructions returns a boolean -value based on a comparison of their two operands.
+The 'lshr' instruction (logical shift right) returns the first +operand shifted to the right a specified number of bits with zero fill.
+Arguments:
-The two arguments to the 'setcc' instructions must -be of first class type (it is not possible -to compare 'label's, 'array's, 'structure' -or 'void' values, etc...). Both arguments must have identical -types.
+Both arguments to the 'lshr' instruction must be the same +integer type.
+Semantics:
-The 'seteq' instruction yields a true 'bool' -value if both operands are equal.
+
-The 'setne' instruction yields a true 'bool' -value if both operands are unequal.
-The 'setlt' instruction yields a true 'bool' -value if the first operand is less than the second operand.
-The 'setgt' instruction yields a true 'bool' -value if the first operand is greater than the second operand.
-The 'setle' instruction yields a true 'bool' -value if the first operand is less than or equal to the second operand.
-The 'setge' instruction yields a true 'bool' -value if the first operand is greater than or equal to the second -operand.This instruction always performs a logical shift right operation. The most +significant bits of the result will be filled with zero bits after the +shift.
+Example:
-<result> = seteq int 4, 5 ; yields {bool}:result = false - <result> = setne float 4, 5 ; yields {bool}:result = true - <result> = setlt uint 4, 5 ; yields {bool}:result = true - <result> = setgt sbyte 4, 5 ; yields {bool}:result = false - <result> = setle sbyte 4, 5 ; yields {bool}:result = true - <result> = setge sbyte 4, 5 ; yields {bool}:result = false ++ <result> = lshr i32 4, 1 ; yields {i32}:result = 2 + <result> = lshr i32 4, 2 ; yields {i32}:result = 1 + <result> = lshr i8 4, 3 ; yields {i8}:result = 0 + <result> = lshr i8 -2, 1 ; yields {i8}:result = 0x7FFFFFFF-+ @@ -1895,7 +2246,7 @@ Instruction its two operands.Bitwise binary operators are used to do various forms of -bit-twiddling in a program. They are generally very efficient -instructions and can commonly be strength reduced from other -instructions. They require two operands, execute an operation on them, -and produce a single value. The resulting value of the bitwise binary -operators is always the same type as its first operand.
+ +Syntax:
+<result> = ashr <ty> <var1>, <var2> ; yields {ty}:result ++ +Overview:
+The 'ashr' instruction (arithmetic shift right) returns the first +operand shifted to the right a specified number of bits with sign extension.
+ +Arguments:
+Both arguments to the 'ashr' instruction must be the same +integer type.
+ +Semantics:
+This instruction always performs an arithmetic shift right operation, +The most significant bits of the result will be filled with the sign bit +of var1.
+ +Example:
++ <result> = ashr i32 4, 1 ; yields {i32}:result = 2 + <result> = ashr i32 4, 2 ; yields {i32}:result = 1 + <result> = ashr i8 4, 3 ; yields {i8}:result = 0 + <result> = ashr i8 -2, 1 ; yields {i8}:result = -1 +Arguments:
The two arguments to the 'and' instruction must be integral values. Both arguments must have + href="#t_integer">integer values. Both arguments must have identical types.
Semantics:
The truth table used for the 'and' instruction is:
@@ -1932,9 +2283,9 @@ identical types.Example:
-<result> = and int 4, %var ; yields {int}:result = 4 & %var - <result> = and int 15, 40 ; yields {int}:result = 8 - <result> = and int 4, 8 ; yields {int}:result = 0 +<result> = and i32 4, %var ; yields {i32}:result = 4 & %var + <result> = and i32 15, 40 ; yields {i32}:result = 8 + <result> = and i32 4, 8 ; yields {i32}:result = 0@@ -1948,7 +2299,7 @@ identical types. or of its two operands.Arguments:
The two arguments to the 'or' instruction must be integral values. Both arguments must have + href="#t_integer">integer values. Both arguments must have identical types.
Semantics:
The truth table used for the 'or' instruction is:
@@ -1985,9 +2336,9 @@ identical types.Example:
-<result> = or int 4, %var ; yields {int}:result = 4 | %var - <result> = or int 15, 40 ; yields {int}:result = 47 - <result> = or int 4, 8 ; yields {int}:result = 12 +<result> = or i32 4, %var ; yields {i32}:result = 4 | %var + <result> = or i32 15, 40 ; yields {i32}:result = 47 + <result> = or i32 4, 8 ; yields {i32}:result = 12@@ -2003,7 +2354,7 @@ or of its two operands. The xor is used to implement the "one's complement" operation, which is the "~" operator in C.Arguments:
The two arguments to the 'xor' instruction must be integral values. Both arguments must have + href="#t_integer">integer values. Both arguments must have identical types.
Semantics:
The truth table used for the 'xor' instruction is:
@@ -2041,59 +2392,10 @@ identical types.
Example:
-<result> = xor int 4, %var ; yields {int}:result = 4 ^ %var - <result> = xor int 15, 40 ; yields {int}:result = 39 - <result> = xor int 4, 8 ; yields {int}:result = 12 - <result> = xor int %V, -1 ; yields {int}:result = ~%V -- - - --- - -Syntax:
-<result> = shl <ty> <var1>, ubyte <var2> ; yields {ty}:result --Overview:
-The 'shl' instruction returns the first operand shifted to -the left a specified number of bits.
-Arguments:
-The first argument to the 'shl' instruction must be an integer type. The second argument must be an 'ubyte' -type.
-Semantics:
-The value produced is var1 * 2var2.
-Example:
-<result> = shl int 4, ubyte %var ; yields {int}:result = 4 << %var - <result> = shl int 4, ubyte 2 ; yields {int}:result = 16 - <result> = shl int 1, ubyte 10 ; yields {int}:result = 1024 ---@@ -2105,7 +2407,7 @@ positions.Syntax:
-<result> = shr <ty> <var1>, ubyte <var2> ; yields {ty}:result --Overview:
-The 'shr' instruction returns the first operand shifted to -the right a specified number of bits.
-Arguments:
-The first argument to the 'shr' instruction must be an integer type. The second argument must be an 'ubyte' -type.
-Semantics:
-If the first argument is a signed type, the -most significant bit is duplicated in the newly free'd bit positions. -If the first argument is unsigned, zero bits shall fill the empty -positions.
-Example:
-<result> = shr int 4, ubyte %var ; yields {int}:result = 4 >> %var - <result> = shr uint 4, ubyte 1 ; yields {uint}:result = 2 - <result> = shr int 4, ubyte 2 ; yields {int}:result = 1 - <result> = shr sbyte 4, ubyte 3 ; yields {sbyte}:result = 0 - <result> = shr sbyte -2, ubyte 1 ; yields {sbyte}:result = -1 +<result> = xor i32 4, %var ; yields {i32}:result = 4 ^ %var + <result> = xor i32 15, 40 ; yields {i32}:result = 39 + <result> = xor i32 4, 8 ; yields {i32}:result = 12 + <result> = xor i32 %V, -1 ; yields {i32}:result = ~%V@@ -2169,14 +2471,14 @@ results are undefined.LLVM supports several instructions to represent vector operations in a -target-independent manner. This instructions cover the element-access and +target-independent manner. These instructions cover the element-access and vector-specific operations needed to process vectors effectively. While LLVM does directly support these vector operations, many sophisticated algorithms will want to use target-specific intrinsics to take full advantage of a specific @@ -2123,14 +2425,14 @@ target.
Syntax:
- <result> = extractelement <n x <ty>> <val>, uint <idx> ; yields <ty> + <result> = extractelement <n x <ty>> <val>, i32 <idx> ; yields <ty>Overview:
The 'extractelement' instruction extracts a single scalar -element from a packed vector at a specified index. +element from a vector at a specified index.
@@ -2138,7 +2440,7 @@ element from a packed vector at a specified index.The first operand of an 'extractelement' instruction is a -value of packed type. The second operand is +value of vector type. The second operand is an index indicating the position from which to extract the element. The index may be a variable.
@@ -2154,7 +2456,7 @@ results are undefined.Example:
- %result = extractelement <4 x int> %vec, uint 0 ; yields int + %result = extractelement <4 x i32> %vec, i32 0 ; yields i32Syntax:
- <result> = insertelement <n x <ty>> <val>, <ty> <elt>, uint <idx> ; yields <n x <ty>> + <result> = insertelement <n x <ty>> <val>, <ty> <elt>, i32 <idx> ; yields <n x <ty>>Overview:
The 'insertelement' instruction inserts a scalar -element into a packed vector at a specified index. +element into a vector at a specified index.
@@ -2184,7 +2486,7 @@ element into a packed vector at a specified index.The first operand of an 'insertelement' instruction is a -value of packed type. The second operand is a +value of vector type. The second operand is a scalar value whose type must equal the element type of the first operand. The third operand is an index indicating the position at which to insert the value. The index may be a variable.
@@ -2192,7 +2494,7 @@ which to insert the value. The index may be a variable.Semantics:
-The result is a packed vector of the same type as val. Its +The result is a vector of the same type as val. Its element values are those of val except at position idx, where it gets the value elt. If idx exceeds the length of val, the results are undefined. @@ -2201,7 +2503,7 @@ exceeds the length of val, the results are undefined.
Example:
- %result = insertelement <4 x int> %vec, int 1, uint 0 ; yields <4 x int> + %result = insertelement <4 x i32> %vec, i32 1, i32 0 ; yields <4 x i32>@@ -2215,7 +2517,7 @@ exceeds the length of val, the results are undefined.Syntax:
- <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <n x uint> <mask> ; yields <n x <ty>> + <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <n x i32> <mask> ; yields <n x <ty>>Overview:
@@ -2231,7 +2533,7 @@ from two input vectors, returning a vector of the same type. The first two operands of a 'shufflevector' instruction are vectors with types that match each other and types that match the result of the instruction. The third argument is a shuffle mask, which has the same number -of elements as the other vector type, but whose element type is always 'uint'. +of elements as the other vector type, but whose element type is always 'i32'.@@ -2252,214 +2554,27 @@ operand may be undef if performing a shuffle from only one vector.
Example:
- %result = shufflevector <4 x int> %v1, <4 x int> %v2, - <4 x uint> <uint 0, uint 4, uint 1, uint 5> ; yields <4 x int> - %result = shufflevector <4 x int> %v1, <4 x int> undef, - <4 x uint> <uint 0, uint 1, uint 2, uint 3> ; yields <4 x int> - Identity shuffle. + %result = shufflevector <4 x i32> %v1, <4 x i32> %v2, + <4 x i32> <i32 0, i32 4, i32 1, i32 5> ; yields <4 x i32> + %result = shufflevector <4 x i32> %v1, <4 x i32> undef, + <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> - Identity shuffle.- - + + +-- - - -Syntax:
-<result> = vsetint <op>, <n x <ty>> <var1>, <var2> ; yields <n x bool> --Overview:
+A key design point of an SSA-based representation is how it +represents memory. In LLVM, no memory locations are in SSA form, which +makes things very simple. This section describes how to read, write, +allocate, and free memory in LLVM.
-The 'vsetint' instruction takes two integer vectors and -returns a vector of boolean values representing, at each position, the -result of the comparison between the values at that position in the -two operands.
- -Arguments:
- -The arguments to a 'vsetint' instruction are a comparison -operation and two value arguments. The value arguments must be of integral packed type, -and they must have identical types. The operation argument must be -one of eq, ne, slt, sgt, -sle, sge, ult, ugt, ule, -uge, true, and false. The result is a -packed bool value with the same length as each operand.
- -Semantics:
- -The following table shows the semantics of 'vsetint'. For -each position of the result, the comparison is done on the -corresponding positions of the two value arguments. Note that the -signedness of the comparison depends on the comparison opcode and -not on the signedness of the value operands. E.g., vsetint -slt <4 x unsigned> %x, %y does an elementwise signed -comparison of %x and %y.
- -- -
- -- Operation Result is true iff Comparison is - eq var1 == var2 -- - ne var1 != var2 -- - slt var1 < var2 signed - sgt var1 > var2 signed - sle var1 <= var2 signed - sge var1 >= var2 signed - ult var1 < var2 unsigned - ugt var1 > var2 unsigned - ule var1 <= var2 unsigned - uge var1 >= var2 unsigned - true always -- - - false never -- Example:
-<result> = vsetint eq <2 x int> <int 0, int 1>, <int 1, int 0> ; yields {<2 x bool>}:result = false, false - <result> = vsetint ne <2 x int> <int 0, int 1>, <int 1, int 0> ; yields {<2 x bool>}:result = true, true - <result> = vsetint slt <2 x int> <int 0, int 1>, <int 1, int 0> ; yields {<2 x bool>}:result = true, false - <result> = vsetint sgt <2 x int> <int 0, int 1>, <int 1, int 0> ; yields {<2 x bool>}:result = false, true - <result> = vsetint sle <2 x int> <int 0, int 1>, <int 1, int 0> ; yields {<2 x bool>}:result = true, false - <result> = vsetint sge <2 x int> <int 0, int 1>, <int 1, int 0> ; yields {<2 x bool>}:result = false, true ---- - - - -Syntax:
-<result> = vsetfp <op>, <n x <ty>> <var1>, <var2> ; yields <n x bool> -- -Overview:
- -The 'vsetfp' instruction takes two floating point vector -arguments and returns a vector of boolean values representing, at each -position, the result of the comparison between the values at that -position in the two operands.
- -Arguments:
- -The arguments to a 'vsetfp' instruction are a comparison -operation and two value arguments. The value arguments must be of floating point packed -type, and they must have identical types. The operation argument must -be one of eq, ne, lt, gt, -le, ge, oeq, one, olt, -ogt, ole, oge, ueq, une, -ult, ugt, ule, uge, o, -u, true, and false. The result is a packed -bool value with the same length as each operand.
- -Semantics:
- -The following table shows the semantics of 'vsetfp' for -floating point types. If either operand is a floating point Not a -Number (NaN) value, the operation is unordered, and the value in the -first column below is produced at that position. Otherwise, the -operation is ordered, and the value in the second column is -produced.
- -- -
- -- Operation If unordered Otherwise true iff - eq undefined var1 == var2 - ne undefined var1 != var2 - lt undefined var1 < var2 - gt undefined var1 > var2 - le undefined var1 <= var2 - ge undefined var1 >= var2 - oeq false var1 == var2 - one false var1 != var2 - olt false var1 < var2 - ogt false var1 > var2 - ole false var1 <= var2 - oge false var1 >= var2 - ueq true var1 == var2 - une true var1 != var2 - ult true var1 < var2 - ugt true var1 > var2 - ule true var1 <= var2 - uge true var1 >= var2 - o false always - u true never - true true always - - false false never Example:
-<result> = vsetfp eq <2 x float> <float 0.0, float 1.0>, <float 1.0, float 0.0> ; yields {<2 x bool>}:result = false, false - <result> = vsetfp ne <2 x float> <float 0.0, float 1.0>, <float 1.0, float 0.0> ; yields {<2 x bool>}:result = true, true - <result> = vsetfp lt <2 x float> <float 0.0, float 1.0>, <float 1.0, float 0.0> ; yields {<2 x bool>}:result = true, false - <result> = vsetfp gt <2 x float> <float 0.0, float 1.0>, <float 1.0, float 0.0> ; yields {<2 x bool>}:result = false, true - <result> = vsetfp le <2 x float> <float 0.0, float 1.0>, <float 1.0, float 0.0> ; yields {<2 x bool>}:result = true, false - <result> = vsetfp ge <2 x float> <float 0.0, float 1.0>, <float 1.0, float 0.0> ; yields {<2 x bool>}:result = false, true --- -- - - - - - -Syntax:
- -- <result> = vselect <n x bool> <cond>, <n x <ty>> <val1>, <n x <ty>> <val2> ; yields <n x <ty>> -- -Overview:
- --The 'vselect' instruction chooses one value at each position -of a vector based on a condition. -
- - -Arguments:
- --The 'vselect' instruction requires a packed bool value indicating the -condition at each vector position, and two values of the same packed -type. All three operands must have the same length. The type of the -result is the same as the type of the two value operands.
- -Semantics:
- --At each position where the bool vector is true, that position -of the result gets its value from the first value argument; otherwise, -it gets its value from the second value argument. -
- -Example:
- -- %X = vselect bool <2 x bool> <bool true, bool false>, <2 x ubyte> <ubyte 17, ubyte 17>, - <2 x ubyte> <ubyte 42, ubyte 42> ; yields <2 x ubyte>:17, 42 --- -+A key design point of an SSA-based representation is how it -represents memory. In LLVM, no memory locations are in SSA form, which -makes things very simple. This section describes how to read, write, -allocate, and free memory in LLVM.
- -@@ -2471,7 +2586,7 @@ allocate, and free memory in LLVM.@@ -2542,8 +2657,8 @@ after this instruction executes.Syntax:
- <result> = malloc <type>[, uint <NumElements>][, align <alignment>] ; yields {type*}:result + <result> = malloc <type>[, i32 <NumElements>][, align <alignment>] ; yields {type*}:resultOverview:
@@ -2500,13 +2615,13 @@ a pointer is returned.Example:
- %array = malloc [4 x ubyte ] ; yields {[%4 x ubyte]*}:array + %array = malloc [4 x i8 ] ; yields {[%4 x i8]*}:array - %size = add uint 2, 2 ; yields {uint}:size = uint 4 - %array1 = malloc ubyte, uint 4 ; yields {ubyte*}:array1 - %array2 = malloc [12 x ubyte], uint %size ; yields {[12 x ubyte]*}:array2 - %array3 = malloc int, uint 4, align 1024 ; yields {int*}:array3 - %array4 = malloc int, align 1024 ; yields {int*}:array4 + %size = add i32 2, 2 ; yields {i32}:size = i32 4 + %array1 = malloc i8, i32 4 ; yields {i8*}:array1 + %array2 = malloc [12 x i8], i32 %size ; yields {[12 x i8]*}:array2 + %array3 = malloc i32, i32 4, align 1024 ; yields {i32*}:array3 + %array4 = malloc i32, align 1024 ; yields {i32*}:array4Example:
- %array = malloc [4 x ubyte] ; yields {[4 x ubyte]*}:array - free [4 x ubyte]* %array + %array = malloc [4 x i8] ; yields {[4 x i8]*}:array + free [4 x i8]* %array@@ -2557,13 +2672,13 @@ after this instruction executes.Syntax:
- <result> = alloca <type>[, uint <NumElements>][, align <alignment>] ; yields {type*}:result + <result> = alloca <type>[, i32 <NumElements>][, align <alignment>] ; yields {type*}:resultOverview:
-The 'alloca' instruction allocates memory on the current -stack frame of the procedure that is live until the current function +
The 'alloca' instruction allocates memory on the stack frame of the +currently executing function, to be automatically released when this function returns to its caller.
Arguments:
@@ -2590,10 +2705,10 @@ instructions), the memory is reclaimed.Example:
- %ptr = alloca int ; yields {int*}:ptr - %ptr = alloca int, uint 4 ; yields {int*}:ptr - %ptr = alloca int, uint 4, align 1024 ; yields {int*}:ptr - %ptr = alloca int, align 1024 ; yields {int*}:ptr + %ptr = alloca i32 ; yields {i32*}:ptr + %ptr = alloca i32, i32 4 ; yields {i32*}:ptr + %ptr = alloca i32, i32 4, align 1024 ; yields {i32*}:ptr + %ptr = alloca i32, align 1024 ; yields {i32*}:ptr@@ -2602,7 +2717,7 @@ instructions), the memory is reclaimed. Instruction+Syntax:
-<result> = load <ty>* <pointer>+
<result> = volatile load <ty>* <pointer><result> = load <ty>* <pointer>[, align <alignment>]
<result> = volatile load <ty>* <pointer>[, align <alignment>]Overview:
The 'load' instruction is used to read from memory.
Arguments:
@@ -2616,24 +2731,25 @@ instructions.Semantics:
The location of memory pointed to is loaded.
Examples:
-%ptr = alloca int ; yields {int*}:ptr +%ptr = alloca i32 ; yields {i32*}:ptr store int 3, int* %ptr ; yields {void} - %val = load int* %ptr ; yields {int}:val = int 3 + href="#i_store">store i32 3, i32* %ptr ; yields {void} + %val = load i32* %ptr ; yields {i32}:val = i32 3+Syntax:
-store <ty> <value>, <ty>* <pointer> ; yields {void} - volatile store <ty> <value>, <ty>* <pointer> ; yields {void} +store <ty> <value>, <ty>* <pointer>[, align <alignment>] ; yields {void} + volatile store <ty> <value>, <ty>* <pointer>[, align <alignment>] ; yields {void}Overview:
The 'store' instruction is used to write to memory.
Arguments:
There are two arguments to the 'store' instruction: a value -to store and an address in which to store it. The type of the '<pointer>' +to store and an address at which to store it. The type of the '<pointer>' operand must be a pointer to the type of the '<value>' operand. If the store is marked as volatile, then the optimizer is not allowed to modify the number or order of execution of @@ -2643,11 +2759,13 @@ this store with other volatile load and The contents of memory are updated to contain '<value>' at the location specified by the '<pointer>' operand.
Example:
-%ptr = alloca int ; yields {int*}:ptr +%ptr = alloca i32 ; yields {i32*}:ptr store int 3, int* %ptr ; yields {void} - %val = load int* %ptr ; yields {int}:val = int 3 + href="#i_store">store i32 3, i32* %ptr ; yields {void} + %val = load i32* %ptr ; yields {i32}:val = i32 3+'getelementptr' Instruction @@ -2667,80 +2785,83 @@ subelement of an aggregate data structure.+ - -Arguments:
-This instruction takes a list of integer constants that indicate what +
This instruction takes a list of integer operands that indicate what elements of the aggregate object to index to. The actual types of the arguments provided depend on the type of the first pointer argument. The 'getelementptr' instruction is used to index down through the type levels of a structure or to a specific index in an array. When indexing into a -structure, only uint -integer constants are allowed. When indexing into an array or pointer, -int and long indexes are allowed of any sign.
+structure, only i32 integer constants are allowed. When indexing +into an array or pointer, only integers of 32 or 64 bits are allowed, and will +be sign extended to 64-bit values.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]; - } +struct RT { + char A; + int B[10][20]; + char C; +}; +struct ST { + int X; + double Y; + struct RT Z; +}; + +int *foo(struct ST *s) { + return &s[1].Z.B[5][13]; +}+The LLVM code generated by the GCC frontend is:
+- %RT = type { sbyte, [10 x [20 x int]], sbyte } - %ST = type { int, double, %RT } - - implementation +%RT = type { i8 , [10 x [20 x i32]], i8 } +%ST = type { i32, double, %RT } - int* %foo(%ST* %s) { - entry: - %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13 - ret int* %reg - } +define i32* %foo(%ST* %s) { +entry: + %reg = getelementptr %ST* %s, i32 1, i32 2, i32 1, i32 5, i32 13 + ret i32* %reg +}+Semantics:
The index types specified for the 'getelementptr' instruction depend on the pointer type that is being indexed into. Pointer -and array types require uint, int, -ulong, or long values, and structure -types require uint constants.
+and array types can use a 32-bit or 64-bit +integer type but the value will always be sign extended +to 64-bits. Structure types require i32 +constants.In the example above, the first index is indexing into the '%ST*' -type, which is a pointer, yielding a '%ST' = '{ int, double, %RT +type, 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' = '{ sbyte, [10 x [20 x int]], -sbyte }' type, another structure. The third index indexes into the second -element of the structure, yielding a '[10 x [20 x int]]' type, an +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 -'int' type. The 'getelementptr' instruction returns a pointer -to this element, thus computing a value of 'int*' type.
+'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:
- int* %foo(%ST* %s) { - %t1 = getelementptr %ST* %s, int 1 ; yields %ST*:%t1 - %t2 = getelementptr %ST* %t1, int 0, uint 2 ; yields %RT*:%t2 - %t3 = getelementptr %RT* %t2, int 0, uint 1 ; yields [10 x [20 x int]]*:%t3 - %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 ; yields [20 x int]*:%t4 - %t5 = getelementptr [20 x int]* %t4, int 0, int 13 ; yields int*:%t5 - ret int* %t5 + 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 }@@ -2757,42 +2878,18 @@ FAQ.Example:
- ; yields [12 x ubyte]*:aptr - %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1 + ; yields [12 x i8]*:aptr + %aptr = getelementptr {i32, [12 x i8]}* %sptr, i64 0, i32 1--@@ -2855,26 +2949,21 @@ If the value was non-zero, the bool result will be true.The instructions in this category are the "miscellaneous" -instructions, which defy better classification.
+ - --@@ -2815,25 +2912,22 @@ The 'trunc' instruction truncates its operand to the type ty2.Syntax:
-<result> = phi <ty> [ <val0>, <label0>], ...-Overview:
-The 'phi' instruction is used to implement the φ node in -the SSA graph representing the function.
-Arguments:
-The type of the incoming values are specified with the first type -field. After this, the 'phi' instruction takes a list of pairs -as arguments, with one pair for each predecessor basic block of the -current block. Only values of first class -type may be used as the value arguments to the PHI node. Only labels -may be used as the label arguments.
-There must be no non-phi instructions between the start of a basic -block and the PHI instructions: i.e. PHI instructions must be first in -a basic block.
-Semantics:
-At runtime, the 'phi' instruction logically takes on the -value specified by the parameter, depending on which basic block we -came from in the last terminator instruction.
-Example:
-Loop: ; Infinite loop that counts from 0 on up...+
%indvar = phi uint [ 0, %LoopHeader ], [ %nextindvar, %Loop ]
%nextindvar = add uint %indvar, 1
br label %LoopThe instructions in this category are the conversion instructions (casting) +which all take a single operand and a type. They perform various bit conversions +on the operand.
The 'trunc' instruction takes a value to trunc, which must be an integer type, and a type that specifies the size -and type of the result, which must be an integral -type.
+and type of the result, which must be an integer +type. The bit size of value must be larger than the bit size of +ty2. Equal sized types are not allowed.Semantics:
The 'trunc' instruction truncates the high order bits in value -and converts the reamining bits to ty2. The bit size of value -must be larger than the bit size of ty2. Equal sized types are not -allowed. This implies that a trunc cannot be a no-op cast. It -will always truncate bits.
- -When truncating to bool, the truncation is done as a comparison against -zero. If the value was zero, the bool result will be false. -If the value was non-zero, the bool result will be true.
+and converts the remaining bits to ty2. Since the source size must be +larger than the destination size, trunc cannot be a no-op cast. +It will always truncate bits.Example:
- %X = trunc int 257 to ubyte ; yields ubyte:1 - %Y = trunc int 123 to bool ; yields bool:true + %X = trunc i32 257 to i8 ; yields i8:1 + %Y = trunc i32 123 to i1 ; yields i1:true + %Y = trunc i32 122 to i1 ; yields i1:falseArguments:
The 'zext' instruction takes a value to cast, which must be of -integral type, and a type to cast it to, which must -also be of integral type. The bit size of the -value must be smaller than or equal to the bit size of the -destination type, ty2.
+integer type, and a type to cast it to, which must +also be of integer type. The bit size of the +value must be smaller than the bit size of the destination type, +ty2.Semantics:
The zext fills the high order bits of the value with zero -bits until it reaches the size of the destination type, ty2. When the -the operand and the type are the same size, no bit filling is done and the -cast is considered a no-op cast because no bits change (only the type -changes).
+bits until it reaches the size of the destination type, ty2. -When zero extending to bool, the extension is done as a comparison against -zero. If the value was zero, the bool result will be false. -If the value was non-zero, the bool result will be true.
+When zero extending from i1, the result will always be either 0 or 1.
Example:
- %X = zext int 257 to ulong ; yields ulong:257 - %Y = zext bool true to int ; yields int:1 + %X = zext i32 257 to i64 ; yields i64:257 + %Y = zext i1 true to i32 ; yields i32:1@@ -2895,103 +2984,102 @@ If the value was non-zero, the bool result will be true.Arguments:
The 'sext' instruction takes a value to cast, which must be of -integral type, and a type to cast it to, which must -also be of integral type.
+integer type, and a type to cast it to, which must +also be of integer type. The bit size of the +value must be smaller than the bit size of the destination type, +ty2.Semantics:
The 'sext' instruction performs a sign extension by copying the sign bit (highest order bit) of the value until it reaches the bit size of -the type ty2. When the the operand and the type are the same size, -no bit filling is done and the cast is considered a no-op cast because -no bits change (only the type changes).
+the type ty2. -When sign extending to bool, the extension is done as a comparison against -zero. If the value was zero, the bool result will be false. -If the value was non-zero, the bool result will be true.
+When sign extending from i1, the extension always results in -1 or 0.
Example:
-- %X = sext sbyte -1 to ushort ; yields ushort:65535 - %Y = sext bool true to int ; yields int:-1 + %X = sext i8 -1 to i16 ; yields i16 :65535 + %Y = sext i1 true to i32 ; yields i32:-1+-Syntax:
+- <result> = fpext <ty> <value> to <ty2> ; yields ty2 + <result> = fptrunc <ty> <value> to <ty2> ; yields ty2Overview:
-The 'fpext' extends a floating point value to a larger -floating point value.
+The 'fptrunc' instruction truncates value to type +ty2.
+Arguments:
-The 'fpext' instruction takes a -floating point value to cast, -and a floating point type to cast it to.
+The 'fptrunc' instruction takes a floating + point value to cast and a floating point type to +cast it to. The size of value must be larger than the size of +ty2. This implies that fptrunc cannot be used to make a +no-op cast.
Semantics:
-The 'fpext' instruction extends the value from one floating -point type to another. If the type of the value and ty2 are -the same, the instruction is considered a no-op cast because no bits -change.
+The 'fptrunc' instruction truncates a value from a larger +floating point type to a smaller +floating point type. If the value cannot fit within +the destination type, ty2, then the results are undefined.
Example:
- %X = fpext float 3.1415 to double ; yields double:3.1415 - %Y = fpext float 1.0 to float ; yields float:1.0 (no-op) + %X = fptrunc double 123.0 to float ; yields float:123.0 + %Y = fptrunc double 1.0E+300 to float ; yields undefinedSyntax:
-- <result> = fptrunc <ty> <value> to <ty2> ; yields ty2 + <result> = fpext <ty> <value> to <ty2> ; yields ty2Overview:
-The 'fptrunc' instruction truncates value to type -ty2.
- +The 'fpext' extends a floating point value to a larger +floating point value.
Arguments:
-The 'fptrunc' instruction takes a floating - point value to cast and a floating point type to -cast it to. The size of value must be larger than the size of -ty2. This implies that fptrunc cannot be used to make a -no-op cast.
+The 'fpext' instruction takes a +floating point value to cast, +and a floating point type to cast it to. The source +type must be smaller than the destination type.
Semantics:
-The 'fptrunc' instruction converts a -floating point value from a larger type to a smaller -type. If the value cannot fit within the destination type, ty2, then -the results are undefined.
+The 'fpext' instruction extends the value from a smaller +floating point type to a larger +floating point type. The fpext cannot be +used to make a no-op cast because it always changes bits. Use +bitcast to make a no-op cast for a floating point cast.
Example:
- %X = fptrunc double 123.0 to float ; yields float:123.0 - %Y = fptrunc double 1.0E+300 to float ; yields undefined + %X = fpext float 3.1415 to double ; yields double:3.1415 + %Y = fpext float 1.0 to float ; yields float:1.0 (no-op)@@ -3008,7 +3096,7 @@ unsigned integer equivalent of type ty2.Arguments:
The 'fp2uint' instruction takes a value to cast, which must be a floating point value, and a type to cast it to, which -must be an integral type.
+must be an integer type.Semantics:
The 'fp2uint' instruction converts its @@ -3016,159 +3104,417 @@ must be an integral type.
towards zero) unsigned integer value. If the value cannot fit in ty2, the results are undefined. -When converting to bool, the conversion is done as a comparison against -zero. If the value was zero, the bool result will be false. -If the value was non-zero, the bool result will be true.
+When converting to i1, the conversion is done as a comparison against +zero. If the value was zero, the i1 result will be false. +If the value was non-zero, the i1 result will be true.
Example:
- %X = fp2uint double 123.0 to int ; yields int:123 - %Y = fp2uint float 1.0E+300 to bool ; yields bool:true - %X = fp2uint float 1.04E+17 to ubyte ; yields undefined:1 + %X = fp2uint double 123.0 to i32 ; yields i32:123 + %Y = fp2uint float 1.0E+300 to i1 ; yields i1:true + %X = fp2uint float 1.04E+17 to i8 ; yields undefined:1Syntax:
- <result> = fp2sint <ty> <value> to <ty2> ; yields ty2 + <result> = fptosi <ty> <value> to <ty2> ; yields ty2Overview:
-The 'fp2sint' instruction converts +
The 'fptosi' instruction converts floating point value to type ty2.
Arguments:
-The 'fp2sint' instruction takes a value to cast, which must be a +
The 'fptosi' instruction takes a value to cast, which must be a floating point value, and a type to cast it to, which -must also be an integral type.
+must also be an integer type.Semantics:
-The 'fp2sint' instruction converts its +
The 'fptosi' instruction converts its floating point operand into the nearest (rounding towards zero) signed integer value. If the value cannot fit in ty2, the results are undefined.
-When converting to bool, the conversion is done as a comparison against -zero. If the value was zero, the bool result will be false. -If the value was non-zero, the bool result will be true.
+When converting to i1, the conversion is done as a comparison against +zero. If the value was zero, the i1 result will be false. +If the value was non-zero, the i1 result will be true.
Example:
- %X = fp2sint double -123.0 to int ; yields int:-123 - %Y = fp2sint float 1.0E-247 to bool ; yields bool:true - %X = fp2sint float 1.04E+17 to sbyte ; yields undefined:1 + %X = fptosi double -123.0 to i32 ; yields i32:-123 + %Y = fptosi float 1.0E-247 to i1 ; yields i1:true + %X = fptosi float 1.04E+17 to i8 ; yields undefined:1Syntax:
- <result> = uint2fp <ty> <value> to <ty2> ; yields ty2 + <result> = uitofp <ty> <value> to <ty2> ; yields ty2Overview:
-The 'uint2fp' instruction regards value as an unsigned +
The 'uitofp' instruction regards value as an unsigned integer and converts that value to the ty2 type.
Arguments:
-The 'uint2fp' instruction takes a value to cast, which must be an -integral value, and a type to cast it to, which must +
The 'uitofp' instruction takes a value to cast, which must be an +integer value, and a type to cast it to, which must be a floating point type.
Semantics:
-The 'uint2fp' instruction interprets its operand as an unsigned +
The 'uitofp' instruction interprets its operand as an unsigned integer quantity and converts it to the corresponding floating point value. If the value cannot fit in the floating point value, the results are undefined.
Example:
- %X = uint2fp int 257 to float ; yields float:257.0 - %Y = uint2fp sbyte -1 to double ; yields double:255.0 + %X = uitofp i32 257 to float ; yields float:257.0 + %Y = uitofp i8 -1 to double ; yields double:255.0+ + + +Syntax:
- <result> = sint2fp <ty> <value> to <ty2> ; yields ty2 + <result> = sitofp <ty> <value> to <ty2> ; yields ty2Overview:
-The 'sint2fp' instruction regards value as a signed +
The 'sitofp' instruction regards value as a signed integer and converts that value to the ty2 type.
Arguments:
-The 'sint2fp' instruction takes a value to cast, which must be an -integral value, and a type to cast it to, which must be +
The 'sitofp' instruction takes a value to cast, which must be an +integer value, and a type to cast it to, which must be a floating point type.
Semantics:
-The 'sint2fp' instruction interprets its operand as a signed +
The 'sitofp' instruction interprets its operand as a signed integer quantity and converts it to the corresponding floating point value. If the value cannot fit in the floating point value, the results are undefined.
Example:
- %X = sint2fp int 257 to float ; yields float:257.0 - %Y = sint2fp sbyte -1 to double ; yields double:-1.0 + %X = sitofp i32 257 to float ; yields float:257.0 + %Y = sitofp i8 -1 to double ; yields double:-1.0 +++ +Syntax:
++ <result> = ptrtoint <ty> <value> to <ty2> ; yields ty2 ++ +Overview:
+The 'ptrtoint' instruction converts the pointer value to +the integer 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. + +
Semantics:
+The 'ptrtoint' instruction converts value to integer type +ty2 by interpreting the pointer value as an integer and either +truncating or zero extending that value to the size of the integer type. If +value is smaller than ty2 then a zero extension is done. If +value is larger than ty2 then a truncation is done. If they +are the same size, then nothing is done (no-op cast) other than a type +change.
+ +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+ + + +Syntax:
- <result> = bitconvert <ty> <value> to <ty2> ; yields ty2 + <result> = inttoptr <ty> <value> to <ty2> ; yields ty2Overview:
-The 'bitconvert' instruction converts value to type +
The 'inttoptr' instruction converts an integer value to +a pointer type, ty2.
+ +Arguments:
+The 'inttoptr' instruction takes an integer +value to cast, and a type to cast it to, which must be a +pointer type. + +
Semantics:
+The 'inttoptr' instruction converts value to type +ty2 by applying either a zero extension or a truncation depending on +the size of the integer value. If value is larger than the +size of a pointer then a truncation is done. If value is smaller than +the size of a pointer then a zero extension is done. If they are the same size, +nothing is done (no-op cast).
+ +Example:
++ %X = inttoptr i32 255 to i32* ; yields zero extension on 64-bit architecture + %X = inttoptr i32 255 to i32* ; yields no-op on 32-bit architecture + %Y = inttoptr i64 0 to i32* ; yields truncation on 32-bit architecture +++ ++ + +Syntax:
++ <result> = bitcast <ty> <value> to <ty2> ; yields ty2 ++ +Overview:
+The 'bitcast' instruction converts value to type ty2 without changing any bits.
Arguments:
-The 'bitconvert' instruction takes a value to cast, which must be +
The 'bitcast' instruction takes a value to cast, which must be a first class value, and a type to cast it to, which must also be a first class type. The bit sizes of value -and the destination type, ty2, must be identical.
+and the destination type, ty2, must be identical. If the source +type is a pointer, the destination type must also be a pointer.Semantics:
-The 'bitconvert' instruction converts value to type -ty2 as if the value had been stored to memory and read back as type -ty2. That is, no bits are changed during the conversion. The -bitconvert instruction may be used to construct no-op casts that -the zext, sext, and fpext instructions do not permit.
+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 pointers to +other types, use the inttoptr or +ptrtoint instructions first.
Example:
- %X = bitconvert ubyte 255 to sbyte ; yields sbyte:-1 - %Y = bitconvert uint* %x to uint ; yields uint:%x + %X = bitcast i8 255 to i8 ; yields i8 :-1 + %Y = bitcast i32* %x to sint* ; yields sint*:%x + %Z = bitcast <2xint> %V to i64; ; yields i64: %V++ + + +The instructions in this category are the "miscellaneous" +instructions, which defy better classification.
+++ + + +Syntax:
+<result> = icmp <cond> <ty> <var1>, <var2> ; yields {i1}:result ++Overview:
+The 'icmp' instruction returns a boolean value based on comparison +of its two integer operands.
+Arguments:
+The 'icmp' instruction takes three operands. The first operand is +the condition code indicating the kind of comparison to perform. It is not +a value, just a keyword. The possible condition code are: +
+
+- eq: equal
+- ne: not equal
+- ugt: unsigned greater than
+- uge: unsigned greater or equal
+- ult: unsigned less than
+- ule: unsigned less or equal
+- sgt: signed greater than
+- sge: signed greater or equal
+- slt: signed less than
+- sle: signed less or equal
+The remaining two arguments must be integer or +pointer typed. They must also be identical types.
+Semantics:
+The 'icmp' compares var1 and var2 according to +the condition code given as cond. The comparison performed always +yields a i1 result, as follows: +
+
+- eq: yields true if the operands are equal, + false otherwise. No sign interpretation is necessary or performed. +
+- ne: yields true if the operands are unequal, + false otherwise. No sign interpretation is necessary or performed. +
- ugt: interprets the operands as unsigned values and yields + true if var1 is greater than var2.
+- uge: interprets the operands as unsigned values and yields + true if var1 is greater than or equal to var2.
+- ult: interprets the operands as unsigned values and yields + true if var1 is less than var2.
+- ule: interprets the operands as unsigned values and yields + true if var1 is less than or equal to var2.
+- sgt: interprets the operands as signed values and yields + true if var1 is greater than var2.
+- sge: interprets the operands as signed values and yields + true if var1 is greater than or equal to var2.
+- slt: interprets the operands as signed values and yields + true if var1 is less than var2.
+- sle: interprets the operands as signed values and yields + true if var1 is less than or equal to var2.
+If the operands are pointer typed, the pointer +values are compared as if they were integers.
+ +Example:
+<result> = icmp eq i32 4, 5 ; yields: result=false + <result> = icmp ne float* %X, %X ; yields: result=false + <result> = icmp ult i16 4, 5 ; yields: result=true + <result> = icmp sgt i16 4, 5 ; yields: result=false + <result> = icmp ule i16 -4, 5 ; yields: result=false + <result> = icmp sge i16 4, 5 ; yields: result=false ++++ + + +Syntax:
+<result> = fcmp <cond> <ty> <var1>, <var2> ; yields {i1}:result ++Overview:
+The 'fcmp' instruction returns a boolean value based on comparison +of its floating point operands.
+Arguments:
+The 'fcmp' instruction takes three operands. The first operand is +the condition code indicating the kind of comparison to perform. It is not +a value, just a keyword. The possible condition code are: +
+
+- false: no comparison, always returns false
+- oeq: ordered and equal
+- ogt: ordered and greater than
+- oge: ordered and greater than or equal
+- olt: ordered and less than
+- ole: ordered and less than or equal
+- one: ordered and not equal
+- ord: ordered (no nans)
+- ueq: unordered or equal
+- ugt: unordered or greater than
+- uge: unordered or greater than or equal
+- ult: unordered or less than
+- ule: unordered or less than or equal
+- une: unordered or not equal
+- uno: unordered (either nans)
+- true: no comparison, always returns true
+Ordered means that neither operand is a QNAN while +unordered means that either operand may be a QNAN.
+The val1 and val2 arguments must be +floating point typed. They must have identical +types.
+Semantics:
+The 'fcmp' compares var1 and var2 according to +the condition code given as cond. The comparison performed always +yields a i1 result, as follows: +
+
+ +- false: always yields false, regardless of operands.
+- oeq: yields true if both operands are not a QNAN and + var1 is equal to var2.
+- ogt: yields true if both operands are not a QNAN and + var1 is greather than var2.
+- oge: yields true if both operands are not a QNAN and + var1 is greater than or equal to var2.
+- olt: yields true if both operands are not a QNAN and + var1 is less than var2.
+- ole: yields true if both operands are not a QNAN and + var1 is less than or equal to var2.
+- one: yields true if both operands are not a QNAN and + var1 is not equal to var2.
+- ord: yields true if both operands are not a QNAN.
+- ueq: yields true if either operand is a QNAN or + var1 is equal to var2.
+- ugt: yields true if either operand is a QNAN or + var1 is greater than var2.
+- uge: yields true if either operand is a QNAN or + var1 is greater than or equal to var2.
+- ult: yields true if either operand is a QNAN or + var1 is less than var2.
+- ule: yields true if either operand is a QNAN or + var1 is less than or equal to var2.
+- une: yields true if either operand is a QNAN or + var1 is not equal to var2.
+- uno: yields true if either operand is a QNAN.
+- true: always yields true, regardless of operands.
+Example:
+<result> = fcmp oeq float 4.0, 5.0 ; yields: result=false + <result> = icmp one float 4.0, 5.0 ; yields: result=true + <result> = icmp olt float 4.0, 5.0 ; yields: result=true + <result> = icmp ueq double 1.0, 2.0 ; yields: result=false ++++Syntax:
+<result> = phi <ty> [ <val0>, <label0>], ...+Overview:
+The 'phi' instruction is used to implement the φ node in +the SSA graph representing the function.
+Arguments:
+The type of the incoming values is specified with the first type +field. After this, the 'phi' instruction takes a list of pairs +as arguments, with one pair for each predecessor basic block of the +current block. Only values of first class +type may be used as the value arguments to the PHI node. Only labels +may be used as the label arguments.
+There must be no non-phi instructions between the start of a basic +block and the PHI instructions: i.e. PHI instructions must be first in +a basic block.
+Semantics:
+At runtime, the 'phi' instruction logically takes on the value +specified by the pair corresponding to the predecessor basic block that executed +just prior to the current block.
+Example:
+Loop: ; Infinite loop that counts from 0 on up...+
%indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]
%nextindvar = add i32 %indvar, 1
br label %Loop'select' Instruction @@ -3179,7 +3525,7 @@ the zext, sext, and fpext instructions do not permit.@@ -3240,7 +3586,7 @@ value argument; otherwise, it returns the second value argument. href="#i_ret">ret instruction.Syntax:
- <result> = select bool <cond>, <ty> <val1>, <ty> <val2> ; yields ty + <result> = select i1 <cond>, <ty> <val1>, <ty> <val2> ; yields tyOverview:
@@ -3206,7 +3552,7 @@ value argument; otherwise, it returns the second value argument.Example:
- %X = select bool true, ubyte 17, ubyte 42 ; yields ubyte:17 + %X = select i1 true, i8 17, i8 42 ; yields i8:17
The optional "cconv" marker indicates which calling
+ The optional "cconv" marker indicates which calling
convention the call should use. If none is specified, the call defaults
to using C calling conventions.
- %retval = call int %test(int %argc) - call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42); - %X = tail call int %foo() - %Y = tail call fastcc int %foo() + %retval = call i32 %test(i32 %argc) + call i32(i8 *, ...) *%printf(i8 * %msg, i32 12, i8 42); + %X = tail call i32 %foo() + %Y = tail call fastcc i32 %foo()@@ -3309,7 +3655,7 @@ the "variable argument" area of a function call. It is used to implement the
This instruction takes a va_list* value and the type of the argument. It returns a value of the specified argument type and -increments the va_list to point to the next argument. Again, the +increments the va_list to point to the next argument. The actual type of va_list is target specific.
LLVM supports the notion of an "intrinsic function". These functions have -well known names and semantics and are required to follow certain -restrictions. Overall, these instructions represent an extension mechanism for -the LLVM language that does not require changing all of the transformations in -LLVM to add to the language (or the bytecode reader/writer, the parser, -etc...).
+well known names and semantics and are required to follow certain restrictions. +Overall, these intrinsics represent an extension mechanism for the LLVM +language that does not require changing all of the transformations in LLVM when +adding to the language (or the bytecode reader/writer, the parser, etc...).Intrinsic function names must all start with an "llvm." prefix. This -prefix is reserved in LLVM for intrinsic names; thus, functions may not be named -this. Intrinsic functions must always be external functions: you cannot define -the body of intrinsic functions. Intrinsic functions may only be used in call -or invoke instructions: it is illegal to take the address of an intrinsic -function. Additionally, because intrinsic functions are part of the LLVM -language, it is required that they all be documented here if any are added.
+prefix is reserved in LLVM for intrinsic names; thus, function names may not +begin with this prefix. Intrinsic functions must always be external functions: +you cannot define the body of intrinsic functions. Intrinsic functions may +only be used in call or invoke instructions: it is illegal to take the address +of an intrinsic function. Additionally, because intrinsic functions are part +of the LLVM language, it is required if any are added that they be documented +here. + +Some intrinsic functions can be overloaded, i.e., the intrinsic represents +a family of functions that perform the same operation but on different data +types. This is most frequent with the integer types. Since LLVM can represent +over 8 million different integer types, there is a way to declare an intrinsic +that can be overloaded based on its arguments. Such an intrinsic will have the +names of its argument types encoded into its function name, each +preceded by a period. For example, the llvm.ctpop function can take an +integer of any width. This leads to a family of functions such as +i32 @llvm.ctpop.i8(i8 %val) and i32 @llvm.ctpop.i29(i29 %val). +
-To learn how to add an intrinsic function, please see the Extending LLVM Guide. +
To learn how to add an intrinsic function, please see the +Extending LLVM Guide.
All of these functions operate on arguments that use a target-specific value type "va_list". The LLVM assembly language reference manual does not define what this type is, so all -transformations should be prepared to handle intrinsics with any type -used.
+transformations should be prepared to handle these functions regardless of +the type used.This example shows how the va_arg instruction and the variable argument handling intrinsic functions are used.
+-int %test(int %X, ...) { +define i32 @test(i32 %X, ...) { ; Initialize variable argument processing - %ap = alloca sbyte* - call void %llvm.va_start(sbyte** %ap) + %ap = alloca i8* + %ap2 = bitcast i8** %ap to i8* + call void @llvm.va_start(i8* %ap2) ; Read a single integer argument - %tmp = va_arg sbyte** %ap, int + %tmp = va_arg i8** %ap, i32 ; Demonstrate usage of llvm.va_copy and llvm.va_end - %aq = alloca sbyte* - call void %llvm.va_copy(sbyte** %aq, sbyte** %ap) - call void %llvm.va_end(sbyte** %aq) + %aq = alloca i8* + %aq2 = bitcast i8** %aq to i8* + call void @llvm.va_copy(i8* %aq2, i8* %ap2) + call void @llvm.va_end(i8* %aq2) ; Stop processing of arguments. - call void %llvm.va_end(sbyte** %ap) - ret int %tmp + call void @llvm.va_end(i8* %ap2) + ret i32 %tmp } + +declare void @llvm.va_start(i8*) +declare void @llvm.va_copy(i8*, i8*) +declare void @llvm.va_end(i8*)
declare void %llvm.va_start(<va_list>* <arglist>)+
declare void %llvm.va_start(i8* <arglist>)
The 'llvm.va_start' intrinsic initializes *<arglist> for subsequent use by va_arg.
The 'llvm.va_start' intrinsic works just like the va_start macro available in C. In a target-dependent way, it initializes the -va_list element the argument points to, so that the next call to +va_list element to which the argument points, so that the next call to va_arg will produce the first variable argument passed to the function. Unlike the C va_start macro, this intrinsic does not need to know the -last argument of the function, the compiler can figure that out.
+last argument of the function as the compiler can figure that out.declare void %llvm.va_end(<va_list*> <arglist>)+
declare void @llvm.va_end(i8* <arglist>)
The 'llvm.va_end' intrinsic destroys <arglist> -which has been initialized previously with llvm.va_start + +
The 'llvm.va_end' intrinsic destroys *<arglist>, +which has been initialized previously with llvm.va_start or llvm.va_copy.
+The argument is a va_list to destroy.
+ +The argument is a pointer to a va_list to destroy.
+The 'llvm.va_end' intrinsic works just like the va_end -macro available in C. In a target-dependent way, it destroys the va_list. -Calls to llvm.va_start and llvm.va_copy must be matched exactly -with calls to llvm.va_end.
+macro available in C. In a target-dependent way, it destroys the +va_list element to which the argument points. Calls to llvm.va_start and +llvm.va_copy must be matched exactly with calls to +llvm.va_end. +- declare void %llvm.va_copy(<va_list>* <destarglist>, - <va_list>* <srcarglist>) + declare void @llvm.va_copy(i8* <destarglist>, i8* <srcarglist>)
The 'llvm.va_copy' intrinsic copies the current argument position from -the source argument list to the destination argument list.
+The 'llvm.va_copy' intrinsic copies the current argument position +from the source argument list to the destination argument list.
The 'llvm.va_copy' intrinsic works just like the va_copy macro -available in C. In a target-dependent way, it copies the source -va_list element into the destination list. This intrinsic is necessary -because the llvm.va_begin intrinsic may be -arbitrarily complex and require memory allocation, for example.
+The 'llvm.va_copy' intrinsic works just like the va_copy +macro available in C. In a target-dependent way, it copies the source +va_list element into the destination va_list element. This +intrinsic is necessary because the +llvm.va_start intrinsic may be arbitrarily complex and require, for +example, memory allocation.
LLVM support for Accurate Garbage Collection requires the implementation and generation of these intrinsics. -These intrinsics allow identification of GC roots on the +These intrinsics allow identification of GC roots on the stack, as well as garbage collector implementations that require read and write barriers. +href="#int_gcread">read and write barriers. Front-ends for type-safe garbage collected languages should generate these intrinsics to make use of the LLVM garbage collectors. For more details, see Accurate Garbage Collection with LLVM. @@ -3512,7 +3885,7 @@ href="GarbageCollection.html">Accurate Garbage Collection with LLVM.
- declare void %llvm.gcroot(<ty>** %ptrloc, <ty2>* %metadata) + declare void @llvm.gcroot(<ty>** %ptrloc, <ty2>* %metadata)
- declare sbyte* %llvm.gcread(sbyte* %ObjPtr, sbyte** %Ptr) + declare i8 * @llvm.gcread(i8 * %ObjPtr, i8 ** %Ptr)
- declare void %llvm.gcwrite(sbyte* %P1, sbyte* %Obj, sbyte** %P2) + declare void @llvm.gcwrite(i8 * %P1, i8 * %Obj, i8 ** %P2)
- declare sbyte *%llvm.returnaddress(uint <level>) + declare i8 *@llvm.returnaddress(i32 <level>)
- declare sbyte *%llvm.frameaddress(uint <level>) + declare i8 *@llvm.frameaddress(i32 <level>)
- declare sbyte *%llvm.stacksave() + declare i8 *@llvm.stacksave()
The 'llvm.stacksave' intrinsic is used to remember the current state of -the function stack, for use with +the function stack, for use with llvm.stackrestore. This is useful for implementing language features like scoped automatic variable sized arrays in C99.
@@ -3741,7 +4114,7 @@ features like scoped automatic variable sized arrays in C99.This intrinsic returns a opaque pointer value that can be passed to llvm.stackrestore. When an +href="#int_stackrestore">llvm.stackrestore. When an llvm.stackrestore intrinsic is executed with a value saved from llvm.stacksave, it effectively restores the state of the stack to the state it was in when the llvm.stacksave intrinsic executed. In @@ -3753,14 +4126,14 @@ that were allocated after the llvm.stacksave was executed.
- declare void %llvm.stackrestore(sbyte* %ptr) + declare void @llvm.stackrestore(i8 * %ptr)
The 'llvm.stackrestore' intrinsic is used to restore the state of the function stack to the state it was in when the corresponding llvm.stacksave intrinsic executed. This is +href="#int_stacksave">llvm.stacksave intrinsic executed. This is useful for implementing language features like scoped automatic variable sized arrays in C99.
@@ -3776,7 +4149,7 @@ arrays in C99.-See the description for llvm.stacksave. +See the description for llvm.stacksave.
- declare void %llvm.prefetch(sbyte * <address>, - uint <rw>, uint <locality>) + declare void @llvm.prefetch(i8 * <address>, + i32 <rw>, i32 <locality>)
- declare void %llvm.pcmarker( uint <id> ) + declare void @llvm.pcmarker( i32 <id> )
- declare ulong %llvm.readcyclecounter( ) + declare i64 @llvm.readcyclecounter( )
- declare void %llvm.memcpy.i32(sbyte* <dest>, sbyte* <src>, - uint <len>, uint <align>) - declare void %llvm.memcpy.i64(sbyte* <dest>, sbyte* <src>, - ulong <len>, uint <align>) + declare void @llvm.memcpy.i32(i8 * <dest>, i8 * <src>, + i32 <len>, i32 <align>) + declare void @llvm.memcpy.i64(i8 * <dest>, i8 * <src>, + i64 <len>, i32 <align>)
- declare void %llvm.memmove.i32(sbyte* <dest>, sbyte* <src>, - uint <len>, uint <align>) - declare void %llvm.memmove.i64(sbyte* <dest>, sbyte* <src>, - ulong <len>, uint <align>) + declare void @llvm.memmove.i32(i8 * <dest>, i8 * <src>, + i32 <len>, i32 <align>) + declare void @llvm.memmove.i64(i8 * <dest>, i8 * <src>, + i64 <len>, i32 <align>)
- declare void %llvm.memset.i32(sbyte* <dest>, ubyte <val>, - uint <len>, uint <align>) - declare void %llvm.memset.i64(sbyte* <dest>, ubyte <val>, - ulong <len>, uint <align>) + declare void @llvm.memset.i32(i8 * <dest>, i8 <val>, + i32 <len>, i32 <align>) + declare void @llvm.memset.i64(i8 * <dest>, i8 <val>, + i64 <len>, i32 <align>)
- declare bool %llvm.isunordered.f32(float Val1, float Val2) - declare bool %llvm.isunordered.f64(double Val1, double Val2) -- -
-The 'llvm.isunordered' intrinsics return true if either or both of the -specified floating point values is a NAN. -
- --The arguments are floating point numbers of the same type. -
- --If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise -false. -
-- declare float %llvm.sqrt.f32(float %Val) - declare double %llvm.sqrt.f64(double %Val) + declare float @llvm.sqrt.f32(float %Val) + declare double @llvm.sqrt.f64(double %Val)
- declare float %llvm.powi.f32(float %Val, int %power) - declare double %llvm.powi.f64(double %Val, int %power) + declare float @llvm.powi.f32(float %Val, i32 %power) + declare double @llvm.powi.f64(double %Val, i32 %power)
This is an overloaded intrinsic function. You can use bswap on any integer +type that is an even number of bytes (i.e. BitWidth % 16 == 0). Note the suffix +that includes the type for the result and the operand.
- declare ushort %llvm.bswap.i16(ushort <id>) - declare uint %llvm.bswap.i32(uint <id>) - declare ulong %llvm.bswap.i64(ulong <id>) + declare i16 @llvm.bswap.i16.i16(i16 <id>) + declare i32 @llvm.bswap.i32.i32(i32 <id>) + declare i64 @llvm.bswap.i64.i64(i64 <id>)
-The 'llvm.bwsap' family of intrinsics is used to byteswap a 16, 32 or -64 bit quantity. These are useful for performing operations on data that is not -in the target's native byte order. +The 'llvm.bswap' family of intrinsics is used to byte swap integer +values with an even number of bytes (positive multiple of 16 bits). These are +useful for performing operations on data that is not in the target's native +byte order.
-The llvm.bswap.16 intrinsic returns a ushort value that has the high and low -byte of the input ushort swapped. Similarly, the llvm.bswap.i32 intrinsic -returns a uint value that has the four bytes of the input uint swapped, so that -if the input bytes are numbered 0, 1, 2, 3 then the returned uint will have its -bytes in 3, 2, 1, 0 order. The llvm.bswap.i64 intrinsic extends this concept -to 64 bits. +The llvm.bswap.16.i16 intrinsic returns an i16 value that has the high +and low byte of the input i16 swapped. Similarly, the llvm.bswap.i32 +intrinsic returns an i32 value that has the four bytes of the input i32 +swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the returned +i32 will have its bytes in 3, 2, 1, 0 order. The llvm.bswap.i48.i48, +llvm.bswap.i64.i64 and other intrinsics extend this concept to +additional even-byte lengths (6 bytes, 8 bytes and more, respectively).
This is an overloaded intrinsic. You can use llvm.ctpop on any integer bit +width. Not all targets support all bit widths however.
- declare ubyte %llvm.ctpop.i8 (ubyte <src>) - declare ushort %llvm.ctpop.i16(ushort <src>) - declare uint %llvm.ctpop.i32(uint <src>) - declare ulong %llvm.ctpop.i64(ulong <src>) + declare i32 @llvm.ctpop.i8 (i8 <src>) + declare i32 @llvm.ctpop.i16(i16 <src>) + declare i32 @llvm.ctpop.i32(i32 <src>) + declare i32 @llvm.ctpop.i64(i64 <src>) + declare i32 @llvm.ctpop.i256(i256 <src>)
The only argument is the value to be counted. The argument may be of any -unsigned integer type. The return type must match the argument type. +integer type. The return type must match the argument type.
This is an overloaded intrinsic. You can use llvm.ctlz on any +integer bit width. Not all targets support all bit widths however.
- declare ubyte %llvm.ctlz.i8 (ubyte <src>) - declare ushort %llvm.ctlz.i16(ushort <src>) - declare uint %llvm.ctlz.i32(uint <src>) - declare ulong %llvm.ctlz.i64(ulong <src>) + declare i32 @llvm.ctlz.i8 (i8 <src>) + declare i32 @llvm.ctlz.i16(i16 <src>) + declare i32 @llvm.ctlz.i32(i32 <src>) + declare i32 @llvm.ctlz.i64(i64 <src>) + declare i32 @llvm.ctlz.i256(i256 <src>)
The only argument is the value to be counted. The argument may be of any -unsigned integer type. The return type must match the argument type. +integer type. The return type must match the argument type.
The 'llvm.ctlz' intrinsic counts the leading (most significant) zeros in a variable. If the src == 0 then the result is the size in bits of the type -of src. For example, llvm.ctlz(int 2) = 30. +of src. For example, llvm.ctlz(i32 2) = 30.
This is an overloaded intrinsic. You can use llvm.cttz on any +integer bit width. Not all targets support all bit widths however.
- declare ubyte %llvm.cttz.i8 (ubyte <src>) - declare ushort %llvm.cttz.i16(ushort <src>) - declare uint %llvm.cttz.i32(uint <src>) - declare ulong %llvm.cttz.i64(ulong <src>) + declare i32 @llvm.cttz.i8 (i8 <src>) + declare i32 @llvm.cttz.i16(i16 <src>) + declare i32 @llvm.cttz.i32(i32 <src>) + declare i32 @llvm.cttz.i64(i64 <src>) + declare i32 @llvm.cttz.i256(i256 <src>)
The only argument is the value to be counted. The argument may be of any -unsigned integer type. The return type must match the argument type. +integer type. The return type must match the argument type.
This is an overloaded intrinsic. You can use llvm.part.select +on any integer bit width. +
+ declare i17 @llvm.part.select.i17.i17 (i17 %val, i32 %loBit, i32 %hiBit) + declare i29 @llvm.part.select.i29.i29 (i29 %val, i32 %loBit, i32 %hiBit) ++ +
The 'llvm.part.select' family of intrinsic functions selects a +range of bits from an integer value and returns them in the same bit width as +the original value.
+ +The first argument, %val and the result may be integer types of +any bit width but they must have the same bit width. The second and third +arguments must be i32 type since they specify only a bit index.
+ +The operation of the 'llvm.part.select' intrinsic has two modes +of operation: forwards and reverse. If %loBit is greater than +%hiBits then the intrinsic operates in reverse mode. Otherwise it +operates in forward mode.
+In forward mode, this intrinsic is the equivalent of shifting %val +right by %loBit bits and then ANDing it with a mask with +only the %hiBit - %loBit bits set, as follows:
+In reverse mode, a similar computation is made except that the bits are +returned in the reverse order. So, for example, if X has the value +i16 0x0ACF (101011001111) and we apply +part.select(i16 X, 8, 3) to it, we get back the value +i16 0x0026 (000000100110).
+This is an overloaded intrinsic. You can use llvm.part.set +on any integer bit width. +
+ declare i17 @llvm.part.set.i17.i17.i9 (i17 %val, i9 %repl, i32 %lo, i32 %hi) + declare i29 @llvm.part.set.i29.i29.i9 (i29 %val, i9 %repl, i32 %lo, i32 %hi) ++ +
The 'llvm.part.set' family of intrinsic functions replaces a range +of bits in an integer value with another integer value. It returns the integer +with the replaced bits.
+ +The first argument, %val and the result may be integer types of +any bit width but they must have the same bit width. %val is the value +whose bits will be replaced. The second argument, %repl may be an +integer of any bit width. The third and fourth arguments must be i32 +type since they specify only a bit index.
+ +The operation of the 'llvm.part.set' intrinsic has two modes +of operation: forwards and reverse. If %lo is greater than +%hi then the intrinsic operates in reverse mode. Otherwise it +operates in forward mode.
+For both modes, the %repl value is prepared for use by either +truncating it down to the size of the replacement area or zero extending it +up to that size.
+In forward mode, the bits between %lo and %hi (inclusive) +are replaced with corresponding bits from %repl. That is the 0th bit +in %repl replaces the %loth bit in %val and etc. up +to the %hith bit. +
In reverse mode, a similar computation is made except that the bits are +reversed. That is, the 0th bit in %repl replaces the +%hi bit in %val and etc. down to the %loth bit. +
+ llvm.part.set(0xFFFF, 0, 4, 7) -> 0xFF0F + llvm.part.set(0xFFFF, 0, 7, 4) -> 0xFF0F + llvm.part.set(0xFFFF, 1, 7, 4) -> 0xFF8F + llvm.part.set(0xFFFF, F, 8, 3) -> 0xFFE7 + llvm.part.set(0xFFFF, 0, 3, 8) -> 0xFE07 ++
The LLVM exception handling intrinsics (which all start with +llvm.eh. prefix), are described in the LLVM Exception +Handling document.
+This class of intrinsics is designed to be generic and has +no specific purpose.
++ declare void @llvm.var.annotation(i8* <val>, i8* <str>, i8* <str>, i32 <int> ) ++ +
+The 'llvm.var.annotation' intrinsic +
+ ++The first argument is a pointer to a value, the second is a pointer to a +global string, the third is a pointer to a global string which is the source +file name, and the last argument is the line number. +
+ ++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 + generation and optimization. +