diff --git a/docs/LangRef.html b/docs/LangRef.html index 86041a4d49f..926d8dca346 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -72,13 +72,14 @@
to label <normal label> except label <exception label> -
+
function to be invoked.
+The single argument to 'not' must be of of integral or bool type.
+ +This returns the remainder of a division (where the result has the same +sign as the divisor), not the modulus (where the result has the same sign +as the dividend) of a value. For more information about the difference, see: The Math +Forum.
+ ...
<result> = setge <ty> <var1>, <var2> ; yields {bool}:result -
+
+values, etc...). Both arguments must have identical types.
-The 'setlt', 'setgt', 'setle', and 'setge' instructions do not operate on 'bool' typed arguments.
+The 'setlt', 'setgt', 'setle', and 'setge' +instructions do not operate on 'bool' typed arguments.
+
+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.
@@ -1057,7 +1080,10 @@ bitwise binary operators is always the same type as its first operand.The 'and' instruction returns the bitwise logical and of its two operands.
Arguments:
-The two arguments to the 'and' instruction must be either integral or bool values. Both arguments must have identical types.+ +The two arguments to the 'and' instruction must be either integral or bool values. Both arguments must +have identical types.
Semantics:
@@ -1087,8 +1113,8 @@ inclusive or of its two operands.
Arguments:
The two arguments to the 'or' instruction must be either integral or bool values. -Both arguments must have identical types.+href="#t_integral">integral or bool values. Both arguments must +have identical types.
Semantics:
@@ -1119,8 +1145,8 @@ two operands.
Arguments:
The two arguments to the 'xor' instruction must be either integral or bool values. -Both arguments must have identical types.+href="#t_integral">integral or bool values. Both arguments must +have identical types.
Semantics:
@@ -1202,7 +1228,7 @@ The first argument to the 'shr' instruction must be an Memory Access Operations-Accessing memory in SSA form is, well, sticky at best. This section describes how to read and write memory in LLVM.
+Accessing memory in SSA form is, well, sticky at best. This section describes how to read, write, allocate and free memory in LLVM.
@@ -1255,12 +1281,13 @@ The 'free' instruction returns memory back to the unused memory heap, t
Arguments:
-'value' shall be a pointer value that points to a value that was allocated with the 'malloc' instruction.+'value' shall be a pointer value that points to a value that was +allocated with the 'malloc' instruction.
Semantics:
-Memory is available for use after this point. The contents of the 'value' pointer are undefined after this instruction.+Access to the memory pointed to by the pointer is not longer defined after this instruction executes.
Example:
@@ -1379,11 +1406,7 @@ operand.
Overview:
The 'getelementptr' instruction is used to get the address of a -subelement of an aggregate data structure. In addition to being present as an -explicit instruction, the 'getelementptr' functionality is present in -both the 'load' and 'store' instructions to allow more compact specification -of common expressions.+subelement of an aggregate data structure.
Arguments:
@@ -1393,15 +1416,77 @@ 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.-TODO. +For example, lets consider a C code fragment and how it gets compiled to +LLVM:
+ +
+struct RT { + char A; + int B[10][20]; + char C; +}; +struct ST { + int X; + double Y; + struct RT Z; +}; + +int *foo(struct ST *s) { + return &s[1].Z.B[5][13]; +} ++ +The LLVM code generated by the GCC frontend is: + ++%RT = type { sbyte, [10 x [20 x int]], sbyte } +%ST = type { int, double, %RT } + +int* "foo"(%ST* %s) { + %reg = getelementptr %ST* %s, uint 1, ubyte 2, ubyte 1, uint 5, uint 13 + ret int* %reg +} +Semantics:
+The index types specified for the 'getelementptr' instruction depend on +the pointer type that is being index into. Pointer and +array types require 'uint' values, and structure types require 'ubyte' +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, 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 +array. The two dimensions of the array are subscripted into, yielding an +'int' type. The 'getelementptr' instruction return a pointer +to this element, thus yielding a 'int*' 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 , uint 1 ; yields %ST*:%t1 + %t2 = getelementptr %ST* %t1, uint 0, ubyte 2 ; yields %RT*:%t2 + %t3 = getelementptr %RT* %t2, uint 0, ubyte 1 ; yields [10 x [20 x int]]*:%t3 + %t4 = getelementptr [10 x [20 x int]]* %t3, uint 0, uint 5 ; yields [20 x int]*:%t4 + %t5 = getelementptr [20 x int]* %t4, uint 0, uint 13 ; yields int*:%t5 + ret int* %t5 +} ++ +Example:
- %aptr = getelementptr {int, [12 x ubyte]}* %sptr, 1 ; yields {[12 x ubyte]*}:aptr - %ub = load [12x ubyte]* %aptr, 4 ;yields {ubyte}:ub + ; yields {[12 x ubyte]*}:aptr + %aptr = getelementptr {int, [12 x ubyte]}* %sptr, uint 0, ubyte 1@@ -1416,30 +1501,73 @@ The instructions in this catagory are the "miscellaneous" functions, that defy b -
'cast .. to' Instruction
'phi' Instruction
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.+ +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 %Loop ++ + + +
'cast .. to' Instruction+ +
Syntax:
++ <result> = cast <ty> <value> to <ty2> ; yields ty2 ++ +Overview:
+ +The 'cast' instruction is used as the primitive means to convert +integers to floating point, change data type sizes, and break type safety (by +casting pointers).+ +
Arguments:
+ +The 'cast' instruction takes a value to case, which must be a first +class value, and a type to cast it to, which must also be a first class type.+ +
Semantics:
+ +This instruction follows the C rules for explicit casts when determining how the +data being cast must change to fit in its new container.+ +When casting to bool, any value that would be considered true in the context of a C 'if' condition is converted to the boolean 'true' values, all else are 'false'.
Example:
+ %X = cast int 257 to ubyte ; yields ubyte:1 + %Y = cast int 123 to bool ; yields bool::true@@ -1449,65 +1577,55 @@ The instructions in this catagory are the "miscellaneous" functions, that defy bSyntax:
- + <result> = call <ty>* <fnptrval>(<param list>)Overview:
+The 'call' instruction represents a simple function call.
Arguments:
+This instruction requires several arguments:+
+ +
- 'ty': shall be the signature of the pointer to function value being +invoked. The argument types must match the types implied by this signature.
+ +
- 'fnptrval': An LLVM value containing a pointer to a function to be +invoked. In most cases, this is a direct function invocation, but indirect +call's are just as possible, calling an arbitrary pointer to function +values.
+ +
- 'function args': argument list whose types match the function +signature argument types. If the function signature indicates the function +accepts a variable number of arguments, the extra arguments can be specified. +
Semantics:
+The 'call' instruction is used to cause control flow to transfer to a +specified function, with its incoming arguments bound to the specified values. +Upon a 'ret' instruction in the called function, +control flow continues with the instruction after the function call, and the +return value of the function is bound to the result argument. This is a simpler +case of the invoke instruction.
Example:
%retval = call int %test(int %argc) + call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42); ++
'icall' Instruction- -Indirect calls are desperately needed to implement virtual function tables (C++, java) and function pointers (C, C++, ...).
- -A new instruction icall or similar should be introduced to represent an indirect call.
- -Example: -
- %retval = icall int %funcptr(int %arg1) ; yields {int}:%retval -- - - - -
'phi' Instruction- -
Syntax:
--- -Overview:
- - -Arguments:
- - -Semantics:
- - -Example:
--- - - - +
Related Work |
@@ -1542,7 +1660,7 @@ Codesigned virtual machines.
- +