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