diff --git a/docs/LangRef.html b/docs/LangRef.html index 57f2603e354..59f9dafb761 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -39,6 +39,7 @@
LLVM uses three different forms of identifiers, for different purposes:
LLVM requires the values start with a '%' sign for two reasons: Compilers don't @@ -346,7 +354,7 @@ Here are some examples of multidimensional arrays:
[3 x [4 x int]] | : 3x4 array integer values. |
[12 x [10 x float]] | : 2x10 array of single precision floating point values. |
[12 x [10 x float]] | : 12x10 array of single precision floating point values. |
[2 x [3 x [4 x uint]]] | : 2x3x4 array of unsigned integer values. |
Where '<parameter list>' is a comma-separated list of type specifiers. Optionally, the parameter list may include a type ..., -which indicates that the function takes a variable number of arguments. Note -that there currently is no way to define a function in LLVM that takes a -variable number of arguments, but it is possible to call a function that -is vararg.
+which indicates that the function takes a variable number of arguments. +Variable argument functions can access their arguments with the variable argument handling intrinsic functions. +
; 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 sbyte] c"hello world\0A\00" ; [13 x sbyte]* -; Forward declaration of puts -declare int "puts"(sbyte*) ; int(sbyte*)* +; External declaration of the puts function +declare int %puts(sbyte*) ; int(sbyte*)* ; Definition of main function -int "main"() { ; int()* +int %main() { ; int()* ; Convert [13x sbyte]* to sbyte *... %cast210 = getelementptr [13 x sbyte]* %.LC0, long 0, long 0 ; sbyte* @@ -510,19 +518,56 @@ This example is made up of a global variable named ".LC0", an external declaration of the "puts" function, and a function definition for "main".- + In general, a module is made up of a list of global values, where both functions and global variables are global values. Global values are 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 can be either "internal" or externally accessible -(which corresponds to the static keyword in C, when used at global scope).
+pointer to a function), and have one of the following linkage types:
+ +
+ +
- internal + +
- Global values with internal linkage are only directly accessible by objects +in the current module. In particular, linking code into a module with 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++.
+ + +
- linkonce: + +
- "linkonce" linkage is similar to internal linkage, with +the twist that linking together two modules defining the same linkonce +globals will cause one of the globals to be discarded. This is typically used +to implement inline functions.
+ 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 "internal" -declarations), they are accessible outside of the current module. It is illegal -for a function declaration to be "internal".
+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".
@@ -547,7 +592,7 @@ of memory, and all memory objects in LLVM are accessed through pointers.
-Function Structure +Functions |
The first basic block in program 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).
+function). Because the block can have no predecessors, it also cannot have any +PHI nodes.
@@ -593,11 +639,12 @@ typically yield a 'void' value: they produce control flow, not values (the one exception being the 'invoke' instruction).
-There are four different terminator instructions: the 'ret' instruction, the 'br' instruction, the 'switch' instruction, and the 'invoke' instruction.
+href="#i_switch">switch' instruction, the 'invoke' instruction, and the 'unwind' instruction.
@@ -628,8 +675,13 @@ that returns a value that does not match the return type of the function.
+the calling function's context. If the caller is a "call instruction, execution continues at the +instruction after the call. If the caller was an "invoke" instruction, execution continues at the +beginning "normal" of the destination block. If the instruction returns a +value, that value shall set the call or invoke instruction's return value.
+
@@ -665,8 +717,8 @@ target.Upon execution of a conditional 'br' instruction, the 'bool' argument is evaluated. If the value is true, control flows to the -'iftrue' 'label' argument. If "cond" is false, -control flows to the 'iffalse' 'label' argument.
+'iftrue' label argument. If "cond" is false, +control flows to the 'iffalse' label argument.
Example:
@@ -685,7 +737,7 @@ IfUnequal:Syntax:
- switch int <value>, label <defaultdest> [ int <val>, label &dest>, ... ] + switch uint <value>, label <defaultdest> [ int <val>, label &dest>, ... ]@@ -718,15 +770,15 @@ conditional branches, or with a lookup table.
; Emulate a conditional br instruction %Val = cast bool %value to uint - switch int %Val, label %truedest [int 0, label %falsedest ] + switch uint %Val, label %truedest [int 0, label %falsedest ] ; Emulate an unconditional br instruction - switch int 0, label %dest [ ] + switch uint 0, label %dest [ ] ; Implement a jump table: - switch int %val, label %otherwise [ int 0, label %onzero, - int 1, label %onone, - int 2, label %ontwo ] + switch uint %val, label %otherwise [ int 0, label %onzero, + int 1, label %onone, + int 2, label %ontwo ]@@ -744,11 +796,12 @@ conditional branches, or with a lookup table.The 'invoke' instruction causes control to transfer to a specified function, with the possibility of control flow transfer to either the -'normal label' label or the 'exception label'. If the callee -function invokes the "ret" instruction, control -flow will return to the "normal" label. If the callee (or any indirect callees) -calls the "llvm.unwind" intrinsic, control is -interrupted, and continued at the "except" label.
+'normal' label label or the 'exception' +label. If the callee function returns with the "ret" instruction, control flow will return to the +"normal" label. If the callee (or any indirect callees) returns with the "unwind" instruction, control is interrupted, and +continued at the dynamically nearest "except" label.
Arguments:
@@ -771,8 +824,8 @@ accepts a variable number of arguments, the extra arguments can be specified.
+ unwind ++ +
There are several different binary operators:
@@ -972,9 +1049,6 @@ href="#t_pointer">pointer type (it is not possible to compare 'label's, 'array's, 'structure' or 'void' values, etc...). Both arguments must have identical types.
-The 'setlt', 'setgt', 'setle', and 'setge' -instructions do not operate on 'bool' typed arguments.
-
+two operands. The xor is used to implement the "one's complement" +operation, which is the "~" operator in C.
<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 @@ -1211,7 +1287,9 @@ argument is unsigned, zero bits shall fill the empty positions.
Memory Access Operations
+A key design point of an SSA-based representation is how it represents memory.
+In LLVM, no memory locations are in SSA form, which makes things very simple.
+This section describes how to read, write, allocate and free memory in LLVM.
@@ -1234,10 +1312,12 @@ system, and returns a pointer of the appropriate type to the program. The
second form of the instruction is a shorter version of the first instruction
that defaults to allocating one element.
-'type' must be a sized type
+'type' must be a sized type.
+
+Memory is allocated using the system "malloc" function, and a pointer
+is returned.
Memory is allocated, a pointer is returned. 'alloca'd memory is
automatically released when the function returns. The 'alloca'
instruction is commonly used to represent automatic variables that must have an
-address available, as well as spilled variables.
+address available. When the function returns (either with the ret or invoke
+instructions), the memory is reclaimed.
-
-
-Accessing memory in SSA form is, well, sticky at best. This section describes how to read, write, allocate and free memory in LLVM.
Semantics:
-Memory is allocated, a pointer is returned.Example:
@@ -1308,7 +1388,9 @@ one element.
Example:
@@ -1803,32 +1885,6 @@ because the llvm.va_begin intrinsic may be
arbitrarily complex and require memory allocation, for example.
'llvm.unwind' Intrinsic
-
-
Syntax:
-
- call void (void)* %llvm.unwind()
-
-
-Overview:
-
-The 'llvm.unwind' intrinsic unwinds the stack, continuing control flow
-at the first callee in the dynamic call stack which used an invoke instruction to perform the call. This is
-primarily used to implement exception handling.
-
-Semantics:
-
-The 'llvm.unwind' intrinsic causes execution of the current function to
-immediately halt. The dynamic call stack is then searched for the first invoke instruction on the call stack. Once found,
-execution continues at the "exceptional" destination block specified by the
-invoke instruction. If there is no invoke instruction in the dynamic
-call chain, undefined behavior results.
-
-
-
@@ -1839,7 +1895,7 @@ call chain, undefined behavior results.
Chris Lattner
-Last modified: Tue Sep 2 18:38:09 CDT 2003
+Last modified: Tue Sep 2 19:41:01 CDT 2003