e6e9c30d69afa419953e2b0ef000a13adeb516ab
[oota-llvm.git] / docs / LangRef.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html><head><title>llvm Assembly Language Reference Manual</title></head>
3 <body bgcolor=white>
4
5 <table width="100%" bgcolor="#330077" border=0 cellpadding=4 cellspacing=0>
6 <tr><td>&nbsp; <font size=+5 color="#EEEEFF" face="Georgia,Palatino,Times,Roman"><b>llvm Assembly Language Reference Manual</b></font></td>
7 </tr></table>
8
9 <ol>
10   <li><a href="#abstract">Abstract</a>
11   <li><a href="#introduction">Introduction</a>
12   <li><a href="#identifiers">Identifiers</a>
13   <li><a href="#typesystem">Type System</a>
14     <ol>
15       <li><a href="#t_primitive">Primitive Types</a>
16         <ol>
17           <li><a href="#t_classifications">Type Classifications</a>
18         </ol>
19       <li><a href="#t_derived">Derived Types</a>
20         <ol>
21           <li><a href="#t_array"  >Array Type</a>
22           <li><a href="#t_function">Function Type</a>
23           <li><a href="#t_pointer">Pointer Type</a>
24           <li><a href="#t_struct" >Structure Type</a>
25           <li><a href="#t_packed" >Packed Type</a>
26         </ol>
27     </ol>
28   <li><a href="#highlevel">High Level Structure</a>
29     <ol>
30       <li><a href="#modulestructure">Module Structure</a>
31       <li><a href="#globalvars">Global Variables</a>
32       <li><a href="#functionstructure">Function Structure</a>
33     </ol>
34   <li><a href="#instref">Instruction Reference</a>
35     <ol>
36       <li><a href="#terminators">Terminator Instructions</a>
37         <ol>
38           <li><a href="#i_ret"   >'<tt>ret</tt>' Instruction</a>
39           <li><a href="#i_br"    >'<tt>br</tt>' Instruction</a>
40           <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a>
41           <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a>
42         </ol>
43       <li><a href="#unaryops">Unary Operations</a>
44         <ol>
45           <li><a href="#i_not" >'<tt>not</tt>' Instruction</a>
46         </ol>
47       <li><a href="#binaryops">Binary Operations</a>
48         <ol>
49           <li><a href="#i_add"  >'<tt>add</tt>' Instruction</a>
50           <li><a href="#i_sub"  >'<tt>sub</tt>' Instruction</a>
51           <li><a href="#i_mul"  >'<tt>mul</tt>' Instruction</a>
52           <li><a href="#i_div"  >'<tt>div</tt>' Instruction</a>
53           <li><a href="#i_rem"  >'<tt>rem</tt>' Instruction</a>
54           <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a>
55         </ol>
56       <li><a href="#bitwiseops">Bitwise Binary Operations</a>
57         <ol>
58           <li><a href="#i_and">'<tt>and</tt>' Instruction</a>
59           <li><a href="#i_or" >'<tt>or</tt>'  Instruction</a>
60           <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a>
61           <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a>
62           <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a>
63         </ol>
64       <li><a href="#memoryops">Memory Access Operations</a>
65         <ol>
66           <li><a href="#i_malloc"  >'<tt>malloc</tt>'   Instruction</a>
67           <li><a href="#i_free"    >'<tt>free</tt>'     Instruction</a>
68           <li><a href="#i_alloca"  >'<tt>alloca</tt>'   Instruction</a>
69           <li><a href="#i_load"    >'<tt>load</tt>'     Instruction</a>
70           <li><a href="#i_store"   >'<tt>store</tt>'    Instruction</a>
71           <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
72         </ol>
73       <li><a href="#otherops">Other Operations</a>
74         <ol>
75           <li><a href="#i_phi"  >'<tt>phi</tt>'   Instruction</a>
76           <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a>
77           <li><a href="#i_call" >'<tt>call</tt>'  Instruction</a>
78         </ol>
79     </ol>
80 <!--
81   <li><a href="#related">Related Work</a>
82 -->
83 </ol>
84
85
86 <!-- *********************************************************************** -->
87 <p><table width="100%" bgcolor="#330077" border=0 cellpadding=4 cellspacing=0>
88 <tr><td align=center><font color="#EEEEFF" size=+2 face="Georgia,Palatino"><b>
89 <a name="abstract">Abstract
90 </b></font></td></tr></table><ul>
91 <!-- *********************************************************************** -->
92
93 <blockquote>
94   This document is a reference manual for the LLVM assembly language.  LLVM is
95   an SSA based representation that provides type safety, low level operations,
96   flexibility, and the capability of representing 'all' high level languages
97   cleanly.  It is the common code representation used throughout all phases of
98   the LLVM compilation strategy.
99 </blockquote>
100
101
102
103
104 <!-- *********************************************************************** -->
105 </ul><table width="100%" bgcolor="#330077" border=0 cellpadding=4 cellspacing=0>
106 <tr><td align=center><font color="#EEEEFF" size=+2 face="Georgia,Palatino"><b>
107 <a name="introduction">Introduction
108 </b></font></td></tr></table><ul>
109 <!-- *********************************************************************** -->
110
111 The LLVM code representation is designed to be used in three different forms: as
112 an in-memory compiler IR, as an on-disk bytecode representation, suitable for
113 fast loading by a dynamic compiler, and as a human readable assembly language
114 representation.  This allows LLVM to provide a powerful intermediate
115 representation for efficient compiler transformations and analysis, while
116 providing a natural means to debug and visualize the transformations.  The three
117 different forms of LLVM are all equivalent.  This document describes the human
118 readable representation and notation.<p>
119
120 The LLVM representation aims to be a light weight and low level while being
121 expressive, typed, and extensible at the same time.  It aims to be a "universal
122 IR" of sorts, by being at a low enough level that high level ideas may be
123 cleanly mapped to it (similar to how microprocessors are "universal IR's",
124 allowing many source languages to be mapped to them).  By providing type
125 information, LLVM can be used as the target of optimizations: for example,
126 through pointer analysis, it can be proven that a C automatic variable is never
127 accessed outside of the current function... allowing it to be promoted to a
128 simple SSA value instead of a memory location.<p>
129
130 <!-- _______________________________________________________________________ -->
131 </ul><a name="wellformed"><h4><hr size=0>Well Formedness</h4><ul>
132
133 It is important to note that this document describes 'well formed' llvm assembly
134 language.  There is a difference between what the parser accepts and what is
135 considered 'well formed'.  For example, the following instruction is
136 syntactically okay, but not well formed:<p>
137
138 <pre>
139   %x = <a href="#i_add">add</a> int 1, %x
140 </pre>
141
142 ...because the definition of %x does not dominate all of its uses.  The LLVM
143 infrastructure provides a verification pass that may be used to verify that an
144 LLVM module is well formed.  This pass is automatically run by the parser after
145 parsing input assembly, and by the optimizer before it outputs bytecode.  The
146 violations pointed out by the verifier pass indicate bugs in transformation
147 passes or input to the parser.<p>
148
149 <!-- Describe the typesetting conventions here. -->
150
151
152 <!-- *********************************************************************** -->
153 </ul><table width="100%" bgcolor="#330077" border=0 cellpadding=4 cellspacing=0>
154 <tr><td align=center><font color="#EEEEFF" size=+2 face="Georgia,Palatino"><b>
155 <a name="identifiers">Identifiers
156 </b></font></td></tr></table><ul>
157 <!-- *********************************************************************** -->
158
159 LLVM uses three different forms of identifiers, for different purposes:<p>
160
161 <ol>
162 <li>Numeric constants are represented as you would expect: 12, -3 123.421, etc.  Floating point constants have an optional hexidecimal notation.
163 <li>Named values are represented as a string of characters with a '%' prefix.  For example, %foo, %DivisionByZero, %a.really.long.identifier.  The actual regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
164 <li>Unnamed values are represented as an unsigned numeric value with a '%' prefix.  For example, %12, %2, %44.
165 </ol><p>
166
167 LLVM requires the values start with a '%' sign for two reasons: Compilers don't
168 need to worry about name clashes with reserved words, and the set of reserved
169 words may be expanded in the future without penalty.  Additionally, unnamed
170 identifiers allow a compiler to quickly come up with a temporary variable
171 without having to avoid symbol table conflicts.<p>
172
173 Reserved words in LLVM are very similar to reserved words in other languages.
174 There are keywords for different opcodes ('<tt><a href="#i_add">add</a></tt>',
175 '<tt><a href="#i_cast">cast</a></tt>', '<tt><a href="#i_ret">ret</a></tt>',
176 etc...), for primitive type names ('<tt><a href="#t_void">void</a></tt>',
177 '<tt><a href="#t_uint">uint</a></tt>', etc...), and others.  These reserved
178 words cannot conflict with variable names, because none of them start with a '%'
179 character.<p>
180
181 Here is an example of LLVM code to multiply the integer variable '<tt>%X</tt>'
182 by 8:<p>
183
184 The easy way:
185 <pre>
186   %result = <a href="#i_mul">mul</a> uint %X, 8
187 </pre>
188
189 After strength reduction:
190 <pre>
191   %result = <a href="#i_shl">shl</a> uint %X, ubyte 3
192 </pre>
193
194 And the hard way:
195 <pre>
196   <a href="#i_add">add</a> uint %X, %X           <i>; yields {uint}:%0</i>
197   <a href="#i_add">add</a> uint %0, %0           <i>; yields {uint}:%1</i>
198   %result = <a href="#i_add">add</a> uint %1, %1
199 </pre>
200
201 This last way of multiplying <tt>%X</tt> by 8 illustrates several important lexical features of LLVM:<p>
202
203 <ol>
204 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of line.
205 <li>Unnamed temporaries are created when the result of a computation is not
206     assigned to a named value.
207 <li>Unnamed temporaries are numbered sequentially
208 </ol><p>
209
210 ...and it also show a convention that we follow in this document.  When
211 demonstrating instructions, we will follow an instruction with a comment that
212 defines the type and name of value produced.  Comments are shown in italic
213 text.<p>
214
215 The one unintuitive notation for constants is the optional hexidecimal form of
216 floating point constants.  For example, the form '<tt>double
217 0x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
218 4.5e+15</tt>' which is also supported by the parser.  The only time hexadecimal
219 floating point constants are useful (and the only time that they are generated
220 by the disassembler) is when an FP constant has to be emitted that is not
221 representable as a decimal floating point number exactly.  For example, NaN's,
222 infinities, and other special cases are represented in their IEEE hexadecimal
223 format so that assembly and disassembly do not cause any bits to change in the
224 constants.<p>
225
226
227 <!-- *********************************************************************** -->
228 </ul><table width="100%" bgcolor="#330077" border=0 cellpadding=4 cellspacing=0>
229 <tr><td align=center><font color="#EEEEFF" size=+2 face="Georgia,Palatino"><b>
230 <a name="typesystem">Type System
231 </b></font></td></tr></table><ul>
232 <!-- *********************************************************************** -->
233
234 The LLVM type system is one of the most important features of the intermediate
235 representation.  Being typed enables a number of optimizations to be performed
236 on the IR directly, without having to do extra analyses on the side before the
237 transformation.  A strong type system makes it easier to read the generated code
238 and enables novel analyses and transformations that are not feasible to perform
239 on normal three address code representations.<p>
240
241 <!-- The written form for the type system was heavily influenced by the
242 syntactic problems with types in the C language<sup><a
243 href="#rw_stroustrup">1</a></sup>.<p> -->
244
245
246
247 <!-- ======================================================================= -->
248 </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0>
249 <tr><td>&nbsp;</td><td width="100%">&nbsp; <font color="#EEEEFF" face="Georgia,Palatino"><b>
250 <a name="t_primitive">Primitive Types
251 </b></font></td></tr></table><ul>
252
253 The primitive types are the fundemental building blocks of the LLVM system.  The
254 current set of primitive types are as follows:<p>
255
256 <table border=0 align=center><tr><td>
257
258 <table border=1 cellspacing=0 cellpadding=4 align=center>
259 <tr><td><tt>void</tt></td>  <td>No value</td></tr>
260 <tr><td><tt>ubyte</tt></td> <td>Unsigned 8 bit value</td></tr>
261 <tr><td><tt>ushort</tt></td><td>Unsigned 16 bit value</td></tr>
262 <tr><td><tt>uint</tt></td>  <td>Unsigned 32 bit value</td></tr>
263 <tr><td><tt>ulong</tt></td> <td>Unsigned 64 bit value</td></tr>
264 <tr><td><tt>float</tt></td> <td>32 bit floating point value</td></tr>
265 <tr><td><tt>label</tt></td> <td>Branch destination</td></tr>
266 </table>
267
268 </td><td valign=top>
269
270 <table border=1 cellspacing=0 cellpadding=4 align=center>
271 <tr><td><tt>bool</tt></td>  <td>True or False value</td></tr>
272 <tr><td><tt>sbyte</tt></td> <td>Signed 8 bit value</td></tr>
273 <tr><td><tt>short</tt></td> <td>Signed 16 bit value</td></tr>
274 <tr><td><tt>int</tt></td>   <td>Signed 32 bit value</td></tr>
275 <tr><td><tt>long</tt></td>  <td>Signed 64 bit value</td></tr>
276 <tr><td><tt>double</tt></td><td>64 bit floating point value</td></tr>
277 </table>
278
279 </td></tr></table><p>
280
281
282
283 <!-- _______________________________________________________________________ -->
284 </ul><a name="t_classifications"><h4><hr size=0>Type Classifications</h4><ul>
285
286 These different primitive types fall into a few useful classifications:<p>
287
288 <table border=1 cellspacing=0 cellpadding=4 align=center>
289 <tr><td><a name="t_signed">signed</td>    <td><tt>sbyte, short, int, long, float, double</tt></td></tr>
290 <tr><td><a name="t_unsigned">unsigned</td><td><tt>ubyte, ushort, uint, ulong</tt></td></tr>
291 <tr><td><a name="t_integral">integral</td><td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td></tr>
292 <tr><td><a name="t_floating">floating point</td><td><tt>float, double</tt></td></tr>
293 <tr><td><a name="t_firstclass">first class</td><td><tt>bool, ubyte, sbyte, ushort, short,<br> uint, int, ulong, long, float, double, <a href="#t_pointer">pointer</a></tt></td></tr>
294 </table><p>
295
296
297
298
299
300 <!-- ======================================================================= -->
301 </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0><tr><td>&nbsp;</td><td width="100%">&nbsp; <font color="#EEEEFF" face="Georgia,Palatino"><b>
302 <a name="t_derived">Derived Types
303 </b></font></td></tr></table><ul>
304
305 The real power in LLVM comes from the derived types in the system.  This is what
306 allows a programmer to represent arrays, functions, pointers, and other useful
307 types.  Note that these derived types may be recursive: For example, it is
308 possible to have a two dimensional array.<p>
309
310
311
312 <!-- _______________________________________________________________________ -->
313 </ul><a name="t_array"><h4><hr size=0>Array Type</h4><ul>
314
315 <h5>Overview:</h5>
316
317 The array type is a very simple derived type that arranges elements sequentially
318 in memory.  The array type requires a size (number of elements) and an
319 underlying data type.<p>
320
321 <h5>Syntax:</h5>
322 <pre>
323   [&lt;# elements&gt; x &lt;elementtype&gt;]
324 </pre>
325
326 The number of elements is a constant integer value, elementtype may be any type
327 with a size.<p>
328
329 <h5>Examples:</h5>
330 <ul>
331    <tt>[40 x int ]</tt>: Array of 40 integer values.<br>
332    <tt>[41 x int ]</tt>: Array of 41 integer values.<br>
333    <tt>[40 x uint]</tt>: Array of 40 unsigned integer values.<p>
334 </ul>
335
336 Here are some examples of multidimensional arrays:<p>
337 <ul>
338 <table border=0 cellpadding=0 cellspacing=0>
339 <tr><td><tt>[3 x [4 x int]]</tt></td><td>: 3x4 array integer values.</td></tr>
340 <tr><td><tt>[12 x [10 x float]]</tt></td><td>: 2x10 array of single precision floating point values.</td></tr>
341 <tr><td><tt>[2 x [3 x [4 x uint]]]</tt></td><td>: 2x3x4 array of unsigned integer values.</td></tr>
342 </table>
343 </ul>
344
345
346 <!-- _______________________________________________________________________ -->
347 </ul><a name="t_function"><h4><hr size=0>Function Type</h4><ul>
348
349 <h5>Overview:</h5>
350
351 The function type can be thought of as a function signature.  It consists of a
352 return type and a list of formal parameter types.  Function types are usually
353 used when to build virtual function tables (which are structures of pointers to
354 functions), for indirect function calls, and when defining a function.<p>
355
356 <h5>Syntax:</h5>
357 <pre>
358   &lt;returntype&gt; (&lt;parameter list&gt;)
359 </pre>
360
361 Where '<tt>&lt;parameter list&gt;</tt>' is a comma seperated list of type
362 specifiers.  Optionally, the parameter list may include a type <tt>...</tt>,
363 which indicates that the function takes a variable number of arguments.  Note
364 that there currently is no way to define a function in LLVM that takes a
365 variable number of arguments, but it is possible to <b>call</b> a function that
366 is vararg.<p>
367
368 <h5>Examples:</h5>
369 <ul>
370 <table border=0 cellpadding=0 cellspacing=0>
371
372 <tr><td><tt>int (int)</tt></td><td>: function taking an <tt>int</tt>, returning
373 an <tt>int</tt></td></tr>
374
375 <tr><td><tt>float (int, int *) *</tt></td><td>: <a href="#t_pointer">Pointer</a>
376 to a function that takes an <tt>int</tt> and a <a href="#t_pointer">pointer</a>
377 to <tt>int</tt>, returning <tt>float</tt>.</td></tr>
378
379 <tr><td><tt>int (sbyte *, ...)</tt></td><td>: A vararg function that takes at
380 least one <a href="#t_pointer">pointer</a> to <tt>sbyte</tt> (signed char in C),
381 which returns an integer.  This is the signature for <tt>printf</tt> in
382 LLVM.</td></tr>
383
384 </table>
385 </ul>
386
387
388
389 <!-- _______________________________________________________________________ -->
390 </ul><a name="t_struct"><h4><hr size=0>Structure Type</h4><ul>
391
392 <h5>Overview:</h5>
393
394 The structure type is used to represent a collection of data members together in
395 memory.  The packing of the field types is defined to match the ABI of the
396 underlying processor.  The elements of a structure may be any type that has a
397 size.<p>
398
399 Structures are accessed using '<tt><a href="#i_load">load</a></tt> and '<tt><a
400 href="#i_store">store</a></tt>' by getting a pointer to a field with the '<tt><a
401 href="#i_getelementptr">getelementptr</a></tt>' instruction.<p>
402
403 <h5>Syntax:</h5>
404 <pre>
405   { &lt;type list&gt; }
406 </pre>
407
408
409 <h5>Examples:</h5>
410 <table border=0 cellpadding=0 cellspacing=0>
411
412 <tr><td><tt>{ int, int, int }</tt></td><td>: a triple of three <tt>int</tt>
413 values</td></tr>
414
415 <tr><td><tt>{ float, int (int) * }</tt></td><td>: A pair, where the first
416 element is a <tt>float</tt> and the second element is a <a
417 href="#t_pointer">pointer</a> to a <a href="t_function">function</a> that takes
418 an <tt>int</tt>, returning an <tt>int</tt>.</td></tr>
419
420 </table>
421
422
423 <!-- _______________________________________________________________________ -->
424 </ul><a name="t_pointer"><h4><hr size=0>Pointer Type</h4><ul>
425
426 <h5>Overview:</h5>
427
428 As in many languages, the pointer type represents a pointer or reference to
429 another object, which must live in memory.<p>
430
431 <h5>Syntax:</h5>
432 <pre>
433   &lt;type&gt; *
434 </pre>
435
436 <h5>Examples:</h5>
437
438 <table border=0 cellpadding=0 cellspacing=0>
439
440 <tr><td><tt>[4x int]*</tt></td><td>: <a href="#t_pointer">pointer</a> to <a
441 href="#t_array">array</a> of four <tt>int</tt> values</td></tr>
442
443 <tr><td><tt>int (int *) *</tt></td><td>: A <a href="#t_pointer">pointer</a> to a
444 <a href="t_function">function</a> that takes an <tt>int</tt>, returning an
445 <tt>int</tt>.</td></tr>
446
447 </table>
448 <p>
449
450
451 <!-- _______________________________________________________________________ -->
452 <!--
453 </ul><a name="t_packed"><h4><hr size=0>Packed Type</h4><ul>
454
455 Mention/decide that packed types work with saturation or not. Maybe have a packed+saturated type in addition to just a packed type.<p>
456
457 Packed types should be 'nonsaturated' because standard data types are not saturated.  Maybe have a saturated packed type?<p>
458
459 -->
460
461
462 <!-- *********************************************************************** -->
463 </ul><table width="100%" bgcolor="#330077" border=0 cellpadding=4 cellspacing=0>
464 <tr><td align=center><font color="#EEEEFF" size=+2 face="Georgia,Palatino"><b>
465 <a name="highlevel">High Level Structure
466 </b></font></td></tr></table><ul>
467 <!-- *********************************************************************** -->
468
469
470 <!-- ======================================================================= -->
471 </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0>
472 <tr><td>&nbsp;</td><td width="100%">&nbsp; <font color="#EEEEFF" face="Georgia,Palatino"><b>
473 <a name="modulestructure">Module Structure
474 </b></font></td></tr></table><ul>
475
476 LLVM programs are composed of "Module"s, each of which is a translation unit of
477 the input programs.  Each module consists of functions, global variables, and
478 symbol table entries.  Modules may be combined together with the LLVM linker,
479 which merges function (and global variable) definitions, resolves forward
480 declarations, and merges symbol table entries. Here is an example of the "hello world" module:<p>
481
482 <pre>
483 <i>; Declare the string constant as a global constant...</i>
484 <a href="#identifiers">%.LC0</a> = <a href="#linkage_decl">internal</a> <a href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00"          <i>; [13 x sbyte]*</i>
485
486 <i>; Forward declaration of puts</i>
487 <a href="#functionstructure">declare</a> int "puts"(sbyte*)                                           <i>; int(sbyte*)* </i>
488
489 <i>; Definition of main function</i>
490 int "main"() {                                                       <i>; int()* </i>
491         <i>; Convert [13x sbyte]* to sbyte *...</i>
492         %cast210 = <a href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, uint 0, uint 0 <i>; sbyte*</i>
493
494         <i>; Call puts function to write out the string to stdout...</i>
495         <a href="#i_call">call</a> int %puts(sbyte* %cast210)                              <i>; int</i>
496         <a href="#i_ret">ret</a> int 0
497 }
498 </pre>
499
500 This example is made up of a <a href="#globalvars">global variable</a> named
501 "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>" function, and a
502 <a href="#functionstructure">function definition</a> for "<tt>main</tt>".<p>
503
504 <a name="linkage_decl">
505 In general, a module is made up of a list of global values, where both functions
506 and global variables are global values.  Global values are represented by a
507 pointer to a memory location (in this case, a pointer to an array of char, and a
508 pointer to a function), and can be either "internal" or externally accessible
509 (which corresponds to the static keyword in C, when used at global scope).<p>
510
511 For example, since the "<tt>.LC0</tt>" variable is defined to be internal, if
512 another module defined a "<tt>.LC0</tt>" variable and was linked with this one,
513 one of the two would be renamed, preventing a collision.  Since "<tt>main</tt>"
514 and "<tt>puts</tt>" are external (i.e., lacking "<tt>internal</tt>"
515 declarations), they are accessible outside of the current module.  It is illegal
516 for a function declaration to be "<tt>internal</tt>".<p>
517
518
519 <!-- ======================================================================= -->
520 </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0>
521 <tr><td>&nbsp;</td><td width="100%">&nbsp; <font color="#EEEEFF" face="Georgia,Palatino"><b>
522 <a name="globalvars">Global Variables
523 </b></font></td></tr></table><ul>
524
525 Global variables define regions of memory allocated at compilation time instead
526 of run-time.  Global variables may optionally be initialized.  A variable may
527 be defined as a global "constant", which indicates that the contents of the
528 variable will never be modified (opening options for optimization).  Constants
529 must always have an initial value.<p>
530
531 As SSA values, global variables define pointer values that are in scope
532 (i.e. they dominate) for all basic blocks in the program.  Global variables
533 always define a pointer to their "content" type because they describe a region
534 of memory, and all memory objects in LLVM are accessed through pointers.<p>
535
536
537
538 <!-- ======================================================================= -->
539 </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0>
540 <tr><td>&nbsp;</td><td width="100%">&nbsp; <font color="#EEEEFF" face="Georgia,Palatino"><b>
541 <a name="functionstructure">Function Structure
542 </b></font></td></tr></table><ul>
543
544 LLVM functions definitions are composed of a (possibly empty) argument list, an
545 opening curly brace, a list of basic blocks, and a closing curly brace.  LLVM
546 function declarations are defined with the "<tt>declare</tt>" keyword, a
547 function name and a function signature.<p>
548
549 A function definition contains a list of basic blocks, forming the CFG for the
550 function.  Each basic block may optionally start with a label (giving the basic
551 block a symbol table entry), contains a list of instructions, and ends with a <a
552 href="#terminators">terminator</a> instruction (such as a branch or function
553 return).<p>
554
555 The first basic block in program is special in two ways: it is immediately
556 executed on entrance to the function, and it is not allowed to have predecessor
557 basic blocks (i.e. there can not be any branches to the entry block of a
558 function).<p>
559
560
561 <!-- *********************************************************************** -->
562 </ul><table width="100%" bgcolor="#330077" border=0 cellpadding=4 cellspacing=0>
563 <tr><td align=center><font color="#EEEEFF" size=+2 face="Georgia,Palatino"><b>
564 <a name="instref">Instruction Reference
565 </b></font></td></tr></table><ul>
566 <!-- *********************************************************************** -->
567
568 The LLVM instruction set consists of several different classifications of
569 instructions: <a href="#terminators">terminator instructions</a>, a <a
570 href="#unaryops">unary instruction</a>, <a href="#binaryops">binary
571 instructions</a>, <a href="#memoryops">memory instructions</a>, and <a
572 href="#otherops">other instructions</a>.<p>
573
574
575 <!-- ======================================================================= -->
576 </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0>
577 <tr><td>&nbsp;</td><td width="100%">&nbsp; <font color="#EEEEFF" face="Georgia,Palatino"><b>
578 <a name="terminators">Terminator Instructions
579 </b></font></td></tr></table><ul>
580
581 As mentioned <a href="#functionstructure">previously</a>, every basic block in a
582 program ends with a "Terminator" instruction, which indicates which block should
583 be executed after the current block is finished. These terminator instructions
584 typically yield a '<tt>void</tt>' value: they produce control flow, not values
585 (the one exception being the '<a href="#i_invoke"><tt>invoke</tt></a>'
586 instruction).<p>
587
588 There are four different terminator instructions: the '<a
589 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a
590 href="#i_br"><tt>br</tt></a>' instruction, the '<a
591 href="#i_switch"><tt>switch</tt></a>' instruction, and the '<a
592 href="#i_invoke"><tt>invoke</tt></a>' instruction.<p>
593
594
595 <!-- _______________________________________________________________________ -->
596 </ul><a name="i_ret"><h4><hr size=0>'<tt>ret</tt>' Instruction</h4><ul>
597
598 <h5>Syntax:</h5>
599 <pre>
600   ret &lt;type&gt; &lt;value&gt;       <i>; Return a value from a non-void function</i>
601   ret void                 <i>; Return from void function</i>
602 </pre>
603
604 <h5>Overview:</h5>
605
606 The '<tt>ret</tt>' instruction is used to return control flow (and a value) from
607 a function, back to the caller.<p>
608
609 There are two forms of the '<tt>ret</tt>' instructruction: one that returns a
610 value and then causes control flow, and one that just causes control flow to
611 occur.<p>
612
613 <h5>Arguments:</h5>
614
615 The '<tt>ret</tt>' instruction may return any '<a href="#t_firstclass">first
616 class</a>' type.  Notice that a function is not <a href="#wellformed">well
617 formed</a> if there exists a '<tt>ret</tt>' instruction inside of the function
618 that returns a value that does not match the return type of the function.<p>
619
620 <h5>Semantics:</h5>
621
622 When the '<tt>ret</tt>' instruction is executed, control flow returns back to
623 the calling function's context.  If the instruction returns a value, that value
624 shall be propogated into the calling function's data space.<p>
625
626 <h5>Example:</h5>
627 <pre>
628   ret int 5                       <i>; Return an integer value of 5</i>
629   ret void                        <i>; Return from a void function</i>
630 </pre>
631
632
633 <!-- _______________________________________________________________________ -->
634 </ul><a name="i_br"><h4><hr size=0>'<tt>br</tt>' Instruction</h4><ul>
635
636 <h5>Syntax:</h5>
637 <pre>
638   br bool &lt;cond&gt;, label &lt;iftrue&gt;, label &lt;iffalse&gt;
639   br label &lt;dest&gt;          <i>; Unconditional branch</i>
640 </pre>
641
642 <h5>Overview:</h5>
643
644 The '<tt>br</tt>' instruction is used to cause control flow to transfer to a
645 different basic block in the current function.  There are two forms of this
646 instruction, corresponding to a conditional branch and an unconditional
647 branch.<p>
648
649 <h5>Arguments:</h5>
650
651 The conditional branch form of the '<tt>br</tt>' instruction takes a single
652 '<tt>bool</tt>' value and two '<tt>label</tt>' values.  The unconditional form
653 of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>' value as a
654 target.<p>
655
656 <h5>Semantics:</h5>
657
658 Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
659 argument is evaluated.  If the value is <tt>true</tt>, control flows to the
660 '<tt>iftrue</tt>' '<tt>label</tt>' argument.  If "cond" is <tt>false</tt>,
661 control flows to the '<tt>iffalse</tt>' '<tt>label</tt>' argument.<p>
662
663 <h5>Example:</h5>
664 <pre>
665 Test:
666   %cond = <a href="#i_setcc">seteq</a> int %a, %b
667   br bool %cond, label %IfEqual, label %IfUnequal
668 IfEqual:
669   <a href="#i_ret">ret</a> int 1
670 IfUnequal:
671   <a href="#i_ret">ret</a> int 0
672 </pre>
673
674
675 <!-- _______________________________________________________________________ -->
676 </ul><a name="i_switch"><h4><hr size=0>'<tt>switch</tt>' Instruction</h4><ul>
677
678 <h5>Syntax:</h5>
679 <pre>
680   <i>; Definitions for lookup indirect branch</i>
681   %switchtype = type [&lt;anysize&gt; x { uint, label }]
682
683   <i>; Lookup indirect branch</i>
684   switch uint &lt;value&gt;, label &lt;defaultdest&gt;, %switchtype &lt;switchtable&gt;
685
686   <i>; Indexed indirect branch</i>
687   switch uint &lt;idxvalue&gt;, label &lt;defaultdest&gt;, [&lt;anysize&gt; x label] &lt;desttable&gt;
688 </pre>
689
690 <h5>Overview:</h5>
691
692 The '<tt>switch</tt>' instruction is used to transfer control flow to one of
693 several different places.  It is a generalization of the '<tt>br</tt>'
694 instruction, allowing a branch to occur to one of many possible destinations.<p>
695
696 The '<tt>switch</tt>' statement supports two different styles of indirect
697 branching: lookup branching and indexed branching.  Lookup branching is
698 generally useful if the values to switch on are spread far appart, where index
699 branching is useful if the values to switch on are generally dense.<p>
700
701 The two different forms of the '<tt>switch</tt>' statement are simple hints to
702 the underlying implementation.  For example, the compiler may choose to
703 implement a small indirect branch table as a series of predicated comparisons:
704 if it is faster for the target architecture.<p>
705
706 <h5>Arguments:</h5>
707
708 The lookup form of the '<tt>switch</tt>' instruction uses three parameters: a
709 '<tt>uint</tt>' comparison value '<tt>value</tt>', a default '<tt>label</tt>'
710 destination, and an array of pairs of comparison value constants and
711 '<tt>label</tt>'s.  The sized array must be a constant value.<p>
712
713 The indexed form of the '<tt>switch</tt>' instruction uses three parameters: an
714 '<tt>uint</tt>' index value, a default '<tt>label</tt>' and a sized array of
715 '<tt>label</tt>'s.  The '<tt>dests</tt>' array must be a constant array.
716
717 <h5>Semantics:</h5>
718
719 The lookup style switch statement specifies a table of values and destinations.
720 When the '<tt>switch</tt>' instruction is executed, this table is searched for
721 the given value.  If the value is found, the corresponding destination is
722 branched to. <p>
723
724 The index branch form simply looks up a label element directly in a table and
725 branches to it.<p>
726
727 In either case, the compiler knows the static size of the array, because it is
728 provided as part of the constant values type.<p>
729
730 <h5>Example:</h5>
731 <pre>
732   <i>; Emulate a conditional br instruction</i>
733   %Val = <a href="#i_cast">cast</a> bool %value to uint
734   switch uint %Val, label %truedest, [1 x label] [label %falsedest ]
735
736   <i>; Emulate an unconditional br instruction</i>
737   switch uint 0, label %dest, [ 0 x label] [ ]
738
739   <i>; Implement a jump table:</i>
740   switch uint %val, label %otherwise, [3 x label] [ label %onzero, 
741                                                     label %onone, 
742                                                     label %ontwo ]
743
744 </pre>
745
746
747
748 <!-- _______________________________________________________________________ -->
749 </ul><a name="i_invoke"><h4><hr size=0>'<tt>invoke</tt>' Instruction</h4><ul>
750
751 <h5>Syntax:</h5>
752 <pre>
753   &lt;result&gt; = invoke &lt;ptr to function ty&gt; %&lt;function ptr val&gt;(&lt;function args&gt;)
754                  to label &lt;normal label&gt; except label &lt;exception label&gt;
755 </pre>
756
757 <h5>Overview:</h5>
758
759 The '<tt>invoke</tt>' instruction is used to cause control flow to transfer to a
760 specified function, with the possibility of control flow transfer to either the
761 '<tt>normal label</tt>' label or the '<tt>exception label</tt>'.  The '<tt><a
762 href="#i_call">call</a></tt>' instruction is closely related, but guarantees
763 that control flow either never returns from the called function, or that it
764 returns to the instruction following the '<tt><a href="#i_call">call</a></tt>'
765 instruction.<p>
766
767 <h5>Arguments:</h5>
768
769 This instruction requires several arguments:<p>
770 <ol>
771
772 <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to
773 function value being invoked.  In most cases, this is a direct function
774 invocation, but indirect <tt>invoke</tt>'s are just as possible, branching off
775 an arbitrary pointer to function value.<p>
776
777 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a
778 function to be invoked.
779
780 <li>'<tt>function args</tt>': argument list whose types match the function
781 signature argument types.  If the function signature indicates the function
782 accepts a variable number of arguments, the extra arguments can be specified. 
783
784 <li>'<tt>normal label</tt>': the label reached when the called function executes
785 a '<tt><a href="#i_ret">ret</a></tt>' instruction.
786
787 <li>'<tt>exception label</tt>': the label reached when an exception is thrown.
788 </ol>
789
790 <h5>Semantics:</h5>
791
792 This instruction is designed to operate as a standard '<tt><a
793 href="#i_call">call</a></tt>' instruction in most regards.  The primary
794 difference is that it associates a label with the function invocation that may
795 be accessed via the runtime library provided by the execution environment.  This
796 instruction is used in languages with destructors to ensure that proper cleanup
797 is performed in the case of either a <tt>longjmp</tt> or a thrown exception.
798 Additionally, this is important for implementation of '<tt>catch</tt>' clauses
799 in high-level languages that support them.<p>
800
801 <!-- For a more comprehensive explanation of how this instruction is used, look in the llvm/docs/2001-05-18-ExceptionHandling.txt document.<p> -->
802
803 <h5>Example:</h5>
804 <pre>
805   %retval = invoke int %Test(int 15)
806               to label %Continue except label %TestCleanup     <i>; {int}:retval set</i>
807 </pre>
808
809
810
811 <!-- ======================================================================= -->
812 </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0>
813 <tr><td>&nbsp;</td><td width="100%">&nbsp; <font color="#EEEEFF" face="Georgia,Palatino"><b>
814 <a name="unaryops">Unary Operations
815 </b></font></td></tr></table><ul>
816
817 Unary operators are used to do a simple operation to a single value.<p>
818
819 There is only one unary operator: the '<a href="#i_not"><tt>not</tt></a>' instruction.<p>
820
821
822 <!-- _______________________________________________________________________ -->
823 </ul><a name="i_not"><h4><hr size=0>'<tt>not</tt>' Instruction</h4><ul>
824
825 <h5>Syntax:</h5>
826 <pre>
827   &lt;result&gt; = not &lt;ty&gt; &lt;var&gt;       <i>; yields {ty}:result</i>
828 </pre>
829
830 <h5>Overview:</h5>
831 The  '<tt>not</tt>' instruction returns the bitwise complement of its operand.<p>
832
833 <h5>Arguments:</h5>
834 The single argument to '<tt>not</tt>' must be of of <a href="#t_integral">integral</a> or bool type.<p>
835
836
837 <h5>Semantics:</h5> The '<tt>not</tt>' instruction returns the bitwise
838 complement (AKA ones complement) of an <a href="#t_integral">integral</a>
839 type.<p>
840
841 <pre>
842   &lt;result&gt; = xor bool true, &lt;var&gt; <i>; yields {bool}:result</i>
843 </pre>
844
845 <h5>Example:</h5>
846 <pre>
847   %x = not int 1                  <i>; {int}:x is now equal to -2</i>
848   %x = not bool true              <i>; {bool}:x is now equal to false</i>
849 </pre>
850
851
852
853 <!-- ======================================================================= -->
854 </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0><tr><td>&nbsp;</td><td width="100%">&nbsp; <font color="#EEEEFF" face="Georgia,Palatino"><b>
855 <a name="binaryops">Binary Operations
856 </b></font></td></tr></table><ul>
857
858 Binary operators are used to do most of the computation in a program.  They
859 require two operands, execute an operation on them, and produce a single value.
860 The result value of a binary operator is not neccesarily the same type as its
861 operands.<p>
862
863 There are several different binary operators:<p>
864
865
866 <!-- _______________________________________________________________________ -->
867 </ul><a name="i_add"><h4><hr size=0>'<tt>add</tt>' Instruction</h4><ul>
868
869 <h5>Syntax:</h5>
870 <pre>
871   &lt;result&gt; = add &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
872 </pre>
873
874 <h5>Overview:</h5>
875 The '<tt>add</tt>' instruction returns the sum of its two operands.<p>
876
877 <h5>Arguments:</h5>
878 The two arguments to the '<tt>add</tt>' instruction must be either <a href="#t_integral">integral</a> or <a href="#t_floating">floating point</a> values.  Both arguments must have identical types.<p>
879
880 <h5>Semantics:</h5>
881
882 The value produced is the integral or floating point sum of the two operands.<p>
883
884 <h5>Example:</h5>
885 <pre>
886   &lt;result&gt; = add int 4, %var          <i>; yields {int}:result = 4 + %var</i>
887 </pre>
888
889
890 <!-- _______________________________________________________________________ -->
891 </ul><a name="i_sub"><h4><hr size=0>'<tt>sub</tt>' Instruction</h4><ul>
892
893 <h5>Syntax:</h5>
894 <pre>
895   &lt;result&gt; = sub &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
896 </pre>
897
898 <h5>Overview:</h5>
899
900 The '<tt>sub</tt>' instruction returns the difference of its two operands.<p>
901
902 Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
903 instruction present in most other intermediate representations.<p>
904
905 <h5>Arguments:</h5>
906
907 The two arguments to the '<tt>sub</tt>' instruction must be either <a
908 href="#t_integral">integral</a> or <a href="#t_floating">floating point</a>
909 values.  Both arguments must have identical types.<p>
910
911 <h5>Semantics:</h5>
912
913 The value produced is the integral or floating point difference of the two
914 operands.<p>
915
916 <h5>Example:</h5>
917 <pre>
918   &lt;result&gt; = sub int 4, %var          <i>; yields {int}:result = 4 - %var</i>
919   &lt;result&gt; = sub int 0, %val          <i>; yields {int}:result = -%var</i>
920 </pre>
921
922 <!-- _______________________________________________________________________ -->
923 </ul><a name="i_mul"><h4><hr size=0>'<tt>mul</tt>' Instruction</h4><ul>
924
925 <h5>Syntax:</h5>
926 <pre>
927   &lt;result&gt; = mul &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
928 </pre>
929
930 <h5>Overview:</h5>
931 The  '<tt>mul</tt>' instruction returns the product of its two operands.<p>
932
933 <h5>Arguments:</h5>
934 The two arguments to the '<tt>mul</tt>' instruction must be either <a href="#t_integral">integral</a> or <a href="#t_floating">floating point</a> values.  Both arguments must have identical types.<p>
935
936 <h5>Semantics:</h5>
937
938 The value produced is the integral or floating point product of the two
939 operands.<p>
940
941 There is no signed vs unsigned multiplication.  The appropriate action is taken
942 based on the type of the operand. <p>
943
944
945 <h5>Example:</h5>
946 <pre>
947   &lt;result&gt; = mul int 4, %var          <i>; yields {int}:result = 4 * %var</i>
948 </pre>
949
950
951 <!-- _______________________________________________________________________ -->
952 </ul><a name="i_div"><h4><hr size=0>'<tt>div</tt>' Instruction</h4><ul>
953
954 <h5>Syntax:</h5>
955 <pre>
956   &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
957 </pre>
958
959 <h5>Overview:</h5>
960
961 The  '<tt>div</tt>' instruction returns the quotient of its two operands.<p>
962
963 <h5>Arguments:</h5>
964
965 The two arguments to the '<tt>div</tt>' instruction must be either <a
966 href="#t_integral">integral</a> or <a href="#t_floating">floating point</a>
967 values.  Both arguments must have identical types.<p>
968
969 <h5>Semantics:</h5>
970
971 The value produced is the integral or floating point quotient of the two
972 operands.<p>
973
974 <h5>Example:</h5>
975 <pre>
976   &lt;result&gt; = div int 4, %var          <i>; yields {int}:result = 4 / %var</i>
977 </pre>
978
979
980 <!-- _______________________________________________________________________ -->
981 </ul><a name="i_rem"><h4><hr size=0>'<tt>rem</tt>' Instruction</h4><ul>
982
983 <h5>Syntax:</h5>
984 <pre>
985   &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
986 </pre>
987
988 <h5>Overview:</h5>
989 The  '<tt>rem</tt>' instruction returns the remainder from the division of its two operands.<p>
990
991 <h5>Arguments:</h5>
992 The two arguments to the '<tt>rem</tt>' instruction must be either <a href="#t_integral">integral</a> or <a href="#t_floating">floating point</a> values.  Both arguments must have identical types.<p>
993
994 <h5>Semantics:</h5>
995
996 This returns the <i>remainder</i> of a division (where the result has the same
997 sign as the divisor), not the <i>modulus</i> (where the result has the same sign
998 as the dividend) of a value.  For more information about the difference, see: <a
999 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The Math
1000 Forum</a>.<p>
1001
1002 <h5>Example:</h5>
1003 <pre>
1004   &lt;result&gt; = rem int 4, %var          <i>; yields {int}:result = 4 % %var</i>
1005 </pre>
1006
1007
1008 <!-- _______________________________________________________________________ -->
1009 </ul><a name="i_setcc"><h4><hr size=0>'<tt>set<i>cc</i></tt>' Instructions</h4><ul>
1010
1011 <h5>Syntax:</h5>
1012 <pre>
1013   &lt;result&gt; = seteq &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {bool}:result</i>
1014   &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {bool}:result</i>
1015   &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {bool}:result</i>
1016   &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {bool}:result</i>
1017   &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {bool}:result</i>
1018   &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {bool}:result</i>
1019 </pre>
1020
1021 <h5>Overview:</h5> The '<tt>set<i>cc</i></tt>' family of instructions returns a
1022 boolean value based on a comparison of their two operands.<p>
1023
1024 <h5>Arguments:</h5> The two arguments to the '<tt>set<i>cc</i></tt>'
1025 instructions must be of <a href="#t_firstclass">first class</a> or <a
1026 href="#t_pointer">pointer</a> type (it is not possible to compare
1027 '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>' or '<tt>void</tt>'
1028 values, etc...).  Both arguments must have identical types.<p>
1029
1030 The '<tt>setlt</tt>', '<tt>setgt</tt>', '<tt>setle</tt>', and '<tt>setge</tt>'
1031 instructions do not operate on '<tt>bool</tt>' typed arguments.<p>
1032
1033 <h5>Semantics:</h5>
1034
1035 The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' value if
1036 both operands are equal.<br>
1037
1038 The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' value if
1039 both operands are unequal.<br>
1040
1041 The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' value if
1042 the first operand is less than the second operand.<br>
1043
1044 The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' value if
1045 the first operand is greater than the second operand.<br>
1046
1047 The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' value if
1048 the first operand is less than or equal to the second operand.<br>
1049
1050 The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' value if
1051 the first operand is greater than or equal to the second operand.<p>
1052
1053 <h5>Example:</h5>
1054 <pre>
1055   &lt;result&gt; = seteq int   4, 5        <i>; yields {bool}:result = false</i>
1056   &lt;result&gt; = setne float 4, 5        <i>; yields {bool}:result = true</i>
1057   &lt;result&gt; = setlt uint  4, 5        <i>; yields {bool}:result = true</i>
1058   &lt;result&gt; = setgt sbyte 4, 5        <i>; yields {bool}:result = false</i>
1059   &lt;result&gt; = setle sbyte 4, 5        <i>; yields {bool}:result = true</i>
1060   &lt;result&gt; = setge sbyte 4, 5        <i>; yields {bool}:result = false</i>
1061 </pre>
1062
1063
1064
1065 <!-- ======================================================================= -->
1066 </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0>
1067 <tr><td>&nbsp;</td><td width="100%">&nbsp; <font color="#EEEEFF" face="Georgia,Palatino"><b>
1068 <a name="bitwiseops">Bitwise Binary Operations
1069 </b></font></td></tr></table><ul>
1070
1071 Bitwise binary operators are used to do various forms of bit-twiddling in a
1072 program.  They are generally very efficient instructions, and can commonly be
1073 strength reduced from other instructions.  They require two operands, execute an
1074 operation on them, and produce a single value.  The resulting value of the
1075 bitwise binary operators is always the same type as its first operand.<p>
1076
1077 <!-- _______________________________________________________________________ -->
1078 </ul><a name="i_and"><h4><hr size=0>'<tt>and</tt>' Instruction</h4><ul>
1079
1080 <h5>Syntax:</h5>
1081 <pre>
1082   &lt;result&gt; = and &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
1083 </pre>
1084
1085 <h5>Overview:</h5>
1086 The '<tt>and</tt>' instruction returns the bitwise logical and of its two operands.<p>
1087
1088 <h5>Arguments:</h5>
1089
1090 The two arguments to the '<tt>and</tt>' instruction must be either <a
1091 href="#t_integral">integral</a> or <tt>bool</tt> values.  Both arguments must
1092 have identical types.<p>
1093
1094
1095 <h5>Semantics:</h5>
1096
1097 The truth table used for the '<tt>and</tt>' instruction is:<p>
1098
1099 <center><table border=1 cellspacing=0 cellpadding=4>
1100 <tr><td>In0</td>  <td>In1</td>  <td>Out</td></tr>
1101 <tr><td>0</td>  <td>0</td>  <td>0</td></tr>
1102 <tr><td>0</td>  <td>1</td>  <td>0</td></tr>
1103 <tr><td>1</td>  <td>0</td>  <td>0</td></tr>
1104 <tr><td>1</td>  <td>1</td>  <td>1</td></tr>
1105 </table></center><p>
1106
1107
1108 <h5>Example:</h5>
1109 <pre>
1110   &lt;result&gt; = and int 4, %var         <i>; yields {int}:result = 4 & %var</i>
1111   &lt;result&gt; = and int 15, 40          <i>; yields {int}:result = 8</i>
1112   &lt;result&gt; = and int 4, 8            <i>; yields {int}:result = 0</i>
1113 </pre>
1114
1115
1116
1117 <!-- _______________________________________________________________________ -->
1118 </ul><a name="i_or"><h4><hr size=0>'<tt>or</tt>' Instruction</h4><ul>
1119
1120 <h5>Syntax:</h5>
1121 <pre>
1122   &lt;result&gt; = or &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
1123 </pre>
1124
1125 <h5>Overview:</h5> The '<tt>or</tt>' instruction returns the bitwise logical
1126 inclusive or of its two operands.<p>
1127
1128 <h5>Arguments:</h5>
1129
1130 The two arguments to the '<tt>or</tt>' instruction must be either <a
1131 href="#t_integral">integral</a> or <tt>bool</tt> values.  Both arguments must
1132 have identical types.<p>
1133
1134
1135 <h5>Semantics:</h5>
1136
1137 The truth table used for the '<tt>or</tt>' instruction is:<p>
1138
1139 <center><table border=1 cellspacing=0 cellpadding=4>
1140 <tr><td>In0</td>  <td>In1</td>  <td>Out</td></tr>
1141 <tr><td>0</td>  <td>0</td>  <td>0</td></tr>
1142 <tr><td>0</td>  <td>1</td>  <td>1</td></tr>
1143 <tr><td>1</td>  <td>0</td>  <td>1</td></tr>
1144 <tr><td>1</td>  <td>1</td>  <td>1</td></tr>
1145 </table></center><p>
1146
1147
1148 <h5>Example:</h5>
1149 <pre>
1150   &lt;result&gt; = or int 4, %var         <i>; yields {int}:result = 4 | %var</i>
1151   &lt;result&gt; = or int 15, 40          <i>; yields {int}:result = 47</i>
1152   &lt;result&gt; = or int 4, 8            <i>; yields {int}:result = 12</i>
1153 </pre>
1154
1155
1156 <!-- _______________________________________________________________________ -->
1157 </ul><a name="i_xor"><h4><hr size=0>'<tt>xor</tt>' Instruction</h4><ul>
1158
1159 <h5>Syntax:</h5>
1160 <pre>
1161   &lt;result&gt; = xor &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
1162 </pre>
1163
1164 <h5>Overview:</h5>
1165
1166 The '<tt>xor</tt>' instruction returns the bitwise logical exclusive or of its
1167 two operands.<p>
1168
1169 <h5>Arguments:</h5>
1170
1171 The two arguments to the '<tt>xor</tt>' instruction must be either <a
1172 href="#t_integral">integral</a> or <tt>bool</tt> values.  Both arguments must
1173 have identical types.<p>
1174
1175
1176 <h5>Semantics:</h5>
1177
1178 The truth table used for the '<tt>xor</tt>' instruction is:<p>
1179
1180 <center><table border=1 cellspacing=0 cellpadding=4>
1181 <tr><td>In0</td>  <td>In1</td>  <td>Out</td></tr>
1182 <tr><td>0</td>  <td>0</td>  <td>0</td></tr>
1183 <tr><td>0</td>  <td>1</td>  <td>1</td></tr>
1184 <tr><td>1</td>  <td>0</td>  <td>1</td></tr>
1185 <tr><td>1</td>  <td>1</td>  <td>0</td></tr>
1186 </table></center><p>
1187
1188
1189 <h5>Example:</h5>
1190 <pre>
1191   &lt;result&gt; = xor int 4, %var         <i>; yields {int}:result = 4 ^ %var</i>
1192   &lt;result&gt; = xor int 15, 40          <i>; yields {int}:result = 39</i>
1193   &lt;result&gt; = xor int 4, 8            <i>; yields {int}:result = 12</i>
1194 </pre>
1195
1196
1197 <!-- _______________________________________________________________________ -->
1198 </ul><a name="i_shl"><h4><hr size=0>'<tt>shl</tt>' Instruction</h4><ul>
1199
1200 <h5>Syntax:</h5>
1201 <pre>
1202   &lt;result&gt; = shl &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt;   <i>; yields {ty}:result</i>
1203 </pre>
1204
1205 <h5>Overview:</h5>
1206
1207 The '<tt>shl</tt>' instruction returns the first operand shifted to the left a
1208 specified number of bits.
1209
1210 <h5>Arguments:</h5>
1211
1212 The first argument to the '<tt>shl</tt>' instruction must be an <a
1213 href="#t_integral">integral</a> type.  The second argument must be an
1214 '<tt>ubyte</tt>' type.<p>
1215
1216 <h5>Semantics:</h5>
1217
1218 The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.<p>
1219
1220
1221 <h5>Example:</h5>
1222 <pre>
1223   &lt;result&gt; = shl int 4, ubyte %var   <i>; yields {int}:result = 4 << %var</i>
1224   &lt;result&gt; = shl int 4, ubyte 2      <i>; yields {int}:result = 16</i>
1225   &lt;result&gt; = shl int 1, ubyte 10     <i>; yields {int}:result = 1024</i>
1226 </pre>
1227
1228
1229 <!-- _______________________________________________________________________ -->
1230 </ul><a name="i_shr"><h4><hr size=0>'<tt>shr</tt>' Instruction</h4><ul>
1231
1232
1233 <h5>Syntax:</h5>
1234 <pre>
1235   &lt;result&gt; = shr &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt;   <i>; yields {ty}:result</i>
1236 </pre>
1237
1238 <h5>Overview:</h5>
1239 The '<tt>shr</tt>' instruction returns the first operand shifted to the right a specified number of bits.
1240
1241 <h5>Arguments:</h5>
1242 The first argument to the '<tt>shr</tt>' instruction must be an  <a href="#t_integral">integral</a> type.  The second argument must be an '<tt>ubyte</tt>' type.<p>
1243
1244 <h5>Semantics:</h5>
1245
1246 If the first argument is a <a href="#t_signed">signed</a> type, the most
1247 significant bit is duplicated in the newly free'd bit positions.  If the first
1248 argument is unsigned, zero bits shall fill the empty positions.<p>
1249
1250 <h5>Example:</h5>
1251 <pre>
1252   &lt;result&gt; = shr int 4, ubyte %var   <i>; yields {int}:result = 4 >> %var</i>
1253   &lt;result&gt; = shr int 4, ubyte 1      <i>; yields {int}:result = 2</i>
1254   &lt;result&gt; = shr int 4, ubyte 2      <i>; yields {int}:result = 1</i>
1255   &lt;result&gt; = shr int 4, ubyte 3      <i>; yields {int}:result = 0</i>
1256 </pre>
1257
1258
1259
1260
1261
1262 <!-- ======================================================================= -->
1263 </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0>
1264 <tr><td>&nbsp;</td><td width="100%">&nbsp; <font color="#EEEEFF" face="Georgia,Palatino"><b>
1265 <a name="memoryops">Memory Access Operations
1266 </b></font></td></tr></table><ul>
1267
1268 Accessing memory in SSA form is, well, sticky at best.  This section describes how to read, write, allocate and free memory in LLVM.<p>
1269
1270
1271 <!-- _______________________________________________________________________ -->
1272 </ul><a name="i_malloc"><h4><hr size=0>'<tt>malloc</tt>' Instruction</h4><ul>
1273
1274 <h5>Syntax:</h5>
1275 <pre>
1276   &lt;result&gt; = malloc &lt;type&gt;, uint &lt;NumElements&gt;     <i>; yields {type*}:result</i>
1277   &lt;result&gt; = malloc &lt;type&gt;                         <i>; yields {type*}:result</i>
1278 </pre>
1279
1280 <h5>Overview:</h5>
1281 The '<tt>malloc</tt>' instruction allocates memory from the system heap and returns a pointer to it.<p>
1282
1283 <h5>Arguments:</h5>
1284
1285 The the '<tt>malloc</tt>' instruction allocates
1286 <tt>sizeof(&lt;type&gt;)*NumElements</tt> bytes of memory from the operating
1287 system, and returns a pointer of the appropriate type to the program.  The
1288 second form of the instruction is a shorter version of the first instruction
1289 that defaults to allocating one element.<p>
1290
1291 '<tt>type</tt>' must be a sized type<p>
1292
1293 <h5>Semantics:</h5>
1294 Memory is allocated, a pointer is returned.<p>
1295
1296 <h5>Example:</h5>
1297 <pre>
1298   %array  = malloc [4 x ubyte ]                    <i>; yields {[%4 x ubyte]*}:array</i>
1299
1300   %size   = <a href="#i_add">add</a> uint 2, 2                          <i>; yields {uint}:size = uint 4</i>
1301   %array1 = malloc ubyte, uint 4                   <i>; yields {ubyte*}:array1</i>
1302   %array2 = malloc [12 x ubyte], uint %size        <i>; yields {[12 x ubyte]*}:array2</i>
1303 </pre>
1304
1305
1306 <!-- _______________________________________________________________________ -->
1307 </ul><a name="i_free"><h4><hr size=0>'<tt>free</tt>' Instruction</h4><ul>
1308
1309 <h5>Syntax:</h5>
1310 <pre>
1311   free &lt;type&gt; &lt;value&gt;                              <i>; yields {void}</i>
1312 </pre>
1313
1314
1315 <h5>Overview:</h5>
1316 The '<tt>free</tt>' instruction returns memory back to the unused memory heap, to be reallocated in the future.<p>
1317
1318
1319 <h5>Arguments:</h5>
1320
1321 '<tt>value</tt>' shall be a pointer value that points to a value that was
1322 allocated with the '<tt><a href="#i_malloc">malloc</a></tt>' instruction.<p>
1323
1324
1325 <h5>Semantics:</h5>
1326
1327 Access to the memory pointed to by the pointer is not longer defined after this instruction executes.<p>
1328
1329 <h5>Example:</h5>
1330 <pre>
1331   %array  = <a href="#i_malloc">malloc</a> [4 x ubyte]                    <i>; yields {[4 x ubyte]*}:array</i>
1332             free   [4 x ubyte]* %array
1333 </pre>
1334
1335
1336 <!-- _______________________________________________________________________ -->
1337 </ul><a name="i_alloca"><h4><hr size=0>'<tt>alloca</tt>' Instruction</h4><ul>
1338
1339 <h5>Syntax:</h5>
1340 <pre>
1341   &lt;result&gt; = alloca &lt;type&gt;, uint &lt;NumElements&gt;  <i>; yields {type*}:result</i>
1342   &lt;result&gt; = alloca &lt;type&gt;                      <i>; yields {type*}:result</i>
1343 </pre>
1344
1345 <h5>Overview:</h5>
1346
1347 The '<tt>alloca</tt>' instruction allocates memory on the current stack frame of
1348 the procedure that is live until the current function returns to its caller.<p>
1349
1350 <h5>Arguments:</h5>
1351
1352 The the '<tt>alloca</tt>' instruction allocates
1353 <tt>sizeof(&lt;type&gt;)*NumElements</tt> bytes of memory on the runtime stack,
1354 returning a pointer of the appropriate type to the program.  The second form of
1355 the instruction is a shorter version of the first that defaults to allocating
1356 one element.<p>
1357
1358 '<tt>type</tt>' may be any sized type.<p>
1359
1360 <h5>Semantics:</h5>
1361
1362 Memory is allocated, a pointer is returned.  '<tt>alloca</tt>'d memory is
1363 automatically released when the function returns.  The '<tt>alloca</tt>'
1364 instruction is commonly used to represent automatic variables that must have an
1365 address available, as well as spilled variables.<p>
1366
1367 <h5>Example:</h5>
1368 <pre>
1369   %ptr = alloca int                              <i>; yields {int*}:ptr</i>
1370   %ptr = alloca int, uint 4                      <i>; yields {int*}:ptr</i>
1371 </pre>
1372
1373
1374 <!-- _______________________________________________________________________ -->
1375 </ul><a name="i_load"><h4><hr size=0>'<tt>load</tt>' Instruction</h4><ul>
1376
1377 <h5>Syntax:</h5>
1378 <pre>
1379   &lt;result&gt; = load &lt;ty&gt;* &lt;pointer&gt;
1380 </pre>
1381
1382 <h5>Overview:</h5>
1383 The '<tt>load</tt>' instruction is used to read from memory.<p>
1384
1385 <h5>Arguments:</h5>
1386
1387 The argument to the '<tt>load</tt>' instruction specifies the memory address to load from.  The pointer must point to a <a href="t_firstclass">first class</a> type.<p>
1388
1389 <h5>Semantics:</h5>
1390
1391 The location of memory pointed to is loaded.
1392
1393 <h5>Examples:</h5>
1394 <pre>
1395   %ptr = <a href="#i_alloca">alloca</a> int                               <i>; yields {int*}:ptr</i>
1396   <a href="#i_store">store</a> int 3, int* %ptr                          <i>; yields {void}</i>
1397   %val = load int* %ptr                           <i>; yields {int}:val = int 3</i>
1398 </pre>
1399
1400
1401
1402
1403 <!-- _______________________________________________________________________ -->
1404 </ul><a name="i_store"><h4><hr size=0>'<tt>store</tt>' Instruction</h4><ul>
1405
1406 <h5>Syntax:</h5>
1407 <pre>
1408   store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt;                   <i>; yields {void}</i>
1409 </pre>
1410
1411 <h5>Overview:</h5>
1412 The '<tt>store</tt>' instruction is used to write to memory.<p>
1413
1414 <h5>Arguments:</h5>
1415
1416 There are two arguments to the '<tt>store</tt>' instruction: a value to store
1417 and an address to store it into.  The type of the '<tt>&lt;pointer&gt;</tt>'
1418 operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
1419 operand.<p>
1420
1421 <h5>Semantics:</h5> The contents of memory are updated to contain
1422 '<tt>&lt;value&gt;</tt>' at the location specified by the
1423 '<tt>&lt;pointer&gt;</tt>' operand.<p>
1424
1425 <h5>Example:</h5>
1426 <pre>
1427   %ptr = <a href="#i_alloca">alloca</a> int                               <i>; yields {int*}:ptr</i>
1428   <a href="#i_store">store</a> int 3, int* %ptr                          <i>; yields {void}</i>
1429   %val = load int* %ptr                           <i>; yields {int}:val = int 3</i>
1430 </pre>
1431
1432
1433
1434
1435 <!-- _______________________________________________________________________ -->
1436 </ul><a name="i_getelementptr"><h4><hr size=0>'<tt>getelementptr</tt>' Instruction</h4><ul>
1437
1438 <h5>Syntax:</h5>
1439 <pre>
1440   &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, uint &lt;aidx&gt;|, ubyte &lt;sidx&gt;}*
1441 </pre>
1442
1443 <h5>Overview:</h5>
1444
1445 The '<tt>getelementptr</tt>' instruction is used to get the address of a
1446 subelement of an aggregate data structure.<p>
1447
1448 <h5>Arguments:</h5>
1449
1450 This instruction takes a list of <tt>uint</tt> values and <tt>ubyte</tt>
1451 constants that indicate what form of addressing to perform.  The actual types of
1452 the arguments provided depend on the type of the first pointer argument.  The
1453 '<tt>getelementptr</tt>' instruction is used to index down through the type
1454 levels of a structure.<p>
1455
1456 For example, lets consider a C code fragment and how it gets compiled to
1457 LLVM:<p>
1458
1459 <pre>
1460 struct RT {
1461   char A;
1462   int B[10][20];
1463   char C;
1464 };
1465 struct ST {
1466   int X;
1467   double Y;
1468   struct RT Z;
1469 };
1470
1471 int *foo(struct ST *s) {
1472   return &amp;s[1].Z.B[5][13];
1473 }
1474 </pre>
1475
1476 The LLVM code generated by the GCC frontend is:
1477
1478 <pre>
1479 %RT = type { sbyte, [10 x [20 x int]], sbyte }
1480 %ST = type { int, double, %RT }
1481
1482 int* "foo"(%ST* %s) {
1483   %reg = getelementptr %ST* %s, uint 1, ubyte 2, ubyte 1, uint 5, uint 13
1484   ret int* %reg
1485 }
1486 </pre>
1487
1488 <h5>Semantics:</h5>
1489
1490 The index types specified for the '<tt>getelementptr</tt>' instruction depend on
1491 the pointer type that is being index into.  <a href="t_pointer">Pointer</a> and
1492 <a href="t_array">array</a> types require '<tt>uint</tt>' values, and <a
1493 href="t_struct">structure</a> types require '<tt>ubyte</tt>'
1494 <b>constants</b>.<p>
1495
1496 In the example above, the first index is indexing into the '<tt>%ST*</tt>' type,
1497 which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT }</tt>'
1498 type, a structure.  The second index indexes into the third element of the
1499 structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]], sbyte
1500 }</tt>' type, another structure.  The third index indexes into the second
1501 element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
1502 array.  The two dimensions of the array are subscripted into, yielding an
1503 '<tt>int</tt>' type.  The '<tt>getelementptr</tt>' instruction return a pointer
1504 to this element, thus yielding a '<tt>int*</tt>' type.<p>
1505
1506 Note that it is perfectly legal to index partially through a structure,
1507 returning a pointer to an inner element.  Because of this, the LLVM code for the
1508 given testcase is equivalent to:<p>
1509
1510 <pre>
1511 int* "foo"(%ST* %s) {
1512   %t1 = getelementptr %ST* %s , uint 1                        <i>; yields %ST*:%t1</i>
1513   %t2 = getelementptr %ST* %t1, uint 0, ubyte 2               <i>; yields %RT*:%t2</i>
1514   %t3 = getelementptr %RT* %t2, uint 0, ubyte 1               <i>; yields [10 x [20 x int]]*:%t3</i>
1515   %t4 = getelementptr [10 x [20 x int]]* %t3, uint 0, uint 5  <i>; yields [20 x int]*:%t4</i>
1516   %t5 = getelementptr [20 x int]* %t4, uint 0, uint 13        <i>; yields int*:%t5</i>
1517   ret int* %t5
1518 }
1519 </pre>
1520
1521
1522
1523 <h5>Example:</h5>
1524 <pre>
1525   <i>; yields {[12 x ubyte]*}:aptr</i>
1526   %aptr = getelementptr {int, [12 x ubyte]}* %sptr, uint 0, ubyte 1
1527 </pre>
1528
1529
1530
1531 <!-- ======================================================================= -->
1532 </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0>
1533 <tr><td>&nbsp;</td><td width="100%">&nbsp; <font color="#EEEEFF" face="Georgia,Palatino"><b>
1534 <a name="otherops">Other Operations
1535 </b></font></td></tr></table><ul>
1536
1537 The instructions in this catagory are the "miscellaneous" functions, that defy better classification.<p>
1538
1539
1540 <!-- _______________________________________________________________________ -->
1541 </ul><a name="i_phi"><h4><hr size=0>'<tt>phi</tt>' Instruction</h4><ul>
1542
1543 <h5>Syntax:</h5>
1544 <pre>
1545   &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...
1546 </pre>
1547
1548 <h5>Overview:</h5>
1549
1550 The '<tt>phi</tt>' instruction is used to implement the &phi; node in the SSA
1551 graph representing the function.<p>
1552
1553 <h5>Arguments:</h5>
1554
1555 The type of the incoming values are specified with the first type field.  After
1556 this, the '<tt>phi</tt>' instruction takes a list of pairs as arguments, with
1557 one pair for each predecessor basic block of the current block.<p>
1558
1559 There must be no non-phi instructions between the start of a basic block and the
1560 PHI instructions: i.e. PHI instructions must be first in a basic block.<p>
1561
1562 <h5>Semantics:</h5>
1563
1564 At runtime, the '<tt>phi</tt>' instruction logically takes on the value
1565 specified by the parameter, depending on which basic block we came from in the
1566 last <a href="#terminators">terminator</a> instruction.<p>
1567
1568 <h5>Example:</h5>
1569
1570 <pre>
1571 Loop:       ; Infinite loop that counts from 0 on up...
1572   %indvar = phi uint [ 0, %LoopHeader ], [ %nextindvar, %Loop ]
1573   %nextindvar = add uint %indvar, 1
1574   br label %Loop
1575 </pre>
1576
1577
1578 <!-- _______________________________________________________________________ -->
1579 </ul><a name="i_cast"><h4><hr size=0>'<tt>cast .. to</tt>' Instruction</h4><ul>
1580
1581 <h5>Syntax:</h5>
1582 <pre>
1583   &lt;result&gt; = cast &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt;             <i>; yields ty2</i>
1584 </pre>
1585
1586 <h5>Overview:</h5>
1587
1588 The '<tt>cast</tt>' instruction is used as the primitive means to convert
1589 integers to floating point, change data type sizes, and break type safety (by
1590 casting pointers).<p>
1591
1592 <h5>Arguments:</h5>
1593
1594 The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
1595 class value, and a type to cast it to, which must also be a first class type.<p>
1596
1597 <h5>Semantics:</h5>
1598
1599 This instruction follows the C rules for explicit casts when determining how the
1600 data being cast must change to fit in its new container.<p>
1601
1602 When casting to bool, any value that would be considered true in the context of
1603 a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
1604 all else are '<tt>false</tt>'.<p>
1605
1606 When extending an integral value from a type of one signness to another (for
1607 example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
1608 <b>source</b> value is signed, and zero-extended if the source value is
1609 unsigned.<p>
1610
1611 <h5>Example:</h5>
1612 <pre>
1613   %X = cast int 257 to ubyte              <i>; yields ubyte:1</i>
1614   %Y = cast int 123 to bool               <i>; yields bool:true</i>
1615 </pre>
1616
1617
1618
1619 <!-- _______________________________________________________________________ -->
1620 </ul><a name="i_call"><h4><hr size=0>'<tt>call</tt>' Instruction</h4><ul>
1621
1622 <h5>Syntax:</h5>
1623 <pre>
1624   &lt;result&gt; = call &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)
1625 </pre>
1626
1627 <h5>Overview:</h5>
1628
1629 The '<tt>call</tt>' instruction represents a simple function call.<p>
1630
1631 <h5>Arguments:</h5>
1632
1633 This instruction requires several arguments:<p>
1634 <ol>
1635
1636 <li>'<tt>ty</tt>': shall be the signature of the pointer to function value being
1637 invoked.  The argument types must match the types implied by this signature.<p>
1638
1639 <li>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to be
1640 invoked. In most cases, this is a direct function invocation, but indirect
1641 <tt>call</tt>'s are just as possible, calling an arbitrary pointer to function
1642 values.<p>
1643
1644 <li>'<tt>function args</tt>': argument list whose types match the function
1645 signature argument types.  If the function signature indicates the function
1646 accepts a variable number of arguments, the extra arguments can be specified. 
1647 </ol>
1648
1649 <h5>Semantics:</h5>
1650
1651 The '<tt>call</tt>' instruction is used to cause control flow to transfer to a
1652 specified function, with its incoming arguments bound to the specified values.
1653 Upon a '<tt><a href="#i_ret">ret</a></tt>' instruction in the called function,
1654 control flow continues with the instruction after the function call, and the
1655 return value of the function is bound to the result argument.  This is a simpler
1656 case of the <a href="#i_invoke">invoke</a> instruction.<p>
1657
1658 <h5>Example:</h5>
1659 <pre>
1660   %retval = call int %test(int %argc)
1661   call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42);
1662
1663 </pre>
1664
1665 <!--
1666
1667 <!x- *********************************************************************** -x>
1668 </ul><table width="100%" bgcolor="#330077" border=0 cellpadding=4 cellspacing=0>
1669 <tr><td align=center><font color="#EEEEFF" size=+2 face="Georgia,Palatino"><b>
1670 <a name="related">Related Work
1671 </b></font></td></tr></table><ul>
1672 <!x- *********************************************************************** -x>
1673
1674
1675 Codesigned virtual machines.<p>
1676
1677 <dl>
1678 <a name="rw_safetsa">
1679 <dt>SafeTSA
1680 <DD>Description here<p>
1681
1682 <a name="rw_java">
1683 <dt><a href="http://www.javasoft.com">Java</a>
1684 <DD>Desciption here<p>
1685
1686 <a name="rw_net">
1687 <dt><a href="http://www.microsoft.com/net">Microsoft .net</a>
1688 <DD>Desciption here<p>
1689
1690 <a name="rw_gccrtl">
1691 <dt><a href="http://www.math.umn.edu/systems_guide/gcc-2.95.1/gcc_15.html">GNU RTL Intermediate Representation</a>
1692 <DD>Desciption here<p>
1693
1694 <a name="rw_ia64">
1695 <dt><a href="http://developer.intel.com/design/ia-64/index.htm">IA64 Architecture &amp; Instruction Set</a>
1696 <DD>Desciption here<p>
1697
1698 <a name="rw_mmix">
1699 <dt><a href="http://www-cs-faculty.stanford.edu/~knuth/mmix-news.html">MMIX Instruction Set</a>
1700 <DD>Desciption here<p>
1701
1702 <a name="rw_stroustrup">
1703 <dt><a href="http://www.research.att.com/~bs/devXinterview.html">"Interview With Bjarne Stroustrup"</a>
1704 <DD>This interview influenced the design and thought process behind LLVM in several ways, most notably the way that derived types are written in text format. See the question that starts with "you defined the C declarator syntax as an experiment that failed".<p>
1705 </dl>
1706
1707 <!x- _______________________________________________________________________ -x>
1708 </ul><a name="rw_vectorization"><h3><hr size=0>Vectorized Architectures</h3><ul>
1709
1710 <dl>
1711 <a name="rw_intel_simd">
1712 <dt>Intel MMX, MMX2, SSE, SSE2
1713 <DD>Description here<p>
1714
1715 <a name="rw_amd_simd">
1716 <dt><a href="http://www.nondot.org/~sabre/os/H1ChipFeatures/3DNow!TechnologyManual.pdf">AMD 3Dnow!, 3Dnow! 2</a>
1717 <DD>Desciption here<p>
1718
1719 <a name="rw_sun_simd">
1720 <dt><a href="http://www.nondot.org/~sabre/os/H1ChipFeatures/VISInstructionSetUsersManual.pdf">Sun VIS ISA</a>
1721 <DD>Desciption here<p>
1722
1723 <a name="rw_powerpc_simd">
1724 <dt>PowerPC Altivec
1725 <DD>Desciption here<p>
1726
1727 </dl>
1728
1729 more...
1730
1731 -->
1732
1733
1734 <!-- *********************************************************************** -->
1735 </ul>
1736 <!-- *********************************************************************** -->
1737
1738
1739 <hr>
1740 <font size=-1>
1741 <address><a href="mailto:sabre@nondot.org">Chris Lattner</a></address>
1742 <!-- Created: Tue Jan 23 15:19:28 CST 2001 -->
1743 <!-- hhmts start -->
1744 Last modified: Tue Aug 13 15:50:47 CDT 2002
1745 <!-- hhmts end -->
1746 </font>
1747 </body></html>