Add notes about LLVM and CygWin from Brian Gaeke
[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="#binaryops">Binary Operations</a>
44         <ol>
45           <li><a href="#i_add"  >'<tt>add</tt>' Instruction</a>
46           <li><a href="#i_sub"  >'<tt>sub</tt>' Instruction</a>
47           <li><a href="#i_mul"  >'<tt>mul</tt>' Instruction</a>
48           <li><a href="#i_div"  >'<tt>div</tt>' Instruction</a>
49           <li><a href="#i_rem"  >'<tt>rem</tt>' Instruction</a>
50           <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a>
51         </ol>
52       <li><a href="#bitwiseops">Bitwise Binary Operations</a>
53         <ol>
54           <li><a href="#i_and">'<tt>and</tt>' Instruction</a>
55           <li><a href="#i_or" >'<tt>or</tt>'  Instruction</a>
56           <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a>
57           <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a>
58           <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a>
59         </ol>
60       <li><a href="#memoryops">Memory Access Operations</a>
61         <ol>
62           <li><a href="#i_malloc"  >'<tt>malloc</tt>'   Instruction</a>
63           <li><a href="#i_free"    >'<tt>free</tt>'     Instruction</a>
64           <li><a href="#i_alloca"  >'<tt>alloca</tt>'   Instruction</a>
65           <li><a href="#i_load"    >'<tt>load</tt>'     Instruction</a>
66           <li><a href="#i_store"   >'<tt>store</tt>'    Instruction</a>
67           <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
68         </ol>
69       <li><a href="#otherops">Other Operations</a>
70         <ol>
71           <li><a href="#i_phi"  >'<tt>phi</tt>'   Instruction</a>
72           <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a>
73           <li><a href="#i_call" >'<tt>call</tt>'  Instruction</a>
74         </ol>
75     </ol>
76 <!--
77   <li><a href="#related">Related Work</a>
78 -->
79
80   <p><b>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a> and <A href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></b><p>
81
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">integer</td><td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td></tr>
292 <tr><td><a name="t_integral">integral</td><td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td></tr>
293 <tr><td><a name="t_floating">floating point</td><td><tt>float, double</tt></td></tr>
294 <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>
295 </table><p>
296
297
298
299
300
301 <!-- ======================================================================= -->
302 </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>
303 <a name="t_derived">Derived Types
304 </b></font></td></tr></table><ul>
305
306 The real power in LLVM comes from the derived types in the system.  This is what
307 allows a programmer to represent arrays, functions, pointers, and other useful
308 types.  Note that these derived types may be recursive: For example, it is
309 possible to have a two dimensional array.<p>
310
311
312
313 <!-- _______________________________________________________________________ -->
314 </ul><a name="t_array"><h4><hr size=0>Array Type</h4><ul>
315
316 <h5>Overview:</h5>
317
318 The array type is a very simple derived type that arranges elements sequentially
319 in memory.  The array type requires a size (number of elements) and an
320 underlying data type.<p>
321
322 <h5>Syntax:</h5>
323 <pre>
324   [&lt;# elements&gt; x &lt;elementtype&gt;]
325 </pre>
326
327 The number of elements is a constant integer value, elementtype may be any type
328 with a size.<p>
329
330 <h5>Examples:</h5>
331 <ul>
332    <tt>[40 x int ]</tt>: Array of 40 integer values.<br>
333    <tt>[41 x int ]</tt>: Array of 41 integer values.<br>
334    <tt>[40 x uint]</tt>: Array of 40 unsigned integer values.<p>
335 </ul>
336
337 Here are some examples of multidimensional arrays:<p>
338 <ul>
339 <table border=0 cellpadding=0 cellspacing=0>
340 <tr><td><tt>[3 x [4 x int]]</tt></td><td>: 3x4 array integer values.</td></tr>
341 <tr><td><tt>[12 x [10 x float]]</tt></td><td>: 2x10 array of single precision floating point values.</td></tr>
342 <tr><td><tt>[2 x [3 x [4 x uint]]]</tt></td><td>: 2x3x4 array of unsigned integer values.</td></tr>
343 </table>
344 </ul>
345
346
347 <!-- _______________________________________________________________________ -->
348 </ul><a name="t_function"><h4><hr size=0>Function Type</h4><ul>
349
350 <h5>Overview:</h5>
351
352 The function type can be thought of as a function signature.  It consists of a
353 return type and a list of formal parameter types.  Function types are usually
354 used when to build virtual function tables (which are structures of pointers to
355 functions), for indirect function calls, and when defining a function.<p>
356
357 <h5>Syntax:</h5>
358 <pre>
359   &lt;returntype&gt; (&lt;parameter list&gt;)
360 </pre>
361
362 Where '<tt>&lt;parameter list&gt;</tt>' is a comma seperated list of type
363 specifiers.  Optionally, the parameter list may include a type <tt>...</tt>,
364 which indicates that the function takes a variable number of arguments.  Note
365 that there currently is no way to define a function in LLVM that takes a
366 variable number of arguments, but it is possible to <b>call</b> a function that
367 is vararg.<p>
368
369 <h5>Examples:</h5>
370 <ul>
371 <table border=0 cellpadding=0 cellspacing=0>
372
373 <tr><td><tt>int (int)</tt></td><td>: function taking an <tt>int</tt>, returning
374 an <tt>int</tt></td></tr>
375
376 <tr><td><tt>float (int, int *) *</tt></td><td>: <a href="#t_pointer">Pointer</a>
377 to a function that takes an <tt>int</tt> and a <a href="#t_pointer">pointer</a>
378 to <tt>int</tt>, returning <tt>float</tt>.</td></tr>
379
380 <tr><td><tt>int (sbyte *, ...)</tt></td><td>: A vararg function that takes at
381 least one <a href="#t_pointer">pointer</a> to <tt>sbyte</tt> (signed char in C),
382 which returns an integer.  This is the signature for <tt>printf</tt> in
383 LLVM.</td></tr>
384
385 </table>
386 </ul>
387
388
389
390 <!-- _______________________________________________________________________ -->
391 </ul><a name="t_struct"><h4><hr size=0>Structure Type</h4><ul>
392
393 <h5>Overview:</h5>
394
395 The structure type is used to represent a collection of data members together in
396 memory.  The packing of the field types is defined to match the ABI of the
397 underlying processor.  The elements of a structure may be any type that has a
398 size.<p>
399
400 Structures are accessed using '<tt><a href="#i_load">load</a></tt> and '<tt><a
401 href="#i_store">store</a></tt>' by getting a pointer to a field with the '<tt><a
402 href="#i_getelementptr">getelementptr</a></tt>' instruction.<p>
403
404 <h5>Syntax:</h5>
405 <pre>
406   { &lt;type list&gt; }
407 </pre>
408
409
410 <h5>Examples:</h5>
411 <table border=0 cellpadding=0 cellspacing=0>
412
413 <tr><td><tt>{ int, int, int }</tt></td><td>: a triple of three <tt>int</tt>
414 values</td></tr>
415
416 <tr><td><tt>{ float, int (int) * }</tt></td><td>: A pair, where the first
417 element is a <tt>float</tt> and the second element is a <a
418 href="#t_pointer">pointer</a> to a <a href="t_function">function</a> that takes
419 an <tt>int</tt>, returning an <tt>int</tt>.</td></tr>
420
421 </table>
422
423
424 <!-- _______________________________________________________________________ -->
425 </ul><a name="t_pointer"><h4><hr size=0>Pointer Type</h4><ul>
426
427 <h5>Overview:</h5>
428
429 As in many languages, the pointer type represents a pointer or reference to
430 another object, which must live in memory.<p>
431
432 <h5>Syntax:</h5>
433 <pre>
434   &lt;type&gt; *
435 </pre>
436
437 <h5>Examples:</h5>
438
439 <table border=0 cellpadding=0 cellspacing=0>
440
441 <tr><td><tt>[4x int]*</tt></td><td>: <a href="#t_pointer">pointer</a> to <a
442 href="#t_array">array</a> of four <tt>int</tt> values</td></tr>
443
444 <tr><td><tt>int (int *) *</tt></td><td>: A <a href="#t_pointer">pointer</a> to a
445 <a href="t_function">function</a> that takes an <tt>int</tt>, returning an
446 <tt>int</tt>.</td></tr>
447
448 </table>
449 <p>
450
451
452 <!-- _______________________________________________________________________ -->
453 <!--
454 </ul><a name="t_packed"><h4><hr size=0>Packed Type</h4><ul>
455
456 Mention/decide that packed types work with saturation or not. Maybe have a packed+saturated type in addition to just a packed type.<p>
457
458 Packed types should be 'nonsaturated' because standard data types are not saturated.  Maybe have a saturated packed type?<p>
459
460 -->
461
462
463 <!-- *********************************************************************** -->
464 </ul><table width="100%" bgcolor="#330077" border=0 cellpadding=4 cellspacing=0>
465 <tr><td align=center><font color="#EEEEFF" size=+2 face="Georgia,Palatino"><b>
466 <a name="highlevel">High Level Structure
467 </b></font></td></tr></table><ul>
468 <!-- *********************************************************************** -->
469
470
471 <!-- ======================================================================= -->
472 </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0>
473 <tr><td>&nbsp;</td><td width="100%">&nbsp; <font color="#EEEEFF" face="Georgia,Palatino"><b>
474 <a name="modulestructure">Module Structure
475 </b></font></td></tr></table><ul>
476
477 LLVM programs are composed of "Module"s, each of which is a translation unit of
478 the input programs.  Each module consists of functions, global variables, and
479 symbol table entries.  Modules may be combined together with the LLVM linker,
480 which merges function (and global variable) definitions, resolves forward
481 declarations, and merges symbol table entries. Here is an example of the "hello world" module:<p>
482
483 <pre>
484 <i>; Declare the string constant as a global constant...</i>
485 <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>
486
487 <i>; Forward declaration of puts</i>
488 <a href="#functionstructure">declare</a> int "puts"(sbyte*)                                           <i>; int(sbyte*)* </i>
489
490 <i>; Definition of main function</i>
491 int "main"() {                                                       <i>; int()* </i>
492         <i>; Convert [13x sbyte]* to sbyte *...</i>
493         %cast210 = <a href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
494
495         <i>; Call puts function to write out the string to stdout...</i>
496         <a href="#i_call">call</a> int %puts(sbyte* %cast210)                              <i>; int</i>
497         <a href="#i_ret">ret</a> int 0
498 }
499 </pre>
500
501 This example is made up of a <a href="#globalvars">global variable</a> named
502 "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>" function, and a
503 <a href="#functionstructure">function definition</a> for "<tt>main</tt>".<p>
504
505 <a name="linkage_decl">
506 In general, a module is made up of a list of global values, where both functions
507 and global variables are global values.  Global values are represented by a
508 pointer to a memory location (in this case, a pointer to an array of char, and a
509 pointer to a function), and can be either "internal" or externally accessible
510 (which corresponds to the static keyword in C, when used at global scope).<p>
511
512 For example, since the "<tt>.LC0</tt>" variable is defined to be internal, if
513 another module defined a "<tt>.LC0</tt>" variable and was linked with this one,
514 one of the two would be renamed, preventing a collision.  Since "<tt>main</tt>"
515 and "<tt>puts</tt>" are external (i.e., lacking "<tt>internal</tt>"
516 declarations), they are accessible outside of the current module.  It is illegal
517 for a function declaration to be "<tt>internal</tt>".<p>
518
519
520 <!-- ======================================================================= -->
521 </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0>
522 <tr><td>&nbsp;</td><td width="100%">&nbsp; <font color="#EEEEFF" face="Georgia,Palatino"><b>
523 <a name="globalvars">Global Variables
524 </b></font></td></tr></table><ul>
525
526 Global variables define regions of memory allocated at compilation time instead
527 of run-time.  Global variables may optionally be initialized.  A variable may
528 be defined as a global "constant", which indicates that the contents of the
529 variable will never be modified (opening options for optimization).  Constants
530 must always have an initial value.<p>
531
532 As SSA values, global variables define pointer values that are in scope
533 (i.e. they dominate) for all basic blocks in the program.  Global variables
534 always define a pointer to their "content" type because they describe a region
535 of memory, and all memory objects in LLVM are accessed through pointers.<p>
536
537
538
539 <!-- ======================================================================= -->
540 </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0>
541 <tr><td>&nbsp;</td><td width="100%">&nbsp; <font color="#EEEEFF" face="Georgia,Palatino"><b>
542 <a name="functionstructure">Function Structure
543 </b></font></td></tr></table><ul>
544
545 LLVM functions definitions are composed of a (possibly empty) argument list, an
546 opening curly brace, a list of basic blocks, and a closing curly brace.  LLVM
547 function declarations are defined with the "<tt>declare</tt>" keyword, a
548 function name and a function signature.<p>
549
550 A function definition contains a list of basic blocks, forming the CFG for the
551 function.  Each basic block may optionally start with a label (giving the basic
552 block a symbol table entry), contains a list of instructions, and ends with a <a
553 href="#terminators">terminator</a> instruction (such as a branch or function
554 return).<p>
555
556 The first basic block in program is special in two ways: it is immediately
557 executed on entrance to the function, and it is not allowed to have predecessor
558 basic blocks (i.e. there can not be any branches to the entry block of a
559 function).<p>
560
561
562 <!-- *********************************************************************** -->
563 </ul><table width="100%" bgcolor="#330077" border=0 cellpadding=4 cellspacing=0>
564 <tr><td align=center><font color="#EEEEFF" size=+2 face="Georgia,Palatino"><b>
565 <a name="instref">Instruction Reference
566 </b></font></td></tr></table><ul>
567 <!-- *********************************************************************** -->
568
569 The LLVM instruction set consists of several different classifications of
570 instructions: <a href="#terminators">terminator instructions</a>, <a
571 href="#binaryops">binary instructions</a>, <a href="#memoryops">memory
572 instructions</a>, and <a 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 propagated 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 -->
689 </pre>
690
691 <h5>Overview:</h5>
692
693 <b>NOTE:</b> The switch instruction may go away in the future.  It is not very
694 well supported in LLVM anyway, so don't go to great lengths to support it.  Talk
695 to <a href="mailto:sabre@nondot.org">Chris</a> for more info if this concerns
696 you.<p>
697
698 The '<tt>switch</tt>' instruction is used to transfer control flow to one of
699 several different places.  It is a generalization of the '<tt>br</tt>'
700 instruction, allowing a branch to occur to one of many possible destinations.<p>
701
702 The '<tt>switch</tt>' statement supports two different styles of indirect
703 branching: lookup branching and indexed branching.  Lookup branching is
704 generally useful if the values to switch on are spread far appart, where index
705 branching is useful if the values to switch on are generally dense.<p>
706
707 The two different forms of the '<tt>switch</tt>' statement are simple hints to
708 the underlying implementation.  For example, the compiler may choose to
709 implement a small indirect branch table as a series of predicated comparisons:
710 if it is faster for the target architecture.<p>
711
712 <h5>Arguments:</h5>
713
714 The lookup form of the '<tt>switch</tt>' instruction uses three parameters: a
715 '<tt>uint</tt>' comparison value '<tt>value</tt>', a default '<tt>label</tt>'
716 destination, and an array of pairs of comparison value constants and
717 '<tt>label</tt>'s.  The sized array must be a constant value.<p>
718
719 The indexed form of the '<tt>switch</tt>' instruction uses three parameters: an
720 '<tt>uint</tt>' index value, a default '<tt>label</tt>' and a sized array of
721 '<tt>label</tt>'s.  The '<tt>dests</tt>' array must be a constant array.
722
723 <h5>Semantics:</h5>
724
725 The lookup style switch statement specifies a table of values and destinations.
726 When the '<tt>switch</tt>' instruction is executed, this table is searched for
727 the given value.  If the value is found, the corresponding destination is
728 branched to. <p>
729
730 The index branch form simply looks up a label element directly in a table and
731 branches to it.<p>
732
733 In either case, the compiler knows the static size of the array, because it is
734 provided as part of the constant values type.<p>
735
736 <h5>Example:</h5>
737 <pre>
738   <i>; Emulate a conditional br instruction</i>
739   %Val = <a href="#i_cast">cast</a> bool %value to uint
740   switch uint %Val, label %truedest, [1 x label] [label %falsedest ]
741
742   <i>; Emulate an unconditional br instruction</i>
743   switch uint 0, label %dest, [ 0 x label] [ ]
744
745   <i>; Implement a jump table:</i>
746   switch uint %val, label %otherwise, [3 x label] [ label %onzero, 
747                                                     label %onone, 
748                                                     label %ontwo ]
749
750 </pre>
751
752
753
754 <!-- _______________________________________________________________________ -->
755 </ul><a name="i_invoke"><h4><hr size=0>'<tt>invoke</tt>' Instruction</h4><ul>
756
757 <h5>Syntax:</h5>
758 <pre>
759   &lt;result&gt; = invoke &lt;ptr to function ty&gt; %&lt;function ptr val&gt;(&lt;function args&gt;)
760                  to label &lt;normal label&gt; except label &lt;exception label&gt;
761 </pre>
762
763 <h5>Overview:</h5>
764
765 The '<tt>invoke</tt>' instruction is used to cause control flow to transfer to a
766 specified function, with the possibility of control flow transfer to either the
767 '<tt>normal label</tt>' label or the '<tt>exception label</tt>'.  The '<tt><a
768 href="#i_call">call</a></tt>' instruction is closely related, but guarantees
769 that control flow either never returns from the called function, or that it
770 returns to the instruction following the '<tt><a href="#i_call">call</a></tt>'
771 instruction.<p>
772
773 <h5>Arguments:</h5>
774
775 This instruction requires several arguments:<p>
776 <ol>
777
778 <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to
779 function value being invoked.  In most cases, this is a direct function
780 invocation, but indirect <tt>invoke</tt>s are just as possible, branching off
781 an arbitrary pointer to function value.<p>
782
783 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a
784 function to be invoked.
785
786 <li>'<tt>function args</tt>': argument list whose types match the function
787 signature argument types.  If the function signature indicates the function
788 accepts a variable number of arguments, the extra arguments can be specified. 
789
790 <li>'<tt>normal label</tt>': the label reached when the called function executes
791 a '<tt><a href="#i_ret">ret</a></tt>' instruction.
792
793 <li>'<tt>exception label</tt>': the label reached when an exception is thrown.
794 </ol>
795
796 <h5>Semantics:</h5>
797
798 This instruction is designed to operate as a standard '<tt><a
799 href="#i_call">call</a></tt>' instruction in most regards.  The primary
800 difference is that it associates a label with the function invocation that may
801 be accessed via the runtime library provided by the execution environment.  This
802 instruction is used in languages with destructors to ensure that proper cleanup
803 is performed in the case of either a <tt>longjmp</tt> or a thrown exception.
804 Additionally, this is important for implementation of '<tt>catch</tt>' clauses
805 in high-level languages that support them.<p>
806
807 <!-- For a more comprehensive explanation of how this instruction is used, look in the llvm/docs/2001-05-18-ExceptionHandling.txt document.<p> -->
808
809 <h5>Example:</h5>
810 <pre>
811   %retval = invoke int %Test(int 15)
812               to label %Continue except label %TestCleanup     <i>; {int}:retval set</i>
813 </pre>
814
815
816
817 <!-- ======================================================================= -->
818 </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>
819 <a name="binaryops">Binary Operations
820 </b></font></td></tr></table><ul>
821
822 Binary operators are used to do most of the computation in a program.  They
823 require two operands, execute an operation on them, and produce a single value.
824 The result value of a binary operator is not neccesarily the same type as its
825 operands.<p>
826
827 There are several different binary operators:<p>
828
829
830 <!-- _______________________________________________________________________ -->
831 </ul><a name="i_add"><h4><hr size=0>'<tt>add</tt>' Instruction</h4><ul>
832
833 <h5>Syntax:</h5>
834 <pre>
835   &lt;result&gt; = add &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
836 </pre>
837
838 <h5>Overview:</h5>
839 The '<tt>add</tt>' instruction returns the sum of its two operands.<p>
840
841 <h5>Arguments:</h5>
842 The two arguments to the '<tt>add</tt>' instruction must be either <a href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.  Both arguments must have identical types.<p>
843
844 <h5>Semantics:</h5>
845
846 The value produced is the integer or floating point sum of the two operands.<p>
847
848 <h5>Example:</h5>
849 <pre>
850   &lt;result&gt; = add int 4, %var          <i>; yields {int}:result = 4 + %var</i>
851 </pre>
852
853
854 <!-- _______________________________________________________________________ -->
855 </ul><a name="i_sub"><h4><hr size=0>'<tt>sub</tt>' Instruction</h4><ul>
856
857 <h5>Syntax:</h5>
858 <pre>
859   &lt;result&gt; = sub &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
860 </pre>
861
862 <h5>Overview:</h5>
863
864 The '<tt>sub</tt>' instruction returns the difference of its two operands.<p>
865
866 Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
867 instruction present in most other intermediate representations.<p>
868
869 <h5>Arguments:</h5>
870
871 The two arguments to the '<tt>sub</tt>' instruction must be either <a
872 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
873 values.  Both arguments must have identical types.<p>
874
875 <h5>Semantics:</h5>
876
877 The value produced is the integer or floating point difference of the two
878 operands.<p>
879
880 <h5>Example:</h5>
881 <pre>
882   &lt;result&gt; = sub int 4, %var          <i>; yields {int}:result = 4 - %var</i>
883   &lt;result&gt; = sub int 0, %val          <i>; yields {int}:result = -%var</i>
884 </pre>
885
886 <!-- _______________________________________________________________________ -->
887 </ul><a name="i_mul"><h4><hr size=0>'<tt>mul</tt>' Instruction</h4><ul>
888
889 <h5>Syntax:</h5>
890 <pre>
891   &lt;result&gt; = mul &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
892 </pre>
893
894 <h5>Overview:</h5>
895 The  '<tt>mul</tt>' instruction returns the product of its two operands.<p>
896
897 <h5>Arguments:</h5>
898 The two arguments to the '<tt>mul</tt>' instruction must be either <a href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.  Both arguments must have identical types.<p>
899
900 <h5>Semantics:</h5>
901
902 The value produced is the integer or floating point product of the two
903 operands.<p>
904
905 There is no signed vs unsigned multiplication.  The appropriate action is taken
906 based on the type of the operand. <p>
907
908
909 <h5>Example:</h5>
910 <pre>
911   &lt;result&gt; = mul int 4, %var          <i>; yields {int}:result = 4 * %var</i>
912 </pre>
913
914
915 <!-- _______________________________________________________________________ -->
916 </ul><a name="i_div"><h4><hr size=0>'<tt>div</tt>' Instruction</h4><ul>
917
918 <h5>Syntax:</h5>
919 <pre>
920   &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
921 </pre>
922
923 <h5>Overview:</h5>
924
925 The  '<tt>div</tt>' instruction returns the quotient of its two operands.<p>
926
927 <h5>Arguments:</h5>
928
929 The two arguments to the '<tt>div</tt>' instruction must be either <a
930 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
931 values.  Both arguments must have identical types.<p>
932
933 <h5>Semantics:</h5>
934
935 The value produced is the integer or floating point quotient of the two
936 operands.<p>
937
938 <h5>Example:</h5>
939 <pre>
940   &lt;result&gt; = div int 4, %var          <i>; yields {int}:result = 4 / %var</i>
941 </pre>
942
943
944 <!-- _______________________________________________________________________ -->
945 </ul><a name="i_rem"><h4><hr size=0>'<tt>rem</tt>' Instruction</h4><ul>
946
947 <h5>Syntax:</h5>
948 <pre>
949   &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
950 </pre>
951
952 <h5>Overview:</h5>
953 The  '<tt>rem</tt>' instruction returns the remainder from the division of its two operands.<p>
954
955 <h5>Arguments:</h5>
956 The two arguments to the '<tt>rem</tt>' instruction must be either <a href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.  Both arguments must have identical types.<p>
957
958 <h5>Semantics:</h5>
959
960 This returns the <i>remainder</i> of a division (where the result has the same
961 sign as the divisor), not the <i>modulus</i> (where the result has the same sign
962 as the dividend) of a value.  For more information about the difference, see: <a
963 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The Math
964 Forum</a>.<p>
965
966 <h5>Example:</h5>
967 <pre>
968   &lt;result&gt; = rem int 4, %var          <i>; yields {int}:result = 4 % %var</i>
969 </pre>
970
971
972 <!-- _______________________________________________________________________ -->
973 </ul><a name="i_setcc"><h4><hr size=0>'<tt>set<i>cc</i></tt>' Instructions</h4><ul>
974
975 <h5>Syntax:</h5>
976 <pre>
977   &lt;result&gt; = seteq &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {bool}:result</i>
978   &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {bool}:result</i>
979   &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {bool}:result</i>
980   &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {bool}:result</i>
981   &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {bool}:result</i>
982   &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {bool}:result</i>
983 </pre>
984
985 <h5>Overview:</h5> The '<tt>set<i>cc</i></tt>' family of instructions returns a
986 boolean value based on a comparison of their two operands.<p>
987
988 <h5>Arguments:</h5> The two arguments to the '<tt>set<i>cc</i></tt>'
989 instructions must be of <a href="#t_firstclass">first class</a> or <a
990 href="#t_pointer">pointer</a> type (it is not possible to compare
991 '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>' or '<tt>void</tt>'
992 values, etc...).  Both arguments must have identical types.<p>
993
994 The '<tt>setlt</tt>', '<tt>setgt</tt>', '<tt>setle</tt>', and '<tt>setge</tt>'
995 instructions do not operate on '<tt>bool</tt>' typed arguments.<p>
996
997 <h5>Semantics:</h5>
998
999 The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' value if
1000 both operands are equal.<br>
1001
1002 The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' value if
1003 both operands are unequal.<br>
1004
1005 The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' value if
1006 the first operand is less than the second operand.<br>
1007
1008 The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' value if
1009 the first operand is greater than the second operand.<br>
1010
1011 The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' value if
1012 the first operand is less than or equal to the second operand.<br>
1013
1014 The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' value if
1015 the first operand is greater than or equal to the second operand.<p>
1016
1017 <h5>Example:</h5>
1018 <pre>
1019   &lt;result&gt; = seteq int   4, 5        <i>; yields {bool}:result = false</i>
1020   &lt;result&gt; = setne float 4, 5        <i>; yields {bool}:result = true</i>
1021   &lt;result&gt; = setlt uint  4, 5        <i>; yields {bool}:result = true</i>
1022   &lt;result&gt; = setgt sbyte 4, 5        <i>; yields {bool}:result = false</i>
1023   &lt;result&gt; = setle sbyte 4, 5        <i>; yields {bool}:result = true</i>
1024   &lt;result&gt; = setge sbyte 4, 5        <i>; yields {bool}:result = false</i>
1025 </pre>
1026
1027
1028
1029 <!-- ======================================================================= -->
1030 </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0>
1031 <tr><td>&nbsp;</td><td width="100%">&nbsp; <font color="#EEEEFF" face="Georgia,Palatino"><b>
1032 <a name="bitwiseops">Bitwise Binary Operations
1033 </b></font></td></tr></table><ul>
1034
1035 Bitwise binary operators are used to do various forms of bit-twiddling in a
1036 program.  They are generally very efficient instructions, and can commonly be
1037 strength reduced from other instructions.  They require two operands, execute an
1038 operation on them, and produce a single value.  The resulting value of the
1039 bitwise binary operators is always the same type as its first operand.<p>
1040
1041 <!-- _______________________________________________________________________ -->
1042 </ul><a name="i_and"><h4><hr size=0>'<tt>and</tt>' Instruction</h4><ul>
1043
1044 <h5>Syntax:</h5>
1045 <pre>
1046   &lt;result&gt; = and &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
1047 </pre>
1048
1049 <h5>Overview:</h5>
1050 The '<tt>and</tt>' instruction returns the bitwise logical and of its two operands.<p>
1051
1052 <h5>Arguments:</h5>
1053
1054 The two arguments to the '<tt>and</tt>' instruction must be <a
1055 href="#t_integral">integral</a> values.  Both arguments must have identical
1056 types.<p>
1057
1058
1059 <h5>Semantics:</h5>
1060
1061 The truth table used for the '<tt>and</tt>' instruction is:<p>
1062
1063 <center><table border=1 cellspacing=0 cellpadding=4>
1064 <tr><td>In0</td>  <td>In1</td>  <td>Out</td></tr>
1065 <tr><td>0</td>  <td>0</td>  <td>0</td></tr>
1066 <tr><td>0</td>  <td>1</td>  <td>0</td></tr>
1067 <tr><td>1</td>  <td>0</td>  <td>0</td></tr>
1068 <tr><td>1</td>  <td>1</td>  <td>1</td></tr>
1069 </table></center><p>
1070
1071
1072 <h5>Example:</h5>
1073 <pre>
1074   &lt;result&gt; = and int 4, %var         <i>; yields {int}:result = 4 & %var</i>
1075   &lt;result&gt; = and int 15, 40          <i>; yields {int}:result = 8</i>
1076   &lt;result&gt; = and int 4, 8            <i>; yields {int}:result = 0</i>
1077 </pre>
1078
1079
1080
1081 <!-- _______________________________________________________________________ -->
1082 </ul><a name="i_or"><h4><hr size=0>'<tt>or</tt>' Instruction</h4><ul>
1083
1084 <h5>Syntax:</h5>
1085 <pre>
1086   &lt;result&gt; = or &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
1087 </pre>
1088
1089 <h5>Overview:</h5> The '<tt>or</tt>' instruction returns the bitwise logical
1090 inclusive or of its two operands.<p>
1091
1092 <h5>Arguments:</h5>
1093
1094 The two arguments to the '<tt>or</tt>' instruction must be <a
1095 href="#t_integral">integral</a> values.  Both arguments must have identical
1096 types.<p>
1097
1098
1099 <h5>Semantics:</h5>
1100
1101 The truth table used for the '<tt>or</tt>' instruction is:<p>
1102
1103 <center><table border=1 cellspacing=0 cellpadding=4>
1104 <tr><td>In0</td>  <td>In1</td>  <td>Out</td></tr>
1105 <tr><td>0</td>  <td>0</td>  <td>0</td></tr>
1106 <tr><td>0</td>  <td>1</td>  <td>1</td></tr>
1107 <tr><td>1</td>  <td>0</td>  <td>1</td></tr>
1108 <tr><td>1</td>  <td>1</td>  <td>1</td></tr>
1109 </table></center><p>
1110
1111
1112 <h5>Example:</h5>
1113 <pre>
1114   &lt;result&gt; = or int 4, %var         <i>; yields {int}:result = 4 | %var</i>
1115   &lt;result&gt; = or int 15, 40          <i>; yields {int}:result = 47</i>
1116   &lt;result&gt; = or int 4, 8            <i>; yields {int}:result = 12</i>
1117 </pre>
1118
1119
1120 <!-- _______________________________________________________________________ -->
1121 </ul><a name="i_xor"><h4><hr size=0>'<tt>xor</tt>' Instruction</h4><ul>
1122
1123 <h5>Syntax:</h5>
1124 <pre>
1125   &lt;result&gt; = xor &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
1126 </pre>
1127
1128 <h5>Overview:</h5>
1129
1130 The '<tt>xor</tt>' instruction returns the bitwise logical exclusive or of its
1131 two operands.<p>
1132
1133 <h5>Arguments:</h5>
1134
1135 The two arguments to the '<tt>xor</tt>' instruction must be <a
1136 href="#t_integral">integral</a> values.  Both arguments must have identical
1137 types.<p>
1138
1139
1140 <h5>Semantics:</h5>
1141
1142 The truth table used for the '<tt>xor</tt>' instruction is:<p>
1143
1144 <center><table border=1 cellspacing=0 cellpadding=4>
1145 <tr><td>In0</td>  <td>In1</td>  <td>Out</td></tr>
1146 <tr><td>0</td>  <td>0</td>  <td>0</td></tr>
1147 <tr><td>0</td>  <td>1</td>  <td>1</td></tr>
1148 <tr><td>1</td>  <td>0</td>  <td>1</td></tr>
1149 <tr><td>1</td>  <td>1</td>  <td>0</td></tr>
1150 </table></center><p>
1151
1152
1153 <h5>Example:</h5>
1154 <pre>
1155   &lt;result&gt; = xor int 4, %var         <i>; yields {int}:result = 4 ^ %var</i>
1156   &lt;result&gt; = xor int 15, 40          <i>; yields {int}:result = 39</i>
1157   &lt;result&gt; = xor int 4, 8            <i>; yields {int}:result = 12</i>
1158 </pre>
1159
1160
1161 <!-- _______________________________________________________________________ -->
1162 </ul><a name="i_shl"><h4><hr size=0>'<tt>shl</tt>' Instruction</h4><ul>
1163
1164 <h5>Syntax:</h5>
1165 <pre>
1166   &lt;result&gt; = shl &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt;   <i>; yields {ty}:result</i>
1167 </pre>
1168
1169 <h5>Overview:</h5>
1170
1171 The '<tt>shl</tt>' instruction returns the first operand shifted to the left a
1172 specified number of bits.
1173
1174 <h5>Arguments:</h5>
1175
1176 The first argument to the '<tt>shl</tt>' instruction must be an <a
1177 href="#t_integer">integer</a> type.  The second argument must be an
1178 '<tt>ubyte</tt>' type.<p>
1179
1180 <h5>Semantics:</h5>
1181
1182 The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.<p>
1183
1184
1185 <h5>Example:</h5>
1186 <pre>
1187   &lt;result&gt; = shl int 4, ubyte %var   <i>; yields {int}:result = 4 << %var</i>
1188   &lt;result&gt; = shl int 4, ubyte 2      <i>; yields {int}:result = 16</i>
1189   &lt;result&gt; = shl int 1, ubyte 10     <i>; yields {int}:result = 1024</i>
1190 </pre>
1191
1192
1193 <!-- _______________________________________________________________________ -->
1194 </ul><a name="i_shr"><h4><hr size=0>'<tt>shr</tt>' Instruction</h4><ul>
1195
1196
1197 <h5>Syntax:</h5>
1198 <pre>
1199   &lt;result&gt; = shr &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt;   <i>; yields {ty}:result</i>
1200 </pre>
1201
1202 <h5>Overview:</h5>
1203 The '<tt>shr</tt>' instruction returns the first operand shifted to the right a specified number of bits.
1204
1205 <h5>Arguments:</h5>
1206 The first argument to the '<tt>shr</tt>' instruction must be an  <a href="#t_integer">integer</a> type.  The second argument must be an '<tt>ubyte</tt>' type.<p>
1207
1208 <h5>Semantics:</h5>
1209
1210 If the first argument is a <a href="#t_signed">signed</a> type, the most
1211 significant bit is duplicated in the newly free'd bit positions.  If the first
1212 argument is unsigned, zero bits shall fill the empty positions.<p>
1213
1214 <h5>Example:</h5>
1215 <pre>
1216   &lt;result&gt; = shr int 4, ubyte %var   <i>; yields {int}:result = 4 >> %var</i>
1217   &lt;result&gt; = shr int 4, ubyte 1      <i>; yields {int}:result = 2</i>
1218   &lt;result&gt; = shr int 4, ubyte 2      <i>; yields {int}:result = 1</i>
1219   &lt;result&gt; = shr int 4, ubyte 3      <i>; yields {int}:result = 0</i>
1220 </pre>
1221
1222
1223
1224
1225
1226 <!-- ======================================================================= -->
1227 </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0>
1228 <tr><td>&nbsp;</td><td width="100%">&nbsp; <font color="#EEEEFF" face="Georgia,Palatino"><b>
1229 <a name="memoryops">Memory Access Operations
1230 </b></font></td></tr></table><ul>
1231
1232 Accessing memory in SSA form is, well, sticky at best.  This section describes how to read, write, allocate and free memory in LLVM.<p>
1233
1234
1235 <!-- _______________________________________________________________________ -->
1236 </ul><a name="i_malloc"><h4><hr size=0>'<tt>malloc</tt>' Instruction</h4><ul>
1237
1238 <h5>Syntax:</h5>
1239 <pre>
1240   &lt;result&gt; = malloc &lt;type&gt;, uint &lt;NumElements&gt;     <i>; yields {type*}:result</i>
1241   &lt;result&gt; = malloc &lt;type&gt;                         <i>; yields {type*}:result</i>
1242 </pre>
1243
1244 <h5>Overview:</h5>
1245 The '<tt>malloc</tt>' instruction allocates memory from the system heap and returns a pointer to it.<p>
1246
1247 <h5>Arguments:</h5>
1248
1249 The the '<tt>malloc</tt>' instruction allocates
1250 <tt>sizeof(&lt;type&gt;)*NumElements</tt> bytes of memory from the operating
1251 system, and returns a pointer of the appropriate type to the program.  The
1252 second form of the instruction is a shorter version of the first instruction
1253 that defaults to allocating one element.<p>
1254
1255 '<tt>type</tt>' must be a sized type<p>
1256
1257 <h5>Semantics:</h5>
1258 Memory is allocated, a pointer is returned.<p>
1259
1260 <h5>Example:</h5>
1261 <pre>
1262   %array  = malloc [4 x ubyte ]                    <i>; yields {[%4 x ubyte]*}:array</i>
1263
1264   %size   = <a href="#i_add">add</a> uint 2, 2                          <i>; yields {uint}:size = uint 4</i>
1265   %array1 = malloc ubyte, uint 4                   <i>; yields {ubyte*}:array1</i>
1266   %array2 = malloc [12 x ubyte], uint %size        <i>; yields {[12 x ubyte]*}:array2</i>
1267 </pre>
1268
1269
1270 <!-- _______________________________________________________________________ -->
1271 </ul><a name="i_free"><h4><hr size=0>'<tt>free</tt>' Instruction</h4><ul>
1272
1273 <h5>Syntax:</h5>
1274 <pre>
1275   free &lt;type&gt; &lt;value&gt;                              <i>; yields {void}</i>
1276 </pre>
1277
1278
1279 <h5>Overview:</h5>
1280 The '<tt>free</tt>' instruction returns memory back to the unused memory heap, to be reallocated in the future.<p>
1281
1282
1283 <h5>Arguments:</h5>
1284
1285 '<tt>value</tt>' shall be a pointer value that points to a value that was
1286 allocated with the '<tt><a href="#i_malloc">malloc</a></tt>' instruction.<p>
1287
1288
1289 <h5>Semantics:</h5>
1290
1291 Access to the memory pointed to by the pointer is not longer defined after this instruction executes.<p>
1292
1293 <h5>Example:</h5>
1294 <pre>
1295   %array  = <a href="#i_malloc">malloc</a> [4 x ubyte]                    <i>; yields {[4 x ubyte]*}:array</i>
1296             free   [4 x ubyte]* %array
1297 </pre>
1298
1299
1300 <!-- _______________________________________________________________________ -->
1301 </ul><a name="i_alloca"><h4><hr size=0>'<tt>alloca</tt>' Instruction</h4><ul>
1302
1303 <h5>Syntax:</h5>
1304 <pre>
1305   &lt;result&gt; = alloca &lt;type&gt;, uint &lt;NumElements&gt;  <i>; yields {type*}:result</i>
1306   &lt;result&gt; = alloca &lt;type&gt;                      <i>; yields {type*}:result</i>
1307 </pre>
1308
1309 <h5>Overview:</h5>
1310
1311 The '<tt>alloca</tt>' instruction allocates memory on the current stack frame of
1312 the procedure that is live until the current function returns to its caller.<p>
1313
1314 <h5>Arguments:</h5>
1315
1316 The the '<tt>alloca</tt>' instruction allocates
1317 <tt>sizeof(&lt;type&gt;)*NumElements</tt> bytes of memory on the runtime stack,
1318 returning a pointer of the appropriate type to the program.  The second form of
1319 the instruction is a shorter version of the first that defaults to allocating
1320 one element.<p>
1321
1322 '<tt>type</tt>' may be any sized type.<p>
1323
1324 <h5>Semantics:</h5>
1325
1326 Memory is allocated, a pointer is returned.  '<tt>alloca</tt>'d memory is
1327 automatically released when the function returns.  The '<tt>alloca</tt>'
1328 instruction is commonly used to represent automatic variables that must have an
1329 address available, as well as spilled variables.<p>
1330
1331 <h5>Example:</h5>
1332 <pre>
1333   %ptr = alloca int                              <i>; yields {int*}:ptr</i>
1334   %ptr = alloca int, uint 4                      <i>; yields {int*}:ptr</i>
1335 </pre>
1336
1337
1338 <!-- _______________________________________________________________________ -->
1339 </ul><a name="i_load"><h4><hr size=0>'<tt>load</tt>' Instruction</h4><ul>
1340
1341 <h5>Syntax:</h5>
1342 <pre>
1343   &lt;result&gt; = load &lt;ty&gt;* &lt;pointer&gt;
1344 </pre>
1345
1346 <h5>Overview:</h5>
1347 The '<tt>load</tt>' instruction is used to read from memory.<p>
1348
1349 <h5>Arguments:</h5>
1350
1351 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>
1352
1353 <h5>Semantics:</h5>
1354
1355 The location of memory pointed to is loaded.
1356
1357 <h5>Examples:</h5>
1358 <pre>
1359   %ptr = <a href="#i_alloca">alloca</a> int                               <i>; yields {int*}:ptr</i>
1360   <a href="#i_store">store</a> int 3, int* %ptr                          <i>; yields {void}</i>
1361   %val = load int* %ptr                           <i>; yields {int}:val = int 3</i>
1362 </pre>
1363
1364
1365
1366
1367 <!-- _______________________________________________________________________ -->
1368 </ul><a name="i_store"><h4><hr size=0>'<tt>store</tt>' Instruction</h4><ul>
1369
1370 <h5>Syntax:</h5>
1371 <pre>
1372   store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt;                   <i>; yields {void}</i>
1373 </pre>
1374
1375 <h5>Overview:</h5>
1376 The '<tt>store</tt>' instruction is used to write to memory.<p>
1377
1378 <h5>Arguments:</h5>
1379
1380 There are two arguments to the '<tt>store</tt>' instruction: a value to store
1381 and an address to store it into.  The type of the '<tt>&lt;pointer&gt;</tt>'
1382 operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
1383 operand.<p>
1384
1385 <h5>Semantics:</h5> The contents of memory are updated to contain
1386 '<tt>&lt;value&gt;</tt>' at the location specified by the
1387 '<tt>&lt;pointer&gt;</tt>' operand.<p>
1388
1389 <h5>Example:</h5>
1390 <pre>
1391   %ptr = <a href="#i_alloca">alloca</a> int                               <i>; yields {int*}:ptr</i>
1392   <a href="#i_store">store</a> int 3, int* %ptr                          <i>; yields {void}</i>
1393   %val = load int* %ptr                           <i>; yields {int}:val = int 3</i>
1394 </pre>
1395
1396
1397
1398
1399 <!-- _______________________________________________________________________ -->
1400 </ul><a name="i_getelementptr"><h4><hr size=0>'<tt>getelementptr</tt>' Instruction</h4><ul>
1401
1402 <h5>Syntax:</h5>
1403 <pre>
1404   &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, long &lt;aidx&gt;|, ubyte &lt;sidx&gt;}*
1405 </pre>
1406
1407 <h5>Overview:</h5>
1408
1409 The '<tt>getelementptr</tt>' instruction is used to get the address of a
1410 subelement of an aggregate data structure.<p>
1411
1412 <h5>Arguments:</h5>
1413
1414 This instruction takes a list of <tt>long</tt> values and <tt>ubyte</tt>
1415 constants that indicate what form of addressing to perform.  The actual types of
1416 the arguments provided depend on the type of the first pointer argument.  The
1417 '<tt>getelementptr</tt>' instruction is used to index down through the type
1418 levels of a structure.<p>
1419
1420 For example, lets consider a C code fragment and how it gets compiled to
1421 LLVM:<p>
1422
1423 <pre>
1424 struct RT {
1425   char A;
1426   int B[10][20];
1427   char C;
1428 };
1429 struct ST {
1430   int X;
1431   double Y;
1432   struct RT Z;
1433 };
1434
1435 int *foo(struct ST *s) {
1436   return &amp;s[1].Z.B[5][13];
1437 }
1438 </pre>
1439
1440 The LLVM code generated by the GCC frontend is:
1441
1442 <pre>
1443 %RT = type { sbyte, [10 x [20 x int]], sbyte }
1444 %ST = type { int, double, %RT }
1445
1446 int* "foo"(%ST* %s) {
1447   %reg = getelementptr %ST* %s, long 1, ubyte 2, ubyte 1, long 5, long 13
1448   ret int* %reg
1449 }
1450 </pre>
1451
1452 <h5>Semantics:</h5>
1453
1454 The index types specified for the '<tt>getelementptr</tt>' instruction depend on
1455 the pointer type that is being index into.  <a href="t_pointer">Pointer</a> and
1456 <a href="t_array">array</a> types require '<tt>long</tt>' values, and <a
1457 href="t_struct">structure</a> types require '<tt>ubyte</tt>'
1458 <b>constants</b>.<p>
1459
1460 In the example above, the first index is indexing into the '<tt>%ST*</tt>' type,
1461 which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT }</tt>'
1462 type, a structure.  The second index indexes into the third element of the
1463 structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]], sbyte
1464 }</tt>' type, another structure.  The third index indexes into the second
1465 element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
1466 array.  The two dimensions of the array are subscripted into, yielding an
1467 '<tt>int</tt>' type.  The '<tt>getelementptr</tt>' instruction return a pointer
1468 to this element, thus yielding a '<tt>int*</tt>' type.<p>
1469
1470 Note that it is perfectly legal to index partially through a structure,
1471 returning a pointer to an inner element.  Because of this, the LLVM code for the
1472 given testcase is equivalent to:<p>
1473
1474 <pre>
1475 int* "foo"(%ST* %s) {
1476   %t1 = getelementptr %ST* %s , long 1                        <i>; yields %ST*:%t1</i>
1477   %t2 = getelementptr %ST* %t1, long 0, ubyte 2               <i>; yields %RT*:%t2</i>
1478   %t3 = getelementptr %RT* %t2, long 0, ubyte 1               <i>; yields [10 x [20 x int]]*:%t3</i>
1479   %t4 = getelementptr [10 x [20 x int]]* %t3, long 0, long 5  <i>; yields [20 x int]*:%t4</i>
1480   %t5 = getelementptr [20 x int]* %t4, long 0, long 13        <i>; yields int*:%t5</i>
1481   ret int* %t5
1482 }
1483 </pre>
1484
1485
1486
1487 <h5>Example:</h5>
1488 <pre>
1489   <i>; yields [12 x ubyte]*:aptr</i>
1490   %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, ubyte 1
1491 </pre>
1492
1493
1494
1495 <!-- ======================================================================= -->
1496 </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0>
1497 <tr><td>&nbsp;</td><td width="100%">&nbsp; <font color="#EEEEFF" face="Georgia,Palatino"><b>
1498 <a name="otherops">Other Operations
1499 </b></font></td></tr></table><ul>
1500
1501 The instructions in this catagory are the "miscellaneous" functions, that defy better classification.<p>
1502
1503
1504 <!-- _______________________________________________________________________ -->
1505 </ul><a name="i_phi"><h4><hr size=0>'<tt>phi</tt>' Instruction</h4><ul>
1506
1507 <h5>Syntax:</h5>
1508 <pre>
1509   &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...
1510 </pre>
1511
1512 <h5>Overview:</h5>
1513
1514 The '<tt>phi</tt>' instruction is used to implement the &phi; node in the SSA
1515 graph representing the function.<p>
1516
1517 <h5>Arguments:</h5>
1518
1519 The type of the incoming values are specified with the first type field.  After
1520 this, the '<tt>phi</tt>' instruction takes a list of pairs as arguments, with
1521 one pair for each predecessor basic block of the current block.<p>
1522
1523 There must be no non-phi instructions between the start of a basic block and the
1524 PHI instructions: i.e. PHI instructions must be first in a basic block.<p>
1525
1526 <h5>Semantics:</h5>
1527
1528 At runtime, the '<tt>phi</tt>' instruction logically takes on the value
1529 specified by the parameter, depending on which basic block we came from in the
1530 last <a href="#terminators">terminator</a> instruction.<p>
1531
1532 <h5>Example:</h5>
1533
1534 <pre>
1535 Loop:       ; Infinite loop that counts from 0 on up...
1536   %indvar = phi uint [ 0, %LoopHeader ], [ %nextindvar, %Loop ]
1537   %nextindvar = add uint %indvar, 1
1538   br label %Loop
1539 </pre>
1540
1541
1542 <!-- _______________________________________________________________________ -->
1543 </ul><a name="i_cast"><h4><hr size=0>'<tt>cast .. to</tt>' Instruction</h4><ul>
1544
1545 <h5>Syntax:</h5>
1546 <pre>
1547   &lt;result&gt; = cast &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt;             <i>; yields ty2</i>
1548 </pre>
1549
1550 <h5>Overview:</h5>
1551
1552 The '<tt>cast</tt>' instruction is used as the primitive means to convert
1553 integers to floating point, change data type sizes, and break type safety (by
1554 casting pointers).<p>
1555
1556 <h5>Arguments:</h5>
1557
1558 The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
1559 class value, and a type to cast it to, which must also be a first class type.<p>
1560
1561 <h5>Semantics:</h5>
1562
1563 This instruction follows the C rules for explicit casts when determining how the
1564 data being cast must change to fit in its new container.<p>
1565
1566 When casting to bool, any value that would be considered true in the context of
1567 a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
1568 all else are '<tt>false</tt>'.<p>
1569
1570 When extending an integral value from a type of one signness to another (for
1571 example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
1572 <b>source</b> value is signed, and zero-extended if the source value is
1573 unsigned.  <tt>bool</tt> values are always zero extended into either zero or
1574 one.<p>
1575
1576 <h5>Example:</h5>
1577 <pre>
1578   %X = cast int 257 to ubyte              <i>; yields ubyte:1</i>
1579   %Y = cast int 123 to bool               <i>; yields bool:true</i>
1580 </pre>
1581
1582
1583
1584 <!-- _______________________________________________________________________ -->
1585 </ul><a name="i_call"><h4><hr size=0>'<tt>call</tt>' Instruction</h4><ul>
1586
1587 <h5>Syntax:</h5>
1588 <pre>
1589   &lt;result&gt; = call &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)
1590 </pre>
1591
1592 <h5>Overview:</h5>
1593
1594 The '<tt>call</tt>' instruction represents a simple function call.<p>
1595
1596 <h5>Arguments:</h5>
1597
1598 This instruction requires several arguments:<p>
1599 <ol>
1600
1601 <li>'<tt>ty</tt>': shall be the signature of the pointer to function value being
1602 invoked.  The argument types must match the types implied by this signature.<p>
1603
1604 <li>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to be
1605 invoked. In most cases, this is a direct function invocation, but indirect
1606 <tt>call</tt>s are just as possible, calling an arbitrary pointer to function
1607 values.<p>
1608
1609 <li>'<tt>function args</tt>': argument list whose types match the function
1610 signature argument types.  If the function signature indicates the function
1611 accepts a variable number of arguments, the extra arguments can be specified. 
1612 </ol>
1613
1614 <h5>Semantics:</h5>
1615
1616 The '<tt>call</tt>' instruction is used to cause control flow to transfer to a
1617 specified function, with its incoming arguments bound to the specified values.
1618 Upon a '<tt><a href="#i_ret">ret</a></tt>' instruction in the called function,
1619 control flow continues with the instruction after the function call, and the
1620 return value of the function is bound to the result argument.  This is a simpler
1621 case of the <a href="#i_invoke">invoke</a> instruction.<p>
1622
1623 <h5>Example:</h5>
1624 <pre>
1625   %retval = call int %test(int %argc)
1626   call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42);
1627
1628 </pre>
1629
1630 <!--
1631
1632 <!x- *********************************************************************** -x>
1633 </ul><table width="100%" bgcolor="#330077" border=0 cellpadding=4 cellspacing=0>
1634 <tr><td align=center><font color="#EEEEFF" size=+2 face="Georgia,Palatino"><b>
1635 <a name="related">Related Work
1636 </b></font></td></tr></table><ul>
1637 <!x- *********************************************************************** -x>
1638
1639
1640 Codesigned virtual machines.<p>
1641
1642 <dl>
1643 <a name="rw_safetsa">
1644 <dt>SafeTSA
1645 <DD>Description here<p>
1646
1647 <a name="rw_java">
1648 <dt><a href="http://www.javasoft.com">Java</a>
1649 <DD>Desciption here<p>
1650
1651 <a name="rw_net">
1652 <dt><a href="http://www.microsoft.com/net">Microsoft .net</a>
1653 <DD>Desciption here<p>
1654
1655 <a name="rw_gccrtl">
1656 <dt><a href="http://www.math.umn.edu/systems_guide/gcc-2.95.1/gcc_15.html">GNU RTL Intermediate Representation</a>
1657 <DD>Desciption here<p>
1658
1659 <a name="rw_ia64">
1660 <dt><a href="http://developer.intel.com/design/ia-64/index.htm">IA64 Architecture &amp; Instruction Set</a>
1661 <DD>Desciption here<p>
1662
1663 <a name="rw_mmix">
1664 <dt><a href="http://www-cs-faculty.stanford.edu/~knuth/mmix-news.html">MMIX Instruction Set</a>
1665 <DD>Desciption here<p>
1666
1667 <a name="rw_stroustrup">
1668 <dt><a href="http://www.research.att.com/~bs/devXinterview.html">"Interview With Bjarne Stroustrup"</a>
1669 <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>
1670 </dl>
1671
1672 <!x- _______________________________________________________________________ -x>
1673 </ul><a name="rw_vectorization"><h3><hr size=0>Vectorized Architectures</h3><ul>
1674
1675 <dl>
1676 <a name="rw_intel_simd">
1677 <dt>Intel MMX, MMX2, SSE, SSE2
1678 <DD>Description here<p>
1679
1680 <a name="rw_amd_simd">
1681 <dt><a href="http://www.nondot.org/~sabre/os/H1ChipFeatures/3DNow!TechnologyManual.pdf">AMD 3Dnow!, 3Dnow! 2</a>
1682 <DD>Desciption here<p>
1683
1684 <a name="rw_sun_simd">
1685 <dt><a href="http://www.nondot.org/~sabre/os/H1ChipFeatures/VISInstructionSetUsersManual.pdf">Sun VIS ISA</a>
1686 <DD>Desciption here<p>
1687
1688 <a name="rw_powerpc_simd">
1689 <dt>PowerPC Altivec
1690 <DD>Desciption here<p>
1691
1692 </dl>
1693
1694 more...
1695
1696 -->
1697
1698
1699 <!-- *********************************************************************** -->
1700 </ul>
1701 <!-- *********************************************************************** -->
1702
1703
1704 <hr>
1705 <font size=-1>
1706 <address><a href="mailto:sabre@nondot.org">Chris Lattner</a></address>
1707 <!-- Created: Tue Jan 23 15:19:28 CST 2001 -->
1708 <!-- hhmts start -->
1709 Last modified: Fri Dec 13 00:00:57 CST 2002
1710 <!-- hhmts end -->
1711 </font>
1712 </body></html>