<h5>Syntax:</h5>
<pre>
- <i>; Definitions for lookup indirect branch</i>
- %switchtype = type [<anysize> x { uint, label }]
+ switch int <value>, label <defaultdest> [ int <val>, label &dest>, ... ]
- <i>; Lookup indirect branch</i>
- switch uint <value>, label <defaultdest>, %switchtype <switchtable>
-<!--
- <i>; Indexed indirect branch</i>
- switch uint <idxvalue>, label <defaultdest>, [<anysize> x label] <desttable>
--->
</pre>
<h5>Overview:</h5>
-<b>NOTE:</b> The switch instruction may go away in the future. It is not very
-well supported in LLVM anyway, so don't go to great lengths to support it. Talk
-to <a href="mailto:sabre@nondot.org">Chris</a> for more info if this concerns
-you.<p>
-
The '<tt>switch</tt>' instruction is used to transfer control flow to one of
several different places. It is a generalization of the '<tt>br</tt>'
instruction, allowing a branch to occur to one of many possible destinations.<p>
-The '<tt>switch</tt>' statement supports two different styles of indirect
-branching: lookup branching and indexed branching. Lookup branching is
-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.<p>
-
-The two different forms of the '<tt>switch</tt>' statement are simple hints to
-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.<p>
-
<h5>Arguments:</h5>
-The lookup form of the '<tt>switch</tt>' instruction uses three parameters: a
-'<tt>uint</tt>' comparison value '<tt>value</tt>', a default '<tt>label</tt>'
-destination, and an array of pairs of comparison value constants and
-'<tt>label</tt>'s. The sized array must be a constant value.<p>
-
-The indexed form of the '<tt>switch</tt>' instruction uses three parameters: an
-'<tt>uint</tt>' index value, a default '<tt>label</tt>' and a sized array of
-'<tt>label</tt>'s. The '<tt>dests</tt>' array must be a constant array.
+The '<tt>switch</tt>' instruction uses three parameters: a '<tt>uint</tt>'
+comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
+an array of pairs of comparison value constants and '<tt>label</tt>'s.<p>
<h5>Semantics:</h5>
-The lookup style switch statement specifies a table of values and destinations.
+The <tt>switch</tt> instruction specifies a table of values and destinations.
When the '<tt>switch</tt>' instruction is executed, this table is searched for
the given value. If the value is found, the corresponding destination is
-branched to. <p>
+branched to, otherwise the default value it transfered to.<p>
-The index branch form simply looks up a label element directly in a table and
-branches to it.<p>
+<h5>Implementation:</h5>
-In either case, the compiler knows the static size of the array, because it is
-provided as part of the constant values type.<p>
+Depending on properties of the target machine and the particular <tt>switch</tt>
+instruction, this instruction may be code generated as a series of chained
+conditional branches, or with a lookup table.<p>
<h5>Example:</h5>
<pre>
<i>; Emulate a conditional br instruction</i>
%Val = <a href="#i_cast">cast</a> bool %value to uint
- switch uint %Val, label %truedest, [1 x label] [label %falsedest ]
+ switch int %Val, label %truedest [int 0, label %falsedest ]
<i>; Emulate an unconditional br instruction</i>
- switch uint 0, label %dest, [ 0 x label] [ ]
+ switch int 0, label %dest [ ]
<i>; Implement a jump table:</i>
- switch uint %val, label %otherwise, [3 x label] [ label %onzero,
- label %onone,
- label %ontwo ]
-
+ switch int %val, label %otherwise [ int 0, label %onzero,
+ int 1, label %onone,
+ int 2, label %ontwo ]
</pre>
%aq = alloca sbyte*
; Initialize variable argument processing
- call void (sbyte**, ...)* %<a href="#i_va_start">llvm.va_start</a>(sbyte** %ap, int %X)
+ call void (sbyte**)* %<a href="#i_va_start">llvm.va_start</a>(sbyte** %ap)
; Read a single integer argument
%tmp = <a href="#i_va_arg">va_arg</a> sbyte** %ap, int
<h5>Syntax:</h5>
<pre>
- call void (va_list*, ...)* %llvm.va_start(<va_list>* <arglist>, <argument>)
+ call void (va_list*)* %llvm.va_start(<va_list>* <arglist>)
</pre>
<h5>Overview:</h5>
<h5>Arguments:</h5>
-The first argument is a pointer to a <tt>va_list</tt> element to initialize.
-The second argument is required to be the last LLVM argument before the
-ellipsis. In the future, this restriction may be relaxed (to allow it to be
-other arguments).<p>
+The argument is a pointer to a <tt>va_list</tt> element to initialize.<p>
<h5>Semantics:</h5>
The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
macro available in C. In a target-dependent way, it initializes the
-<tt>va_list</tt> element the first argument points to, so that the next call to
-<tt>va_arg</tt> will produce the first variable argument passed to the
-function.<p>
+<tt>va_list</tt> element the argument points to, so that the next call to
+<tt>va_arg</tt> will produce the first variable argument passed to the function.
+Unlike the C <tt>va_start</tt> macro, this intrinsic does not need to know the
+last argument of the function, the compiler can figure that out.<p>
<!-- _______________________________________________________________________ -->
<address><a href="mailto:sabre@nondot.org">Chris Lattner</a></address>
<!-- Created: Tue Jan 23 15:19:28 CST 2001 -->
<!-- hhmts start -->
-Last modified: Wed May 7 23:56:16 CDT 2003
+Last modified: Thu May 8 10:48:46 CDT 2003
<!-- hhmts end -->
</font>
</body></html>