-
-
-As was mentioned previously, every basic block
-in a program ends with a "Terminator" instruction. All of these terminator
-instructions yield a 'void' value: they produce control flow, not
-values.
+As mentioned previously, every basic block in a
+program ends with a "Terminator" instruction, which indicates where control flow
+should go now that this basic block has been completely executed. These
+terminator instructions 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 'invoke' instruction.
Overview:
- The 'ret' instruction is used to return control flow (and optionally a
- value) from a function, back to the caller.
+The 'ret' instruction is used to return control flow (and a value) from
+a function, back to the caller.
There are two forms of the 'ret' instructruction: one that returns a
value and then causes control flow, and one that just causes control flow to
@@ -578,9 +664,9 @@ Test:
%cond = seteq int %a, %b
br bool %cond, label %IfEqual, label %IfUnequal
IfEqual:
- ret bool true
+ ret int 1
IfUnequal:
- ret bool false
+ ret int 0
@@ -611,9 +697,9 @@ generally useful if the values to switch on are spread far appart, where index
branching is useful if the values to switch on are generally dense.
The two different forms of the 'switch' statement are simple hints to
-the underlying virtual machine implementation. For example, a virtual machine
-may choose to implement a small indirect branch table as a series of predicated
-comparisons: if it is faster for the target architecture.
+the underlying implementation. For example, the compiler may choose to
+implement a small indirect branch table as a series of predicated comparisons:
+if it is faster for the target architecture.
Arguments:
@@ -648,16 +734,7 @@ provided as part of the constant values type.
; Emulate an unconditional br instruction
switch uint 0, label %dest, [ 0 x label] [ ]
- ; Implement a jump table using the constant pool:
- void "testmeth"(int %arg0)
- %switchdests = [3 x label] [ label %onzero, label %onone, label %ontwo ]
- begin
- ...
- switch uint %val, label %otherwise, [3 x label] %switchdests...
- ...
- end
-
- ; Implement the equivilent jump table directly:
+ ; Implement a jump table:
switch uint %val, label %otherwise, [3 x label] [ label %onzero,
label %onone,
label %ontwo ]
@@ -689,7 +766,7 @@ This instruction requires several arguments:
- 'ptr to function ty': shall be the signature of the pointer to
-function value being invoked. In most cases, this is a direct method
+function value being invoked. In most cases, this is a direct function
invocation, but indirect invoke's are just as possible, branching off
an arbitrary pointer to function value.
@@ -707,7 +784,14 @@ a 'ret' instruction.
Semantics:
-This instruction is designed to operate as a standard 'call' instruction in most regards. The primary difference is that it assiciates a label with the function invocation that may be accessed via the runtime library provided by the execution environment. This instruction is used in languages with destructors to ensure that proper cleanup is performed in the case of either a longjmp or a thrown exception. Additionally, this is important for implementation of 'catch' clauses in high-level languages that support them.
+This instruction is designed to operate as a standard 'call' instruction in most regards. The primary
+difference is that it associates a label with the function invocation that may
+be accessed via the runtime library provided by the execution environment. This
+instruction is used in languages with destructors to ensure that proper cleanup
+is performed in the case of either a longjmp or a thrown exception.
+Additionally, this is important for implementation of 'catch' clauses
+in high-level languages that support them.
For a more comprehensive explanation of this instruction look in the llvm/docs/2001-05-18-ExceptionHandling.txt document.
@@ -720,7 +804,8 @@ For a more comprehensive explanation of this instruction look in the llvm/docs/2
-