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