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