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 <link rel="stylesheet" href="llvm.css" type="text/css">
9 <div class="doc_title"> LLVM Language Reference Manual </div>
11 <li><a href="#abstract">Abstract</a></li>
12 <li><a href="#introduction">Introduction</a></li>
13 <li><a href="#identifiers">Identifiers</a></li>
14 <li><a href="#typesystem">Type System</a>
16 <li><a href="#t_primitive">Primitive Types</a>
18 <li><a href="#t_classifications">Type Classifications</a></li>
21 <li><a href="#t_derived">Derived Types</a>
23 <li><a href="#t_array">Array Type</a></li>
24 <li><a href="#t_function">Function Type</a></li>
25 <li><a href="#t_pointer">Pointer Type</a></li>
26 <li><a href="#t_struct">Structure Type</a></li>
27 <!-- <li><a href="#t_packed" >Packed Type</a> -->
32 <li><a href="#highlevel">High Level Structure</a>
34 <li><a href="#modulestructure">Module Structure</a></li>
35 <li><a href="#globalvars">Global Variables</a></li>
36 <li><a href="#functionstructure">Function Structure</a></li>
39 <li><a href="#instref">Instruction Reference</a>
41 <li><a href="#terminators">Terminator Instructions</a>
43 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
44 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
45 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
46 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
47 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
50 <li><a href="#binaryops">Binary Operations</a>
52 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
53 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
54 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
55 <li><a href="#i_div">'<tt>div</tt>' Instruction</a></li>
56 <li><a href="#i_rem">'<tt>rem</tt>' Instruction</a></li>
57 <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li>
60 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
62 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
63 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
64 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
65 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
66 <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a></li>
69 <li><a href="#memoryops">Memory Access Operations</a>
71 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
72 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
73 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
74 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
75 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
76 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
79 <li><a href="#otherops">Other Operations</a>
81 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
82 <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li>
83 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
84 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
85 <li><a href="#i_vanext">'<tt>vanext</tt>' Instruction</a></li>
86 <li><a href="#i_vaarg">'<tt>vaarg</tt>' Instruction</a></li>
91 <li><a href="#intrinsics">Intrinsic Functions</a>
93 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
95 <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
96 <li><a href="#i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
97 <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
100 <li><a href="#int_codegen">Code Generator Intrinsics</a>
102 <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
103 <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
104 <li><a href="#i_readport">'<tt>llvm.readport</tt>' Intrinsic</a></li>
105 <li><a href="#i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a></li>
108 <li><a href="#int_libc">Standard C Library Intrinsics</a>
110 <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li>
111 <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li>
112 <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li>
115 <li><a href="#int_debugger">Debugger intrinsics</a>
119 <div class="doc_text">
120 <p><b>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
121 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></b></p>
124 <!-- *********************************************************************** -->
125 <div class="doc_section"> <a name="abstract">Abstract </a></div>
126 <!-- *********************************************************************** -->
127 <div class="doc_text">
128 <p>This document is a reference manual for the LLVM assembly language.
129 LLVM is an SSA based representation that provides type safety,
130 low-level operations, flexibility, and the capability of representing
131 'all' high-level languages cleanly. It is the common code
132 representation used throughout all phases of the LLVM compilation
135 <!-- *********************************************************************** -->
136 <div class="doc_section"> <a name="introduction">Introduction</a> </div>
137 <!-- *********************************************************************** -->
138 <div class="doc_text">
139 <p>The LLVM code representation is designed to be used in three
140 different forms: as an in-memory compiler IR, as an on-disk bytecode
141 representation (suitable for fast loading by a Just-In-Time compiler),
142 and as a human readable assembly language representation. This allows
143 LLVM to provide a powerful intermediate representation for efficient
144 compiler transformations and analysis, while providing a natural means
145 to debug and visualize the transformations. The three different forms
146 of LLVM are all equivalent. This document describes the human readable
147 representation and notation.</p>
148 <p>The LLVM representation aims to be a light-weight and low-level
149 while being expressive, typed, and extensible at the same time. It
150 aims to be a "universal IR" of sorts, by being at a low enough level
151 that high-level ideas may be cleanly mapped to it (similar to how
152 microprocessors are "universal IR's", allowing many source languages to
153 be mapped to them). By providing type information, LLVM can be used as
154 the target of optimizations: for example, through pointer analysis, it
155 can be proven that a C automatic variable is never accessed outside of
156 the current function... allowing it to be promoted to a simple SSA
157 value instead of a memory location.</p>
159 <!-- _______________________________________________________________________ -->
160 <div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
161 <div class="doc_text">
162 <p>It is important to note that this document describes 'well formed'
163 LLVM assembly language. There is a difference between what the parser
164 accepts and what is considered 'well formed'. For example, the
165 following instruction is syntactically okay, but not well formed:</p>
166 <pre> %x = <a href="#i_add">add</a> int 1, %x<br></pre>
167 <p>...because the definition of <tt>%x</tt> does not dominate all of
168 its uses. The LLVM infrastructure provides a verification pass that may
169 be used to verify that an LLVM module is well formed. This pass is
170 automatically run by the parser after parsing input assembly, and by
171 the optimizer before it outputs bytecode. The violations pointed out
172 by the verifier pass indicate bugs in transformation passes or input to
174 <!-- Describe the typesetting conventions here. --> </div>
175 <!-- *********************************************************************** -->
176 <div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
177 <!-- *********************************************************************** -->
178 <div class="doc_text">
179 <p>LLVM uses three different forms of identifiers, for different
182 <li>Numeric constants are represented as you would expect: 12, -3
183 123.421, etc. Floating point constants have an optional hexidecimal
185 <li>Named values are represented as a string of characters with a '%'
186 prefix. For example, %foo, %DivisionByZero,
187 %a.really.long.identifier. The actual regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
188 Identifiers which require other characters in their names can be
189 surrounded with quotes. In this way, anything except a <tt>"</tt>
190 character can be used in a name.</li>
191 <li>Unnamed values are represented as an unsigned numeric value with
192 a '%' prefix. For example, %12, %2, %44.</li>
194 <p>LLVM requires that values start with a '%' sign for two reasons:
195 Compilers don't need to worry about name clashes with reserved words,
196 and the set of reserved words may be expanded in the future without
197 penalty. Additionally, unnamed identifiers allow a compiler to quickly
198 come up with a temporary variable without having to avoid symbol table
200 <p>Reserved words in LLVM are very similar to reserved words in other
201 languages. There are keywords for different opcodes ('<tt><a
202 href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
203 href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
204 href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>',
205 etc...), and others. These reserved words cannot conflict with
206 variable names, because none of them start with a '%' character.</p>
207 <p>Here is an example of LLVM code to multiply the integer variable '<tt>%X</tt>'
210 <pre> %result = <a href="#i_mul">mul</a> uint %X, 8<br></pre>
211 <p>After strength reduction:</p>
212 <pre> %result = <a href="#i_shl">shl</a> uint %X, ubyte 3<br></pre>
213 <p>And the hard way:</p>
214 <pre> <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
216 href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
218 href="#i_add">add</a> uint %1, %1<br></pre>
219 <p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
220 important lexical features of LLVM:</p>
222 <li>Comments are delimited with a '<tt>;</tt>' and go until the end
224 <li>Unnamed temporaries are created when the result of a computation
225 is not assigned to a named value.</li>
226 <li>Unnamed temporaries are numbered sequentially</li>
228 <p>...and it also show a convention that we follow in this document.
229 When demonstrating instructions, we will follow an instruction with a
230 comment that defines the type and name of value produced. Comments are
231 shown in italic text.</p>
232 <p>The one non-intuitive notation for constants is the optional
233 hexidecimal form of floating point constants. For example, the form '<tt>double
234 0x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
235 4.5e+15</tt>' which is also supported by the parser. The only time
236 hexadecimal floating point constants are useful (and the only time that
237 they are generated by the disassembler) is when an FP constant has to
238 be emitted that is not representable as a decimal floating point number
239 exactly. For example, NaN's, infinities, and other special cases are
240 represented in their IEEE hexadecimal format so that assembly and
241 disassembly do not cause any bits to change in the constants.</p>
243 <!-- *********************************************************************** -->
244 <div class="doc_section"> <a name="typesystem">Type System</a> </div>
245 <!-- *********************************************************************** -->
246 <div class="doc_text">
247 <p>The LLVM type system is one of the most important features of the
248 intermediate representation. Being typed enables a number of
249 optimizations to be performed on the IR directly, without having to do
250 extra analyses on the side before the transformation. A strong type
251 system makes it easier to read the generated code and enables novel
252 analyses and transformations that are not feasible to perform on normal
253 three address code representations.</p>
254 <!-- The written form for the type system was heavily influenced by the
255 syntactic problems with types in the C language<sup><a
256 href="#rw_stroustrup">1</a></sup>.<p> --> </div>
257 <!-- ======================================================================= -->
258 <div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
259 <div class="doc_text">
260 <p>The primitive types are the fundemental building blocks of the LLVM
261 system. The current set of primitive types are as follows:</p>
263 <table border="0" style="align: center">
267 <table border="1" cellspacing="0" cellpadding="4" style="align: center">
270 <td><tt>void</tt></td>
274 <td><tt>ubyte</tt></td>
275 <td>Unsigned 8 bit value</td>
278 <td><tt>ushort</tt></td>
279 <td>Unsigned 16 bit value</td>
282 <td><tt>uint</tt></td>
283 <td>Unsigned 32 bit value</td>
286 <td><tt>ulong</tt></td>
287 <td>Unsigned 64 bit value</td>
290 <td><tt>float</tt></td>
291 <td>32 bit floating point value</td>
294 <td><tt>label</tt></td>
295 <td>Branch destination</td>
301 <table border="1" cellspacing="0" cellpadding="4">
304 <td><tt>bool</tt></td>
305 <td>True or False value</td>
308 <td><tt>sbyte</tt></td>
309 <td>Signed 8 bit value</td>
312 <td><tt>short</tt></td>
313 <td>Signed 16 bit value</td>
316 <td><tt>int</tt></td>
317 <td>Signed 32 bit value</td>
320 <td><tt>long</tt></td>
321 <td>Signed 64 bit value</td>
324 <td><tt>double</tt></td>
325 <td>64 bit floating point value</td>
335 <!-- _______________________________________________________________________ -->
336 <div class="doc_subsubsection"> <a name="t_classifications">Type
337 Classifications</a> </div>
338 <div class="doc_text">
339 <p>These different primitive types fall into a few useful
342 <table border="1" cellspacing="0" cellpadding="4">
345 <td><a name="t_signed">signed</a></td>
346 <td><tt>sbyte, short, int, long, float, double</tt></td>
349 <td><a name="t_unsigned">unsigned</a></td>
350 <td><tt>ubyte, ushort, uint, ulong</tt></td>
353 <td><a name="t_integer">integer</a></td>
354 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
357 <td><a name="t_integral">integral</a></td>
358 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
361 <td><a name="t_floating">floating point</a></td>
362 <td><tt>float, double</tt></td>
365 <td><a name="t_firstclass">first class</a></td>
366 <td><tt>bool, ubyte, sbyte, ushort, short,<br>
367 uint, int, ulong, long, float, double, <a href="#t_pointer">pointer</a></tt></td>
372 <p>The <a href="#t_firstclass">first class</a> types are perhaps the
373 most important. Values of these types are the only ones which can be
374 produced by instructions, passed as arguments, or used as operands to
375 instructions. This means that all structures and arrays must be
376 manipulated either by pointer or by component.</p>
378 <!-- ======================================================================= -->
379 <div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
380 <div class="doc_text">
381 <p>The real power in LLVM comes from the derived types in the system.
382 This is what allows a programmer to represent arrays, functions,
383 pointers, and other useful types. Note that these derived types may be
384 recursive: For example, it is possible to have a two dimensional array.</p>
386 <!-- _______________________________________________________________________ -->
387 <div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
388 <div class="doc_text">
390 <p>The array type is a very simple derived type that arranges elements
391 sequentially in memory. The array type requires a size (number of
392 elements) and an underlying data type.</p>
394 <pre> [<# elements> x <elementtype>]<br></pre>
395 <p>The number of elements is a constant integer value, elementtype may
396 be any type with a size.</p>
398 <p> <tt>[40 x int ]</tt>: Array of 40 integer values.<br>
399 <tt>[41 x int ]</tt>: Array of 41 integer values.<br>
400 <tt>[40 x uint]</tt>: Array of 40 unsigned integer values.</p>
402 <p>Here are some examples of multidimensional arrays:</p>
404 <table border="0" cellpadding="0" cellspacing="0">
407 <td><tt>[3 x [4 x int]]</tt></td>
408 <td>: 3x4 array integer values.</td>
411 <td><tt>[12 x [10 x float]]</tt></td>
412 <td>: 12x10 array of single precision floating point values.</td>
415 <td><tt>[2 x [3 x [4 x uint]]]</tt></td>
416 <td>: 2x3x4 array of unsigned integer values.</td>
422 <!-- _______________________________________________________________________ -->
423 <div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
424 <div class="doc_text">
426 <p>The function type can be thought of as a function signature. It
427 consists of a return type and a list of formal parameter types.
428 Function types are usually used to build virtual function tables
429 (which are structures of pointers to functions), for indirect function
430 calls, and when defining a function.</p>
432 The return type of a function type cannot be an aggregate type.
435 <pre> <returntype> (<parameter list>)<br></pre>
436 <p>Where '<tt><parameter list></tt>' is a comma-separated list of
437 type specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
438 which indicates that the function takes a variable number of arguments.
439 Variable argument functions can access their arguments with the <a
440 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
443 <table border="0" cellpadding="0" cellspacing="0">
446 <td><tt>int (int)</tt></td>
447 <td>: function taking an <tt>int</tt>, returning an <tt>int</tt></td>
450 <td><tt>float (int, int *) *</tt></td>
451 <td>: <a href="#t_pointer">Pointer</a> to a function that takes
452 an <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
453 returning <tt>float</tt>.</td>
456 <td><tt>int (sbyte *, ...)</tt></td>
457 <td>: A vararg function that takes at least one <a
458 href="#t_pointer">pointer</a> to <tt>sbyte</tt> (signed char in C),
459 which returns an integer. This is the signature for <tt>printf</tt>
466 <!-- _______________________________________________________________________ -->
467 <div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
468 <div class="doc_text">
470 <p>The structure type is used to represent a collection of data members
471 together in memory. The packing of the field types is defined to match
472 the ABI of the underlying processor. The elements of a structure may
473 be any type that has a size.</p>
474 <p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
475 and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
476 field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
479 <pre> { <type list> }<br></pre>
482 <table border="0" cellpadding="0" cellspacing="0">
485 <td><tt>{ int, int, int }</tt></td>
486 <td>: a triple of three <tt>int</tt> values</td>
489 <td><tt>{ float, int (int) * }</tt></td>
490 <td>: A pair, where the first element is a <tt>float</tt> and the
491 second element is a <a href="#t_pointer">pointer</a> to a <a
492 href="t_function">function</a> that takes an <tt>int</tt>, returning
493 an <tt>int</tt>.</td>
499 <!-- _______________________________________________________________________ -->
500 <div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
501 <div class="doc_text">
503 <p>As in many languages, the pointer type represents a pointer or
504 reference to another object, which must live in memory.</p>
506 <pre> <type> *<br></pre>
509 <table border="0" cellpadding="0" cellspacing="0">
512 <td><tt>[4x int]*</tt></td>
513 <td>: <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a>
514 of four <tt>int</tt> values</td>
517 <td><tt>int (int *) *</tt></td>
518 <td>: A <a href="#t_pointer">pointer</a> to a <a
519 href="t_function">function</a> that takes an <tt>int</tt>, returning
520 an <tt>int</tt>.</td>
526 <!-- _______________________________________________________________________ --><!--
527 <div class="doc_subsubsection">
528 <a name="t_packed">Packed Type</a>
531 <div class="doc_text">
533 Mention/decide that packed types work with saturation or not. Maybe have a packed+saturated type in addition to just a packed type.<p>
535 Packed types should be 'nonsaturated' because standard data types are not saturated. Maybe have a saturated packed type?<p>
539 --><!-- *********************************************************************** -->
540 <div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
541 <!-- *********************************************************************** --><!-- ======================================================================= -->
542 <div class="doc_subsection"> <a name="modulestructure">Module Structure</a> </div>
543 <div class="doc_text">
544 <p>LLVM programs are composed of "Module"s, each of which is a
545 translation unit of the input programs. Each module consists of
546 functions, global variables, and symbol table entries. Modules may be
547 combined together with the LLVM linker, which merges function (and
548 global variable) definitions, resolves forward declarations, and merges
549 symbol table entries. Here is an example of the "hello world" module:</p>
550 <pre><i>; Declare the string constant as a global constant...</i>
551 <a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
552 href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00" <i>; [13 x sbyte]*</i>
554 <i>; External declaration of the puts function</i>
555 <a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
557 <i>; Definition of main function</i>
558 int %main() { <i>; int()* </i>
559 <i>; Convert [13x sbyte]* to sbyte *...</i>
561 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
563 <i>; Call puts function to write out the string to stdout...</i>
565 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
567 href="#i_ret">ret</a> int 0<br>}<br></pre>
568 <p>This example is made up of a <a href="#globalvars">global variable</a>
569 named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
570 function, and a <a href="#functionstructure">function definition</a>
571 for "<tt>main</tt>".</p>
572 <a name="linkage"> In general, a module is made up of a list of global
573 values, where both functions and global variables are global values.
574 Global values are represented by a pointer to a memory location (in
575 this case, a pointer to an array of char, and a pointer to a function),
576 and have one of the following linkage types:</a>
579 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
580 <dd>Global values with internal linkage are only directly accessible
581 by objects in the current module. In particular, linking code into a
582 module with an internal global value may cause the internal to be
583 renamed as necessary to avoid collisions. Because the symbol is
584 internal to the module, all references can be updated. This
585 corresponds to the notion of the '<tt>static</tt>' keyword in C, or the
586 idea of "anonymous namespaces" in C++.
589 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
590 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt>
591 linkage, with the twist that linking together two modules defining the
592 same <tt>linkonce</tt> globals will cause one of the globals to be
593 discarded. This is typically used to implement inline functions.
594 Unreferenced <tt>linkonce</tt> globals are allowed to be discarded.
597 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
598 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt>
599 linkage, except that unreferenced <tt>weak</tt> globals may not be
600 discarded. This is used to implement constructs in C such as "<tt>int
601 X;</tt>" at global scope.
604 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
605 <dd>"<tt>appending</tt>" linkage may only be applied to global
606 variables of pointer to array type. When two global variables with
607 appending linkage are linked together, the two global arrays are
608 appended together. This is the LLVM, typesafe, equivalent of having
609 the system linker append together "sections" with identical names when
613 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
614 <dd>If none of the above identifiers are used, the global is
615 externally visible, meaning that it participates in linkage and can be
616 used to resolve external symbol references.
621 <p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
622 variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
623 variable and was linked with this one, one of the two would be renamed,
624 preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
625 external (i.e., lacking any linkage declarations), they are accessible
626 outside of the current module. It is illegal for a function <i>declaration</i>
627 to have any linkage type other than "externally visible".</a></p>
630 <!-- ======================================================================= -->
631 <div class="doc_subsection">
632 <a name="globalvars">Global Variables</a>
635 <div class="doc_text">
637 <p>Global variables define regions of memory allocated at compilation
638 time instead of run-time. Global variables may optionally be
639 initialized. A variable may be defined as a global "constant", which
640 indicates that the contents of the variable will never be modified
641 (opening options for optimization).</p>
643 <p>As SSA values, global variables define pointer values that are in
644 scope (i.e. they dominate) for all basic blocks in the program. Global
645 variables always define a pointer to their "content" type because they
646 describe a region of memory, and all memory objects in LLVM are
647 accessed through pointers.</p>
652 <!-- ======================================================================= -->
653 <div class="doc_subsection">
654 <a name="functionstructure">Functions</a>
657 <div class="doc_text">
659 <p>LLVM function definitions are composed of a (possibly empty) argument list,
660 an opening curly brace, a list of basic blocks, and a closing curly brace. LLVM
661 function declarations are defined with the "<tt>declare</tt>" keyword, a
662 function name, and a function signature.</p>
664 <p>A function definition contains a list of basic blocks, forming the CFG for
665 the function. Each basic block may optionally start with a label (giving the
666 basic block a symbol table entry), contains a list of instructions, and ends
667 with a <a href="#terminators">terminator</a> instruction (such as a branch or
668 function return).</p>
670 <p>The first basic block in program is special in two ways: it is immediately
671 executed on entrance to the function, and it is not allowed to have predecessor
672 basic blocks (i.e. there can not be any branches to the entry block of a
673 function). Because the block can have no predecessors, it also cannot have any
674 <a href="#i_phi">PHI nodes</a>.</p>
676 <p>LLVM functions are identified by their name and type signature. Hence, two
677 functions with the same name but different parameter lists or return values are
678 considered different functions, and LLVM will resolves references to each
684 <!-- *********************************************************************** -->
685 <div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
686 <!-- *********************************************************************** -->
687 <div class="doc_text">
688 <p>The LLVM instruction set consists of several different
689 classifications of instructions: <a href="#terminators">terminator
690 instructions</a>, <a href="#binaryops">binary instructions</a>, <a
691 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
692 instructions</a>.</p>
694 <!-- ======================================================================= -->
695 <div class="doc_subsection"> <a name="terminators">Terminator
696 Instructions</a> </div>
697 <div class="doc_text">
698 <p>As mentioned <a href="#functionstructure">previously</a>, every
699 basic block in a program ends with a "Terminator" instruction, which
700 indicates which block should be executed after the current block is
701 finished. These terminator instructions typically yield a '<tt>void</tt>'
702 value: they produce control flow, not values (the one exception being
703 the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
704 <p>There are five different terminator instructions: the '<a
705 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
706 instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
707 the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, and the '<a
708 href="#i_unwind"><tt>unwind</tt></a>' instruction.</p>
710 <!-- _______________________________________________________________________ -->
711 <div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
712 Instruction</a> </div>
713 <div class="doc_text">
715 <pre> ret <type> <value> <i>; Return a value from a non-void function</i>
716 ret void <i>; Return from void function</i>
719 <p>The '<tt>ret</tt>' instruction is used to return control flow (and a
720 value) from a function, back to the caller.</p>
721 <p>There are two forms of the '<tt>ret</tt>' instructruction: one that
722 returns a value and then causes control flow, and one that just causes
723 control flow to occur.</p>
725 <p>The '<tt>ret</tt>' instruction may return any '<a
726 href="#t_firstclass">first class</a>' type. Notice that a function is
727 not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
728 instruction inside of the function that returns a value that does not
729 match the return type of the function.</p>
731 <p>When the '<tt>ret</tt>' instruction is executed, control flow
732 returns back to the calling function's context. If the caller is a "<a
733 href="#i_call"><tt>call</tt></a> instruction, execution continues at
734 the instruction after the call. If the caller was an "<a
735 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
736 at the beginning "normal" of the destination block. If the instruction
737 returns a value, that value shall set the call or invoke instruction's
740 <pre> ret int 5 <i>; Return an integer value of 5</i>
741 ret void <i>; Return from a void function</i>
744 <!-- _______________________________________________________________________ -->
745 <div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
746 <div class="doc_text">
748 <pre> br bool <cond>, label <iftrue>, label <iffalse><br> br label <dest> <i>; Unconditional branch</i>
751 <p>The '<tt>br</tt>' instruction is used to cause control flow to
752 transfer to a different basic block in the current function. There are
753 two forms of this instruction, corresponding to a conditional branch
754 and an unconditional branch.</p>
756 <p>The conditional branch form of the '<tt>br</tt>' instruction takes a
757 single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
758 unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
759 value as a target.</p>
761 <p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
762 argument is evaluated. If the value is <tt>true</tt>, control flows
763 to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
764 control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
766 <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
767 href="#i_ret">ret</a> int 1<br>IfUnequal:<br> <a href="#i_ret">ret</a> int 0<br></pre>
769 <!-- _______________________________________________________________________ -->
770 <div class="doc_subsubsection">
771 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
774 <div class="doc_text">
778 switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ]
783 <p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
784 several different places. It is a generalization of the '<tt>br</tt>'
785 instruction, allowing a branch to occur to one of many possible
791 <p>The '<tt>switch</tt>' instruction uses three parameters: an integer
792 comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
793 an array of pairs of comparison value constants and '<tt>label</tt>'s. The
794 table is not allowed to contain duplicate constant entries.</p>
798 <p>The <tt>switch</tt> instruction specifies a table of values and
799 destinations. When the '<tt>switch</tt>' instruction is executed, this
800 table is searched for the given value. If the value is found, the
801 corresponding destination is branched to, otherwise the default value
802 it transfered to.</p>
804 <h5>Implementation:</h5>
806 <p>Depending on properties of the target machine and the particular
807 <tt>switch</tt> instruction, this instruction may be code generated in different
808 ways, for example as a series of chained conditional branches, or with a lookup
814 <i>; Emulate a conditional br instruction</i>
815 %Val = <a href="#i_cast">cast</a> bool %value to int
816 switch int %Val, label %truedest [int 0, label %falsedest ]
818 <i>; Emulate an unconditional br instruction</i>
819 switch uint 0, label %dest [ ]
821 <i>; Implement a jump table:</i>
822 switch uint %val, label %otherwise [ uint 0, label %onzero
824 uint 2, label %ontwo ]
827 <!-- _______________________________________________________________________ -->
828 <div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>'
829 Instruction</a> </div>
830 <div class="doc_text">
832 <pre> <result> = invoke <ptr to function ty> %<function ptr val>(<function args>)<br> to label <normal label> except label <exception label><br></pre>
834 <p>The '<tt>invoke</tt>' instruction causes control to transfer to a
835 specified function, with the possibility of control flow transfer to
836 either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>.
837 If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>"
838 instruction, control flow will return to the "normal" label. If the
839 callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
840 instruction, control is interrupted, and continued at the dynamically
841 nearest "except" label.</p>
843 <p>This instruction requires several arguments:</p>
845 <li>'<tt>ptr to function ty</tt>': shall be the signature of the
846 pointer to function value being invoked. In most cases, this is a
847 direct function invocation, but indirect <tt>invoke</tt>s are just as
848 possible, branching off an arbitrary pointer to function value. </li>
849 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer
850 to a function to be invoked. </li>
851 <li>'<tt>function args</tt>': argument list whose types match the
852 function signature argument types. If the function signature indicates
853 the function accepts a variable number of arguments, the extra
854 arguments can be specified. </li>
855 <li>'<tt>normal label</tt>': the label reached when the called
856 function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
857 <li>'<tt>exception label</tt>': the label reached when a callee
858 returns with the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
861 <p>This instruction is designed to operate as a standard '<tt><a
862 href="#i_call">call</a></tt>' instruction in most regards. The
863 primary difference is that it establishes an association with a label,
864 which is used by the runtime library to unwind the stack.</p>
865 <p>This instruction is used in languages with destructors to ensure
866 that proper cleanup is performed in the case of either a <tt>longjmp</tt>
867 or a thrown exception. Additionally, this is important for
868 implementation of '<tt>catch</tt>' clauses in high-level languages that
871 <pre> %retval = invoke int %Test(int 15)<br> to label %Continue<br> except label %TestCleanup <i>; {int}:retval set</i>
874 <!-- _______________________________________________________________________ -->
875 <div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
876 Instruction</a> </div>
877 <div class="doc_text">
879 <pre> unwind<br></pre>
881 <p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing
882 control flow at the first callee in the dynamic call stack which used
883 an <a href="#i_invoke"><tt>invoke</tt></a> instruction to perform the
884 call. This is primarily used to implement exception handling.</p>
886 <p>The '<tt>unwind</tt>' intrinsic causes execution of the current
887 function to immediately halt. The dynamic call stack is then searched
888 for the first <a href="#i_invoke"><tt>invoke</tt></a> instruction on
889 the call stack. Once found, execution continues at the "exceptional"
890 destination block specified by the <tt>invoke</tt> instruction. If
891 there is no <tt>invoke</tt> instruction in the dynamic call chain,
892 undefined behavior results.</p>
894 <!-- ======================================================================= -->
895 <div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
896 <div class="doc_text">
897 <p>Binary operators are used to do most of the computation in a
898 program. They require two operands, execute an operation on them, and
899 produce a single value. The result value of a binary operator is not
900 necessarily the same type as its operands.</p>
901 <p>There are several different binary operators:</p>
903 <!-- _______________________________________________________________________ -->
904 <div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
905 Instruction</a> </div>
906 <div class="doc_text">
908 <pre> <result> = add <ty> <var1>, <var2> <i>; yields {ty}:result</i>
911 <p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
913 <p>The two arguments to the '<tt>add</tt>' instruction must be either <a
914 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
915 values. Both arguments must have identical types.</p>
917 <p>The value produced is the integer or floating point sum of the two
920 <pre> <result> = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
923 <!-- _______________________________________________________________________ -->
924 <div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
925 Instruction</a> </div>
926 <div class="doc_text">
928 <pre> <result> = sub <ty> <var1>, <var2> <i>; yields {ty}:result</i>
931 <p>The '<tt>sub</tt>' instruction returns the difference of its two
933 <p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
934 instruction present in most other intermediate representations.</p>
936 <p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
937 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
938 values. Both arguments must have identical types.</p>
940 <p>The value produced is the integer or floating point difference of
941 the two operands.</p>
943 <pre> <result> = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
944 <result> = sub int 0, %val <i>; yields {int}:result = -%var</i>
947 <!-- _______________________________________________________________________ -->
948 <div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
949 Instruction</a> </div>
950 <div class="doc_text">
952 <pre> <result> = mul <ty> <var1>, <var2> <i>; yields {ty}:result</i>
955 <p>The '<tt>mul</tt>' instruction returns the product of its two
958 <p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
959 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
960 values. Both arguments must have identical types.</p>
962 <p>The value produced is the integer or floating point product of the
964 <p>There is no signed vs unsigned multiplication. The appropriate
965 action is taken based on the type of the operand.</p>
967 <pre> <result> = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
970 <!-- _______________________________________________________________________ -->
971 <div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
972 Instruction</a> </div>
973 <div class="doc_text">
975 <pre> <result> = div <ty> <var1>, <var2> <i>; yields {ty}:result</i>
978 <p>The '<tt>div</tt>' instruction returns the quotient of its two
981 <p>The two arguments to the '<tt>div</tt>' instruction must be either <a
982 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
983 values. Both arguments must have identical types.</p>
985 <p>The value produced is the integer or floating point quotient of the
988 <pre> <result> = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
991 <!-- _______________________________________________________________________ -->
992 <div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
993 Instruction</a> </div>
994 <div class="doc_text">
996 <pre> <result> = rem <ty> <var1>, <var2> <i>; yields {ty}:result</i>
999 <p>The '<tt>rem</tt>' instruction returns the remainder from the
1000 division of its two operands.</p>
1002 <p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1003 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
1004 values. Both arguments must have identical types.</p>
1006 <p>This returns the <i>remainder</i> of a division (where the result
1007 has the same sign as the divisor), not the <i>modulus</i> (where the
1008 result has the same sign as the dividend) of a value. For more
1009 information about the difference, see: <a
1010 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1013 <pre> <result> = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1016 <!-- _______________________________________________________________________ -->
1017 <div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1018 Instructions</a> </div>
1019 <div class="doc_text">
1021 <pre> <result> = seteq <ty> <var1>, <var2> <i>; yields {bool}:result</i>
1022 <result> = setne <ty> <var1>, <var2> <i>; yields {bool}:result</i>
1023 <result> = setlt <ty> <var1>, <var2> <i>; yields {bool}:result</i>
1024 <result> = setgt <ty> <var1>, <var2> <i>; yields {bool}:result</i>
1025 <result> = setle <ty> <var1>, <var2> <i>; yields {bool}:result</i>
1026 <result> = setge <ty> <var1>, <var2> <i>; yields {bool}:result</i>
1029 <p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1030 value based on a comparison of their two operands.</p>
1032 <p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1033 be of <a href="#t_firstclass">first class</a> type (it is not possible
1034 to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1035 or '<tt>void</tt>' values, etc...). Both arguments must have identical
1038 <p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1039 value if both operands are equal.<br>
1040 The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1041 value if both operands are unequal.<br>
1042 The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1043 value if the first operand is less than the second operand.<br>
1044 The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1045 value if the first operand is greater than the second operand.<br>
1046 The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1047 value if the first operand is less than or equal to the second operand.<br>
1048 The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1049 value if the first operand is greater than or equal to the second
1052 <pre> <result> = seteq int 4, 5 <i>; yields {bool}:result = false</i>
1053 <result> = setne float 4, 5 <i>; yields {bool}:result = true</i>
1054 <result> = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1055 <result> = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1056 <result> = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1057 <result> = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1060 <!-- ======================================================================= -->
1061 <div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1062 Operations</a> </div>
1063 <div class="doc_text">
1064 <p>Bitwise binary operators are used to do various forms of
1065 bit-twiddling in a program. They are generally very efficient
1066 instructions, and can commonly be strength reduced from other
1067 instructions. They require two operands, execute an operation on them,
1068 and produce a single value. The resulting value of the bitwise binary
1069 operators is always the same type as its first operand.</p>
1071 <!-- _______________________________________________________________________ -->
1072 <div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1073 Instruction</a> </div>
1074 <div class="doc_text">
1076 <pre> <result> = and <ty> <var1>, <var2> <i>; yields {ty}:result</i>
1079 <p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1080 its two operands.</p>
1082 <p>The two arguments to the '<tt>and</tt>' instruction must be <a
1083 href="#t_integral">integral</a> values. Both arguments must have
1084 identical types.</p>
1086 <p>The truth table used for the '<tt>and</tt>' instruction is:</p>
1088 <div style="align: center">
1089 <table border="1" cellspacing="0" cellpadding="4">
1120 <pre> <result> = and int 4, %var <i>; yields {int}:result = 4 & %var</i>
1121 <result> = and int 15, 40 <i>; yields {int}:result = 8</i>
1122 <result> = and int 4, 8 <i>; yields {int}:result = 0</i>
1125 <!-- _______________________________________________________________________ -->
1126 <div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
1127 <div class="doc_text">
1129 <pre> <result> = or <ty> <var1>, <var2> <i>; yields {ty}:result</i>
1132 <p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1133 or of its two operands.</p>
1135 <p>The two arguments to the '<tt>or</tt>' instruction must be <a
1136 href="#t_integral">integral</a> values. Both arguments must have
1137 identical types.</p>
1139 <p>The truth table used for the '<tt>or</tt>' instruction is:</p>
1141 <div style="align: center">
1142 <table border="1" cellspacing="0" cellpadding="4">
1173 <pre> <result> = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
1174 <result> = or int 15, 40 <i>; yields {int}:result = 47</i>
1175 <result> = or int 4, 8 <i>; yields {int}:result = 12</i>
1178 <!-- _______________________________________________________________________ -->
1179 <div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1180 Instruction</a> </div>
1181 <div class="doc_text">
1183 <pre> <result> = xor <ty> <var1>, <var2> <i>; yields {ty}:result</i>
1186 <p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1187 or of its two operands. The <tt>xor</tt> is used to implement the
1188 "one's complement" operation, which is the "~" operator in C.</p>
1190 <p>The two arguments to the '<tt>xor</tt>' instruction must be <a
1191 href="#t_integral">integral</a> values. Both arguments must have
1192 identical types.</p>
1194 <p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
1196 <div style="align: center">
1197 <table border="1" cellspacing="0" cellpadding="4">
1229 <pre> <result> = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
1230 <result> = xor int 15, 40 <i>; yields {int}:result = 39</i>
1231 <result> = xor int 4, 8 <i>; yields {int}:result = 12</i>
1232 <result> = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
1235 <!-- _______________________________________________________________________ -->
1236 <div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1237 Instruction</a> </div>
1238 <div class="doc_text">
1240 <pre> <result> = shl <ty> <var1>, ubyte <var2> <i>; yields {ty}:result</i>
1243 <p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1244 the left a specified number of bits.</p>
1246 <p>The first argument to the '<tt>shl</tt>' instruction must be an <a
1247 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1250 <p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
1252 <pre> <result> = shl int 4, ubyte %var <i>; yields {int}:result = 4 << %var</i>
1253 <result> = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1254 <result> = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1257 <!-- _______________________________________________________________________ -->
1258 <div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1259 Instruction</a> </div>
1260 <div class="doc_text">
1262 <pre> <result> = shr <ty> <var1>, ubyte <var2> <i>; yields {ty}:result</i>
1265 <p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1266 the right a specified number of bits.</p>
1268 <p>The first argument to the '<tt>shr</tt>' instruction must be an <a
1269 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1272 <p>If the first argument is a <a href="#t_signed">signed</a> type, the
1273 most significant bit is duplicated in the newly free'd bit positions.
1274 If the first argument is unsigned, zero bits shall fill the empty
1277 <pre> <result> = shr int 4, ubyte %var <i>; yields {int}:result = 4 >> %var</i>
1278 <result> = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
1279 <result> = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
1280 <result> = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1281 <result> = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
1284 <!-- ======================================================================= -->
1285 <div class="doc_subsection"> <a name="memoryops">Memory Access
1286 Operations</a></div>
1287 <div class="doc_text">
1288 <p>A key design point of an SSA-based representation is how it
1289 represents memory. In LLVM, no memory locations are in SSA form, which
1290 makes things very simple. This section describes how to read, write,
1291 allocate and free memory in LLVM.</p>
1293 <!-- _______________________________________________________________________ -->
1294 <div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>'
1295 Instruction</a> </div>
1296 <div class="doc_text">
1298 <pre> <result> = malloc <type>, uint <NumElements> <i>; yields {type*}:result</i>
1299 <result> = malloc <type> <i>; yields {type*}:result</i>
1302 <p>The '<tt>malloc</tt>' instruction allocates memory from the system
1303 heap and returns a pointer to it.</p>
1305 <p>The '<tt>malloc</tt>' instruction allocates <tt>sizeof(<type>)*NumElements</tt>
1306 bytes of memory from the operating system and returns a pointer of the
1307 appropriate type to the program. The second form of the instruction is
1308 a shorter version of the first instruction that defaults to allocating
1310 <p>'<tt>type</tt>' must be a sized type.</p>
1312 <p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1313 a pointer is returned.</p>
1315 <pre> %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
1318 href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
1319 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1320 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
1323 <!-- _______________________________________________________________________ -->
1324 <div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>'
1325 Instruction</a> </div>
1326 <div class="doc_text">
1328 <pre> free <type> <value> <i>; yields {void}</i>
1331 <p>The '<tt>free</tt>' instruction returns memory back to the unused
1332 memory heap, to be reallocated in the future.</p>
1335 <p>'<tt>value</tt>' shall be a pointer value that points to a value
1336 that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1339 <p>Access to the memory pointed to by the pointer is not longer defined
1340 after this instruction executes.</p>
1342 <pre> %array = <a href="#i_malloc">malloc</a> [4 x ubyte] <i>; yields {[4 x ubyte]*}:array</i>
1343 free [4 x ubyte]* %array
1346 <!-- _______________________________________________________________________ -->
1347 <div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>'
1348 Instruction</a> </div>
1349 <div class="doc_text">
1351 <pre> <result> = alloca <type>, uint <NumElements> <i>; yields {type*}:result</i>
1352 <result> = alloca <type> <i>; yields {type*}:result</i>
1355 <p>The '<tt>alloca</tt>' instruction allocates memory on the current
1356 stack frame of the procedure that is live until the current function
1357 returns to its caller.</p>
1359 <p>The the '<tt>alloca</tt>' instruction allocates <tt>sizeof(<type>)*NumElements</tt>
1360 bytes of memory on the runtime stack, returning a pointer of the
1361 appropriate type to the program. The second form of the instruction is
1362 a shorter version of the first that defaults to allocating one element.</p>
1363 <p>'<tt>type</tt>' may be any sized type.</p>
1365 <p>Memory is allocated, a pointer is returned. '<tt>alloca</tt>'d
1366 memory is automatically released when the function returns. The '<tt>alloca</tt>'
1367 instruction is commonly used to represent automatic variables that must
1368 have an address available. When the function returns (either with the <tt><a
1369 href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt>
1370 instructions), the memory is reclaimed.</p>
1372 <pre> %ptr = alloca int <i>; yields {int*}:ptr</i>
1373 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
1376 <!-- _______________________________________________________________________ -->
1377 <div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1378 Instruction</a> </div>
1379 <div class="doc_text">
1381 <pre> <result> = load <ty>* <pointer><br> <result> = volatile load <ty>* <pointer><br></pre>
1383 <p>The '<tt>load</tt>' instruction is used to read from memory.</p>
1385 <p>The argument to the '<tt>load</tt>' instruction specifies the memory
1386 address to load from. The pointer must point to a <a
1387 href="t_firstclass">first class</a> type. If the <tt>load</tt> is
1388 marked as <tt>volatile</tt> then the optimizer is not allowed to modify
1389 the number or order of execution of this <tt>load</tt> with other
1390 volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1393 <p>The location of memory pointed to is loaded.</p>
1395 <pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1397 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
1398 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1401 <!-- _______________________________________________________________________ -->
1402 <div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1403 Instruction</a> </div>
1405 <pre> store <ty> <value>, <ty>* <pointer> <i>; yields {void}</i>
1406 volatile store <ty> <value>, <ty>* <pointer> <i>; yields {void}</i>
1409 <p>The '<tt>store</tt>' instruction is used to write to memory.</p>
1411 <p>There are two arguments to the '<tt>store</tt>' instruction: a value
1412 to store and an address to store it into. The type of the '<tt><pointer></tt>'
1413 operand must be a pointer to the type of the '<tt><value></tt>'
1414 operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the
1415 optimizer is not allowed to modify the number or order of execution of
1416 this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1417 href="#i_store">store</a></tt> instructions.</p>
1419 <p>The contents of memory are updated to contain '<tt><value></tt>'
1420 at the location specified by the '<tt><pointer></tt>' operand.</p>
1422 <pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1424 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
1425 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1427 <!-- _______________________________________________________________________ -->
1428 <div class="doc_subsubsection">
1429 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
1432 <div class="doc_text">
1435 <result> = getelementptr <ty>* <ptrval>{, <ty> <idx>}*
1441 The '<tt>getelementptr</tt>' instruction is used to get the address of a
1442 subelement of an aggregate data structure.</p>
1446 <p>This instruction takes a list of integer constants that indicate what
1447 elements of the aggregate object to index to. The actual types of the arguments
1448 provided depend on the type of the first pointer argument. The
1449 '<tt>getelementptr</tt>' instruction is used to index down through the type
1450 levels of a structure. When indexing into a structure, only <tt>uint</tt>
1451 integer constants are allowed. When indexing into an array or pointer
1452 <tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
1454 <p>For example, let's consider a C code fragment and how it gets
1455 compiled to LLVM:</p>
1469 int *foo(struct ST *s) {
1470 return &s[1].Z.B[5][13];
1474 <p>The LLVM code generated by the GCC frontend is:</p>
1477 %RT = type { sbyte, [10 x [20 x int]], sbyte }
1478 %ST = type { int, double, %RT }
1480 int* "foo"(%ST* %s) {
1481 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13<br>
1488 <p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
1489 on the pointer type that is being index into. <a href="t_pointer">Pointer</a>
1490 and <a href="t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
1491 <tt>ulong</tt>, or <tt>long</tt> values, and <a href="t_struct">structure</a>
1492 types require <tt>uint</tt> <b>constants</b>.</p>
1494 <p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
1495 type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
1496 }</tt>' type, a structure. The second index indexes into the third element of
1497 the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
1498 sbyte }</tt>' type, another structure. The third index indexes into the second
1499 element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
1500 array. The two dimensions of the array are subscripted into, yielding an
1501 '<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction return a pointer
1502 to this element, thus computing a value of '<tt>int*</tt>' type.</p>
1504 <p>Note that it is perfectly legal to index partially through a
1505 structure, returning a pointer to an inner element. Because of this,
1506 the LLVM code for the given testcase is equivalent to:</p>
1509 int* "foo"(%ST* %s) {
1510 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
1511 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
1512 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
1513 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
1514 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
1520 <i>; yields [12 x ubyte]*:aptr</i>
1521 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
1525 <!-- ======================================================================= -->
1526 <div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
1527 <div class="doc_text">
1528 <p>The instructions in this catagory are the "miscellaneous"
1529 instructions, which defy better classification.</p>
1531 <!-- _______________________________________________________________________ -->
1532 <div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
1533 Instruction</a> </div>
1534 <div class="doc_text">
1536 <pre> <result> = phi <ty> [ <val0>, <label0>], ...<br></pre>
1538 <p>The '<tt>phi</tt>' instruction is used to implement the φ node in
1539 the SSA graph representing the function.</p>
1541 <p>The type of the incoming values are specified with the first type
1542 field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
1543 as arguments, with one pair for each predecessor basic block of the
1544 current block. Only values of <a href="#t_firstclass">first class</a>
1545 type may be used as the value arguments to the PHI node. Only labels
1546 may be used as the label arguments.</p>
1547 <p>There must be no non-phi instructions between the start of a basic
1548 block and the PHI instructions: i.e. PHI instructions must be first in
1551 <p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
1552 value specified by the parameter, depending on which basic block we
1553 came from in the last <a href="#terminators">terminator</a> instruction.</p>
1555 <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>
1558 <!-- _______________________________________________________________________ -->
1559 <div class="doc_subsubsection">
1560 <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
1563 <div class="doc_text">
1568 <result> = cast <ty> <value> to <ty2> <i>; yields ty2</i>
1574 The '<tt>cast</tt>' instruction is used as the primitive means to convert
1575 integers to floating point, change data type sizes, and break type safety (by
1583 The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
1584 class value, and a type to cast it to, which must also be a <a
1585 href="#t_firstclass">first class</a> type.
1591 This instruction follows the C rules for explicit casts when determining how the
1592 data being cast must change to fit in its new container.
1596 When casting to bool, any value that would be considered true in the context of
1597 a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
1598 all else are '<tt>false</tt>'.
1602 When extending an integral value from a type of one signness to another (for
1603 example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
1604 <b>source</b> value is signed, and zero-extended if the source value is
1605 unsigned. <tt>bool</tt> values are always zero extended into either zero or
1612 %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
1613 %Y = cast int 123 to bool <i>; yields bool:true</i>
1617 <!-- _______________________________________________________________________ -->
1618 <div class="doc_subsubsection">
1619 <a name="i_select">'<tt>select</tt>' Instruction</a>
1622 <div class="doc_text">
1627 <result> = select bool <cond>, <ty> <val1>, <ty> <val2> <i>; yields ty</i>
1633 The '<tt>select</tt>' instruction is used to choose one value based on a
1634 condition, without branching.
1641 The '<tt>select</tt>' instruction requires a boolean value indicating the condition, and two values of the same <a href="#t_firstclass">first class</a> type.
1647 If the boolean condition evaluates to true, the instruction returns the first
1648 value argument, otherwise it returns the second value argument.
1654 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
1662 <!-- _______________________________________________________________________ -->
1663 <div class="doc_subsubsection"> <a name="i_call">'<tt>call</tt>'
1664 Instruction</a> </div>
1665 <div class="doc_text">
1667 <pre> <result> = call <ty>* <fnptrval>(<param list>)<br></pre>
1669 <p>The '<tt>call</tt>' instruction represents a simple function call.</p>
1671 <p>This instruction requires several arguments:</p>
1674 <p>'<tt>ty</tt>': shall be the signature of the pointer to function
1675 value being invoked. The argument types must match the types implied
1676 by this signature.</p>
1679 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a
1680 function to be invoked. In most cases, this is a direct function
1681 invocation, but indirect <tt>call</tt>s are just as possible,
1682 calling an arbitrary pointer to function values.</p>
1685 <p>'<tt>function args</tt>': argument list whose types match the
1686 function signature argument types. If the function signature
1687 indicates the function accepts a variable number of arguments, the
1688 extra arguments can be specified.</p>
1692 <p>The '<tt>call</tt>' instruction is used to cause control flow to
1693 transfer to a specified function, with its incoming arguments bound to
1694 the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
1695 instruction in the called function, control flow continues with the
1696 instruction after the function call, and the return value of the
1697 function is bound to the result argument. This is a simpler case of
1698 the <a href="#i_invoke">invoke</a> instruction.</p>
1700 <pre> %retval = call int %test(int %argc)<br> call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42);<br></pre>
1702 <!-- _______________________________________________________________________ -->
1703 <div class="doc_subsubsection"> <a name="i_vanext">'<tt>vanext</tt>'
1704 Instruction</a> </div>
1705 <div class="doc_text">
1707 <pre> <resultarglist> = vanext <va_list> <arglist>, <argty><br></pre>
1709 <p>The '<tt>vanext</tt>' instruction is used to access arguments passed
1710 through the "variable argument" area of a function call. It is used to
1711 implement the <tt>va_arg</tt> macro in C.</p>
1713 <p>This instruction takes a <tt>valist</tt> value and the type of the
1714 argument. It returns another <tt>valist</tt>.</p>
1716 <p>The '<tt>vanext</tt>' instruction advances the specified <tt>valist</tt>
1717 past an argument of the specified type. In conjunction with the <a
1718 href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement
1719 the <tt>va_arg</tt> macro available in C. For more information, see
1720 the variable argument handling <a href="#int_varargs">Intrinsic
1722 <p>It is legal for this instruction to be called in a function which
1723 does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
1725 <p><tt>vanext</tt> is an LLVM instruction instead of an <a
1726 href="#intrinsics">intrinsic function</a> because it takes an type as
1729 <p>See the <a href="#int_varargs">variable argument processing</a>
1732 <!-- _______________________________________________________________________ -->
1733 <div class="doc_subsubsection"> <a name="i_vaarg">'<tt>vaarg</tt>'
1734 Instruction</a> </div>
1735 <div class="doc_text">
1737 <pre> <resultval> = vaarg <va_list> <arglist>, <argty><br></pre>
1739 <p>The '<tt>vaarg</tt>' instruction is used to access arguments passed
1740 through the "variable argument" area of a function call. It is used to
1741 implement the <tt>va_arg</tt> macro in C.</p>
1743 <p>This instruction takes a <tt>valist</tt> value and the type of the
1744 argument. It returns a value of the specified argument type.</p>
1746 <p>The '<tt>vaarg</tt>' instruction loads an argument of the specified
1747 type from the specified <tt>va_list</tt>. In conjunction with the <a
1748 href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to
1749 implement the <tt>va_arg</tt> macro available in C. For more
1750 information, see the variable argument handling <a href="#int_varargs">Intrinsic
1752 <p>It is legal for this instruction to be called in a function which
1753 does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
1755 <p><tt>vaarg</tt> is an LLVM instruction instead of an <a
1756 href="#intrinsics">intrinsic function</a> because it takes an type as
1759 <p>See the <a href="#int_varargs">variable argument processing</a>
1763 <!-- *********************************************************************** -->
1764 <div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
1765 <!-- *********************************************************************** -->
1767 <div class="doc_text">
1769 <p>LLVM supports the notion of an "intrinsic function". These functions have
1770 well known names and semantics, and are required to follow certain
1771 restrictions. Overall, these instructions represent an extension mechanism for
1772 the LLVM language that does not require changing all of the transformations in
1773 LLVM to add to the language (or the bytecode reader/writer, the parser,
1776 <p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix, this
1777 prefix is reserved in LLVM for intrinsic names, thus functions may not be named
1778 this. Intrinsic functions must always be external functions: you cannot define
1779 the body of intrinsic functions. Intrinsic functions may only be used in call
1780 or invoke instructions: it is illegal to take the address of an intrinsic
1781 function. Additionally, because intrinsic functions are part of the LLVM
1782 language, it is required that they all be documented here if any are added.</p>
1786 Adding an intrinsic to LLVM is straight-forward if it is possible to express the
1787 concept in LLVM directly (ie, code generator support is not _required_). To do
1788 this, extend the default implementation of the IntrinsicLowering class to handle
1789 the intrinsic. Code generators use this class to lower intrinsics they do not
1790 understand to raw LLVM instructions that they do.
1795 <!-- ======================================================================= -->
1796 <div class="doc_subsection">
1797 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
1800 <div class="doc_text">
1801 <p>Variable argument support is defined in LLVM with the <a
1802 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
1803 intrinsic functions. These functions are related to the similarly
1804 named macros defined in the <tt><stdarg.h></tt> header file.</p>
1805 <p>All of these functions operate on arguments that use a
1806 target-specific value type "<tt>va_list</tt>". The LLVM assembly
1807 language reference manual does not define what this type is, so all
1808 transformations should be prepared to handle intrinsics with any type
1810 <p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
1811 instruction and the variable argument handling intrinsic functions are
1814 int %test(int %X, ...) {
1815 ; Initialize variable argument processing
1816 %ap = call sbyte* %<a href="#i_va_start">llvm.va_start</a>()
1818 ; Read a single integer argument
1819 %tmp = vaarg sbyte* %ap, int
1821 ; Advance to the next argument
1822 %ap2 = vanext sbyte* %ap, int
1824 ; Demonstrate usage of llvm.va_copy and llvm.va_end
1825 %aq = call sbyte* %<a href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2)
1826 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %aq)
1828 ; Stop processing of arguments.
1829 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %ap2)
1835 <!-- _______________________________________________________________________ -->
1836 <div class="doc_subsubsection">
1837 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
1841 <div class="doc_text">
1843 <pre> call va_list ()* %llvm.va_start()<br></pre>
1845 <p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt><arglist></tt>
1846 for subsequent use by the variable argument intrinsics.</p>
1848 <p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
1849 macro available in C. In a target-dependent way, it initializes and
1850 returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt>
1851 will produce the first variable argument passed to the function. Unlike
1852 the C <tt>va_start</tt> macro, this intrinsic does not need to know the
1853 last argument of the function, the compiler can figure that out.</p>
1854 <p>Note that this intrinsic function is only legal to be called from
1855 within the body of a variable argument function.</p>
1858 <!-- _______________________________________________________________________ -->
1859 <div class="doc_subsubsection">
1860 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
1863 <div class="doc_text">
1865 <pre> call void (va_list)* %llvm.va_end(va_list <arglist>)<br></pre>
1867 <p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt><arglist></tt>
1868 which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
1869 or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
1871 <p>The argument is a <tt>va_list</tt> to destroy.</p>
1873 <p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
1874 macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
1875 Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
1876 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
1877 with calls to <tt>llvm.va_end</tt>.</p>
1880 <!-- _______________________________________________________________________ -->
1881 <div class="doc_subsubsection">
1882 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
1885 <div class="doc_text">
1887 <pre> call va_list (va_list)* %llvm.va_copy(va_list <destarglist>)<br></pre>
1889 <p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument
1890 position from the source argument list to the destination argument list.</p>
1892 <p>The argument is the <tt>va_list</tt> to copy.</p>
1894 <p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
1895 macro available in C. In a target-dependent way, it copies the source <tt>va_list</tt>
1896 element into the returned list. This intrinsic is necessary because the <tt><a
1897 href="i_va_start">llvm.va_start</a></tt> intrinsic may be arbitrarily
1898 complex and require memory allocation, for example.</p>
1901 <!-- ======================================================================= -->
1902 <div class="doc_subsection">
1903 <a name="int_codegen">Code Generator Intrinsics</a>
1906 <div class="doc_text">
1908 These intrinsics are provided by LLVM to expose special features that may only
1909 be implemented with code generator support.
1914 <!-- _______________________________________________________________________ -->
1915 <div class="doc_subsubsection">
1916 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
1919 <div class="doc_text">
1923 call void* ()* %llvm.returnaddress(uint <level>)
1929 The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
1930 indicating the return address of the current function or one of its callers.
1936 The argument to this intrinsic indicates which function to return the address
1937 for. Zero indicates the calling function, one indicates its caller, etc. The
1938 argument is <b>required</b> to be a constant integer value.
1944 The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
1945 the return address of the specified call frame, or zero if it cannot be
1946 identified. The value returned by this intrinsic is likely to be incorrect or 0
1947 for arguments other than zero, so it should only be used for debugging purposes.
1951 Note that calling this intrinsic does not prevent function inlining or other
1952 aggressive transformations, so the value returned may not that of the obvious
1953 source-language caller.
1958 <!-- _______________________________________________________________________ -->
1959 <div class="doc_subsubsection">
1960 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
1963 <div class="doc_text">
1967 call void* ()* %llvm.frameaddress(uint <level>)
1973 The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
1974 pointer value for the specified stack frame.
1980 The argument to this intrinsic indicates which function to return the frame
1981 pointer for. Zero indicates the calling function, one indicates its caller,
1982 etc. The argument is <b>required</b> to be a constant integer value.
1988 The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
1989 the frame address of the specified call frame, or zero if it cannot be
1990 identified. The value returned by this intrinsic is likely to be incorrect or 0
1991 for arguments other than zero, so it should only be used for debugging purposes.
1995 Note that calling this intrinsic does not prevent function inlining or other
1996 aggressive transformations, so the value returned may not that of the obvious
1997 source-language caller.
2001 <!-- _______________________________________________________________________ -->
2002 <div class="doc_subsubsection">
2003 <a name="i_readport">'<tt>llvm.readport</tt>' Intrinsic</a>
2006 <div class="doc_text">
2010 call sbyte (ushort address)* %llvm.readport(ushort <address>)
2011 call ubyte (ushort address)* %llvm.readport(ushort <address>)
2012 call short (ushort address)* %llvm.readport(ushort <address>)
2013 call ushort (ushort address)* %llvm.readport(ushort <address>)
2014 call int (ushort address)* %llvm.readport(ushort <address>)
2015 call uint (ushort address)* %llvm.readport(ushort <address>)
2021 The '<tt>llvm.readport</tt>' intrinsic reads data from the specified I/O port.
2027 The argument to this intrinsic indicates the I/O address from which to read
2028 the data. The address is in the I/O address namespace; it is not a memory
2035 The '<tt>llvm.readport</tt>' intrinsic reads data from the I/O port specified
2036 by <i>address</i> and returns the value. The address and return value must
2037 be integers, but the size is dependent upon the platform upon which the
2038 program is code generated. For example, on x86, the address must be a
2039 ushort, and the return value must be 8, 16, or 32 bits.
2044 <!-- _______________________________________________________________________ -->
2045 <div class="doc_subsubsection">
2046 <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a>
2049 <div class="doc_text">
2053 call void (ushort address, sbyte value)* %llvm.writeport(ushort <address>, sbyte <value>)
2054 call void (ushort address, ubyte value)* %llvm.writeport(ushort <address>, ubyte <value>)
2055 call void (ushort address, short value)* %llvm.writeport(ushort <address>, short <value>)
2056 call void (ushort address, ushort value)* %llvm.writeport(ushort <address>, ushort <value>)
2057 call void (ushort address, int value)* %llvm.writeport(ushort <address>, int <value>)
2058 call void (ushort address, uint value)* %llvm.writeport(ushort <address>, uint <value>)
2064 The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified I/O port.
2070 The first argument to this intrinsic indicates the I/O address to which data
2071 should be written. The address is in the I/O address namespace; it is not a
2076 The second argument is the value to write to the I/O port.
2082 The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port
2083 specified by <i>address</i>. The address and value must be integers, but the
2084 size is dependent upon the platform upon which the program is code generated.
2085 For example, on x86, the address must be a ushort, and the value written must
2086 be 8, 16, or 32 bits in length.
2091 <!-- ======================================================================= -->
2092 <div class="doc_subsection">
2093 <a name="int_libc">Standard C Library Intrinsics</a>
2096 <div class="doc_text">
2098 LLVM provides intrinsics for a few important standard C library functions.
2099 These intrinsics allow source-language front-ends to pass information about the
2100 alignment of the pointer arguments to the code generator, providing opportunity
2101 for more efficient code generation.
2106 <!-- _______________________________________________________________________ -->
2107 <div class="doc_subsubsection">
2108 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
2111 <div class="doc_text">
2115 call void (sbyte*, sbyte*, uint, uint)* %llvm.memcpy(sbyte* <dest>, sbyte* <src>,
2116 uint <len>, uint <align>)
2122 The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2123 location to the destination location.
2127 Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
2128 does not return a value, and takes an extra alignment argument.
2134 The first argument is a pointer to the destination, the second is a pointer to
2135 the source. The third argument is an (arbitrarily sized) integer argument
2136 specifying the number of bytes to copy, and the fourth argument is the alignment
2137 of the source and destination locations.
2141 If the call to this intrinisic has an alignment value that is not 0 or 1, then
2142 the caller guarantees that the size of the copy is a multiple of the alignment
2143 and that both the source and destination pointers are aligned to that boundary.
2149 The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2150 location to the destination location, which are not allowed to overlap. It
2151 copies "len" bytes of memory over. If the argument is known to be aligned to
2152 some boundary, this can be specified as the fourth argument, otherwise it should
2158 <!-- _______________________________________________________________________ -->
2159 <div class="doc_subsubsection">
2160 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
2163 <div class="doc_text">
2167 call void (sbyte*, sbyte*, uint, uint)* %llvm.memmove(sbyte* <dest>, sbyte* <src>,
2168 uint <len>, uint <align>)
2174 The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
2175 location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>'
2176 intrinsic but allows the two memory locations to overlap.
2180 Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
2181 does not return a value, and takes an extra alignment argument.
2187 The first argument is a pointer to the destination, the second is a pointer to
2188 the source. The third argument is an (arbitrarily sized) integer argument
2189 specifying the number of bytes to copy, and the fourth argument is the alignment
2190 of the source and destination locations.
2194 If the call to this intrinisic has an alignment value that is not 0 or 1, then
2195 the caller guarantees that the size of the copy is a multiple of the alignment
2196 and that both the source and destination pointers are aligned to that boundary.
2202 The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
2203 location to the destination location, which may overlap. It
2204 copies "len" bytes of memory over. If the argument is known to be aligned to
2205 some boundary, this can be specified as the fourth argument, otherwise it should
2211 <!-- _______________________________________________________________________ -->
2212 <div class="doc_subsubsection">
2213 <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a>
2216 <div class="doc_text">
2220 call void (sbyte*, ubyte, uint, uint)* %llvm.memset(sbyte* <dest>, ubyte <val>,
2221 uint <len>, uint <align>)
2227 The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular
2232 Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
2233 does not return a value, and takes an extra alignment argument.
2239 The first argument is a pointer to the destination to fill, the second is the
2240 byte value to fill it with, the third argument is an (arbitrarily sized) integer
2241 argument specifying the number of bytes to fill, and the fourth argument is the
2242 known alignment of destination location.
2246 If the call to this intrinisic has an alignment value that is not 0 or 1, then
2247 the caller guarantees that the size of the copy is a multiple of the alignment
2248 and that the destination pointer is aligned to that boundary.
2254 The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the
2255 destination location. If the argument is known to be aligned to some boundary,
2256 this can be specified as the fourth argument, otherwise it should be set to 0 or
2262 <!-- ======================================================================= -->
2263 <div class="doc_subsection">
2264 <a name="int_debugger">Debugger Intrinsics</a>
2267 <div class="doc_text">
2269 The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
2270 are described in the <a
2271 href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
2272 Debugging</a> document.
2277 <!-- *********************************************************************** -->
2280 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
2281 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
2282 <a href="http://validator.w3.org/check/referer"><img
2283 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
2285 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
2286 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
2287 Last modified: $Date$