42767e63d50afbdd7fa7534df2797bc0ea1d0aca
[oota-llvm.git] / docs / LangRef.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2                       "http://www.w3.org/TR/html4/strict.dtd">
3 <html>
4 <head>
5   <title>LLVM Assembly Language Reference Manual</title>
6   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7   <meta name="author" content="Chris Lattner">
8   <meta name="description" 
9   content="LLVM Assembly Language Reference Manual.">
10   <link rel="stylesheet" href="llvm.css" type="text/css">
11 </head>
12
13 <body>
14
15 <div class="doc_title"> LLVM Language Reference Manual </div>
16 <ol>
17   <li><a href="#abstract">Abstract</a></li>
18   <li><a href="#introduction">Introduction</a></li>
19   <li><a href="#identifiers">Identifiers</a></li>
20   <li><a href="#highlevel">High Level Structure</a>
21     <ol>
22       <li><a href="#modulestructure">Module Structure</a></li>
23       <li><a href="#linkage">Linkage Types</a></li>
24       <li><a href="#globalvars">Global Variables</a></li>
25       <li><a href="#functionstructure">Function Structure</a></li>
26     </ol>
27   </li>
28   <li><a href="#typesystem">Type System</a>
29     <ol>
30       <li><a href="#t_primitive">Primitive Types</a>    
31         <ol>
32           <li><a href="#t_classifications">Type Classifications</a></li>
33         </ol>
34       </li>
35       <li><a href="#t_derived">Derived Types</a>
36         <ol>
37           <li><a href="#t_array">Array Type</a></li>
38           <li><a href="#t_function">Function Type</a></li>
39           <li><a href="#t_pointer">Pointer Type</a></li>
40           <li><a href="#t_struct">Structure Type</a></li>
41           <li><a href="#t_packed">Packed Type</a></li>
42         </ol>
43       </li>
44     </ol>
45   </li>
46   <li><a href="#constants">Constants</a>
47   </li>
48   <li><a href="#instref">Instruction Reference</a>
49     <ol>
50       <li><a href="#terminators">Terminator Instructions</a>
51         <ol>
52           <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
53           <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
54           <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
55           <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
56           <li><a href="#i_unwind">'<tt>unwind</tt>'  Instruction</a></li>
57           <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
58         </ol>
59       </li>
60       <li><a href="#binaryops">Binary Operations</a>
61         <ol>
62           <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
63           <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
64           <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
65           <li><a href="#i_div">'<tt>div</tt>' Instruction</a></li>
66           <li><a href="#i_rem">'<tt>rem</tt>' Instruction</a></li>
67           <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li>
68         </ol>
69       </li>
70       <li><a href="#bitwiseops">Bitwise Binary Operations</a>
71         <ol>
72           <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
73           <li><a href="#i_or">'<tt>or</tt>'  Instruction</a></li>
74           <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
75           <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
76           <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a></li>
77         </ol>
78       </li>
79       <li><a href="#memoryops">Memory Access Operations</a>
80         <ol>
81           <li><a href="#i_malloc">'<tt>malloc</tt>'   Instruction</a></li>
82           <li><a href="#i_free">'<tt>free</tt>'     Instruction</a></li>
83           <li><a href="#i_alloca">'<tt>alloca</tt>'   Instruction</a></li>
84          <li><a href="#i_load">'<tt>load</tt>'     Instruction</a></li>
85          <li><a href="#i_store">'<tt>store</tt>'    Instruction</a></li>
86          <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
87         </ol>
88       </li>
89       <li><a href="#otherops">Other Operations</a>
90         <ol>
91           <li><a href="#i_phi">'<tt>phi</tt>'   Instruction</a></li>
92           <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li>
93           <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
94           <li><a href="#i_call">'<tt>call</tt>'  Instruction</a></li>
95           <li><a href="#i_vanext">'<tt>vanext</tt>' Instruction</a></li>
96           <li><a href="#i_vaarg">'<tt>vaarg</tt>'  Instruction</a></li>
97         </ol>
98       </li>
99     </ol>
100   </li>
101   <li><a href="#intrinsics">Intrinsic Functions</a>
102     <ol>
103       <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
104         <ol>
105           <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
106           <li><a href="#i_va_end">'<tt>llvm.va_end</tt>'   Intrinsic</a></li>
107           <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>'  Intrinsic</a></li>
108         </ol>
109       </li>
110       <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
111         <ol>
112           <li><a href="#i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li>
113           <li><a href="#i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li>
114           <li><a href="#i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li>
115         </ol>
116       </li>
117       <li><a href="#int_codegen">Code Generator Intrinsics</a>
118         <ol>
119           <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
120           <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>'   Intrinsic</a></li>
121         </ol>
122       </li>
123       <li><a href="#int_os">Operating System Intrinsics</a>
124         <ol>
125           <li><a href="#i_readport">'<tt>llvm.readport</tt>' Intrinsic</a></li>
126           <li><a href="#i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a></li>
127           <li><a href="#i_readio">'<tt>llvm.readio</tt>'   Intrinsic</a></li>
128           <li><a href="#i_writeio">'<tt>llvm.writeio</tt>'   Intrinsic</a></li>
129         </ol>
130       <li><a href="#int_libc">Standard C Library Intrinsics</a>
131         <ol>
132           <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li>
133           <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li>
134           <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li>
135           <li><a href="#i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a></li>
136         </ol>
137       </li>
138       <li><a href="#int_debugger">Debugger intrinsics</a></li>
139     </ol>
140   </li>
141 </ol>
142
143 <div class="doc_author">
144   <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
145             and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
146 </div>
147
148 <!-- *********************************************************************** -->
149 <div class="doc_section"> <a name="abstract">Abstract </a></div>
150 <!-- *********************************************************************** -->
151
152 <div class="doc_text">
153 <p>This document is a reference manual for the LLVM assembly language. 
154 LLVM is an SSA based representation that provides type safety,
155 low-level operations, flexibility, and the capability of representing
156 'all' high-level languages cleanly.  It is the common code
157 representation used throughout all phases of the LLVM compilation
158 strategy.</p>
159 </div>
160
161 <!-- *********************************************************************** -->
162 <div class="doc_section"> <a name="introduction">Introduction</a> </div>
163 <!-- *********************************************************************** -->
164
165 <div class="doc_text">
166
167 <p>The LLVM code representation is designed to be used in three
168 different forms: as an in-memory compiler IR, as an on-disk bytecode
169 representation (suitable for fast loading by a Just-In-Time compiler),
170 and as a human readable assembly language representation.  This allows
171 LLVM to provide a powerful intermediate representation for efficient
172 compiler transformations and analysis, while providing a natural means
173 to debug and visualize the transformations.  The three different forms
174 of LLVM are all equivalent.  This document describes the human readable
175 representation and notation.</p>
176
177 <p>The LLVM representation aims to be a light-weight and low-level
178 while being expressive, typed, and extensible at the same time.  It
179 aims to be a "universal IR" of sorts, by being at a low enough level
180 that high-level ideas may be cleanly mapped to it (similar to how
181 microprocessors are "universal IR's", allowing many source languages to
182 be mapped to them).  By providing type information, LLVM can be used as
183 the target of optimizations: for example, through pointer analysis, it
184 can be proven that a C automatic variable is never accessed outside of
185 the current function... allowing it to be promoted to a simple SSA
186 value instead of a memory location.</p>
187
188 </div>
189
190 <!-- _______________________________________________________________________ -->
191 <div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
192
193 <div class="doc_text">
194
195 <p>It is important to note that this document describes 'well formed'
196 LLVM assembly language.  There is a difference between what the parser
197 accepts and what is considered 'well formed'.  For example, the
198 following instruction is syntactically okay, but not well formed:</p>
199
200 <pre>
201   %x = <a href="#i_add">add</a> int 1, %x
202 </pre>
203
204 <p>...because the definition of <tt>%x</tt> does not dominate all of
205 its uses. The LLVM infrastructure provides a verification pass that may
206 be used to verify that an LLVM module is well formed.  This pass is
207 automatically run by the parser after parsing input assembly, and by
208 the optimizer before it outputs bytecode.  The violations pointed out
209 by the verifier pass indicate bugs in transformation passes or input to
210 the parser.</p>
211
212 <!-- Describe the typesetting conventions here. --> </div>
213
214 <!-- *********************************************************************** -->
215 <div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
216 <!-- *********************************************************************** -->
217
218 <div class="doc_text">
219
220 <p>LLVM uses three different forms of identifiers, for different
221 purposes:</p>
222
223 <ol>
224   <li>Numeric constants are represented as you would expect: 12, -3 123.421,
225   etc.  Floating point constants have an optional hexadecimal notation.</li>
226
227   <li>Named values are represented as a string of characters with a '%' prefix.
228   For example, %foo, %DivisionByZero, %a.really.long.identifier.  The actual
229   regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
230   Identifiers which require other characters in their names can be surrounded
231   with quotes.  In this way, anything except a <tt>"</tt> character can be used
232   in a name.</li>
233
234   <li>Unnamed values are represented as an unsigned numeric value with a '%'
235   prefix.  For example, %12, %2, %44.</li>
236
237 </ol>
238
239 <p>LLVM requires that values start with a '%' sign for two reasons: Compilers
240 don't need to worry about name clashes with reserved words, and the set of
241 reserved words may be expanded in the future without penalty.  Additionally,
242 unnamed identifiers allow a compiler to quickly come up with a temporary
243 variable without having to avoid symbol table conflicts.</p>
244
245 <p>Reserved words in LLVM are very similar to reserved words in other
246 languages. There are keywords for different opcodes ('<tt><a
247 href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
248 href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
249 href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>', etc...),
250 and others.  These reserved words cannot conflict with variable names, because
251 none of them start with a '%' character.</p>
252
253 <p>Here is an example of LLVM code to multiply the integer variable
254 '<tt>%X</tt>' by 8:</p>
255
256 <p>The easy way:</p>
257
258 <pre>
259   %result = <a href="#i_mul">mul</a> uint %X, 8
260 </pre>
261
262 <p>After strength reduction:</p>
263
264 <pre>
265   %result = <a href="#i_shl">shl</a> uint %X, ubyte 3
266 </pre>
267
268 <p>And the hard way:</p>
269
270 <pre>
271   <a href="#i_add">add</a> uint %X, %X           <i>; yields {uint}:%0</i>
272   <a href="#i_add">add</a> uint %0, %0           <i>; yields {uint}:%1</i>
273   %result = <a href="#i_add">add</a> uint %1, %1
274 </pre>
275
276 <p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
277 important lexical features of LLVM:</p>
278
279 <ol>
280
281   <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
282   line.</li>
283
284   <li>Unnamed temporaries are created when the result of a computation is not
285   assigned to a named value.</li>
286
287   <li>Unnamed temporaries are numbered sequentially</li>
288
289 </ol>
290
291 <p>...and it also show a convention that we follow in this document.  When
292 demonstrating instructions, we will follow an instruction with a comment that
293 defines the type and name of value produced.  Comments are shown in italic
294 text.</p>
295
296 <p>The one non-intuitive notation for constants is the optional hexidecimal form
297 of floating point constants.  For example, the form '<tt>double
298 0x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
299 4.5e+15</tt>' which is also supported by the parser.  The only time hexadecimal
300 floating point constants are useful (and the only time that they are generated
301 by the disassembler) is when an FP constant has to be emitted that is not
302 representable as a decimal floating point number exactly.  For example, NaN's,
303 infinities, and other special cases are represented in their IEEE hexadecimal
304 format so that assembly and disassembly do not cause any bits to change in the
305 constants.</p>
306 </div>
307
308 <!-- *********************************************************************** -->
309 <div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
310 <!-- *********************************************************************** -->
311
312 <!-- ======================================================================= -->
313 <div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
314 </div>
315
316 <div class="doc_text">
317
318 <p>LLVM programs are composed of "Module"s, each of which is a
319 translation unit of the input programs.  Each module consists of
320 functions, global variables, and symbol table entries.  Modules may be
321 combined together with the LLVM linker, which merges function (and
322 global variable) definitions, resolves forward declarations, and merges
323 symbol table entries. Here is an example of the "hello world" module:</p>
324
325 <pre><i>; Declare the string constant as a global constant...</i>
326 <a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
327  href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00"          <i>; [13 x sbyte]*</i>
328
329 <i>; External declaration of the puts function</i>
330 <a href="#functionstructure">declare</a> int %puts(sbyte*)                                            <i>; int(sbyte*)* </i>
331
332 <i>; Definition of main function</i>
333 int %main() {                                                        <i>; int()* </i>
334         <i>; Convert [13x sbyte]* to sbyte *...</i>
335         %cast210 = <a
336  href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
337
338         <i>; Call puts function to write out the string to stdout...</i>
339         <a
340  href="#i_call">call</a> int %puts(sbyte* %cast210)                              <i>; int</i>
341         <a
342  href="#i_ret">ret</a> int 0<br>}<br></pre>
343
344 <p>This example is made up of a <a href="#globalvars">global variable</a>
345 named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
346 function, and a <a href="#functionstructure">function definition</a>
347 for "<tt>main</tt>".</p>
348
349 <p>In general, a module is made up of a list of global values,
350 where both functions and global variables are global values.  Global values are
351 represented by a pointer to a memory location (in this case, a pointer to an
352 array of char, and a pointer to a function), and have one of the following <a
353 href="#linkage">linkage types</a>.</p>
354
355 </div>
356
357 <!-- ======================================================================= -->
358 <div class="doc_subsection">
359   <a name="linkage">Linkage Types</a>
360 </div>
361
362 <div class="doc_text">
363
364 <p>
365 All Global Variables and Functions have one of the following types of linkage:
366 </p>
367
368 <dl>
369
370   <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
371
372   <dd>Global values with internal linkage are only directly accessible by
373   objects in the current module.  In particular, linking code into a module with
374   an internal global value may cause the internal to be renamed as necessary to
375   avoid collisions.  Because the symbol is internal to the module, all
376   references can be updated.  This corresponds to the notion of the
377   '<tt>static</tt>' keyword in C, or the idea of "anonymous namespaces" in C++.
378   </dd>
379
380   <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
381
382   <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt> linkage, with
383   the twist that linking together two modules defining the same
384   <tt>linkonce</tt> globals will cause one of the globals to be discarded.  This
385   is typically used to implement inline functions.  Unreferenced
386   <tt>linkonce</tt> globals are allowed to be discarded.
387   </dd>
388
389   <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
390
391   <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage,
392   except that unreferenced <tt>weak</tt> globals may not be discarded.  This is
393   used to implement constructs in C such as "<tt>int X;</tt>" at global scope.
394   </dd>
395
396   <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
397
398   <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
399   pointer to array type.  When two global variables with appending linkage are
400   linked together, the two global arrays are appended together.  This is the
401   LLVM, typesafe, equivalent of having the system linker append together
402   "sections" with identical names when .o files are linked.
403   </dd>
404
405   <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
406
407   <dd>If none of the above identifiers are used, the global is externally
408   visible, meaning that it participates in linkage and can be used to resolve
409   external symbol references.
410   </dd>
411 </dl>
412
413 <p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
414 variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
415 variable and was linked with this one, one of the two would be renamed,
416 preventing a collision.  Since "<tt>main</tt>" and "<tt>puts</tt>" are
417 external (i.e., lacking any linkage declarations), they are accessible
418 outside of the current module.  It is illegal for a function <i>declaration</i>
419 to have any linkage type other than "externally visible".</a></p>
420
421 </div>
422
423 <!-- ======================================================================= -->
424 <div class="doc_subsection">
425   <a name="globalvars">Global Variables</a>
426 </div>
427
428 <div class="doc_text">
429
430 <p>Global variables define regions of memory allocated at compilation
431 time instead of run-time.  Global variables may optionally be
432 initialized.  A variable may be defined as a global "constant", which
433 indicates that the contents of the variable will never be modified
434 (enabling better optimization, allowing the global data to be placed in the
435 read-only section of an executable, etc).</p>
436
437 <p>As SSA values, global variables define pointer values that are in
438 scope (i.e. they dominate) all basic blocks in the program.  Global
439 variables always define a pointer to their "content" type because they
440 describe a region of memory, and all memory objects in LLVM are
441 accessed through pointers.</p>
442
443 </div>
444
445
446 <!-- ======================================================================= -->
447 <div class="doc_subsection">
448   <a name="functionstructure">Functions</a>
449 </div>
450
451 <div class="doc_text">
452
453 <p>LLVM function definitions are composed of a (possibly empty) argument list,
454 an opening curly brace, a list of basic blocks, and a closing curly brace.  LLVM
455 function declarations are defined with the "<tt>declare</tt>" keyword, a
456 function name, and a function signature.</p>
457
458 <p>A function definition contains a list of basic blocks, forming the CFG for
459 the function.  Each basic block may optionally start with a label (giving the
460 basic block a symbol table entry), contains a list of instructions, and ends
461 with a <a href="#terminators">terminator</a> instruction (such as a branch or
462 function return).</p>
463
464 <p>The first basic block in program is special in two ways: it is immediately
465 executed on entrance to the function, and it is not allowed to have predecessor
466 basic blocks (i.e. there can not be any branches to the entry block of a
467 function).  Because the block can have no predecessors, it also cannot have any
468 <a href="#i_phi">PHI nodes</a>.</p>
469
470 <p>LLVM functions are identified by their name and type signature.  Hence, two
471 functions with the same name but different parameter lists or return values are
472 considered different functions, and LLVM will resolves references to each
473 appropriately.</p>
474
475 </div>
476
477
478
479 <!-- *********************************************************************** -->
480 <div class="doc_section"> <a name="typesystem">Type System</a> </div>
481 <!-- *********************************************************************** -->
482
483 <div class="doc_text">
484
485 <p>The LLVM type system is one of the most important features of the
486 intermediate representation.  Being typed enables a number of
487 optimizations to be performed on the IR directly, without having to do
488 extra analyses on the side before the transformation.  A strong type
489 system makes it easier to read the generated code and enables novel
490 analyses and transformations that are not feasible to perform on normal
491 three address code representations.</p>
492
493 </div>
494
495 <!-- ======================================================================= -->
496 <div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
497 <div class="doc_text">
498 <p>The primitive types are the fundamental building blocks of the LLVM
499 system. The current set of primitive types are as follows:</p>
500
501 <table class="layout">
502   <tr class="layout">
503     <td class="left">
504       <table>
505         <tbody>
506         <tr><th>Type</th><th>Description</th></tr>
507         <tr><td><tt>void</tt></td><td>No value</td></tr>
508         <tr><td><tt>ubyte</tt></td><td>Unsigned 8 bit value</td></tr>
509         <tr><td><tt>ushort</tt></td><td>Unsigned 16 bit value</td></tr>
510         <tr><td><tt>uint</tt></td><td>Unsigned 32 bit value</td></tr>
511         <tr><td><tt>ulong</tt></td><td>Unsigned 64 bit value</td></tr>
512         <tr><td><tt>float</tt></td><td>32 bit floating point value</td></tr>
513         <tr><td><tt>label</tt></td><td>Branch destination</td></tr>
514         </tbody>
515       </table>
516     </td>
517     <td class="right">
518       <table>
519         <tbody>
520           <tr><th>Type</th><th>Description</th></tr>
521           <tr><td><tt>bool</tt></td><td>True or False value</td></tr>
522           <tr><td><tt>sbyte</tt></td><td>Signed 8 bit value</td></tr>
523           <tr><td><tt>short</tt></td><td>Signed 16 bit value</td></tr>
524           <tr><td><tt>int</tt></td><td>Signed 32 bit value</td></tr>
525           <tr><td><tt>long</tt></td><td>Signed 64 bit value</td></tr>
526           <tr><td><tt>double</tt></td><td>64 bit floating point value</td></tr>
527         </tbody>
528       </table>
529     </td>
530   </tr>
531 </table>
532 </div>
533
534 <!-- _______________________________________________________________________ -->
535 <div class="doc_subsubsection"> <a name="t_classifications">Type
536 Classifications</a> </div>
537 <div class="doc_text">
538 <p>These different primitive types fall into a few useful
539 classifications:</p>
540
541 <table border="1" cellspacing="0" cellpadding="4">
542   <tbody>
543     <tr><th>Classification</th><th>Types</th></tr>
544     <tr>
545       <td><a name="t_signed">signed</a></td>
546       <td><tt>sbyte, short, int, long, float, double</tt></td>
547     </tr>
548     <tr>
549       <td><a name="t_unsigned">unsigned</a></td>
550       <td><tt>ubyte, ushort, uint, ulong</tt></td>
551     </tr>
552     <tr>
553       <td><a name="t_integer">integer</a></td>
554       <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
555     </tr>
556     <tr>
557       <td><a name="t_integral">integral</a></td>
558       <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt>
559       </td>
560     </tr>
561     <tr>
562       <td><a name="t_floating">floating point</a></td>
563       <td><tt>float, double</tt></td>
564     </tr>
565     <tr>
566       <td><a name="t_firstclass">first class</a></td>
567       <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long,<br> 
568       float, double, <a href="#t_pointer">pointer</a>, 
569       <a href="#t_packed">packed</a></tt></td>
570     </tr>
571   </tbody>
572 </table>
573
574 <p>The <a href="#t_firstclass">first class</a> types are perhaps the
575 most important.  Values of these types are the only ones which can be
576 produced by instructions, passed as arguments, or used as operands to
577 instructions.  This means that all structures and arrays must be
578 manipulated either by pointer or by component.</p>
579 </div>
580 <!-- ======================================================================= -->
581 <div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
582 <div class="doc_text">
583 <p>The real power in LLVM comes from the derived types in the system. 
584 This is what allows a programmer to represent arrays, functions,
585 pointers, and other useful types.  Note that these derived types may be
586 recursive: For example, it is possible to have a two dimensional array.</p>
587 </div>
588 <!-- _______________________________________________________________________ -->
589 <div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
590 <div class="doc_text">
591 <h5>Overview:</h5>
592 <p>The array type is a very simple derived type that arranges elements
593 sequentially in memory.  The array type requires a size (number of
594 elements) and an underlying data type.</p>
595 <h5>Syntax:</h5>
596 <pre>  [&lt;# elements&gt; x &lt;elementtype&gt;]<br></pre>
597 <p>The number of elements is a constant integer value, elementtype may
598 be any type with a size.</p>
599 <h5>Examples:</h5>
600 <table class="layout">
601   <tr class="layout">
602     <td class="left">
603       <tt>[40 x int ]</tt><br/>
604       <tt>[41 x int ]</tt><br/>
605       <tt>[40 x uint]</tt><br/>
606     </td>
607     <td class="left">
608       Array of 40 integer values.<br/>
609       Array of 41 integer values.<br/>
610       Array of 40 unsigned integer values.<br/>
611     </td>
612   </tr>
613 </table>
614 <p>Here are some examples of multidimensional arrays:</p>
615 <table class="layout">
616   <tr class="layout">
617     <td class="left">
618       <tt>[3 x [4 x int]]</tt><br/>
619       <tt>[12 x [10 x float]]</tt><br/>
620       <tt>[2 x [3 x [4 x uint]]]</tt><br/>
621     </td>
622     <td class="left">
623       3x4 array integer values.<br/>
624       12x10 array of single precision floating point values.<br/>
625       2x3x4 array of unsigned integer values.<br/>
626     </td>
627   </tr>
628 </table>
629 </div>
630
631 <!-- _______________________________________________________________________ -->
632 <div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
633 <div class="doc_text">
634 <h5>Overview:</h5>
635 <p>The function type can be thought of as a function signature.  It
636 consists of a return type and a list of formal parameter types. 
637 Function types are usually used to build virtual function tables
638 (which are structures of pointers to functions), for indirect function
639 calls, and when defining a function.</p>
640 <p>
641 The return type of a function type cannot be an aggregate type.
642 </p>
643 <h5>Syntax:</h5>
644 <pre>  &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
645 <p>Where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
646 specifiers.  Optionally, the parameter list may include a type <tt>...</tt>,
647 which indicates that the function takes a variable number of arguments.
648 Variable argument functions can access their arguments with the <a
649  href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
650 <h5>Examples:</h5>
651 <table class="layout">
652   <tr class="layout">
653     <td class="left">
654       <tt>int (int)</tt> <br/>
655       <tt>float (int, int *) *</tt><br/>
656       <tt>int (sbyte *, ...)</tt><br/>
657     </td>
658     <td class="left">
659       function taking an <tt>int</tt>, returning an <tt>int</tt><br/>
660       <a href="#t_pointer">Pointer</a> to a function that takes an
661       <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
662       returning <tt>float</tt>.<br/>
663       A vararg function that takes at least one <a href="#t_pointer">pointer</a> 
664       to <tt>sbyte</tt> (signed char in C), which returns an integer.  This is 
665       the signature for <tt>printf</tt> in LLVM.<br/>
666     </td>
667   </tr>
668 </table>
669
670 </div>
671 <!-- _______________________________________________________________________ -->
672 <div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
673 <div class="doc_text">
674 <h5>Overview:</h5>
675 <p>The structure type is used to represent a collection of data members
676 together in memory.  The packing of the field types is defined to match
677 the ABI of the underlying processor.  The elements of a structure may
678 be any type that has a size.</p>
679 <p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
680 and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
681 field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
682 instruction.</p>
683 <h5>Syntax:</h5>
684 <pre>  { &lt;type list&gt; }<br></pre>
685 <h5>Examples:</h5>
686 <table class="layout">
687   <tr class="layout">
688     <td class="left">
689       <tt>{ int, int, int }</tt><br/>
690       <tt>{ float, int (int) * }</tt><br/>
691     </td>
692     <td class="left">
693       a triple of three <tt>int</tt> values<br/>
694       A pair, where the first element is a <tt>float</tt> and the second element 
695       is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a> 
696       that takes an <tt>int</tt>, returning an <tt>int</tt>.<br/>
697     </td>
698   </tr>
699 </table>
700 </div>
701
702 <!-- _______________________________________________________________________ -->
703 <div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
704 <div class="doc_text">
705 <h5>Overview:</h5>
706 <p>As in many languages, the pointer type represents a pointer or
707 reference to another object, which must live in memory.</p>
708 <h5>Syntax:</h5>
709 <pre>  &lt;type&gt; *<br></pre>
710 <h5>Examples:</h5>
711 <table class="layout">
712   <tr class="layout">
713     <td class="left">
714       <tt>[4x int]*</tt><br/>
715       <tt>int (int *) *</tt><br/>
716     </td>
717     <td class="left">
718       A <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of
719       four <tt>int</tt> values<br/>
720       A <a href="#t_pointer">pointer</a> to a <a
721       href="#t_function">function</a> that takes an <tt>int</tt>, returning an
722       <tt>int</tt>.<br/>
723     </td>
724   </tr>
725 </table>
726 </div>
727
728 <!-- _______________________________________________________________________ -->
729 <div class="doc_subsubsection"> <a name="t_packed">Packed Type</a> </div>
730 <div class="doc_text">
731 <h5>Overview:</h5>
732 <p>A packed type is a simple derived type that represents a vector
733 of elements.  Packed types are used when multiple primitive data 
734 are operated in parallel using a single instruction (SIMD). 
735 A packed type requires a size (number of
736 elements) and an underlying primitive data type.  Packed types are
737 considered <a href="#t_firstclass">first class</a>.</p>
738 <h5>Syntax:</h5>
739 <pre>  &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;<br></pre>
740 <p>The number of elements is a constant integer value, elementtype may
741 be any integral or floating point type.</p>
742 <h5>Examples:</h5>
743 <table class="layout">
744   <tr class="layout">
745     <td class="left">
746       <tt>&lt;4 x int&gt;</tt><br/>
747       <tt>&lt;8 x float&gt;</tt><br/>
748       <tt>&lt;2 x uint&gt;</tt><br/>
749     </td>
750     <td class="left">
751       Packed vector of 4 integer values.<br/>
752       Packed vector of 8 floating-point values.<br/>
753       Packed vector of 2 unsigned integer values.<br/>
754     </td>
755   </tr>
756 </table>
757 </div>
758
759
760 <!-- *********************************************************************** -->
761 <div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
762 <!-- *********************************************************************** -->
763 <div class="doc_text">
764 <p>The LLVM instruction set consists of several different
765 classifications of instructions: <a href="#terminators">terminator
766 instructions</a>, <a href="#binaryops">binary instructions</a>, <a
767  href="#memoryops">memory instructions</a>, and <a href="#otherops">other
768 instructions</a>.</p>
769 </div>
770 <!-- ======================================================================= -->
771 <div class="doc_subsection"> <a name="terminators">Terminator
772 Instructions</a> </div>
773 <div class="doc_text">
774 <p>As mentioned <a href="#functionstructure">previously</a>, every
775 basic block in a program ends with a "Terminator" instruction, which
776 indicates which block should be executed after the current block is
777 finished. These terminator instructions typically yield a '<tt>void</tt>'
778 value: they produce control flow, not values (the one exception being
779 the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
780 <p>There are five different terminator instructions: the '<a
781  href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
782 instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
783 the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
784  href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
785  href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
786 </div>
787 <!-- _______________________________________________________________________ -->
788 <div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
789 Instruction</a> </div>
790 <div class="doc_text">
791 <h5>Syntax:</h5>
792 <pre>  ret &lt;type&gt; &lt;value&gt;       <i>; Return a value from a non-void function</i>
793   ret void                 <i>; Return from void function</i>
794 </pre>
795 <h5>Overview:</h5>
796 <p>The '<tt>ret</tt>' instruction is used to return control flow (and a
797 value) from a function, back to the caller.</p>
798 <p>There are two forms of the '<tt>ret</tt>' instruction: one that
799 returns a value and then causes control flow, and one that just causes
800 control flow to occur.</p>
801 <h5>Arguments:</h5>
802 <p>The '<tt>ret</tt>' instruction may return any '<a
803  href="#t_firstclass">first class</a>' type.  Notice that a function is
804 not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
805 instruction inside of the function that returns a value that does not
806 match the return type of the function.</p>
807 <h5>Semantics:</h5>
808 <p>When the '<tt>ret</tt>' instruction is executed, control flow
809 returns back to the calling function's context.  If the caller is a "<a
810  href="#i_call"><tt>call</tt></a>" instruction, execution continues at
811 the instruction after the call.  If the caller was an "<a
812  href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
813 at the beginning "normal" of the destination block.  If the instruction
814 returns a value, that value shall set the call or invoke instruction's
815 return value.</p>
816 <h5>Example:</h5>
817 <pre>  ret int 5                       <i>; Return an integer value of 5</i>
818   ret void                        <i>; Return from a void function</i>
819 </pre>
820 </div>
821 <!-- _______________________________________________________________________ -->
822 <div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
823 <div class="doc_text">
824 <h5>Syntax:</h5>
825 <pre>  br bool &lt;cond&gt;, label &lt;iftrue&gt;, label &lt;iffalse&gt;<br>  br label &lt;dest&gt;          <i>; Unconditional branch</i>
826 </pre>
827 <h5>Overview:</h5>
828 <p>The '<tt>br</tt>' instruction is used to cause control flow to
829 transfer to a different basic block in the current function.  There are
830 two forms of this instruction, corresponding to a conditional branch
831 and an unconditional branch.</p>
832 <h5>Arguments:</h5>
833 <p>The conditional branch form of the '<tt>br</tt>' instruction takes a
834 single '<tt>bool</tt>' value and two '<tt>label</tt>' values.  The
835 unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
836 value as a target.</p>
837 <h5>Semantics:</h5>
838 <p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
839 argument is evaluated.  If the value is <tt>true</tt>, control flows
840 to the '<tt>iftrue</tt>' <tt>label</tt> argument.  If "cond" is <tt>false</tt>,
841 control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
842 <h5>Example:</h5>
843 <pre>Test:<br>  %cond = <a href="#i_setcc">seteq</a> int %a, %b<br>  br bool %cond, label %IfEqual, label %IfUnequal<br>IfEqual:<br>  <a
844  href="#i_ret">ret</a> int 1<br>IfUnequal:<br>  <a href="#i_ret">ret</a> int 0<br></pre>
845 </div>
846 <!-- _______________________________________________________________________ -->
847 <div class="doc_subsubsection">
848    <a name="i_switch">'<tt>switch</tt>' Instruction</a>
849 </div>
850
851 <div class="doc_text">
852 <h5>Syntax:</h5>
853
854 <pre>
855   switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
856 </pre>
857
858 <h5>Overview:</h5>
859
860 <p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
861 several different places.  It is a generalization of the '<tt>br</tt>'
862 instruction, allowing a branch to occur to one of many possible
863 destinations.</p>
864
865
866 <h5>Arguments:</h5>
867
868 <p>The '<tt>switch</tt>' instruction uses three parameters: an integer
869 comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
870 an array of pairs of comparison value constants and '<tt>label</tt>'s.  The
871 table is not allowed to contain duplicate constant entries.</p>
872
873 <h5>Semantics:</h5>
874
875 <p>The <tt>switch</tt> instruction specifies a table of values and
876 destinations. When the '<tt>switch</tt>' instruction is executed, this
877 table is searched for the given value.  If the value is found, control flow is
878 transfered to the corresponding destination; otherwise, control flow is
879 transfered to the default destination.</p>
880
881 <h5>Implementation:</h5>
882
883 <p>Depending on properties of the target machine and the particular
884 <tt>switch</tt> instruction, this instruction may be code generated in different
885 ways.  For example, it could be generated as a series of chained conditional
886 branches or with a lookup table.</p>
887
888 <h5>Example:</h5>
889
890 <pre>
891  <i>; Emulate a conditional br instruction</i>
892  %Val = <a href="#i_cast">cast</a> bool %value to int
893  switch int %Val, label %truedest [int 0, label %falsedest ]
894
895  <i>; Emulate an unconditional br instruction</i>
896  switch uint 0, label %dest [ ]
897
898  <i>; Implement a jump table:</i>
899  switch uint %val, label %otherwise [ uint 0, label %onzero 
900                                       uint 1, label %onone 
901                                       uint 2, label %ontwo ]
902 </pre>
903 </div>
904 <!-- _______________________________________________________________________ -->
905 <div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>'
906 Instruction</a> </div>
907 <div class="doc_text">
908 <h5>Syntax:</h5>
909 <pre>  &lt;result&gt; = invoke &lt;ptr to function ty&gt; %&lt;function ptr val&gt;(&lt;function args&gt;)<br>                 to label &lt;normal label&gt; except label &lt;exception label&gt;<br></pre>
910 <h5>Overview:</h5>
911 <p>The '<tt>invoke</tt>' instruction causes control to transfer to a
912 specified function, with the possibility of control flow transfer to
913 either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>.
914 If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>"
915 instruction, control flow will return to the "normal" label.  If the
916 callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
917 instruction, control is interrupted, and continued at the dynamically
918 nearest "except" label.</p>
919 <h5>Arguments:</h5>
920 <p>This instruction requires several arguments:</p>
921 <ol>
922   <li>'<tt>ptr to function ty</tt>': shall be the signature of the
923 pointer to function value being invoked.  In most cases, this is a
924 direct function invocation, but indirect <tt>invoke</tt>s are just as
925 possible, branching off an arbitrary pointer to function value. </li>
926   <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer
927 to a function to be invoked. </li>
928   <li>'<tt>function args</tt>': argument list whose types match the
929 function signature argument types.  If the function signature indicates
930 the function accepts a variable number of arguments, the extra
931 arguments can be specified. </li>
932   <li>'<tt>normal label</tt>': the label reached when the called
933 function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
934   <li>'<tt>exception label</tt>': the label reached when a callee
935 returns with the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
936 </ol>
937 <h5>Semantics:</h5>
938 <p>This instruction is designed to operate as a standard '<tt><a
939  href="#i_call">call</a></tt>' instruction in most regards.  The
940 primary difference is that it establishes an association with a label,
941 which is used by the runtime library to unwind the stack.</p>
942 <p>This instruction is used in languages with destructors to ensure
943 that proper cleanup is performed in the case of either a <tt>longjmp</tt>
944 or a thrown exception.  Additionally, this is important for
945 implementation of '<tt>catch</tt>' clauses in high-level languages that
946 support them.</p>
947 <h5>Example:</h5>
948 <pre>  %retval = invoke int %Test(int 15)<br>              to label %Continue<br>              except label %TestCleanup     <i>; {int}:retval set</i>
949 </pre>
950 </div>
951
952
953 <!-- _______________________________________________________________________ -->
954
955 <div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
956 Instruction</a> </div>
957
958 <div class="doc_text">
959
960 <h5>Syntax:</h5>
961 <pre>
962   unwind
963 </pre>
964
965 <h5>Overview:</h5>
966
967 <p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
968 at the first callee in the dynamic call stack which used an <a
969 href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call.  This is
970 primarily used to implement exception handling.</p>
971
972 <h5>Semantics:</h5>
973
974 <p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to
975 immediately halt.  The dynamic call stack is then searched for the first <a
976 href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack.  Once found,
977 execution continues at the "exceptional" destination block specified by the
978 <tt>invoke</tt> instruction.  If there is no <tt>invoke</tt> instruction in the
979 dynamic call chain, undefined behavior results.</p>
980 </div>
981
982 <!-- _______________________________________________________________________ -->
983
984 <div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
985 Instruction</a> </div>
986
987 <div class="doc_text">
988
989 <h5>Syntax:</h5>
990 <pre>
991   unreachable
992 </pre>
993
994 <h5>Overview:</h5>
995
996 <p>The '<tt>unreachable</tt>' instruction has no defined semantics.  This
997 instruction is used to inform the optimizer that a particular portion of the
998 code is not reachable.  This can be used to indicate that the code after a
999 no-return function cannot be reached, and other facts.</p>
1000
1001 <h5>Semantics:</h5>
1002
1003 <p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
1004 </div>
1005
1006
1007
1008 <!-- ======================================================================= -->
1009 <div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
1010 <div class="doc_text">
1011 <p>Binary operators are used to do most of the computation in a
1012 program.  They require two operands, execute an operation on them, and
1013 produce a single value.  Although, that single value might represent 
1014 multiple data, as is the case with the <a href="#t_packed">packed</a> data type. 
1015 The result value of a binary operator is not
1016 necessarily the same type as its operands.</p>
1017 <p>There are several different binary operators:</p>
1018 </div>
1019 <!-- _______________________________________________________________________ -->
1020 <div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
1021 Instruction</a> </div>
1022 <div class="doc_text">
1023 <h5>Syntax:</h5>
1024 <pre>  &lt;result&gt; = add &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
1025 </pre>
1026 <h5>Overview:</h5>
1027 <p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
1028 <h5>Arguments:</h5>
1029 <p>The two arguments to the '<tt>add</tt>' instruction must be either <a
1030  href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
1031  This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1032 Both arguments must have identical types.</p>
1033 <h5>Semantics:</h5>
1034 <p>The value produced is the integer or floating point sum of the two
1035 operands.</p>
1036 <h5>Example:</h5>
1037 <pre>  &lt;result&gt; = add int 4, %var          <i>; yields {int}:result = 4 + %var</i>
1038 </pre>
1039 </div>
1040 <!-- _______________________________________________________________________ -->
1041 <div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
1042 Instruction</a> </div>
1043 <div class="doc_text">
1044 <h5>Syntax:</h5>
1045 <pre>  &lt;result&gt; = sub &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
1046 </pre>
1047 <h5>Overview:</h5>
1048 <p>The '<tt>sub</tt>' instruction returns the difference of its two
1049 operands.</p>
1050 <p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
1051 instruction present in most other intermediate representations.</p>
1052 <h5>Arguments:</h5>
1053 <p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
1054  href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
1055 values. 
1056 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1057 Both arguments must have identical types.</p>
1058 <h5>Semantics:</h5>
1059 <p>The value produced is the integer or floating point difference of
1060 the two operands.</p>
1061 <h5>Example:</h5>
1062 <pre>  &lt;result&gt; = sub int 4, %var          <i>; yields {int}:result = 4 - %var</i>
1063   &lt;result&gt; = sub int 0, %val          <i>; yields {int}:result = -%var</i>
1064 </pre>
1065 </div>
1066 <!-- _______________________________________________________________________ -->
1067 <div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
1068 Instruction</a> </div>
1069 <div class="doc_text">
1070 <h5>Syntax:</h5>
1071 <pre>  &lt;result&gt; = mul &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
1072 </pre>
1073 <h5>Overview:</h5>
1074 <p>The  '<tt>mul</tt>' instruction returns the product of its two
1075 operands.</p>
1076 <h5>Arguments:</h5>
1077 <p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
1078  href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
1079 values. 
1080 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1081 Both arguments must have identical types.</p>
1082 <h5>Semantics:</h5>
1083 <p>The value produced is the integer or floating point product of the
1084 two operands.</p>
1085 <p>There is no signed vs unsigned multiplication.  The appropriate
1086 action is taken based on the type of the operand.</p>
1087 <h5>Example:</h5>
1088 <pre>  &lt;result&gt; = mul int 4, %var          <i>; yields {int}:result = 4 * %var</i>
1089 </pre>
1090 </div>
1091 <!-- _______________________________________________________________________ -->
1092 <div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
1093 Instruction</a> </div>
1094 <div class="doc_text">
1095 <h5>Syntax:</h5>
1096 <pre>  &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
1097 </pre>
1098 <h5>Overview:</h5>
1099 <p>The '<tt>div</tt>' instruction returns the quotient of its two
1100 operands.</p>
1101 <h5>Arguments:</h5>
1102 <p>The two arguments to the '<tt>div</tt>' instruction must be either <a
1103  href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
1104 values. 
1105 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1106 Both arguments must have identical types.</p>
1107 <h5>Semantics:</h5>
1108 <p>The value produced is the integer or floating point quotient of the
1109 two operands.</p>
1110 <h5>Example:</h5>
1111 <pre>  &lt;result&gt; = div int 4, %var          <i>; yields {int}:result = 4 / %var</i>
1112 </pre>
1113 </div>
1114 <!-- _______________________________________________________________________ -->
1115 <div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
1116 Instruction</a> </div>
1117 <div class="doc_text">
1118 <h5>Syntax:</h5>
1119 <pre>  &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
1120 </pre>
1121 <h5>Overview:</h5>
1122 <p>The '<tt>rem</tt>' instruction returns the remainder from the
1123 division of its two operands.</p>
1124 <h5>Arguments:</h5>
1125 <p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1126  href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
1127 values. 
1128 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1129 Both arguments must have identical types.</p>
1130 <h5>Semantics:</h5>
1131 <p>This returns the <i>remainder</i> of a division (where the result
1132 has the same sign as the divisor), not the <i>modulus</i> (where the
1133 result has the same sign as the dividend) of a value.  For more
1134 information about the difference, see: <a
1135  href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1136 Math Forum</a>.</p>
1137 <h5>Example:</h5>
1138 <pre>  &lt;result&gt; = rem int 4, %var          <i>; yields {int}:result = 4 % %var</i>
1139 </pre>
1140 </div>
1141 <!-- _______________________________________________________________________ -->
1142 <div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1143 Instructions</a> </div>
1144 <div class="doc_text">
1145 <h5>Syntax:</h5>
1146 <pre>  &lt;result&gt; = seteq &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {bool}:result</i>
1147   &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {bool}:result</i>
1148   &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {bool}:result</i>
1149   &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {bool}:result</i>
1150   &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {bool}:result</i>
1151   &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {bool}:result</i>
1152 </pre>
1153 <h5>Overview:</h5>
1154 <p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1155 value based on a comparison of their two operands.</p>
1156 <h5>Arguments:</h5>
1157 <p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1158 be of <a href="#t_firstclass">first class</a> type (it is not possible
1159 to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1160 or '<tt>void</tt>' values, etc...).  Both arguments must have identical
1161 types.</p>
1162 <h5>Semantics:</h5>
1163 <p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1164 value if both operands are equal.<br>
1165 The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1166 value if both operands are unequal.<br>
1167 The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1168 value if the first operand is less than the second operand.<br>
1169 The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1170 value if the first operand is greater than the second operand.<br>
1171 The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1172 value if the first operand is less than or equal to the second operand.<br>
1173 The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1174 value if the first operand is greater than or equal to the second
1175 operand.</p>
1176 <h5>Example:</h5>
1177 <pre>  &lt;result&gt; = seteq int   4, 5        <i>; yields {bool}:result = false</i>
1178   &lt;result&gt; = setne float 4, 5        <i>; yields {bool}:result = true</i>
1179   &lt;result&gt; = setlt uint  4, 5        <i>; yields {bool}:result = true</i>
1180   &lt;result&gt; = setgt sbyte 4, 5        <i>; yields {bool}:result = false</i>
1181   &lt;result&gt; = setle sbyte 4, 5        <i>; yields {bool}:result = true</i>
1182   &lt;result&gt; = setge sbyte 4, 5        <i>; yields {bool}:result = false</i>
1183 </pre>
1184 </div>
1185 <!-- ======================================================================= -->
1186 <div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1187 Operations</a> </div>
1188 <div class="doc_text">
1189 <p>Bitwise binary operators are used to do various forms of
1190 bit-twiddling in a program.  They are generally very efficient
1191 instructions, and can commonly be strength reduced from other
1192 instructions.  They require two operands, execute an operation on them,
1193 and produce a single value.  The resulting value of the bitwise binary
1194 operators is always the same type as its first operand.</p>
1195 </div>
1196 <!-- _______________________________________________________________________ -->
1197 <div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1198 Instruction</a> </div>
1199 <div class="doc_text">
1200 <h5>Syntax:</h5>
1201 <pre>  &lt;result&gt; = and &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
1202 </pre>
1203 <h5>Overview:</h5>
1204 <p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1205 its two operands.</p>
1206 <h5>Arguments:</h5>
1207 <p>The two arguments to the '<tt>and</tt>' instruction must be <a
1208  href="#t_integral">integral</a> values.  Both arguments must have
1209 identical types.</p>
1210 <h5>Semantics:</h5>
1211 <p>The truth table used for the '<tt>and</tt>' instruction is:</p>
1212 <p> </p>
1213 <div style="align: center">
1214 <table border="1" cellspacing="0" cellpadding="4">
1215   <tbody>
1216     <tr>
1217       <td>In0</td>
1218       <td>In1</td>
1219       <td>Out</td>
1220     </tr>
1221     <tr>
1222       <td>0</td>
1223       <td>0</td>
1224       <td>0</td>
1225     </tr>
1226     <tr>
1227       <td>0</td>
1228       <td>1</td>
1229       <td>0</td>
1230     </tr>
1231     <tr>
1232       <td>1</td>
1233       <td>0</td>
1234       <td>0</td>
1235     </tr>
1236     <tr>
1237       <td>1</td>
1238       <td>1</td>
1239       <td>1</td>
1240     </tr>
1241   </tbody>
1242 </table>
1243 </div>
1244 <h5>Example:</h5>
1245 <pre>  &lt;result&gt; = and int 4, %var         <i>; yields {int}:result = 4 &amp; %var</i>
1246   &lt;result&gt; = and int 15, 40          <i>; yields {int}:result = 8</i>
1247   &lt;result&gt; = and int 4, 8            <i>; yields {int}:result = 0</i>
1248 </pre>
1249 </div>
1250 <!-- _______________________________________________________________________ -->
1251 <div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
1252 <div class="doc_text">
1253 <h5>Syntax:</h5>
1254 <pre>  &lt;result&gt; = or &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
1255 </pre>
1256 <h5>Overview:</h5>
1257 <p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1258 or of its two operands.</p>
1259 <h5>Arguments:</h5>
1260 <p>The two arguments to the '<tt>or</tt>' instruction must be <a
1261  href="#t_integral">integral</a> values.  Both arguments must have
1262 identical types.</p>
1263 <h5>Semantics:</h5>
1264 <p>The truth table used for the '<tt>or</tt>' instruction is:</p>
1265 <p> </p>
1266 <div style="align: center">
1267 <table border="1" cellspacing="0" cellpadding="4">
1268   <tbody>
1269     <tr>
1270       <td>In0</td>
1271       <td>In1</td>
1272       <td>Out</td>
1273     </tr>
1274     <tr>
1275       <td>0</td>
1276       <td>0</td>
1277       <td>0</td>
1278     </tr>
1279     <tr>
1280       <td>0</td>
1281       <td>1</td>
1282       <td>1</td>
1283     </tr>
1284     <tr>
1285       <td>1</td>
1286       <td>0</td>
1287       <td>1</td>
1288     </tr>
1289     <tr>
1290       <td>1</td>
1291       <td>1</td>
1292       <td>1</td>
1293     </tr>
1294   </tbody>
1295 </table>
1296 </div>
1297 <h5>Example:</h5>
1298 <pre>  &lt;result&gt; = or int 4, %var         <i>; yields {int}:result = 4 | %var</i>
1299   &lt;result&gt; = or int 15, 40          <i>; yields {int}:result = 47</i>
1300   &lt;result&gt; = or int 4, 8            <i>; yields {int}:result = 12</i>
1301 </pre>
1302 </div>
1303 <!-- _______________________________________________________________________ -->
1304 <div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1305 Instruction</a> </div>
1306 <div class="doc_text">
1307 <h5>Syntax:</h5>
1308 <pre>  &lt;result&gt; = xor &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;   <i>; yields {ty}:result</i>
1309 </pre>
1310 <h5>Overview:</h5>
1311 <p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1312 or of its two operands.  The <tt>xor</tt> is used to implement the
1313 "one's complement" operation, which is the "~" operator in C.</p>
1314 <h5>Arguments:</h5>
1315 <p>The two arguments to the '<tt>xor</tt>' instruction must be <a
1316  href="#t_integral">integral</a> values.  Both arguments must have
1317 identical types.</p>
1318 <h5>Semantics:</h5>
1319 <p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
1320 <p> </p>
1321 <div style="align: center">
1322 <table border="1" cellspacing="0" cellpadding="4">
1323   <tbody>
1324     <tr>
1325       <td>In0</td>
1326       <td>In1</td>
1327       <td>Out</td>
1328     </tr>
1329     <tr>
1330       <td>0</td>
1331       <td>0</td>
1332       <td>0</td>
1333     </tr>
1334     <tr>
1335       <td>0</td>
1336       <td>1</td>
1337       <td>1</td>
1338     </tr>
1339     <tr>
1340       <td>1</td>
1341       <td>0</td>
1342       <td>1</td>
1343     </tr>
1344     <tr>
1345       <td>1</td>
1346       <td>1</td>
1347       <td>0</td>
1348     </tr>
1349   </tbody>
1350 </table>
1351 </div>
1352 <p> </p>
1353 <h5>Example:</h5>
1354 <pre>  &lt;result&gt; = xor int 4, %var         <i>; yields {int}:result = 4 ^ %var</i>
1355   &lt;result&gt; = xor int 15, 40          <i>; yields {int}:result = 39</i>
1356   &lt;result&gt; = xor int 4, 8            <i>; yields {int}:result = 12</i>
1357   &lt;result&gt; = xor int %V, -1          <i>; yields {int}:result = ~%V</i>
1358 </pre>
1359 </div>
1360 <!-- _______________________________________________________________________ -->
1361 <div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1362 Instruction</a> </div>
1363 <div class="doc_text">
1364 <h5>Syntax:</h5>
1365 <pre>  &lt;result&gt; = shl &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt;   <i>; yields {ty}:result</i>
1366 </pre>
1367 <h5>Overview:</h5>
1368 <p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1369 the left a specified number of bits.</p>
1370 <h5>Arguments:</h5>
1371 <p>The first argument to the '<tt>shl</tt>' instruction must be an <a
1372  href="#t_integer">integer</a> type.  The second argument must be an '<tt>ubyte</tt>'
1373 type.</p>
1374 <h5>Semantics:</h5>
1375 <p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
1376 <h5>Example:</h5>
1377 <pre>  &lt;result&gt; = shl int 4, ubyte %var   <i>; yields {int}:result = 4 &lt;&lt; %var</i>
1378   &lt;result&gt; = shl int 4, ubyte 2      <i>; yields {int}:result = 16</i>
1379   &lt;result&gt; = shl int 1, ubyte 10     <i>; yields {int}:result = 1024</i>
1380 </pre>
1381 </div>
1382 <!-- _______________________________________________________________________ -->
1383 <div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1384 Instruction</a> </div>
1385 <div class="doc_text">
1386 <h5>Syntax:</h5>
1387 <pre>  &lt;result&gt; = shr &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt;   <i>; yields {ty}:result</i>
1388 </pre>
1389 <h5>Overview:</h5>
1390 <p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1391 the right a specified number of bits.</p>
1392 <h5>Arguments:</h5>
1393 <p>The first argument to the '<tt>shr</tt>' instruction must be an <a
1394  href="#t_integer">integer</a> type.  The second argument must be an '<tt>ubyte</tt>'
1395 type.</p>
1396 <h5>Semantics:</h5>
1397 <p>If the first argument is a <a href="#t_signed">signed</a> type, the
1398 most significant bit is duplicated in the newly free'd bit positions. 
1399 If the first argument is unsigned, zero bits shall fill the empty
1400 positions.</p>
1401 <h5>Example:</h5>
1402 <pre>  &lt;result&gt; = shr int 4, ubyte %var   <i>; yields {int}:result = 4 &gt;&gt; %var</i>
1403   &lt;result&gt; = shr uint 4, ubyte 1     <i>; yields {uint}:result = 2</i>
1404   &lt;result&gt; = shr int 4, ubyte 2      <i>; yields {int}:result = 1</i>
1405   &lt;result&gt; = shr sbyte 4, ubyte 3    <i>; yields {sbyte}:result = 0</i>
1406   &lt;result&gt; = shr sbyte -2, ubyte 1   <i>; yields {sbyte}:result = -1</i>
1407 </pre>
1408 </div>
1409 <!-- ======================================================================= -->
1410 <div class="doc_subsection"> <a name="memoryops">Memory Access
1411 Operations</a></div>
1412 <div class="doc_text">
1413 <p>A key design point of an SSA-based representation is how it
1414 represents memory.  In LLVM, no memory locations are in SSA form, which
1415 makes things very simple.  This section describes how to read, write,
1416 allocate and free memory in LLVM.</p>
1417 </div>
1418 <!-- _______________________________________________________________________ -->
1419 <div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>'
1420 Instruction</a> </div>
1421 <div class="doc_text">
1422 <h5>Syntax:</h5>
1423 <pre>  &lt;result&gt; = malloc &lt;type&gt;, uint &lt;NumElements&gt;     <i>; yields {type*}:result</i>
1424   &lt;result&gt; = malloc &lt;type&gt;                         <i>; yields {type*}:result</i>
1425 </pre>
1426 <h5>Overview:</h5>
1427 <p>The '<tt>malloc</tt>' instruction allocates memory from the system
1428 heap and returns a pointer to it.</p>
1429 <h5>Arguments:</h5>
1430 <p>The '<tt>malloc</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1431 bytes of memory from the operating system and returns a pointer of the
1432 appropriate type to the program.  The second form of the instruction is
1433 a shorter version of the first instruction that defaults to allocating
1434 one element.</p>
1435 <p>'<tt>type</tt>' must be a sized type.</p>
1436 <h5>Semantics:</h5>
1437 <p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1438 a pointer is returned.</p>
1439 <h5>Example:</h5>
1440 <pre>  %array  = malloc [4 x ubyte ]                    <i>; yields {[%4 x ubyte]*}:array</i>
1441
1442   %size   = <a
1443  href="#i_add">add</a> uint 2, 2                          <i>; yields {uint}:size = uint 4</i>
1444   %array1 = malloc ubyte, uint 4                   <i>; yields {ubyte*}:array1</i>
1445   %array2 = malloc [12 x ubyte], uint %size        <i>; yields {[12 x ubyte]*}:array2</i>
1446 </pre>
1447 </div>
1448 <!-- _______________________________________________________________________ -->
1449 <div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>'
1450 Instruction</a> </div>
1451 <div class="doc_text">
1452 <h5>Syntax:</h5>
1453 <pre>  free &lt;type&gt; &lt;value&gt;                              <i>; yields {void}</i>
1454 </pre>
1455 <h5>Overview:</h5>
1456 <p>The '<tt>free</tt>' instruction returns memory back to the unused
1457 memory heap, to be reallocated in the future.</p>
1458 <p> </p>
1459 <h5>Arguments:</h5>
1460 <p>'<tt>value</tt>' shall be a pointer value that points to a value
1461 that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1462 instruction.</p>
1463 <h5>Semantics:</h5>
1464 <p>Access to the memory pointed to by the pointer is not longer defined
1465 after this instruction executes.</p>
1466 <h5>Example:</h5>
1467 <pre>  %array  = <a href="#i_malloc">malloc</a> [4 x ubyte]                    <i>; yields {[4 x ubyte]*}:array</i>
1468             free   [4 x ubyte]* %array
1469 </pre>
1470 </div>
1471 <!-- _______________________________________________________________________ -->
1472 <div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>'
1473 Instruction</a> </div>
1474 <div class="doc_text">
1475 <h5>Syntax:</h5>
1476 <pre>  &lt;result&gt; = alloca &lt;type&gt;, uint &lt;NumElements&gt;  <i>; yields {type*}:result</i>
1477   &lt;result&gt; = alloca &lt;type&gt;                      <i>; yields {type*}:result</i>
1478 </pre>
1479 <h5>Overview:</h5>
1480 <p>The '<tt>alloca</tt>' instruction allocates memory on the current
1481 stack frame of the procedure that is live until the current function
1482 returns to its caller.</p>
1483 <h5>Arguments:</h5>
1484 <p>The the '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1485 bytes of memory on the runtime stack, returning a pointer of the
1486 appropriate type to the program.  The second form of the instruction is
1487 a shorter version of the first that defaults to allocating one element.</p>
1488 <p>'<tt>type</tt>' may be any sized type.</p>
1489 <h5>Semantics:</h5>
1490 <p>Memory is allocated, a pointer is returned.  '<tt>alloca</tt>'d
1491 memory is automatically released when the function returns.  The '<tt>alloca</tt>'
1492 instruction is commonly used to represent automatic variables that must
1493 have an address available.  When the function returns (either with the <tt><a
1494  href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt>
1495 instructions), the memory is reclaimed.</p>
1496 <h5>Example:</h5>
1497 <pre>  %ptr = alloca int                              <i>; yields {int*}:ptr</i>
1498   %ptr = alloca int, uint 4                      <i>; yields {int*}:ptr</i>
1499 </pre>
1500 </div>
1501 <!-- _______________________________________________________________________ -->
1502 <div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1503 Instruction</a> </div>
1504 <div class="doc_text">
1505 <h5>Syntax:</h5>
1506 <pre>  &lt;result&gt; = load &lt;ty&gt;* &lt;pointer&gt;<br>  &lt;result&gt; = volatile load &lt;ty&gt;* &lt;pointer&gt;<br></pre>
1507 <h5>Overview:</h5>
1508 <p>The '<tt>load</tt>' instruction is used to read from memory.</p>
1509 <h5>Arguments:</h5>
1510 <p>The argument to the '<tt>load</tt>' instruction specifies the memory
1511 address to load from.  The pointer must point to a <a
1512  href="#t_firstclass">first class</a> type.  If the <tt>load</tt> is
1513 marked as <tt>volatile</tt> then the optimizer is not allowed to modify
1514 the number or order of execution of this <tt>load</tt> with other
1515 volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1516 instructions. </p>
1517 <h5>Semantics:</h5>
1518 <p>The location of memory pointed to is loaded.</p>
1519 <h5>Examples:</h5>
1520 <pre>  %ptr = <a href="#i_alloca">alloca</a> int                               <i>; yields {int*}:ptr</i>
1521   <a
1522  href="#i_store">store</a> int 3, int* %ptr                          <i>; yields {void}</i>
1523   %val = load int* %ptr                           <i>; yields {int}:val = int 3</i>
1524 </pre>
1525 </div>
1526 <!-- _______________________________________________________________________ -->
1527 <div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1528 Instruction</a> </div>
1529 <h5>Syntax:</h5>
1530 <pre>  store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt;                   <i>; yields {void}</i>
1531   volatile store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt;                   <i>; yields {void}</i>
1532 </pre>
1533 <h5>Overview:</h5>
1534 <p>The '<tt>store</tt>' instruction is used to write to memory.</p>
1535 <h5>Arguments:</h5>
1536 <p>There are two arguments to the '<tt>store</tt>' instruction: a value
1537 to store and an address to store it into.  The type of the '<tt>&lt;pointer&gt;</tt>'
1538 operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
1539 operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the
1540 optimizer is not allowed to modify the number or order of execution of
1541 this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1542  href="#i_store">store</a></tt> instructions.</p>
1543 <h5>Semantics:</h5>
1544 <p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
1545 at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
1546 <h5>Example:</h5>
1547 <pre>  %ptr = <a href="#i_alloca">alloca</a> int                               <i>; yields {int*}:ptr</i>
1548   <a
1549  href="#i_store">store</a> int 3, int* %ptr                          <i>; yields {void}</i>
1550   %val = load int* %ptr                           <i>; yields {int}:val = int 3</i>
1551 </pre>
1552 <!-- _______________________________________________________________________ -->
1553 <div class="doc_subsubsection">
1554    <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
1555 </div>
1556
1557 <div class="doc_text">
1558 <h5>Syntax:</h5>
1559 <pre>
1560   &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
1561 </pre>
1562
1563 <h5>Overview:</h5>
1564
1565 <p>
1566 The '<tt>getelementptr</tt>' instruction is used to get the address of a
1567 subelement of an aggregate data structure.</p>
1568
1569 <h5>Arguments:</h5>
1570
1571 <p>This instruction takes a list of integer constants that indicate what
1572 elements of the aggregate object to index to.  The actual types of the arguments
1573 provided depend on the type of the first pointer argument.  The
1574 '<tt>getelementptr</tt>' instruction is used to index down through the type
1575 levels of a structure.  When indexing into a structure, only <tt>uint</tt>
1576 integer constants are allowed.  When indexing into an array or pointer
1577 <tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
1578
1579 <p>For example, let's consider a C code fragment and how it gets
1580 compiled to LLVM:</p>
1581
1582 <pre>
1583   struct RT {
1584     char A;
1585     int B[10][20];
1586     char C;
1587   };
1588   struct ST {
1589     int X;
1590     double Y;
1591     struct RT Z;
1592   };
1593
1594   int *foo(struct ST *s) {
1595     return &amp;s[1].Z.B[5][13];
1596   }
1597 </pre>
1598
1599 <p>The LLVM code generated by the GCC frontend is:</p>
1600
1601 <pre>
1602   %RT = type { sbyte, [10 x [20 x int]], sbyte }
1603   %ST = type { int, double, %RT }
1604
1605   implementation
1606
1607   int* %foo(%ST* %s) {
1608   entry:
1609     %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13
1610     ret int* %reg
1611   }
1612 </pre>
1613
1614 <h5>Semantics:</h5>
1615
1616 <p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
1617 on the pointer type that is being index into. <a href="#t_pointer">Pointer</a>
1618 and <a href="#t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
1619 <tt>ulong</tt>, or <tt>long</tt> values, and <a href="#t_struct">structure</a>
1620 types require <tt>uint</tt> <b>constants</b>.</p>
1621
1622 <p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
1623 type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
1624 }</tt>' type, a structure.  The second index indexes into the third element of
1625 the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
1626 sbyte }</tt>' type, another structure.  The third index indexes into the second
1627 element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
1628 array.  The two dimensions of the array are subscripted into, yielding an
1629 '<tt>int</tt>' type.  The '<tt>getelementptr</tt>' instruction return a pointer
1630 to this element, thus computing a value of '<tt>int*</tt>' type.</p>
1631
1632 <p>Note that it is perfectly legal to index partially through a
1633 structure, returning a pointer to an inner element.  Because of this,
1634 the LLVM code for the given testcase is equivalent to:</p>
1635
1636 <pre>
1637   int* "foo"(%ST* %s) {
1638     %t1 = getelementptr %ST* %s, int 1                        <i>; yields %ST*:%t1</i>
1639     %t2 = getelementptr %ST* %t1, int 0, uint 2               <i>; yields %RT*:%t2</i>
1640     %t3 = getelementptr %RT* %t2, int 0, uint 1               <i>; yields [10 x [20 x int]]*:%t3</i>
1641     %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5  <i>; yields [20 x int]*:%t4</i>
1642     %t5 = getelementptr [20 x int]* %t4, int 0, int 13        <i>; yields int*:%t5</i>
1643     ret int* %t5
1644   }
1645 </pre>
1646 <h5>Example:</h5>
1647 <pre>
1648     <i>; yields [12 x ubyte]*:aptr</i>
1649     %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
1650 </pre>
1651
1652 </div>
1653 <!-- ======================================================================= -->
1654 <div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
1655 <div class="doc_text">
1656 <p>The instructions in this category are the "miscellaneous"
1657 instructions, which defy better classification.</p>
1658 </div>
1659 <!-- _______________________________________________________________________ -->
1660 <div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
1661 Instruction</a> </div>
1662 <div class="doc_text">
1663 <h5>Syntax:</h5>
1664 <pre>  &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
1665 <h5>Overview:</h5>
1666 <p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
1667 the SSA graph representing the function.</p>
1668 <h5>Arguments:</h5>
1669 <p>The type of the incoming values are specified with the first type
1670 field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
1671 as arguments, with one pair for each predecessor basic block of the
1672 current block.  Only values of <a href="#t_firstclass">first class</a>
1673 type may be used as the value arguments to the PHI node.  Only labels
1674 may be used as the label arguments.</p>
1675 <p>There must be no non-phi instructions between the start of a basic
1676 block and the PHI instructions: i.e. PHI instructions must be first in
1677 a basic block.</p>
1678 <h5>Semantics:</h5>
1679 <p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
1680 value specified by the parameter, depending on which basic block we
1681 came from in the last <a href="#terminators">terminator</a> instruction.</p>
1682 <h5>Example:</h5>
1683 <pre>Loop:       ; Infinite loop that counts from 0 on up...<br>  %indvar = phi uint [ 0, %LoopHeader ], [ %nextindvar, %Loop ]<br>  %nextindvar = add uint %indvar, 1<br>  br label %Loop<br></pre>
1684 </div>
1685
1686 <!-- _______________________________________________________________________ -->
1687 <div class="doc_subsubsection">
1688    <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
1689 </div>
1690
1691 <div class="doc_text">
1692
1693 <h5>Syntax:</h5>
1694
1695 <pre>
1696   &lt;result&gt; = cast &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt;             <i>; yields ty2</i>
1697 </pre>
1698
1699 <h5>Overview:</h5>
1700
1701 <p>
1702 The '<tt>cast</tt>' instruction is used as the primitive means to convert
1703 integers to floating point, change data type sizes, and break type safety (by
1704 casting pointers).
1705 </p>
1706
1707
1708 <h5>Arguments:</h5>
1709
1710 <p>
1711 The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
1712 class value, and a type to cast it to, which must also be a <a
1713 href="#t_firstclass">first class</a> type.
1714 </p>
1715
1716 <h5>Semantics:</h5>
1717
1718 <p>
1719 This instruction follows the C rules for explicit casts when determining how the
1720 data being cast must change to fit in its new container.
1721 </p>
1722
1723 <p>
1724 When casting to bool, any value that would be considered true in the context of
1725 a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
1726 all else are '<tt>false</tt>'.
1727 </p>
1728
1729 <p>
1730 When extending an integral value from a type of one signness to another (for
1731 example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
1732 <b>source</b> value is signed, and zero-extended if the source value is
1733 unsigned. <tt>bool</tt> values are always zero extended into either zero or
1734 one.
1735 </p>
1736
1737 <h5>Example:</h5>
1738
1739 <pre>
1740   %X = cast int 257 to ubyte              <i>; yields ubyte:1</i>
1741   %Y = cast int 123 to bool               <i>; yields bool:true</i>
1742 </pre>
1743 </div>
1744
1745 <!-- _______________________________________________________________________ -->
1746 <div class="doc_subsubsection">
1747    <a name="i_select">'<tt>select</tt>' Instruction</a>
1748 </div>
1749
1750 <div class="doc_text">
1751
1752 <h5>Syntax:</h5>
1753
1754 <pre>
1755   &lt;result&gt; = select bool &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt;             <i>; yields ty</i>
1756 </pre>
1757
1758 <h5>Overview:</h5>
1759
1760 <p>
1761 The '<tt>select</tt>' instruction is used to choose one value based on a
1762 condition, without branching.
1763 </p>
1764
1765
1766 <h5>Arguments:</h5>
1767
1768 <p>
1769 The '<tt>select</tt>' instruction requires a boolean value indicating the condition, and two values of the same <a href="#t_firstclass">first class</a> type.
1770 </p>
1771
1772 <h5>Semantics:</h5>
1773
1774 <p>
1775 If the boolean condition evaluates to true, the instruction returns the first
1776 value argument, otherwise it returns the second value argument.
1777 </p>
1778
1779 <h5>Example:</h5>
1780
1781 <pre>
1782   %X = select bool true, ubyte 17, ubyte 42          <i>; yields ubyte:17</i>
1783 </pre>
1784 </div>
1785
1786
1787
1788
1789
1790 <!-- _______________________________________________________________________ -->
1791 <div class="doc_subsubsection"> <a name="i_call">'<tt>call</tt>'
1792 Instruction</a> </div>
1793 <div class="doc_text">
1794 <h5>Syntax:</h5>
1795 <pre>  &lt;result&gt; = call &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)<br></pre>
1796 <h5>Overview:</h5>
1797 <p>The '<tt>call</tt>' instruction represents a simple function call.</p>
1798 <h5>Arguments:</h5>
1799 <p>This instruction requires several arguments:</p>
1800 <ol>
1801   <li>
1802     <p>'<tt>ty</tt>': shall be the signature of the pointer to function
1803 value   being invoked.  The argument types must match the types implied
1804 by this   signature.</p>
1805   </li>
1806   <li>
1807     <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a
1808 function   to be invoked. In most cases, this is a direct function
1809 invocation, but   indirect <tt>call</tt>s are just as possible,
1810 calling an arbitrary pointer to   function values.</p>
1811   </li>
1812   <li>
1813     <p>'<tt>function args</tt>': argument list whose types match the
1814 function   signature argument types.  If the function signature
1815 indicates the function   accepts a variable number of arguments, the
1816 extra arguments can be   specified.</p>
1817   </li>
1818 </ol>
1819 <h5>Semantics:</h5>
1820 <p>The '<tt>call</tt>' instruction is used to cause control flow to
1821 transfer to a specified function, with its incoming arguments bound to
1822 the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
1823 instruction in the called function, control flow continues with the
1824 instruction after the function call, and the return value of the
1825 function is bound to the result argument.  This is a simpler case of
1826 the <a href="#i_invoke">invoke</a> instruction.</p>
1827 <h5>Example:</h5>
1828 <pre>  %retval = call int %test(int %argc)<br>  call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42);<br></pre>
1829 </div>
1830
1831 <!-- _______________________________________________________________________ -->
1832 <div class="doc_subsubsection">
1833   <a name="i_vanext">'<tt>vanext</tt>' Instruction</a>
1834 </div>
1835
1836 <div class="doc_text">
1837
1838 <h5>Syntax:</h5>
1839
1840 <pre>
1841   &lt;resultarglist&gt; = vanext &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;
1842 </pre>
1843
1844 <h5>Overview:</h5>
1845
1846 <p>The '<tt>vanext</tt>' instruction is used to access arguments passed
1847 through the "variable argument" area of a function call.  It is used to
1848 implement the <tt>va_arg</tt> macro in C.</p>
1849
1850 <h5>Arguments:</h5>
1851
1852 <p>This instruction takes a <tt>va_list</tt> value and the type of the
1853 argument. It returns another <tt>va_list</tt>. The actual type of
1854 <tt>va_list</tt> may be defined differently for different targets.  Most targets
1855 use a <tt>va_list</tt> type of <tt>sbyte*</tt> or some other pointer type.</p>
1856
1857 <h5>Semantics:</h5>
1858
1859 <p>The '<tt>vanext</tt>' instruction advances the specified <tt>va_list</tt>
1860 past an argument of the specified type.  In conjunction with the <a
1861  href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement
1862 the <tt>va_arg</tt> macro available in C.  For more information, see
1863 the variable argument handling <a href="#int_varargs">Intrinsic
1864 Functions</a>.</p>
1865
1866 <p>It is legal for this instruction to be called in a function which
1867 does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
1868 function.</p>
1869
1870 <p><tt>vanext</tt> is an LLVM instruction instead of an <a
1871 href="#intrinsics">intrinsic function</a> because it takes a type as an
1872 argument.  The type refers to the current argument in the <tt>va_list</tt>, it
1873 tells the compiler how far on the stack it needs to advance to find the next
1874 argument</p>
1875
1876 <h5>Example:</h5>
1877
1878 <p>See the <a href="#int_varargs">variable argument processing</a>
1879 section.</p>
1880
1881 </div>
1882
1883 <!-- _______________________________________________________________________ -->
1884 <div class="doc_subsubsection">
1885   <a name="i_vaarg">'<tt>vaarg</tt>' Instruction</a>
1886 </div>
1887
1888 <div class="doc_text">
1889
1890 <h5>Syntax:</h5>
1891
1892 <pre>
1893   &lt;resultval&gt; = vaarg &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;
1894 </pre>
1895
1896 <h5>Overview:</h5>
1897
1898 <p>The '<tt>vaarg</tt>' instruction is used to access arguments passed through
1899 the "variable argument" area of a function call.  It is used to implement the
1900 <tt>va_arg</tt> macro in C.</p>
1901
1902 <h5>Arguments:</h5>
1903
1904 <p>This instruction takes a <tt>va_list</tt> value and the type of the
1905 argument. It returns a value of the specified argument type.  Again, the actual
1906 type of <tt>va_list</tt> is target specific.</p>
1907
1908 <h5>Semantics:</h5>
1909
1910 <p>The '<tt>vaarg</tt>' instruction loads an argument of the specified type from
1911 the specified <tt>va_list</tt>.  In conjunction with the <a
1912 href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to implement the
1913 <tt>va_arg</tt> macro available in C.  For more information, see the variable
1914 argument handling <a href="#int_varargs">Intrinsic Functions</a>.</p>
1915
1916 <p>It is legal for this instruction to be called in a function which does not
1917 take a variable number of arguments, for example, the <tt>vfprintf</tt>
1918 function.</p>
1919
1920 <p><tt>vaarg</tt> is an LLVM instruction instead of an <a
1921 href="#intrinsics">intrinsic function</a> because it takes an type as an
1922 argument.</p>
1923
1924 <h5>Example:</h5>
1925
1926 <p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
1927
1928 </div>
1929
1930 <!-- *********************************************************************** -->
1931 <div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
1932 <!-- *********************************************************************** -->
1933
1934 <div class="doc_text">
1935
1936 <p>LLVM supports the notion of an "intrinsic function".  These functions have
1937 well known names and semantics, and are required to follow certain
1938 restrictions. Overall, these instructions represent an extension mechanism for
1939 the LLVM language that does not require changing all of the transformations in
1940 LLVM to add to the language (or the bytecode reader/writer, the parser,
1941 etc...).</p>
1942
1943 <p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix, this
1944 prefix is reserved in LLVM for intrinsic names, thus functions may not be named
1945 this.  Intrinsic functions must always be external functions: you cannot define
1946 the body of intrinsic functions.  Intrinsic functions may only be used in call
1947 or invoke instructions: it is illegal to take the address of an intrinsic
1948 function.  Additionally, because intrinsic functions are part of the LLVM
1949 language, it is required that they all be documented here if any are added.</p>
1950
1951
1952 <p>
1953 Adding an intrinsic to LLVM is straight-forward if it is possible to express the
1954 concept in LLVM directly (ie, code generator support is not _required_).  To do
1955 this, extend the default implementation of the IntrinsicLowering class to handle
1956 the intrinsic.  Code generators use this class to lower intrinsics they do not
1957 understand to raw LLVM instructions that they do.
1958 </p>
1959
1960 </div>
1961
1962 <!-- ======================================================================= -->
1963 <div class="doc_subsection">
1964   <a name="int_varargs">Variable Argument Handling Intrinsics</a>
1965 </div>
1966
1967 <div class="doc_text">
1968
1969 <p>Variable argument support is defined in LLVM with the <a
1970  href="#i_vanext"><tt>vanext</tt></a> instruction and these three
1971 intrinsic functions.  These functions are related to the similarly
1972 named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
1973
1974 <p>All of these functions operate on arguments that use a
1975 target-specific value type "<tt>va_list</tt>".  The LLVM assembly
1976 language reference manual does not define what this type is, so all
1977 transformations should be prepared to handle intrinsics with any type
1978 used.</p>
1979
1980 <p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
1981 instruction and the variable argument handling intrinsic functions are
1982 used.</p>
1983
1984 <pre>
1985 int %test(int %X, ...) {
1986   ; Initialize variable argument processing
1987   %ap = call sbyte* %<a href="#i_va_start">llvm.va_start</a>()
1988
1989   ; Read a single integer argument
1990   %tmp = vaarg sbyte* %ap, int
1991
1992   ; Advance to the next argument
1993   %ap2 = vanext sbyte* %ap, int
1994
1995   ; Demonstrate usage of llvm.va_copy and llvm.va_end
1996   %aq = call sbyte* %<a href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2)
1997   call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %aq)
1998
1999   ; Stop processing of arguments.
2000   call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %ap2)
2001   ret int %tmp
2002 }
2003 </pre>
2004 </div>
2005
2006 <!-- _______________________________________________________________________ -->
2007 <div class="doc_subsubsection">
2008   <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
2009 </div>
2010
2011
2012 <div class="doc_text">
2013 <h5>Syntax:</h5>
2014 <pre>  call &lt;va_list&gt; ()* %llvm.va_start()<br></pre>
2015 <h5>Overview:</h5>
2016 <p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt>&lt;arglist&gt;</tt>
2017 for subsequent use by the variable argument intrinsics.</p>
2018 <h5>Semantics:</h5>
2019 <p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
2020 macro available in C.  In a target-dependent way, it initializes and
2021 returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt>
2022 will produce the first variable argument passed to the function.  Unlike
2023 the C <tt>va_start</tt> macro, this intrinsic does not need to know the
2024 last argument of the function, the compiler can figure that out.</p>
2025 <p>Note that this intrinsic function is only legal to be called from
2026 within the body of a variable argument function.</p>
2027 </div>
2028
2029 <!-- _______________________________________________________________________ -->
2030 <div class="doc_subsubsection">
2031  <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
2032 </div>
2033
2034 <div class="doc_text">
2035 <h5>Syntax:</h5>
2036 <pre>  call void (&lt;va_list&gt;)* %llvm.va_end(&lt;va_list&gt; &lt;arglist&gt;)<br></pre>
2037 <h5>Overview:</h5>
2038 <p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
2039 which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
2040 or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
2041 <h5>Arguments:</h5>
2042 <p>The argument is a <tt>va_list</tt> to destroy.</p>
2043 <h5>Semantics:</h5>
2044 <p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
2045 macro available in C.  In a target-dependent way, it destroys the <tt>va_list</tt>.
2046 Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
2047  href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
2048 with calls to <tt>llvm.va_end</tt>.</p>
2049 </div>
2050
2051 <!-- _______________________________________________________________________ -->
2052 <div class="doc_subsubsection">
2053   <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
2054 </div>
2055
2056 <div class="doc_text">
2057
2058 <h5>Syntax:</h5>
2059
2060 <pre>
2061   call  &lt;va_list&gt; (&lt;va_list&gt;)* %llvm.va_copy(&lt;va_list&gt; &lt;destarglist&gt;)
2062 </pre>
2063
2064 <h5>Overview:</h5>
2065
2066 <p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position
2067 from the source argument list to the destination argument list.</p>
2068
2069 <h5>Arguments:</h5>
2070
2071 <p>The argument is the <tt>va_list</tt> to copy.</p>
2072
2073 <h5>Semantics:</h5>
2074
2075 <p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
2076 macro available in C.  In a target-dependent way, it copies the source
2077 <tt>va_list</tt> element into the returned list.  This intrinsic is necessary
2078 because the <tt><a href="#i_va_start">llvm.va_start</a></tt> intrinsic may be
2079 arbitrarily complex and require memory allocation, for example.</p>
2080
2081 </div>
2082
2083 <!-- ======================================================================= -->
2084 <div class="doc_subsection">
2085   <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
2086 </div>
2087
2088 <div class="doc_text">
2089
2090 <p>
2091 LLVM support for <a href="GarbageCollection.html">Accurate Garbage
2092 Collection</a> requires the implementation and generation of these intrinsics.
2093 These intrinsics allow identification of <a href="#i_gcroot">GC roots on the
2094 stack</a>, as well as garbage collector implementations that require <a
2095 href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers.
2096 Front-ends for type-safe garbage collected languages should generate these
2097 intrinsics to make use of the LLVM garbage collectors.  For more details, see <a
2098 href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
2099 </p>
2100 </div>
2101
2102 <!-- _______________________________________________________________________ -->
2103 <div class="doc_subsubsection">
2104   <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
2105 </div>
2106
2107 <div class="doc_text">
2108
2109 <h5>Syntax:</h5>
2110
2111 <pre>
2112   call void (&lt;ty&gt;**, &lt;ty2&gt;*)* %llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
2113 </pre>
2114
2115 <h5>Overview:</h5>
2116
2117 <p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existance of a GC root to
2118 the code generator, and allows some metadata to be associated with it.</p>
2119
2120 <h5>Arguments:</h5>
2121
2122 <p>The first argument specifies the address of a stack object that contains the
2123 root pointer.  The second pointer (which must be either a constant or a global
2124 value address) contains the meta-data to be associated with the root.</p>
2125
2126 <h5>Semantics:</h5>
2127
2128 <p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
2129 location.  At compile-time, the code generator generates information to allow
2130 the runtime to find the pointer at GC safe points.
2131 </p>
2132
2133 </div>
2134
2135
2136 <!-- _______________________________________________________________________ -->
2137 <div class="doc_subsubsection">
2138   <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
2139 </div>
2140
2141 <div class="doc_text">
2142
2143 <h5>Syntax:</h5>
2144
2145 <pre>
2146   call sbyte* (sbyte**)* %llvm.gcread(sbyte** %Ptr)
2147 </pre>
2148
2149 <h5>Overview:</h5>
2150
2151 <p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
2152 locations, allowing garbage collector implementations that require read
2153 barriers.</p>
2154
2155 <h5>Arguments:</h5>
2156
2157 <p>The argument is the address to read from, which should be an address
2158 allocated from the garbage collector.</p>
2159
2160 <h5>Semantics:</h5>
2161
2162 <p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
2163 instruction, but may be replaced with substantially more complex code by the
2164 garbage collector runtime, as needed.</p>
2165
2166 </div>
2167
2168
2169 <!-- _______________________________________________________________________ -->
2170 <div class="doc_subsubsection">
2171   <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
2172 </div>
2173
2174 <div class="doc_text">
2175
2176 <h5>Syntax:</h5>
2177
2178 <pre>
2179   call void (sbyte*, sbyte**)* %llvm.gcwrite(sbyte* %P1, sbyte** %P2)
2180 </pre>
2181
2182 <h5>Overview:</h5>
2183
2184 <p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
2185 locations, allowing garbage collector implementations that require write
2186 barriers (such as generational or reference counting collectors).</p>
2187
2188 <h5>Arguments:</h5>
2189
2190 <p>The first argument is the reference to store, and the second is the heap
2191 location to store to.</p>
2192
2193 <h5>Semantics:</h5>
2194
2195 <p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
2196 instruction, but may be replaced with substantially more complex code by the
2197 garbage collector runtime, as needed.</p>
2198
2199 </div>
2200
2201
2202
2203 <!-- ======================================================================= -->
2204 <div class="doc_subsection">
2205   <a name="int_codegen">Code Generator Intrinsics</a>
2206 </div>
2207
2208 <div class="doc_text">
2209 <p>
2210 These intrinsics are provided by LLVM to expose special features that may only
2211 be implemented with code generator support.
2212 </p>
2213
2214 </div>
2215
2216 <!-- _______________________________________________________________________ -->
2217 <div class="doc_subsubsection">
2218   <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
2219 </div>
2220
2221 <div class="doc_text">
2222
2223 <h5>Syntax:</h5>
2224 <pre>
2225   call void* ()* %llvm.returnaddress(uint &lt;level&gt;)
2226 </pre>
2227
2228 <h5>Overview:</h5>
2229
2230 <p>
2231 The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
2232 indicating the return address of the current function or one of its callers.
2233 </p>
2234
2235 <h5>Arguments:</h5>
2236
2237 <p>
2238 The argument to this intrinsic indicates which function to return the address
2239 for.  Zero indicates the calling function, one indicates its caller, etc.  The
2240 argument is <b>required</b> to be a constant integer value.
2241 </p>
2242
2243 <h5>Semantics:</h5>
2244
2245 <p>
2246 The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
2247 the return address of the specified call frame, or zero if it cannot be
2248 identified.  The value returned by this intrinsic is likely to be incorrect or 0
2249 for arguments other than zero, so it should only be used for debugging purposes.
2250 </p>
2251
2252 <p>
2253 Note that calling this intrinsic does not prevent function inlining or other
2254 aggressive transformations, so the value returned may not that of the obvious
2255 source-language caller.
2256 </p>
2257 </div>
2258
2259
2260 <!-- _______________________________________________________________________ -->
2261 <div class="doc_subsubsection">
2262   <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
2263 </div>
2264
2265 <div class="doc_text">
2266
2267 <h5>Syntax:</h5>
2268 <pre>
2269   call void* ()* %llvm.frameaddress(uint &lt;level&gt;)
2270 </pre>
2271
2272 <h5>Overview:</h5>
2273
2274 <p>
2275 The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
2276 pointer value for the specified stack frame.
2277 </p>
2278
2279 <h5>Arguments:</h5>
2280
2281 <p>
2282 The argument to this intrinsic indicates which function to return the frame
2283 pointer for.  Zero indicates the calling function, one indicates its caller,
2284 etc.  The argument is <b>required</b> to be a constant integer value.
2285 </p>
2286
2287 <h5>Semantics:</h5>
2288
2289 <p>
2290 The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
2291 the frame address of the specified call frame, or zero if it cannot be
2292 identified.  The value returned by this intrinsic is likely to be incorrect or 0
2293 for arguments other than zero, so it should only be used for debugging purposes.
2294 </p>
2295
2296 <p>
2297 Note that calling this intrinsic does not prevent function inlining or other
2298 aggressive transformations, so the value returned may not that of the obvious
2299 source-language caller.
2300 </p>
2301 </div>
2302
2303 <!-- ======================================================================= -->
2304 <div class="doc_subsection">
2305   <a name="int_os">Operating System Intrinsics</a>
2306 </div>
2307
2308 <div class="doc_text">
2309 <p>
2310 These intrinsics are provided by LLVM to support the implementation of
2311 operating system level code.
2312 </p>
2313
2314 </div>
2315
2316 <!-- _______________________________________________________________________ -->
2317 <div class="doc_subsubsection">
2318   <a name="i_readport">'<tt>llvm.readport</tt>' Intrinsic</a>
2319 </div>
2320
2321 <div class="doc_text">
2322
2323 <h5>Syntax:</h5>
2324 <pre>
2325   call &lt;integer type&gt; (&lt;integer type&gt;)* %llvm.readport (&lt;integer type&gt; &lt;address&gt;)
2326 </pre>
2327
2328 <h5>Overview:</h5>
2329
2330 <p>
2331 The '<tt>llvm.readport</tt>' intrinsic reads data from the specified hardware
2332 I/O port.
2333 </p>
2334
2335 <h5>Arguments:</h5>
2336
2337 <p>
2338 The argument to this intrinsic indicates the hardware I/O address from which
2339 to read the data.  The address is in the hardware I/O address namespace (as
2340 opposed to being a memory location for memory mapped I/O).
2341 </p>
2342
2343 <h5>Semantics:</h5>
2344
2345 <p>
2346 The '<tt>llvm.readport</tt>' intrinsic reads data from the hardware I/O port
2347 specified by <i>address</i> and returns the value.  The address and return
2348 value must be integers, but the size is dependent upon the platform upon which
2349 the program is code generated.  For example, on x86, the address must be an
2350 unsigned 16 bit value, and the return value must be 8, 16, or 32 bits.
2351 </p>
2352
2353 </div>
2354
2355 <!-- _______________________________________________________________________ -->
2356 <div class="doc_subsubsection">
2357   <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a>
2358 </div>
2359
2360 <div class="doc_text">
2361
2362 <h5>Syntax:</h5>
2363 <pre>
2364   call void (&lt;integer type&gt;, &lt;integer type&gt;)* %llvm.writeport (&lt;integer type&gt; &lt;value&gt;, &lt;integer type&gt; &lt;address&gt;)
2365 </pre>
2366
2367 <h5>Overview:</h5>
2368
2369 <p>
2370 The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified hardware
2371 I/O port.
2372 </p>
2373
2374 <h5>Arguments:</h5>
2375
2376 <p>
2377 The first argument is the value to write to the I/O port.
2378 </p>
2379
2380 <p>
2381 The second argument indicates the hardware I/O address to which data should be
2382 written.  The address is in the hardware I/O address namespace (as opposed to
2383 being a memory location for memory mapped I/O).
2384 </p>
2385
2386 <h5>Semantics:</h5>
2387
2388 <p>
2389 The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port
2390 specified by <i>address</i>.  The address and value must be integers, but the
2391 size is dependent upon the platform upon which the program is code generated.
2392 For example, on x86, the address must be an unsigned 16 bit value, and the
2393 value written must be 8, 16, or 32 bits in length.
2394 </p>
2395
2396 </div>
2397
2398 <!-- _______________________________________________________________________ -->
2399 <div class="doc_subsubsection">
2400   <a name="i_readio">'<tt>llvm.readio</tt>' Intrinsic</a>
2401 </div>
2402
2403 <div class="doc_text">
2404
2405 <h5>Syntax:</h5>
2406 <pre>
2407   call &lt;result&gt; (&lt;ty&gt;*)* %llvm.readio (&lt;ty&gt; * &lt;pointer&gt;)
2408 </pre>
2409
2410 <h5>Overview:</h5>
2411
2412 <p>
2413 The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
2414 address.
2415 </p>
2416
2417 <h5>Arguments:</h5>
2418
2419 <p>
2420 The argument to this intrinsic is a pointer indicating the memory address from
2421 which to read the data.  The data must be a
2422 <a href="#t_firstclass">first class</a> type.
2423 </p>
2424
2425 <h5>Semantics:</h5>
2426
2427 <p>
2428 The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
2429 location specified by <i>pointer</i> and returns the value.  The argument must
2430 be a pointer, and the return value must be a
2431 <a href="#t_firstclass">first class</a> type.  However, certain architectures
2432 may not support I/O on all first class types.  For example, 32 bit processors
2433 may only support I/O on data types that are 32 bits or less.
2434 </p>
2435
2436 <p>
2437 This intrinsic enforces an in-order memory model for llvm.readio and
2438 llvm.writeio calls on machines that use dynamic scheduling.  Dynamically
2439 scheduled processors may execute loads and stores out of order, re-ordering at
2440 run time accesses to memory mapped I/O registers.  Using these intrinsics
2441 ensures that accesses to memory mapped I/O registers occur in program order.
2442 </p>
2443
2444 </div>
2445
2446 <!-- _______________________________________________________________________ -->
2447 <div class="doc_subsubsection">
2448   <a name="i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a>
2449 </div>
2450
2451 <div class="doc_text">
2452
2453 <h5>Syntax:</h5>
2454 <pre>
2455   call void (&lt;ty1&gt;, &lt;ty2&gt;*)* %llvm.writeio (&lt;ty1&gt; &lt;value&gt;, &lt;ty2&gt; * &lt;pointer&gt;)
2456 </pre>
2457
2458 <h5>Overview:</h5>
2459
2460 <p>
2461 The '<tt>llvm.writeio</tt>' intrinsic writes data to the specified memory
2462 mapped I/O address.
2463 </p>
2464
2465 <h5>Arguments:</h5>
2466
2467 <p>
2468 The first argument is the value to write to the memory mapped I/O location.
2469 The second argument is a pointer indicating the memory address to which the
2470 data should be written.
2471 </p>
2472
2473 <h5>Semantics:</h5>
2474
2475 <p>
2476 The '<tt>llvm.writeio</tt>' intrinsic writes <i>value</i> to the memory mapped
2477 I/O address specified by <i>pointer</i>.  The value must be a
2478 <a href="#t_firstclass">first class</a> type.  However, certain architectures
2479 may not support I/O on all first class types.  For example, 32 bit processors
2480 may only support I/O on data types that are 32 bits or less.
2481 </p>
2482
2483 <p>
2484 This intrinsic enforces an in-order memory model for llvm.readio and
2485 llvm.writeio calls on machines that use dynamic scheduling.  Dynamically
2486 scheduled processors may execute loads and stores out of order, re-ordering at
2487 run time accesses to memory mapped I/O registers.  Using these intrinsics
2488 ensures that accesses to memory mapped I/O registers occur in program order.
2489 </p>
2490
2491 </div>
2492
2493 <!-- ======================================================================= -->
2494 <div class="doc_subsection">
2495   <a name="int_libc">Standard C Library Intrinsics</a>
2496 </div>
2497
2498 <div class="doc_text">
2499 <p>
2500 LLVM provides intrinsics for a few important standard C library functions.
2501 These intrinsics allow source-language front-ends to pass information about the
2502 alignment of the pointer arguments to the code generator, providing opportunity
2503 for more efficient code generation.
2504 </p>
2505
2506 </div>
2507
2508 <!-- _______________________________________________________________________ -->
2509 <div class="doc_subsubsection">
2510   <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
2511 </div>
2512
2513 <div class="doc_text">
2514
2515 <h5>Syntax:</h5>
2516 <pre>
2517   call void (sbyte*, sbyte*, uint, uint)* %llvm.memcpy(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2518                                                        uint &lt;len&gt;, uint &lt;align&gt;)
2519 </pre>
2520
2521 <h5>Overview:</h5>
2522
2523 <p>
2524 The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2525 location to the destination location.
2526 </p>
2527
2528 <p>
2529 Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
2530 does not return a value, and takes an extra alignment argument.
2531 </p>
2532
2533 <h5>Arguments:</h5>
2534
2535 <p>
2536 The first argument is a pointer to the destination, the second is a pointer to
2537 the source.  The third argument is an (arbitrarily sized) integer argument
2538 specifying the number of bytes to copy, and the fourth argument is the alignment
2539 of the source and destination locations.
2540 </p>
2541
2542 <p>
2543 If the call to this intrinisic has an alignment value that is not 0 or 1, then
2544 the caller guarantees that the size of the copy is a multiple of the alignment
2545 and that both the source and destination pointers are aligned to that boundary.
2546 </p>
2547
2548 <h5>Semantics:</h5>
2549
2550 <p>
2551 The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2552 location to the destination location, which are not allowed to overlap.  It
2553 copies "len" bytes of memory over.  If the argument is known to be aligned to
2554 some boundary, this can be specified as the fourth argument, otherwise it should
2555 be set to 0 or 1.
2556 </p>
2557 </div>
2558
2559
2560 <!-- _______________________________________________________________________ -->
2561 <div class="doc_subsubsection">
2562   <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
2563 </div>
2564
2565 <div class="doc_text">
2566
2567 <h5>Syntax:</h5>
2568 <pre>
2569   call void (sbyte*, sbyte*, uint, uint)* %llvm.memmove(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2570                                                        uint &lt;len&gt;, uint &lt;align&gt;)
2571 </pre>
2572
2573 <h5>Overview:</h5>
2574
2575 <p>
2576 The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
2577 location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>' 
2578 intrinsic but allows the two memory locations to overlap.
2579 </p>
2580
2581 <p>
2582 Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
2583 does not return a value, and takes an extra alignment argument.
2584 </p>
2585
2586 <h5>Arguments:</h5>
2587
2588 <p>
2589 The first argument is a pointer to the destination, the second is a pointer to
2590 the source.  The third argument is an (arbitrarily sized) integer argument
2591 specifying the number of bytes to copy, and the fourth argument is the alignment
2592 of the source and destination locations.
2593 </p>
2594
2595 <p>
2596 If the call to this intrinisic has an alignment value that is not 0 or 1, then
2597 the caller guarantees that the size of the copy is a multiple of the alignment
2598 and that both the source and destination pointers are aligned to that boundary.
2599 </p>
2600
2601 <h5>Semantics:</h5>
2602
2603 <p>
2604 The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
2605 location to the destination location, which may overlap.  It
2606 copies "len" bytes of memory over.  If the argument is known to be aligned to
2607 some boundary, this can be specified as the fourth argument, otherwise it should
2608 be set to 0 or 1.
2609 </p>
2610 </div>
2611
2612
2613 <!-- _______________________________________________________________________ -->
2614 <div class="doc_subsubsection">
2615   <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a>
2616 </div>
2617
2618 <div class="doc_text">
2619
2620 <h5>Syntax:</h5>
2621 <pre>
2622   call void (sbyte*, ubyte, uint, uint)* %llvm.memset(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
2623                                                       uint &lt;len&gt;, uint &lt;align&gt;)
2624 </pre>
2625
2626 <h5>Overview:</h5>
2627
2628 <p>
2629 The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular
2630 byte value.
2631 </p>
2632
2633 <p>
2634 Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
2635 does not return a value, and takes an extra alignment argument.
2636 </p>
2637
2638 <h5>Arguments:</h5>
2639
2640 <p>
2641 The first argument is a pointer to the destination to fill, the second is the
2642 byte value to fill it with, the third argument is an (arbitrarily sized) integer
2643 argument specifying the number of bytes to fill, and the fourth argument is the
2644 known alignment of destination location.
2645 </p>
2646
2647 <p>
2648 If the call to this intrinisic has an alignment value that is not 0 or 1, then
2649 the caller guarantees that the size of the copy is a multiple of the alignment
2650 and that the destination pointer is aligned to that boundary.
2651 </p>
2652
2653 <h5>Semantics:</h5>
2654
2655 <p>
2656 The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the
2657 destination location.  If the argument is known to be aligned to some boundary,
2658 this can be specified as the fourth argument, otherwise it should be set to 0 or
2659 1.
2660 </p>
2661 </div>
2662
2663
2664 <!-- _______________________________________________________________________ -->
2665 <div class="doc_subsubsection">
2666   <a name="i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a>
2667 </div>
2668
2669 <div class="doc_text">
2670
2671 <h5>Syntax:</h5>
2672 <pre>
2673   call bool (&lt;float or double&gt;, &lt;float or double&gt;)* %llvm.isunordered(&lt;float or double&gt; Val1,
2674                                                                       &lt;float or double&gt; Val2)
2675 </pre>
2676
2677 <h5>Overview:</h5>
2678
2679 <p>
2680 The '<tt>llvm.isunordered</tt>' intrinsic returns true if either or both of the
2681 specified floating point values is a NAN.
2682 </p>
2683
2684 <h5>Arguments:</h5>
2685
2686 <p>
2687 The arguments are floating point numbers of the same type.
2688 </p>
2689
2690 <h5>Semantics:</h5>
2691
2692 <p>
2693 If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise
2694 false.
2695 </p>
2696 </div>
2697
2698
2699
2700
2701 <!-- ======================================================================= -->
2702 <div class="doc_subsection">
2703   <a name="int_debugger">Debugger Intrinsics</a>
2704 </div>
2705
2706 <div class="doc_text">
2707 <p>
2708 The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
2709 are described in the <a
2710 href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
2711 Debugging</a> document.
2712 </p>
2713 </div>
2714
2715
2716 <!-- *********************************************************************** -->
2717 <hr>
2718 <address>
2719   <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
2720   src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
2721   <a href="http://validator.w3.org/check/referer"><img
2722   src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
2723
2724   <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
2725   <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
2726   Last modified: $Date$
2727 </address>
2728 </body>
2729 </html>