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