1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
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">
15 <div class="doc_title"> LLVM Language Reference Manual </div>
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>
22 <li><a href="#modulestructure">Module Structure</a></li>
23 <li><a href="#linkage">Linkage Types</a></li>
24 <li><a href="#globalvars">Global Variables</a></li>
25 <li><a href="#functionstructure">Function Structure</a></li>
28 <li><a href="#typesystem">Type System</a>
30 <li><a href="#t_primitive">Primitive Types</a>
32 <li><a href="#t_classifications">Type Classifications</a></li>
35 <li><a href="#t_derived">Derived Types</a>
37 <li><a href="#t_array">Array Type</a></li>
38 <li><a href="#t_function">Function Type</a></li>
39 <li><a href="#t_pointer">Pointer Type</a></li>
40 <li><a href="#t_struct">Structure Type</a></li>
41 <li><a href="#t_packed">Packed Type</a></li>
42 <li><a href="#t_opaque">Opaque Type</a></li>
47 <li><a href="#constants">Constants</a>
49 <li><a href="#simpleconstants">Simple Constants</a>
50 <li><a href="#aggregateconstants">Aggregate Constants</a>
51 <li><a href="#globalconstants">Global Variable and Function Addresses</a>
52 <li><a href="#undefvalues">Undefined Values</a>
53 <li><a href="#constantexprs">Constant Expressions</a>
56 <li><a href="#instref">Instruction Reference</a>
58 <li><a href="#terminators">Terminator Instructions</a>
60 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
61 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
62 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
63 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
64 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
65 <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
68 <li><a href="#binaryops">Binary Operations</a>
70 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
71 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
72 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
73 <li><a href="#i_div">'<tt>div</tt>' Instruction</a></li>
74 <li><a href="#i_rem">'<tt>rem</tt>' Instruction</a></li>
75 <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li>
78 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
80 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
81 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
82 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
83 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
84 <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a></li>
87 <li><a href="#memoryops">Memory Access Operations</a>
89 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
90 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
91 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
92 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
93 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
94 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
97 <li><a href="#otherops">Other Operations</a>
99 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
100 <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li>
101 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
102 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
103 <li><a href="#i_vanext">'<tt>vanext</tt>' Instruction</a></li>
104 <li><a href="#i_vaarg">'<tt>vaarg</tt>' Instruction</a></li>
109 <li><a href="#intrinsics">Intrinsic Functions</a>
111 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
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>
118 <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
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>
125 <li><a href="#int_codegen">Code Generator Intrinsics</a>
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>
133 <li><a href="#int_os">Operating System Intrinsics</a>
135 <li><a href="#i_readport">'<tt>llvm.readport</tt>' Intrinsic</a></li>
136 <li><a href="#i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a></li>
137 <li><a href="#i_readio">'<tt>llvm.readio</tt>' Intrinsic</a></li>
138 <li><a href="#i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a></li>
140 <li><a href="#int_libc">Standard C Library Intrinsics</a>
142 <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li>
143 <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li>
144 <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li>
145 <li><a href="#i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a></li>
148 <li><a href="#int_count">Bit counting Intrinsics</a>
150 <li><a href="#int_ctpop">'<tt>llvm.ctpop</tt>' Intrinsic </a></li>
151 <li><a href="#int_cttz">'<tt>llvm.cttz</tt>' Intrinsic </a></li>
152 <li><a href="#int_ctlz">'<tt>llvm.ctlz</tt>' Intrinsic </a></li>
155 <li><a href="#int_debugger">Debugger intrinsics</a></li>
160 <div class="doc_author">
161 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
162 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
165 <!-- *********************************************************************** -->
166 <div class="doc_section"> <a name="abstract">Abstract </a></div>
167 <!-- *********************************************************************** -->
169 <div class="doc_text">
170 <p>This document is a reference manual for the LLVM assembly language.
171 LLVM is an SSA based representation that provides type safety,
172 low-level operations, flexibility, and the capability of representing
173 'all' high-level languages cleanly. It is the common code
174 representation used throughout all phases of the LLVM compilation
178 <!-- *********************************************************************** -->
179 <div class="doc_section"> <a name="introduction">Introduction</a> </div>
180 <!-- *********************************************************************** -->
182 <div class="doc_text">
184 <p>The LLVM code representation is designed to be used in three
185 different forms: as an in-memory compiler IR, as an on-disk bytecode
186 representation (suitable for fast loading by a Just-In-Time compiler),
187 and as a human readable assembly language representation. This allows
188 LLVM to provide a powerful intermediate representation for efficient
189 compiler transformations and analysis, while providing a natural means
190 to debug and visualize the transformations. The three different forms
191 of LLVM are all equivalent. This document describes the human readable
192 representation and notation.</p>
194 <p>The LLVM representation aims to be a light-weight and low-level
195 while being expressive, typed, and extensible at the same time. It
196 aims to be a "universal IR" of sorts, by being at a low enough level
197 that high-level ideas may be cleanly mapped to it (similar to how
198 microprocessors are "universal IR's", allowing many source languages to
199 be mapped to them). By providing type information, LLVM can be used as
200 the target of optimizations: for example, through pointer analysis, it
201 can be proven that a C automatic variable is never accessed outside of
202 the current function... allowing it to be promoted to a simple SSA
203 value instead of a memory location.</p>
207 <!-- _______________________________________________________________________ -->
208 <div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
210 <div class="doc_text">
212 <p>It is important to note that this document describes 'well formed'
213 LLVM assembly language. There is a difference between what the parser
214 accepts and what is considered 'well formed'. For example, the
215 following instruction is syntactically okay, but not well formed:</p>
218 %x = <a href="#i_add">add</a> int 1, %x
221 <p>...because the definition of <tt>%x</tt> does not dominate all of
222 its uses. The LLVM infrastructure provides a verification pass that may
223 be used to verify that an LLVM module is well formed. This pass is
224 automatically run by the parser after parsing input assembly, and by
225 the optimizer before it outputs bytecode. The violations pointed out
226 by the verifier pass indicate bugs in transformation passes or input to
229 <!-- Describe the typesetting conventions here. --> </div>
231 <!-- *********************************************************************** -->
232 <div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
233 <!-- *********************************************************************** -->
235 <div class="doc_text">
237 <p>LLVM uses three different forms of identifiers, for different
241 <li>Named values are represented as a string of characters with a '%' prefix.
242 For example, %foo, %DivisionByZero, %a.really.long.identifier. The actual
243 regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
244 Identifiers which require other characters in their names can be surrounded
245 with quotes. In this way, anything except a <tt>"</tt> character can be used
248 <li>Unnamed values are represented as an unsigned numeric value with a '%'
249 prefix. For example, %12, %2, %44.</li>
251 <li>Constants, which are described in a <a href="#constants">section about
252 constants</a>, below.</li>
255 <p>LLVM requires that values start with a '%' sign for two reasons: Compilers
256 don't need to worry about name clashes with reserved words, and the set of
257 reserved words may be expanded in the future without penalty. Additionally,
258 unnamed identifiers allow a compiler to quickly come up with a temporary
259 variable without having to avoid symbol table conflicts.</p>
261 <p>Reserved words in LLVM are very similar to reserved words in other
262 languages. There are keywords for different opcodes ('<tt><a
263 href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
264 href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
265 href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>', etc...),
266 and others. These reserved words cannot conflict with variable names, because
267 none of them start with a '%' character.</p>
269 <p>Here is an example of LLVM code to multiply the integer variable
270 '<tt>%X</tt>' by 8:</p>
275 %result = <a href="#i_mul">mul</a> uint %X, 8
278 <p>After strength reduction:</p>
281 %result = <a href="#i_shl">shl</a> uint %X, ubyte 3
284 <p>And the hard way:</p>
287 <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
288 <a href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
289 %result = <a href="#i_add">add</a> uint %1, %1
292 <p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
293 important lexical features of LLVM:</p>
297 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
300 <li>Unnamed temporaries are created when the result of a computation is not
301 assigned to a named value.</li>
303 <li>Unnamed temporaries are numbered sequentially</li>
307 <p>...and it also show a convention that we follow in this document. When
308 demonstrating instructions, we will follow an instruction with a comment that
309 defines the type and name of value produced. Comments are shown in italic
314 <!-- *********************************************************************** -->
315 <div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
316 <!-- *********************************************************************** -->
318 <!-- ======================================================================= -->
319 <div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
322 <div class="doc_text">
324 <p>LLVM programs are composed of "Module"s, each of which is a
325 translation unit of the input programs. Each module consists of
326 functions, global variables, and symbol table entries. Modules may be
327 combined together with the LLVM linker, which merges function (and
328 global variable) definitions, resolves forward declarations, and merges
329 symbol table entries. Here is an example of the "hello world" module:</p>
331 <pre><i>; Declare the string constant as a global constant...</i>
332 <a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
333 href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00" <i>; [13 x sbyte]*</i>
335 <i>; External declaration of the puts function</i>
336 <a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
338 <i>; Definition of main function</i>
339 int %main() { <i>; int()* </i>
340 <i>; Convert [13x sbyte]* to sbyte *...</i>
342 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
344 <i>; Call puts function to write out the string to stdout...</i>
346 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
348 href="#i_ret">ret</a> int 0<br>}<br></pre>
350 <p>This example is made up of a <a href="#globalvars">global variable</a>
351 named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
352 function, and a <a href="#functionstructure">function definition</a>
353 for "<tt>main</tt>".</p>
355 <p>In general, a module is made up of a list of global values,
356 where both functions and global variables are global values. Global values are
357 represented by a pointer to a memory location (in this case, a pointer to an
358 array of char, and a pointer to a function), and have one of the following <a
359 href="#linkage">linkage types</a>.</p>
363 <!-- ======================================================================= -->
364 <div class="doc_subsection">
365 <a name="linkage">Linkage Types</a>
368 <div class="doc_text">
371 All Global Variables and Functions have one of the following types of linkage:
376 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
378 <dd>Global values with internal linkage are only directly accessible by
379 objects in the current module. In particular, linking code into a module with
380 an internal global value may cause the internal to be renamed as necessary to
381 avoid collisions. Because the symbol is internal to the module, all
382 references can be updated. This corresponds to the notion of the
383 '<tt>static</tt>' keyword in C, or the idea of "anonymous namespaces" in C++.
386 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
388 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt> linkage, with
389 the twist that linking together two modules defining the same
390 <tt>linkonce</tt> globals will cause one of the globals to be discarded. This
391 is typically used to implement inline functions. Unreferenced
392 <tt>linkonce</tt> globals are allowed to be discarded.
395 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
397 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage,
398 except that unreferenced <tt>weak</tt> globals may not be discarded. This is
399 used to implement constructs in C such as "<tt>int X;</tt>" at global scope.
402 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
404 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
405 pointer to array type. When two global variables with appending linkage are
406 linked together, the two global arrays are appended together. This is the
407 LLVM, typesafe, equivalent of having the system linker append together
408 "sections" with identical names when .o files are linked.
411 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
413 <dd>If none of the above identifiers are used, the global is externally
414 visible, meaning that it participates in linkage and can be used to resolve
415 external symbol references.
419 <p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
420 variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
421 variable and was linked with this one, one of the two would be renamed,
422 preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
423 external (i.e., lacking any linkage declarations), they are accessible
424 outside of the current module. It is illegal for a function <i>declaration</i>
425 to have any linkage type other than "externally visible".</a></p>
429 <!-- ======================================================================= -->
430 <div class="doc_subsection">
431 <a name="globalvars">Global Variables</a>
434 <div class="doc_text">
436 <p>Global variables define regions of memory allocated at compilation time
437 instead of run-time. Global variables may optionally be initialized. A
438 variable may be defined as a global "constant", which indicates that the
439 contents of the variable will <b>never</b> be modified (enabling better
440 optimization, allowing the global data to be placed in the read-only section of
441 an executable, etc). Note that variables that need runtime initialization
442 cannot be marked "constant", as there is a store to the variable.</p>
445 LLVM explicitly allows <em>declarations</em> of global variables to be marked
446 constant, even if the final definition of the global is not. This capability
447 can be used to enable slightly better optimization of the program, but requires
448 the language definition to guarantee that optimizations based on the
449 'constantness' are valid for the translation units that do not include the
453 <p>As SSA values, global variables define pointer values that are in
454 scope (i.e. they dominate) all basic blocks in the program. Global
455 variables always define a pointer to their "content" type because they
456 describe a region of memory, and all memory objects in LLVM are
457 accessed through pointers.</p>
462 <!-- ======================================================================= -->
463 <div class="doc_subsection">
464 <a name="functionstructure">Functions</a>
467 <div class="doc_text">
469 <p>LLVM function definitions are composed of a (possibly empty) argument list,
470 an opening curly brace, a list of basic blocks, and a closing curly brace. LLVM
471 function declarations are defined with the "<tt>declare</tt>" keyword, a
472 function name, and a function signature.</p>
474 <p>A function definition contains a list of basic blocks, forming the CFG for
475 the function. Each basic block may optionally start with a label (giving the
476 basic block a symbol table entry), contains a list of instructions, and ends
477 with a <a href="#terminators">terminator</a> instruction (such as a branch or
478 function return).</p>
480 <p>The first basic block in program is special in two ways: it is immediately
481 executed on entrance to the function, and it is not allowed to have predecessor
482 basic blocks (i.e. there can not be any branches to the entry block of a
483 function). Because the block can have no predecessors, it also cannot have any
484 <a href="#i_phi">PHI nodes</a>.</p>
486 <p>LLVM functions are identified by their name and type signature. Hence, two
487 functions with the same name but different parameter lists or return values are
488 considered different functions, and LLVM will resolve references to each
495 <!-- *********************************************************************** -->
496 <div class="doc_section"> <a name="typesystem">Type System</a> </div>
497 <!-- *********************************************************************** -->
499 <div class="doc_text">
501 <p>The LLVM type system is one of the most important features of the
502 intermediate representation. Being typed enables a number of
503 optimizations to be performed on the IR directly, without having to do
504 extra analyses on the side before the transformation. A strong type
505 system makes it easier to read the generated code and enables novel
506 analyses and transformations that are not feasible to perform on normal
507 three address code representations.</p>
511 <!-- ======================================================================= -->
512 <div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
513 <div class="doc_text">
514 <p>The primitive types are the fundamental building blocks of the LLVM
515 system. The current set of primitive types is as follows:</p>
517 <table class="layout">
522 <tr><th>Type</th><th>Description</th></tr>
523 <tr><td><tt>void</tt></td><td>No value</td></tr>
524 <tr><td><tt>ubyte</tt></td><td>Unsigned 8-bit value</td></tr>
525 <tr><td><tt>ushort</tt></td><td>Unsigned 16-bit value</td></tr>
526 <tr><td><tt>uint</tt></td><td>Unsigned 32-bit value</td></tr>
527 <tr><td><tt>ulong</tt></td><td>Unsigned 64-bit value</td></tr>
528 <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr>
529 <tr><td><tt>label</tt></td><td>Branch destination</td></tr>
536 <tr><th>Type</th><th>Description</th></tr>
537 <tr><td><tt>bool</tt></td><td>True or False value</td></tr>
538 <tr><td><tt>sbyte</tt></td><td>Signed 8-bit value</td></tr>
539 <tr><td><tt>short</tt></td><td>Signed 16-bit value</td></tr>
540 <tr><td><tt>int</tt></td><td>Signed 32-bit value</td></tr>
541 <tr><td><tt>long</tt></td><td>Signed 64-bit value</td></tr>
542 <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr>
550 <!-- _______________________________________________________________________ -->
551 <div class="doc_subsubsection"> <a name="t_classifications">Type
552 Classifications</a> </div>
553 <div class="doc_text">
554 <p>These different primitive types fall into a few useful
557 <table border="1" cellspacing="0" cellpadding="4">
559 <tr><th>Classification</th><th>Types</th></tr>
561 <td><a name="t_signed">signed</a></td>
562 <td><tt>sbyte, short, int, long, float, double</tt></td>
565 <td><a name="t_unsigned">unsigned</a></td>
566 <td><tt>ubyte, ushort, uint, ulong</tt></td>
569 <td><a name="t_integer">integer</a></td>
570 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
573 <td><a name="t_integral">integral</a></td>
574 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt>
578 <td><a name="t_floating">floating point</a></td>
579 <td><tt>float, double</tt></td>
582 <td><a name="t_firstclass">first class</a></td>
583 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long,<br>
584 float, double, <a href="#t_pointer">pointer</a>,
585 <a href="#t_packed">packed</a></tt></td>
590 <p>The <a href="#t_firstclass">first class</a> types are perhaps the
591 most important. Values of these types are the only ones which can be
592 produced by instructions, passed as arguments, or used as operands to
593 instructions. This means that all structures and arrays must be
594 manipulated either by pointer or by component.</p>
597 <!-- ======================================================================= -->
598 <div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
600 <div class="doc_text">
602 <p>The real power in LLVM comes from the derived types in the system.
603 This is what allows a programmer to represent arrays, functions,
604 pointers, and other useful types. Note that these derived types may be
605 recursive: For example, it is possible to have a two dimensional array.</p>
609 <!-- _______________________________________________________________________ -->
610 <div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
612 <div class="doc_text">
616 <p>The array type is a very simple derived type that arranges elements
617 sequentially in memory. The array type requires a size (number of
618 elements) and an underlying data type.</p>
623 [<# elements> x <elementtype>]
626 <p>The number of elements is a constant integer value, elementtype may
627 be any type with a size.</p>
630 <table class="layout">
633 <tt>[40 x int ]</tt><br/>
634 <tt>[41 x int ]</tt><br/>
635 <tt>[40 x uint]</tt><br/>
638 Array of 40 integer values.<br/>
639 Array of 41 integer values.<br/>
640 Array of 40 unsigned integer values.<br/>
644 <p>Here are some examples of multidimensional arrays:</p>
645 <table class="layout">
648 <tt>[3 x [4 x int]]</tt><br/>
649 <tt>[12 x [10 x float]]</tt><br/>
650 <tt>[2 x [3 x [4 x uint]]]</tt><br/>
653 3x4 array integer values.<br/>
654 12x10 array of single precision floating point values.<br/>
655 2x3x4 array of unsigned integer values.<br/>
661 <!-- _______________________________________________________________________ -->
662 <div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
663 <div class="doc_text">
665 <p>The function type can be thought of as a function signature. It
666 consists of a return type and a list of formal parameter types.
667 Function types are usually used to build virtual function tables
668 (which are structures of pointers to functions), for indirect function
669 calls, and when defining a function.</p>
671 The return type of a function type cannot be an aggregate type.
674 <pre> <returntype> (<parameter list>)<br></pre>
675 <p>Where '<tt><parameter list></tt>' is a comma-separated list of type
676 specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
677 which indicates that the function takes a variable number of arguments.
678 Variable argument functions can access their arguments with the <a
679 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
681 <table class="layout">
684 <tt>int (int)</tt> <br/>
685 <tt>float (int, int *) *</tt><br/>
686 <tt>int (sbyte *, ...)</tt><br/>
689 function taking an <tt>int</tt>, returning an <tt>int</tt><br/>
690 <a href="#t_pointer">Pointer</a> to a function that takes an
691 <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
692 returning <tt>float</tt>.<br/>
693 A vararg function that takes at least one <a href="#t_pointer">pointer</a>
694 to <tt>sbyte</tt> (signed char in C), which returns an integer. This is
695 the signature for <tt>printf</tt> in LLVM.<br/>
701 <!-- _______________________________________________________________________ -->
702 <div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
703 <div class="doc_text">
705 <p>The structure type is used to represent a collection of data members
706 together in memory. The packing of the field types is defined to match
707 the ABI of the underlying processor. The elements of a structure may
708 be any type that has a size.</p>
709 <p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
710 and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
711 field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
714 <pre> { <type list> }<br></pre>
716 <table class="layout">
719 <tt>{ int, int, int }</tt><br/>
720 <tt>{ float, int (int) * }</tt><br/>
723 a triple of three <tt>int</tt> values<br/>
724 A pair, where the first element is a <tt>float</tt> and the second element
725 is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a>
726 that takes an <tt>int</tt>, returning an <tt>int</tt>.<br/>
732 <!-- _______________________________________________________________________ -->
733 <div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
734 <div class="doc_text">
736 <p>As in many languages, the pointer type represents a pointer or
737 reference to another object, which must live in memory.</p>
739 <pre> <type> *<br></pre>
741 <table class="layout">
744 <tt>[4x int]*</tt><br/>
745 <tt>int (int *) *</tt><br/>
748 A <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of
749 four <tt>int</tt> values<br/>
750 A <a href="#t_pointer">pointer</a> to a <a
751 href="#t_function">function</a> that takes an <tt>int*</tt>, returning an
758 <!-- _______________________________________________________________________ -->
759 <div class="doc_subsubsection"> <a name="t_packed">Packed Type</a> </div>
760 <div class="doc_text">
764 <p>A packed type is a simple derived type that represents a vector
765 of elements. Packed types are used when multiple primitive data
766 are operated in parallel using a single instruction (SIMD).
767 A packed type requires a size (number of
768 elements) and an underlying primitive data type. Packed types are
769 considered <a href="#t_firstclass">first class</a>.</p>
774 < <# elements> x <elementtype> >
777 <p>The number of elements is a constant integer value, elementtype may
778 be any integral or floating point type.</p>
782 <table class="layout">
785 <tt><4 x int></tt><br/>
786 <tt><8 x float></tt><br/>
787 <tt><2 x uint></tt><br/>
790 Packed vector of 4 integer values.<br/>
791 Packed vector of 8 floating-point values.<br/>
792 Packed vector of 2 unsigned integer values.<br/>
798 <!-- _______________________________________________________________________ -->
799 <div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div>
800 <div class="doc_text">
804 <p>Opaque types are used to represent unknown types in the system. This
805 corresponds (for example) to the C notion of a foward declared structure type.
806 In LLVM, opaque types can eventually be resolved to any type (not just a
817 <table class="layout">
830 <!-- *********************************************************************** -->
831 <div class="doc_section"> <a name="constants">Constants</a> </div>
832 <!-- *********************************************************************** -->
834 <div class="doc_text">
836 <p>LLVM has several different basic types of constants. This section describes
837 them all and their syntax.</p>
841 <!-- ======================================================================= -->
842 <div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
844 <div class="doc_text">
847 <dt><b>Boolean constants</b></dt>
849 <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
850 constants of the <tt><a href="#t_primitive">bool</a></tt> type.
853 <dt><b>Integer constants</b></dt>
855 <dd>Standard integers (such as '4') are constants of the <a
856 href="#t_integer">integer</a> type. Negative numbers may be used with signed
860 <dt><b>Floating point constants</b></dt>
862 <dd>Floating point constants use standard decimal notation (e.g. 123.421),
863 exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
864 notation. Floating point constants have an optional hexadecimal
865 notation (see below). Floating point constants must have a <a
866 href="#t_floating">floating point</a> type. </dd>
868 <dt><b>Null pointer constants</b></dt>
870 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
871 and must be of <a href="#t_pointer">pointer type</a>.</dd>
875 <p>The one non-intuitive notation for constants is the optional hexadecimal form
876 of floating point constants. For example, the form '<tt>double
877 0x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
878 4.5e+15</tt>'. The only time hexadecimal floating point constants are required
879 (and the only time that they are generated by the disassembler) is when a
880 floating point constant must be emitted but it cannot be represented as a
881 decimal floating point number. For example, NaN's, infinities, and other
882 special values are represented in their IEEE hexadecimal format so that
883 assembly and disassembly do not cause any bits to change in the constants.</p>
887 <!-- ======================================================================= -->
888 <div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a>
891 <div class="doc_text">
892 <p>Aggregate constants arise from aggregation of simple constants
893 and smaller aggregate constants.</p>
896 <dt><b>Structure constants</b></dt>
898 <dd>Structure constants are represented with notation similar to structure
899 type definitions (a comma separated list of elements, surrounded by braces
900 (<tt>{}</tt>)). For example: "<tt>{ int 4, float 17.0, int* %G }</tt>",
901 where "<tt>%G</tt>" is declared as "<tt>%G = external global int</tt>". Structure constants
902 must have <a href="#t_struct">structure type</a>, and the number and
903 types of elements must match those specified by the type.
906 <dt><b>Array constants</b></dt>
908 <dd>Array constants are represented with notation similar to array type
909 definitions (a comma separated list of elements, surrounded by square brackets
910 (<tt>[]</tt>)). For example: "<tt>[ int 42, int 11, int 74 ]</tt>". Array
911 constants must have <a href="#t_array">array type</a>, and the number and
912 types of elements must match those specified by the type.
915 <dt><b>Packed constants</b></dt>
917 <dd>Packed constants are represented with notation similar to packed type
918 definitions (a comma separated list of elements, surrounded by
919 less-than/greater-than's (<tt><></tt>)). For example: "<tt>< int 42,
920 int 11, int 74, int 100 ></tt>". Packed constants must have <a
921 href="#t_packed">packed type</a>, and the number and types of elements must
922 match those specified by the type.
925 <dt><b>Zero initialization</b></dt>
927 <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
928 value to zero of <em>any</em> type, including scalar and aggregate types.
929 This is often used to avoid having to print large zero initializers (e.g. for
930 large arrays), and is always exactly equivalent to using explicit zero
937 <!-- ======================================================================= -->
938 <div class="doc_subsection">
939 <a name="globalconstants">Global Variable and Function Addresses</a>
942 <div class="doc_text">
944 <p>The addresses of <a href="#globalvars">global variables</a> and <a
945 href="#functionstructure">functions</a> are always implicitly valid (link-time)
946 constants. These constants are explicitly referenced when the <a
947 href="#identifiers">identifier for the global</a> is used and always have <a
948 href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
954 %Z = global [2 x int*] [ int* %X, int* %Y ]
959 <!-- ======================================================================= -->
960 <div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
961 <div class="doc_text">
962 <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has
963 no specific value. Undefined values may be of any type, and be used anywhere
964 a constant is permitted.</p>
966 <p>Undefined values indicate to the compiler that the program is well defined
967 no matter what value is used, giving the compiler more freedom to optimize.
971 <!-- ======================================================================= -->
972 <div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
975 <div class="doc_text">
977 <p>Constant expressions are used to allow expressions involving other constants
978 to be used as constants. Constant expressions may be of any <a
979 href="#t_firstclass">first class</a> type, and may involve any LLVM operation
980 that does not have side effects (e.g. load and call are not supported). The
981 following is the syntax for constant expressions:</p>
984 <dt><b><tt>cast ( CST to TYPE )</tt></b></dt>
986 <dd>Cast a constant to another type.</dd>
988 <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
990 <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
991 constants. As with the <a href="#i_getelementptr">getelementptr</a>
992 instruction, the index list may have zero or more indexes, which are required
993 to make sense for the type of "CSTPTR".</dd>
995 <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
997 <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
998 be any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise
999 binary</a> operations. The constraints on operands are the same as those for
1000 the corresponding instruction (e.g. no bitwise operations on floating point
1005 <!-- *********************************************************************** -->
1006 <div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
1007 <!-- *********************************************************************** -->
1009 <div class="doc_text">
1011 <p>The LLVM instruction set consists of several different
1012 classifications of instructions: <a href="#terminators">terminator
1013 instructions</a>, <a href="#binaryops">binary instructions</a>, <a
1014 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
1015 instructions</a>.</p>
1019 <!-- ======================================================================= -->
1020 <div class="doc_subsection"> <a name="terminators">Terminator
1021 Instructions</a> </div>
1023 <div class="doc_text">
1025 <p>As mentioned <a href="#functionstructure">previously</a>, every
1026 basic block in a program ends with a "Terminator" instruction, which
1027 indicates which block should be executed after the current block is
1028 finished. These terminator instructions typically yield a '<tt>void</tt>'
1029 value: they produce control flow, not values (the one exception being
1030 the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
1031 <p>There are six different terminator instructions: the '<a
1032 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
1033 instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
1034 the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
1035 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
1036 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
1040 <!-- _______________________________________________________________________ -->
1041 <div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
1042 Instruction</a> </div>
1043 <div class="doc_text">
1045 <pre> ret <type> <value> <i>; Return a value from a non-void function</i>
1046 ret void <i>; Return from void function</i>
1049 <p>The '<tt>ret</tt>' instruction is used to return control flow (and a
1050 value) from a function, back to the caller.</p>
1051 <p>There are two forms of the '<tt>ret</tt>' instruction: one that
1052 returns a value and then causes control flow, and one that just causes
1053 control flow to occur.</p>
1055 <p>The '<tt>ret</tt>' instruction may return any '<a
1056 href="#t_firstclass">first class</a>' type. Notice that a function is
1057 not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
1058 instruction inside of the function that returns a value that does not
1059 match the return type of the function.</p>
1061 <p>When the '<tt>ret</tt>' instruction is executed, control flow
1062 returns back to the calling function's context. If the caller is a "<a
1063 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
1064 the instruction after the call. If the caller was an "<a
1065 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
1066 at the beginning "normal" of the destination block. If the instruction
1067 returns a value, that value shall set the call or invoke instruction's
1070 <pre> ret int 5 <i>; Return an integer value of 5</i>
1071 ret void <i>; Return from a void function</i>
1074 <!-- _______________________________________________________________________ -->
1075 <div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
1076 <div class="doc_text">
1078 <pre> br bool <cond>, label <iftrue>, label <iffalse><br> br label <dest> <i>; Unconditional branch</i>
1081 <p>The '<tt>br</tt>' instruction is used to cause control flow to
1082 transfer to a different basic block in the current function. There are
1083 two forms of this instruction, corresponding to a conditional branch
1084 and an unconditional branch.</p>
1086 <p>The conditional branch form of the '<tt>br</tt>' instruction takes a
1087 single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
1088 unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
1089 value as a target.</p>
1091 <p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
1092 argument is evaluated. If the value is <tt>true</tt>, control flows
1093 to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
1094 control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
1096 <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
1097 href="#i_ret">ret</a> int 1<br>IfUnequal:<br> <a href="#i_ret">ret</a> int 0<br></pre>
1099 <!-- _______________________________________________________________________ -->
1100 <div class="doc_subsubsection">
1101 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
1104 <div class="doc_text">
1108 switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ]
1113 <p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
1114 several different places. It is a generalization of the '<tt>br</tt>'
1115 instruction, allowing a branch to occur to one of many possible
1121 <p>The '<tt>switch</tt>' instruction uses three parameters: an integer
1122 comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
1123 an array of pairs of comparison value constants and '<tt>label</tt>'s. The
1124 table is not allowed to contain duplicate constant entries.</p>
1128 <p>The <tt>switch</tt> instruction specifies a table of values and
1129 destinations. When the '<tt>switch</tt>' instruction is executed, this
1130 table is searched for the given value. If the value is found, control flow is
1131 transfered to the corresponding destination; otherwise, control flow is
1132 transfered to the default destination.</p>
1134 <h5>Implementation:</h5>
1136 <p>Depending on properties of the target machine and the particular
1137 <tt>switch</tt> instruction, this instruction may be code generated in different
1138 ways. For example, it could be generated as a series of chained conditional
1139 branches or with a lookup table.</p>
1144 <i>; Emulate a conditional br instruction</i>
1145 %Val = <a href="#i_cast">cast</a> bool %value to int
1146 switch int %Val, label %truedest [int 0, label %falsedest ]
1148 <i>; Emulate an unconditional br instruction</i>
1149 switch uint 0, label %dest [ ]
1151 <i>; Implement a jump table:</i>
1152 switch uint %val, label %otherwise [ uint 0, label %onzero
1153 uint 1, label %onone
1154 uint 2, label %ontwo ]
1157 <!-- _______________________________________________________________________ -->
1158 <div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>'
1159 Instruction</a> </div>
1160 <div class="doc_text">
1162 <pre> <result> = invoke <ptr to function ty> %<function ptr val>(<function args>)<br> to label <normal label> except label <exception label><br></pre>
1164 <p>The '<tt>invoke</tt>' instruction causes control to transfer to a
1165 specified function, with the possibility of control flow transfer to
1166 either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>.
1167 If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>"
1168 instruction, control flow will return to the "normal" label. If the
1169 callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
1170 instruction, control is interrupted, and continued at the dynamically
1171 nearest "except" label.</p>
1173 <p>This instruction requires several arguments:</p>
1175 <li>'<tt>ptr to function ty</tt>': shall be the signature of the
1176 pointer to function value being invoked. In most cases, this is a
1177 direct function invocation, but indirect <tt>invoke</tt>s are just as
1178 possible, branching off an arbitrary pointer to function value. </li>
1179 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer
1180 to a function to be invoked. </li>
1181 <li>'<tt>function args</tt>': argument list whose types match the
1182 function signature argument types. If the function signature indicates
1183 the function accepts a variable number of arguments, the extra
1184 arguments can be specified. </li>
1185 <li>'<tt>normal label</tt>': the label reached when the called
1186 function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
1187 <li>'<tt>exception label</tt>': the label reached when a callee
1188 returns with the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
1191 <p>This instruction is designed to operate as a standard '<tt><a
1192 href="#i_call">call</a></tt>' instruction in most regards. The
1193 primary difference is that it establishes an association with a label,
1194 which is used by the runtime library to unwind the stack.</p>
1195 <p>This instruction is used in languages with destructors to ensure
1196 that proper cleanup is performed in the case of either a <tt>longjmp</tt>
1197 or a thrown exception. Additionally, this is important for
1198 implementation of '<tt>catch</tt>' clauses in high-level languages that
1201 <pre> %retval = invoke int %Test(int 15)<br> to label %Continue<br> except label %TestCleanup <i>; {int}:retval set</i>
1206 <!-- _______________________________________________________________________ -->
1208 <div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
1209 Instruction</a> </div>
1211 <div class="doc_text">
1220 <p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
1221 at the first callee in the dynamic call stack which used an <a
1222 href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
1223 primarily used to implement exception handling.</p>
1227 <p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to
1228 immediately halt. The dynamic call stack is then searched for the first <a
1229 href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
1230 execution continues at the "exceptional" destination block specified by the
1231 <tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
1232 dynamic call chain, undefined behavior results.</p>
1235 <!-- _______________________________________________________________________ -->
1237 <div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
1238 Instruction</a> </div>
1240 <div class="doc_text">
1249 <p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
1250 instruction is used to inform the optimizer that a particular portion of the
1251 code is not reachable. This can be used to indicate that the code after a
1252 no-return function cannot be reached, and other facts.</p>
1256 <p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
1261 <!-- ======================================================================= -->
1262 <div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
1263 <div class="doc_text">
1264 <p>Binary operators are used to do most of the computation in a
1265 program. They require two operands, execute an operation on them, and
1266 produce a single value. The operands might represent
1267 multiple data, as is the case with the <a href="#t_packed">packed</a> data type.
1268 The result value of a binary operator is not
1269 necessarily the same type as its operands.</p>
1270 <p>There are several different binary operators:</p>
1272 <!-- _______________________________________________________________________ -->
1273 <div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
1274 Instruction</a> </div>
1275 <div class="doc_text">
1277 <pre> <result> = add <ty> <var1>, <var2> <i>; yields {ty}:result</i>
1280 <p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
1282 <p>The two arguments to the '<tt>add</tt>' instruction must be either <a
1283 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
1284 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1285 Both arguments must have identical types.</p>
1287 <p>The value produced is the integer or floating point sum of the two
1290 <pre> <result> = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
1293 <!-- _______________________________________________________________________ -->
1294 <div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
1295 Instruction</a> </div>
1296 <div class="doc_text">
1298 <pre> <result> = sub <ty> <var1>, <var2> <i>; yields {ty}:result</i>
1301 <p>The '<tt>sub</tt>' instruction returns the difference of its two
1303 <p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
1304 instruction present in most other intermediate representations.</p>
1306 <p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
1307 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
1309 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1310 Both arguments must have identical types.</p>
1312 <p>The value produced is the integer or floating point difference of
1313 the two operands.</p>
1315 <pre> <result> = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
1316 <result> = sub int 0, %val <i>; yields {int}:result = -%var</i>
1319 <!-- _______________________________________________________________________ -->
1320 <div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
1321 Instruction</a> </div>
1322 <div class="doc_text">
1324 <pre> <result> = mul <ty> <var1>, <var2> <i>; yields {ty}:result</i>
1327 <p>The '<tt>mul</tt>' instruction returns the product of its two
1330 <p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
1331 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
1333 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1334 Both arguments must have identical types.</p>
1336 <p>The value produced is the integer or floating point product of the
1338 <p>There is no signed vs unsigned multiplication. The appropriate
1339 action is taken based on the type of the operand.</p>
1341 <pre> <result> = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
1344 <!-- _______________________________________________________________________ -->
1345 <div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
1346 Instruction</a> </div>
1347 <div class="doc_text">
1349 <pre> <result> = div <ty> <var1>, <var2> <i>; yields {ty}:result</i>
1352 <p>The '<tt>div</tt>' instruction returns the quotient of its two
1355 <p>The two arguments to the '<tt>div</tt>' instruction must be either <a
1356 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
1358 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1359 Both arguments must have identical types.</p>
1361 <p>The value produced is the integer or floating point quotient of the
1364 <pre> <result> = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
1367 <!-- _______________________________________________________________________ -->
1368 <div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
1369 Instruction</a> </div>
1370 <div class="doc_text">
1372 <pre> <result> = rem <ty> <var1>, <var2> <i>; yields {ty}:result</i>
1375 <p>The '<tt>rem</tt>' instruction returns the remainder from the
1376 division of its two operands.</p>
1378 <p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1379 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
1381 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1382 Both arguments must have identical types.</p>
1384 <p>This returns the <i>remainder</i> of a division (where the result
1385 has the same sign as the divisor), not the <i>modulus</i> (where the
1386 result has the same sign as the dividend) of a value. For more
1387 information about the difference, see: <a
1388 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1391 <pre> <result> = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1394 <!-- _______________________________________________________________________ -->
1395 <div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1396 Instructions</a> </div>
1397 <div class="doc_text">
1399 <pre> <result> = seteq <ty> <var1>, <var2> <i>; yields {bool}:result</i>
1400 <result> = setne <ty> <var1>, <var2> <i>; yields {bool}:result</i>
1401 <result> = setlt <ty> <var1>, <var2> <i>; yields {bool}:result</i>
1402 <result> = setgt <ty> <var1>, <var2> <i>; yields {bool}:result</i>
1403 <result> = setle <ty> <var1>, <var2> <i>; yields {bool}:result</i>
1404 <result> = setge <ty> <var1>, <var2> <i>; yields {bool}:result</i>
1407 <p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1408 value based on a comparison of their two operands.</p>
1410 <p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1411 be of <a href="#t_firstclass">first class</a> type (it is not possible
1412 to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1413 or '<tt>void</tt>' values, etc...). Both arguments must have identical
1416 <p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1417 value if both operands are equal.<br>
1418 The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1419 value if both operands are unequal.<br>
1420 The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1421 value if the first operand is less than the second operand.<br>
1422 The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1423 value if the first operand is greater than the second operand.<br>
1424 The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1425 value if the first operand is less than or equal to the second operand.<br>
1426 The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1427 value if the first operand is greater than or equal to the second
1430 <pre> <result> = seteq int 4, 5 <i>; yields {bool}:result = false</i>
1431 <result> = setne float 4, 5 <i>; yields {bool}:result = true</i>
1432 <result> = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1433 <result> = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1434 <result> = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1435 <result> = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1438 <!-- ======================================================================= -->
1439 <div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1440 Operations</a> </div>
1441 <div class="doc_text">
1442 <p>Bitwise binary operators are used to do various forms of
1443 bit-twiddling in a program. They are generally very efficient
1444 instructions and can commonly be strength reduced from other
1445 instructions. They require two operands, execute an operation on them,
1446 and produce a single value. The resulting value of the bitwise binary
1447 operators is always the same type as its first operand.</p>
1449 <!-- _______________________________________________________________________ -->
1450 <div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1451 Instruction</a> </div>
1452 <div class="doc_text">
1454 <pre> <result> = and <ty> <var1>, <var2> <i>; yields {ty}:result</i>
1457 <p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1458 its two operands.</p>
1460 <p>The two arguments to the '<tt>and</tt>' instruction must be <a
1461 href="#t_integral">integral</a> values. Both arguments must have
1462 identical types.</p>
1464 <p>The truth table used for the '<tt>and</tt>' instruction is:</p>
1466 <div style="align: center">
1467 <table border="1" cellspacing="0" cellpadding="4">
1498 <pre> <result> = and int 4, %var <i>; yields {int}:result = 4 & %var</i>
1499 <result> = and int 15, 40 <i>; yields {int}:result = 8</i>
1500 <result> = and int 4, 8 <i>; yields {int}:result = 0</i>
1503 <!-- _______________________________________________________________________ -->
1504 <div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
1505 <div class="doc_text">
1507 <pre> <result> = or <ty> <var1>, <var2> <i>; yields {ty}:result</i>
1510 <p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1511 or of its two operands.</p>
1513 <p>The two arguments to the '<tt>or</tt>' instruction must be <a
1514 href="#t_integral">integral</a> values. Both arguments must have
1515 identical types.</p>
1517 <p>The truth table used for the '<tt>or</tt>' instruction is:</p>
1519 <div style="align: center">
1520 <table border="1" cellspacing="0" cellpadding="4">
1551 <pre> <result> = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
1552 <result> = or int 15, 40 <i>; yields {int}:result = 47</i>
1553 <result> = or int 4, 8 <i>; yields {int}:result = 12</i>
1556 <!-- _______________________________________________________________________ -->
1557 <div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1558 Instruction</a> </div>
1559 <div class="doc_text">
1561 <pre> <result> = xor <ty> <var1>, <var2> <i>; yields {ty}:result</i>
1564 <p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1565 or of its two operands. The <tt>xor</tt> is used to implement the
1566 "one's complement" operation, which is the "~" operator in C.</p>
1568 <p>The two arguments to the '<tt>xor</tt>' instruction must be <a
1569 href="#t_integral">integral</a> values. Both arguments must have
1570 identical types.</p>
1572 <p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
1574 <div style="align: center">
1575 <table border="1" cellspacing="0" cellpadding="4">
1607 <pre> <result> = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
1608 <result> = xor int 15, 40 <i>; yields {int}:result = 39</i>
1609 <result> = xor int 4, 8 <i>; yields {int}:result = 12</i>
1610 <result> = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
1613 <!-- _______________________________________________________________________ -->
1614 <div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1615 Instruction</a> </div>
1616 <div class="doc_text">
1618 <pre> <result> = shl <ty> <var1>, ubyte <var2> <i>; yields {ty}:result</i>
1621 <p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1622 the left a specified number of bits.</p>
1624 <p>The first argument to the '<tt>shl</tt>' instruction must be an <a
1625 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1628 <p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
1630 <pre> <result> = shl int 4, ubyte %var <i>; yields {int}:result = 4 << %var</i>
1631 <result> = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1632 <result> = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1635 <!-- _______________________________________________________________________ -->
1636 <div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1637 Instruction</a> </div>
1638 <div class="doc_text">
1640 <pre> <result> = shr <ty> <var1>, ubyte <var2> <i>; yields {ty}:result</i>
1643 <p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1644 the right a specified number of bits.</p>
1646 <p>The first argument to the '<tt>shr</tt>' instruction must be an <a
1647 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1650 <p>If the first argument is a <a href="#t_signed">signed</a> type, the
1651 most significant bit is duplicated in the newly free'd bit positions.
1652 If the first argument is unsigned, zero bits shall fill the empty
1655 <pre> <result> = shr int 4, ubyte %var <i>; yields {int}:result = 4 >> %var</i>
1656 <result> = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
1657 <result> = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
1658 <result> = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1659 <result> = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
1662 <!-- ======================================================================= -->
1663 <div class="doc_subsection"> <a name="memoryops">Memory Access
1664 Operations</a></div>
1665 <div class="doc_text">
1666 <p>A key design point of an SSA-based representation is how it
1667 represents memory. In LLVM, no memory locations are in SSA form, which
1668 makes things very simple. This section describes how to read, write,
1669 allocate, and free memory in LLVM.</p>
1671 <!-- _______________________________________________________________________ -->
1672 <div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>'
1673 Instruction</a> </div>
1674 <div class="doc_text">
1676 <pre> <result> = malloc <type>, uint <NumElements> <i>; yields {type*}:result</i>
1677 <result> = malloc <type> <i>; yields {type*}:result</i>
1680 <p>The '<tt>malloc</tt>' instruction allocates memory from the system
1681 heap and returns a pointer to it.</p>
1683 <p>The '<tt>malloc</tt>' instruction allocates <tt>sizeof(<type>)*NumElements</tt>
1684 bytes of memory from the operating system and returns a pointer of the
1685 appropriate type to the program. The second form of the instruction is
1686 a shorter version of the first instruction that defaults to allocating
1688 <p>'<tt>type</tt>' must be a sized type.</p>
1690 <p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1691 a pointer is returned.</p>
1693 <pre> %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
1696 href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
1697 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1698 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
1701 <!-- _______________________________________________________________________ -->
1702 <div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>'
1703 Instruction</a> </div>
1704 <div class="doc_text">
1706 <pre> free <type> <value> <i>; yields {void}</i>
1709 <p>The '<tt>free</tt>' instruction returns memory back to the unused
1710 memory heap, to be reallocated in the future.</p>
1713 <p>'<tt>value</tt>' shall be a pointer value that points to a value
1714 that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1717 <p>Access to the memory pointed to by the pointer is no longer defined
1718 after this instruction executes.</p>
1720 <pre> %array = <a href="#i_malloc">malloc</a> [4 x ubyte] <i>; yields {[4 x ubyte]*}:array</i>
1721 free [4 x ubyte]* %array
1724 <!-- _______________________________________________________________________ -->
1725 <div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>'
1726 Instruction</a> </div>
1727 <div class="doc_text">
1729 <pre> <result> = alloca <type>, uint <NumElements> <i>; yields {type*}:result</i>
1730 <result> = alloca <type> <i>; yields {type*}:result</i>
1733 <p>The '<tt>alloca</tt>' instruction allocates memory on the current
1734 stack frame of the procedure that is live until the current function
1735 returns to its caller.</p>
1737 <p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(<type>)*NumElements</tt>
1738 bytes of memory on the runtime stack, returning a pointer of the
1739 appropriate type to the program. The second form of the instruction is
1740 a shorter version of the first that defaults to allocating one element.</p>
1741 <p>'<tt>type</tt>' may be any sized type.</p>
1743 <p>Memory is allocated, a pointer is returned. '<tt>alloca</tt>'d
1744 memory is automatically released when the function returns. The '<tt>alloca</tt>'
1745 instruction is commonly used to represent automatic variables that must
1746 have an address available. When the function returns (either with the <tt><a
1747 href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt>
1748 instructions), the memory is reclaimed.</p>
1750 <pre> %ptr = alloca int <i>; yields {int*}:ptr</i>
1751 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
1754 <!-- _______________________________________________________________________ -->
1755 <div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1756 Instruction</a> </div>
1757 <div class="doc_text">
1759 <pre> <result> = load <ty>* <pointer><br> <result> = volatile load <ty>* <pointer><br></pre>
1761 <p>The '<tt>load</tt>' instruction is used to read from memory.</p>
1763 <p>The argument to the '<tt>load</tt>' instruction specifies the memory
1764 address to load from. The pointer must point to a <a
1765 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
1766 marked as <tt>volatile</tt> then the optimizer is not allowed to modify
1767 the number or order of execution of this <tt>load</tt> with other
1768 volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1771 <p>The location of memory pointed to is loaded.</p>
1773 <pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1775 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
1776 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1779 <!-- _______________________________________________________________________ -->
1780 <div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1781 Instruction</a> </div>
1783 <pre> store <ty> <value>, <ty>* <pointer> <i>; yields {void}</i>
1784 volatile store <ty> <value>, <ty>* <pointer> <i>; yields {void}</i>
1787 <p>The '<tt>store</tt>' instruction is used to write to memory.</p>
1789 <p>There are two arguments to the '<tt>store</tt>' instruction: a value
1790 to store and an address to store it into. The type of the '<tt><pointer></tt>'
1791 operand must be a pointer to the type of the '<tt><value></tt>'
1792 operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the
1793 optimizer is not allowed to modify the number or order of execution of
1794 this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1795 href="#i_store">store</a></tt> instructions.</p>
1797 <p>The contents of memory are updated to contain '<tt><value></tt>'
1798 at the location specified by the '<tt><pointer></tt>' operand.</p>
1800 <pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1802 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
1803 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1805 <!-- _______________________________________________________________________ -->
1806 <div class="doc_subsubsection">
1807 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
1810 <div class="doc_text">
1813 <result> = getelementptr <ty>* <ptrval>{, <ty> <idx>}*
1819 The '<tt>getelementptr</tt>' instruction is used to get the address of a
1820 subelement of an aggregate data structure.</p>
1824 <p>This instruction takes a list of integer constants that indicate what
1825 elements of the aggregate object to index to. The actual types of the arguments
1826 provided depend on the type of the first pointer argument. The
1827 '<tt>getelementptr</tt>' instruction is used to index down through the type
1828 levels of a structure. When indexing into a structure, only <tt>uint</tt>
1829 integer constants are allowed. When indexing into an array or pointer
1830 <tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
1832 <p>For example, let's consider a C code fragment and how it gets
1833 compiled to LLVM:</p>
1847 int *foo(struct ST *s) {
1848 return &s[1].Z.B[5][13];
1852 <p>The LLVM code generated by the GCC frontend is:</p>
1855 %RT = type { sbyte, [10 x [20 x int]], sbyte }
1856 %ST = type { int, double, %RT }
1860 int* %foo(%ST* %s) {
1862 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13
1869 <p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
1870 on the pointer type that is being index into. <a href="#t_pointer">Pointer</a>
1871 and <a href="#t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
1872 <tt>ulong</tt>, or <tt>long</tt> values, and <a href="#t_struct">structure</a>
1873 types require <tt>uint</tt> <b>constants</b>.</p>
1875 <p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
1876 type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
1877 }</tt>' type, a structure. The second index indexes into the third element of
1878 the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
1879 sbyte }</tt>' type, another structure. The third index indexes into the second
1880 element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
1881 array. The two dimensions of the array are subscripted into, yielding an
1882 '<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction return a pointer
1883 to this element, thus computing a value of '<tt>int*</tt>' type.</p>
1885 <p>Note that it is perfectly legal to index partially through a
1886 structure, returning a pointer to an inner element. Because of this,
1887 the LLVM code for the given testcase is equivalent to:</p>
1890 int* %foo(%ST* %s) {
1891 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
1892 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
1893 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
1894 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
1895 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
1901 <i>; yields [12 x ubyte]*:aptr</i>
1902 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
1906 <!-- ======================================================================= -->
1907 <div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
1908 <div class="doc_text">
1909 <p>The instructions in this category are the "miscellaneous"
1910 instructions, which defy better classification.</p>
1912 <!-- _______________________________________________________________________ -->
1913 <div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
1914 Instruction</a> </div>
1915 <div class="doc_text">
1917 <pre> <result> = phi <ty> [ <val0>, <label0>], ...<br></pre>
1919 <p>The '<tt>phi</tt>' instruction is used to implement the φ node in
1920 the SSA graph representing the function.</p>
1922 <p>The type of the incoming values are specified with the first type
1923 field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
1924 as arguments, with one pair for each predecessor basic block of the
1925 current block. Only values of <a href="#t_firstclass">first class</a>
1926 type may be used as the value arguments to the PHI node. Only labels
1927 may be used as the label arguments.</p>
1928 <p>There must be no non-phi instructions between the start of a basic
1929 block and the PHI instructions: i.e. PHI instructions must be first in
1932 <p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
1933 value specified by the parameter, depending on which basic block we
1934 came from in the last <a href="#terminators">terminator</a> instruction.</p>
1936 <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>
1939 <!-- _______________________________________________________________________ -->
1940 <div class="doc_subsubsection">
1941 <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
1944 <div class="doc_text">
1949 <result> = cast <ty> <value> to <ty2> <i>; yields ty2</i>
1955 The '<tt>cast</tt>' instruction is used as the primitive means to convert
1956 integers to floating point, change data type sizes, and break type safety (by
1964 The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
1965 class value, and a type to cast it to, which must also be a <a
1966 href="#t_firstclass">first class</a> type.
1972 This instruction follows the C rules for explicit casts when determining how the
1973 data being cast must change to fit in its new container.
1977 When casting to bool, any value that would be considered true in the context of
1978 a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
1979 all else are '<tt>false</tt>'.
1983 When extending an integral value from a type of one signness to another (for
1984 example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
1985 <b>source</b> value is signed, and zero-extended if the source value is
1986 unsigned. <tt>bool</tt> values are always zero extended into either zero or
1993 %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
1994 %Y = cast int 123 to bool <i>; yields bool:true</i>
1998 <!-- _______________________________________________________________________ -->
1999 <div class="doc_subsubsection">
2000 <a name="i_select">'<tt>select</tt>' Instruction</a>
2003 <div class="doc_text">
2008 <result> = select bool <cond>, <ty> <val1>, <ty> <val2> <i>; yields ty</i>
2014 The '<tt>select</tt>' instruction is used to choose one value based on a
2015 condition, without branching.
2022 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.
2028 If the boolean condition evaluates to true, the instruction returns the first
2029 value argument, otherwise it returns the second value argument.
2035 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
2043 <!-- _______________________________________________________________________ -->
2044 <div class="doc_subsubsection"> <a name="i_call">'<tt>call</tt>'
2045 Instruction</a> </div>
2046 <div class="doc_text">
2048 <pre> <result> = call <ty>* <fnptrval>(<param list>)<br></pre>
2050 <p>The '<tt>call</tt>' instruction represents a simple function call.</p>
2052 <p>This instruction requires several arguments:</p>
2055 <p>'<tt>ty</tt>': shall be the signature of the pointer to function
2056 value being invoked. The argument types must match the types implied
2057 by this signature.</p>
2060 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a
2061 function to be invoked. In most cases, this is a direct function
2062 invocation, but indirect <tt>call</tt>s are just as possible,
2063 calling an arbitrary pointer to function values.</p>
2066 <p>'<tt>function args</tt>': argument list whose types match the
2067 function signature argument types. All arguments must be of
2068 <a href="#t_firstclass">first class</a> type. If the function signature
2069 indicates the function accepts a variable number of arguments, the extra
2070 arguments can be specified.</p>
2074 <p>The '<tt>call</tt>' instruction is used to cause control flow to
2075 transfer to a specified function, with its incoming arguments bound to
2076 the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
2077 instruction in the called function, control flow continues with the
2078 instruction after the function call, and the return value of the
2079 function is bound to the result argument. This is a simpler case of
2080 the <a href="#i_invoke">invoke</a> instruction.</p>
2082 <pre> %retval = call int %test(int %argc)<br> call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42);<br></pre>
2085 <!-- _______________________________________________________________________ -->
2086 <div class="doc_subsubsection">
2087 <a name="i_vanext">'<tt>vanext</tt>' Instruction</a>
2090 <div class="doc_text">
2095 <resultarglist> = vanext <va_list> <arglist>, <argty>
2100 <p>The '<tt>vanext</tt>' instruction is used to access arguments passed
2101 through the "variable argument" area of a function call. It is used to
2102 implement the <tt>va_arg</tt> macro in C.</p>
2106 <p>This instruction takes a <tt>va_list</tt> value and the type of the
2107 argument. It returns another <tt>va_list</tt>. The actual type of
2108 <tt>va_list</tt> may be defined differently for different targets. Most targets
2109 use a <tt>va_list</tt> type of <tt>sbyte*</tt> or some other pointer type.</p>
2113 <p>The '<tt>vanext</tt>' instruction advances the specified <tt>va_list</tt>
2114 past an argument of the specified type. In conjunction with the <a
2115 href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement
2116 the <tt>va_arg</tt> macro available in C. For more information, see
2117 the variable argument handling <a href="#int_varargs">Intrinsic
2120 <p>It is legal for this instruction to be called in a function which
2121 does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
2124 <p><tt>vanext</tt> is an LLVM instruction instead of an <a
2125 href="#intrinsics">intrinsic function</a> because it takes a type as an
2126 argument. The type refers to the current argument in the <tt>va_list</tt>, it
2127 tells the compiler how far on the stack it needs to advance to find the next
2132 <p>See the <a href="#int_varargs">variable argument processing</a>
2137 <!-- _______________________________________________________________________ -->
2138 <div class="doc_subsubsection">
2139 <a name="i_vaarg">'<tt>vaarg</tt>' Instruction</a>
2142 <div class="doc_text">
2147 <resultval> = vaarg <va_list> <arglist>, <argty>
2152 <p>The '<tt>vaarg</tt>' instruction is used to access arguments passed through
2153 the "variable argument" area of a function call. It is used to implement the
2154 <tt>va_arg</tt> macro in C.</p>
2158 <p>This instruction takes a <tt>va_list</tt> value and the type of the
2159 argument. It returns a value of the specified argument type. Again, the actual
2160 type of <tt>va_list</tt> is target specific.</p>
2164 <p>The '<tt>vaarg</tt>' instruction loads an argument of the specified type from
2165 the specified <tt>va_list</tt>. In conjunction with the <a
2166 href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to implement the
2167 <tt>va_arg</tt> macro available in C. For more information, see the variable
2168 argument handling <a href="#int_varargs">Intrinsic Functions</a>.</p>
2170 <p>It is legal for this instruction to be called in a function which does not
2171 take a variable number of arguments, for example, the <tt>vfprintf</tt>
2174 <p><tt>vaarg</tt> is an LLVM instruction instead of an <a
2175 href="#intrinsics">intrinsic function</a> because it takes an type as an
2180 <p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
2184 <!-- *********************************************************************** -->
2185 <div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
2186 <!-- *********************************************************************** -->
2188 <div class="doc_text">
2190 <p>LLVM supports the notion of an "intrinsic function". These functions have
2191 well known names and semantics, and are required to follow certain
2192 restrictions. Overall, these instructions represent an extension mechanism for
2193 the LLVM language that does not require changing all of the transformations in
2194 LLVM to add to the language (or the bytecode reader/writer, the parser,
2197 <p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix, this
2198 prefix is reserved in LLVM for intrinsic names, thus functions may not be named
2199 this. Intrinsic functions must always be external functions: you cannot define
2200 the body of intrinsic functions. Intrinsic functions may only be used in call
2201 or invoke instructions: it is illegal to take the address of an intrinsic
2202 function. Additionally, because intrinsic functions are part of the LLVM
2203 language, it is required that they all be documented here if any are added.</p>
2207 Adding an intrinsic to LLVM is straight-forward if it is possible to express the
2208 concept in LLVM directly (ie, code generator support is not _required_). To do
2209 this, extend the default implementation of the IntrinsicLowering class to handle
2210 the intrinsic. Code generators use this class to lower intrinsics they do not
2211 understand to raw LLVM instructions that they do.
2216 <!-- ======================================================================= -->
2217 <div class="doc_subsection">
2218 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
2221 <div class="doc_text">
2223 <p>Variable argument support is defined in LLVM with the <a
2224 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
2225 intrinsic functions. These functions are related to the similarly
2226 named macros defined in the <tt><stdarg.h></tt> header file.</p>
2228 <p>All of these functions operate on arguments that use a
2229 target-specific value type "<tt>va_list</tt>". The LLVM assembly
2230 language reference manual does not define what this type is, so all
2231 transformations should be prepared to handle intrinsics with any type
2234 <p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
2235 instruction and the variable argument handling intrinsic functions are
2239 int %test(int %X, ...) {
2240 ; Initialize variable argument processing
2241 %ap = call sbyte* %<a href="#i_va_start">llvm.va_start</a>()
2243 ; Read a single integer argument
2244 %tmp = vaarg sbyte* %ap, int
2246 ; Advance to the next argument
2247 %ap2 = vanext sbyte* %ap, int
2249 ; Demonstrate usage of llvm.va_copy and llvm.va_end
2250 %aq = call sbyte* %<a href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2)
2251 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %aq)
2253 ; Stop processing of arguments.
2254 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %ap2)
2260 <!-- _______________________________________________________________________ -->
2261 <div class="doc_subsubsection">
2262 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
2266 <div class="doc_text">
2268 <pre> declare <va_list> %llvm.va_start()<br></pre>
2270 <p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt><arglist></tt>
2271 for subsequent use by the variable argument intrinsics.</p>
2273 <p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
2274 macro available in C. In a target-dependent way, it initializes and
2275 returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt>
2276 will produce the first variable argument passed to the function. Unlike
2277 the C <tt>va_start</tt> macro, this intrinsic does not need to know the
2278 last argument of the function, the compiler can figure that out.</p>
2279 <p>Note that this intrinsic function is only legal to be called from
2280 within the body of a variable argument function.</p>
2283 <!-- _______________________________________________________________________ -->
2284 <div class="doc_subsubsection">
2285 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
2288 <div class="doc_text">
2290 <pre> declare void %llvm.va_end(<va_list> <arglist>)<br></pre>
2292 <p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt><arglist></tt>
2293 which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
2294 or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
2296 <p>The argument is a <tt>va_list</tt> to destroy.</p>
2298 <p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
2299 macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
2300 Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
2301 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
2302 with calls to <tt>llvm.va_end</tt>.</p>
2305 <!-- _______________________________________________________________________ -->
2306 <div class="doc_subsubsection">
2307 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
2310 <div class="doc_text">
2315 declare <va_list> %llvm.va_copy(<va_list> <destarglist>)
2320 <p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position
2321 from the source argument list to the destination argument list.</p>
2325 <p>The argument is the <tt>va_list</tt> to copy.</p>
2329 <p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
2330 macro available in C. In a target-dependent way, it copies the source
2331 <tt>va_list</tt> element into the returned list. This intrinsic is necessary
2332 because the <tt><a href="#i_va_start">llvm.va_start</a></tt> intrinsic may be
2333 arbitrarily complex and require memory allocation, for example.</p>
2337 <!-- ======================================================================= -->
2338 <div class="doc_subsection">
2339 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
2342 <div class="doc_text">
2345 LLVM support for <a href="GarbageCollection.html">Accurate Garbage
2346 Collection</a> requires the implementation and generation of these intrinsics.
2347 These intrinsics allow identification of <a href="#i_gcroot">GC roots on the
2348 stack</a>, as well as garbage collector implementations that require <a
2349 href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers.
2350 Front-ends for type-safe garbage collected languages should generate these
2351 intrinsics to make use of the LLVM garbage collectors. For more details, see <a
2352 href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
2356 <!-- _______________________________________________________________________ -->
2357 <div class="doc_subsubsection">
2358 <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
2361 <div class="doc_text">
2366 declare void %llvm.gcroot(<ty>** %ptrloc, <ty2>* %metadata)
2371 <p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
2372 the code generator, and allows some metadata to be associated with it.</p>
2376 <p>The first argument specifies the address of a stack object that contains the
2377 root pointer. The second pointer (which must be either a constant or a global
2378 value address) contains the meta-data to be associated with the root.</p>
2382 <p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
2383 location. At compile-time, the code generator generates information to allow
2384 the runtime to find the pointer at GC safe points.
2390 <!-- _______________________________________________________________________ -->
2391 <div class="doc_subsubsection">
2392 <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
2395 <div class="doc_text">
2400 declare sbyte* %llvm.gcread(sbyte** %Ptr)
2405 <p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
2406 locations, allowing garbage collector implementations that require read
2411 <p>The argument is the address to read from, which should be an address
2412 allocated from the garbage collector.</p>
2416 <p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
2417 instruction, but may be replaced with substantially more complex code by the
2418 garbage collector runtime, as needed.</p>
2423 <!-- _______________________________________________________________________ -->
2424 <div class="doc_subsubsection">
2425 <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
2428 <div class="doc_text">
2433 declare void %llvm.gcwrite(sbyte* %P1, sbyte** %P2)
2438 <p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
2439 locations, allowing garbage collector implementations that require write
2440 barriers (such as generational or reference counting collectors).</p>
2444 <p>The first argument is the reference to store, and the second is the heap
2445 location to store to.</p>
2449 <p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
2450 instruction, but may be replaced with substantially more complex code by the
2451 garbage collector runtime, as needed.</p>
2457 <!-- ======================================================================= -->
2458 <div class="doc_subsection">
2459 <a name="int_codegen">Code Generator Intrinsics</a>
2462 <div class="doc_text">
2464 These intrinsics are provided by LLVM to expose special features that may only
2465 be implemented with code generator support.
2470 <!-- _______________________________________________________________________ -->
2471 <div class="doc_subsubsection">
2472 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
2475 <div class="doc_text">
2479 declare void* %llvm.returnaddress(uint <level>)
2485 The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
2486 indicating the return address of the current function or one of its callers.
2492 The argument to this intrinsic indicates which function to return the address
2493 for. Zero indicates the calling function, one indicates its caller, etc. The
2494 argument is <b>required</b> to be a constant integer value.
2500 The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
2501 the return address of the specified call frame, or zero if it cannot be
2502 identified. The value returned by this intrinsic is likely to be incorrect or 0
2503 for arguments other than zero, so it should only be used for debugging purposes.
2507 Note that calling this intrinsic does not prevent function inlining or other
2508 aggressive transformations, so the value returned may not be that of the obvious
2509 source-language caller.
2514 <!-- _______________________________________________________________________ -->
2515 <div class="doc_subsubsection">
2516 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
2519 <div class="doc_text">
2523 declare void* %llvm.frameaddress(uint <level>)
2529 The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
2530 pointer value for the specified stack frame.
2536 The argument to this intrinsic indicates which function to return the frame
2537 pointer for. Zero indicates the calling function, one indicates its caller,
2538 etc. The argument is <b>required</b> to be a constant integer value.
2544 The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
2545 the frame address of the specified call frame, or zero if it cannot be
2546 identified. The value returned by this intrinsic is likely to be incorrect or 0
2547 for arguments other than zero, so it should only be used for debugging purposes.
2551 Note that calling this intrinsic does not prevent function inlining or other
2552 aggressive transformations, so the value returned may not be that of the obvious
2553 source-language caller.
2557 <!-- _______________________________________________________________________ -->
2558 <div class="doc_subsubsection">
2559 <a name="i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a>
2562 <div class="doc_text">
2566 declare void %llvm.prefetch(sbyte * <address>,
2567 uint <rw>, uint <locality>)
2574 The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to insert
2575 a prefetch instruction if supported, otherwise it is a noop. Prefetches have no
2576 effect on the behavior of the program, but can change its performance
2583 <tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier
2584 determining if the fetch should be for a read (0) or write (1), and
2585 <tt>locality</tt> is a temporal locality specifier ranging from (0) - no
2586 locality, to (3) - extremely local keep in cache. The <tt>rw</tt> and
2587 <tt>locality</tt> arguments must be constant integers.
2593 This intrinsic does not modify the behavior of the program. In particular,
2594 prefetches cannot trap and do not produce a value. On targets that support this
2595 intrinsic, the prefetch can provide hints to the processor cache for better
2601 <!-- _______________________________________________________________________ -->
2602 <div class="doc_subsubsection">
2603 <a name="i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a>
2606 <div class="doc_text">
2610 declare void %llvm.pcmarker( uint <id> )
2617 The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a PC in a region of
2618 code to simulators and other tools. The method is target specific, but it is
2619 expected that the marker will use exported symbols to transmit the PC of the marker.
2620 The marker makes no guaranties that it will remain with any specific instruction
2621 after optimizations. It is possible that the presense of a marker will inhibit
2622 optimizations. The intended use is to be inserted after optmizations to allow
2623 corrolations of simulation runs.
2629 <tt>id</tt> is a numerical id identifying the marker.
2635 This intrinsic does not modify the behavior of the program. Backends that do not
2636 support this intrinisic may ignore it.
2642 <!-- ======================================================================= -->
2643 <div class="doc_subsection">
2644 <a name="int_os">Operating System Intrinsics</a>
2647 <div class="doc_text">
2649 These intrinsics are provided by LLVM to support the implementation of
2650 operating system level code.
2655 <!-- _______________________________________________________________________ -->
2656 <div class="doc_subsubsection">
2657 <a name="i_readport">'<tt>llvm.readport</tt>' Intrinsic</a>
2660 <div class="doc_text">
2664 declare <integer type> %llvm.readport (<integer type> <address>)
2670 The '<tt>llvm.readport</tt>' intrinsic reads data from the specified hardware
2677 The argument to this intrinsic indicates the hardware I/O address from which
2678 to read the data. The address is in the hardware I/O address namespace (as
2679 opposed to being a memory location for memory mapped I/O).
2685 The '<tt>llvm.readport</tt>' intrinsic reads data from the hardware I/O port
2686 specified by <i>address</i> and returns the value. The address and return
2687 value must be integers, but the size is dependent upon the platform upon which
2688 the program is code generated. For example, on x86, the address must be an
2689 unsigned 16-bit value, and the return value must be 8, 16, or 32 bits.
2694 <!-- _______________________________________________________________________ -->
2695 <div class="doc_subsubsection">
2696 <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a>
2699 <div class="doc_text">
2703 call void (<integer type>, <integer type>)*
2704 %llvm.writeport (<integer type> <value>,
2705 <integer type> <address>)
2711 The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified hardware
2718 The first argument is the value to write to the I/O port.
2722 The second argument indicates the hardware I/O address to which data should be
2723 written. The address is in the hardware I/O address namespace (as opposed to
2724 being a memory location for memory mapped I/O).
2730 The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port
2731 specified by <i>address</i>. The address and value must be integers, but the
2732 size is dependent upon the platform upon which the program is code generated.
2733 For example, on x86, the address must be an unsigned 16-bit value, and the
2734 value written must be 8, 16, or 32 bits in length.
2739 <!-- _______________________________________________________________________ -->
2740 <div class="doc_subsubsection">
2741 <a name="i_readio">'<tt>llvm.readio</tt>' Intrinsic</a>
2744 <div class="doc_text">
2748 declare <result> %llvm.readio (<ty> * <pointer>)
2754 The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
2761 The argument to this intrinsic is a pointer indicating the memory address from
2762 which to read the data. The data must be a
2763 <a href="#t_firstclass">first class</a> type.
2769 The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
2770 location specified by <i>pointer</i> and returns the value. The argument must
2771 be a pointer, and the return value must be a
2772 <a href="#t_firstclass">first class</a> type. However, certain architectures
2773 may not support I/O on all first class types. For example, 32-bit processors
2774 may only support I/O on data types that are 32 bits or less.
2778 This intrinsic enforces an in-order memory model for llvm.readio and
2779 llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2780 scheduled processors may execute loads and stores out of order, re-ordering at
2781 run time accesses to memory mapped I/O registers. Using these intrinsics
2782 ensures that accesses to memory mapped I/O registers occur in program order.
2787 <!-- _______________________________________________________________________ -->
2788 <div class="doc_subsubsection">
2789 <a name="i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a>
2792 <div class="doc_text">
2796 declare void %llvm.writeio (<ty1> <value>, <ty2> * <pointer>)
2802 The '<tt>llvm.writeio</tt>' intrinsic writes data to the specified memory
2809 The first argument is the value to write to the memory mapped I/O location.
2810 The second argument is a pointer indicating the memory address to which the
2811 data should be written.
2817 The '<tt>llvm.writeio</tt>' intrinsic writes <i>value</i> to the memory mapped
2818 I/O address specified by <i>pointer</i>. The value must be a
2819 <a href="#t_firstclass">first class</a> type. However, certain architectures
2820 may not support I/O on all first class types. For example, 32-bit processors
2821 may only support I/O on data types that are 32 bits or less.
2825 This intrinsic enforces an in-order memory model for llvm.readio and
2826 llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2827 scheduled processors may execute loads and stores out of order, re-ordering at
2828 run time accesses to memory mapped I/O registers. Using these intrinsics
2829 ensures that accesses to memory mapped I/O registers occur in program order.
2834 <!-- ======================================================================= -->
2835 <div class="doc_subsection">
2836 <a name="int_libc">Standard C Library Intrinsics</a>
2839 <div class="doc_text">
2841 LLVM provides intrinsics for a few important standard C library functions.
2842 These intrinsics allow source-language front-ends to pass information about the
2843 alignment of the pointer arguments to the code generator, providing opportunity
2844 for more efficient code generation.
2849 <!-- _______________________________________________________________________ -->
2850 <div class="doc_subsubsection">
2851 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
2854 <div class="doc_text">
2858 declare void %llvm.memcpy(sbyte* <dest>, sbyte* <src>,
2859 uint <len>, uint <align>)
2865 The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2866 location to the destination location.
2870 Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
2871 does not return a value, and takes an extra alignment argument.
2877 The first argument is a pointer to the destination, the second is a pointer to
2878 the source. The third argument is an (arbitrarily sized) integer argument
2879 specifying the number of bytes to copy, and the fourth argument is the alignment
2880 of the source and destination locations.
2884 If the call to this intrinisic has an alignment value that is not 0 or 1, then
2885 the caller guarantees that the size of the copy is a multiple of the alignment
2886 and that both the source and destination pointers are aligned to that boundary.
2892 The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2893 location to the destination location, which are not allowed to overlap. It
2894 copies "len" bytes of memory over. If the argument is known to be aligned to
2895 some boundary, this can be specified as the fourth argument, otherwise it should
2901 <!-- _______________________________________________________________________ -->
2902 <div class="doc_subsubsection">
2903 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
2906 <div class="doc_text">
2910 declare void %llvm.memmove(sbyte* <dest>, sbyte* <src>,
2911 uint <len>, uint <align>)
2917 The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
2918 location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>'
2919 intrinsic but allows the two memory locations to overlap.
2923 Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
2924 does not return a value, and takes an extra alignment argument.
2930 The first argument is a pointer to the destination, the second is a pointer to
2931 the source. The third argument is an (arbitrarily sized) integer argument
2932 specifying the number of bytes to copy, and the fourth argument is the alignment
2933 of the source and destination locations.
2937 If the call to this intrinisic has an alignment value that is not 0 or 1, then
2938 the caller guarantees that the size of the copy is a multiple of the alignment
2939 and that both the source and destination pointers are aligned to that boundary.
2945 The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
2946 location to the destination location, which may overlap. It
2947 copies "len" bytes of memory over. If the argument is known to be aligned to
2948 some boundary, this can be specified as the fourth argument, otherwise it should
2954 <!-- _______________________________________________________________________ -->
2955 <div class="doc_subsubsection">
2956 <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a>
2959 <div class="doc_text">
2963 declare void %llvm.memset(sbyte* <dest>, ubyte <val>,
2964 uint <len>, uint <align>)
2970 The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular
2975 Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
2976 does not return a value, and takes an extra alignment argument.
2982 The first argument is a pointer to the destination to fill, the second is the
2983 byte value to fill it with, the third argument is an (arbitrarily sized) integer
2984 argument specifying the number of bytes to fill, and the fourth argument is the
2985 known alignment of destination location.
2989 If the call to this intrinisic has an alignment value that is not 0 or 1, then
2990 the caller guarantees that the size of the copy is a multiple of the alignment
2991 and that the destination pointer is aligned to that boundary.
2997 The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the
2998 destination location. If the argument is known to be aligned to some boundary,
2999 this can be specified as the fourth argument, otherwise it should be set to 0 or
3005 <!-- _______________________________________________________________________ -->
3006 <div class="doc_subsubsection">
3007 <a name="i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a>
3010 <div class="doc_text">
3014 declare bool %llvm.isunordered(<float or double> Val1, <float or double> Val2)
3020 The '<tt>llvm.isunordered</tt>' intrinsic returns true if either or both of the
3021 specified floating point values is a NAN.
3027 The arguments are floating point numbers of the same type.
3033 If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise
3039 <!-- ======================================================================= -->
3040 <div class="doc_subsection">
3041 <a name="int_count">Bit Counting Intrinsics</a>
3044 <div class="doc_text">
3046 LLVM provides intrinsics for a few important bit counting operations.
3047 These allow efficient code generation for some algorithms.
3052 <!-- _______________________________________________________________________ -->
3053 <div class="doc_subsubsection">
3054 <a name="int_ctpop">'<tt>llvm.ctpop</tt>' Intrinsic</a>
3057 <div class="doc_text">
3061 declare int %llvm.ctpop(int <src>)
3068 The '<tt>llvm.ctpop</tt>' intrinsic counts the number of ones in a variable.
3074 The only argument is the value to be counted. The argument may be of any integer type.
3080 The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable.
3084 <!-- _______________________________________________________________________ -->
3085 <div class="doc_subsubsection">
3086 <a name="int_cttz">'<tt>llvm.cttz</tt>' Intrinsic</a>
3089 <div class="doc_text">
3093 declare int %llvm.cttz(int <src>)
3100 The '<tt>llvm.cttz</tt>' intrinsic counts the number of trailing zeros.
3106 The only argument is the value to be counted. The argument may be of any integer type.
3112 The '<tt>llvm.cttz</tt>' intrinsic counts the trailing zeros in a variable. If the src == 0
3113 then the result is the size in bits of the type of src.
3117 <!-- _______________________________________________________________________ -->
3118 <div class="doc_subsubsection">
3119 <a name="int_ctlz">'<tt>llvm.ctlz</tt>' Intrinsic</a>
3122 <div class="doc_text">
3126 declare int %llvm.ctlz(int <src>)
3133 The '<tt>llvm.ctlz</tt>' intrinsic counts the number of leading zeros in a variable.
3139 The only argument is the value to be counted. The argument may be of any integer type.
3145 The '<tt>llvm.ctlz</tt>' intrinsic counts the leading zeros in a variable. If the src == 0
3146 then the result is the size in bits of the type of src.
3151 <!-- ======================================================================= -->
3152 <div class="doc_subsection">
3153 <a name="int_debugger">Debugger Intrinsics</a>
3156 <div class="doc_text">
3158 The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
3159 are described in the <a
3160 href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
3161 Debugging</a> document.
3166 <!-- *********************************************************************** -->
3169 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
3170 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
3171 <a href="http://validator.w3.org/check/referer"><img
3172 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
3174 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
3175 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
3176 Last modified: $Date$