1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <title>LLVM Assembly Language Reference Manual</title>
5 <link rel="stylesheet" href="llvm.css" type="text/css">
8 <div class="doc_title"> LLVM Language Reference Manual </div>
10 <li><a href="#abstract">Abstract</a></li>
11 <li><a href="#introduction">Introduction</a></li>
12 <li><a href="#identifiers">Identifiers</a></li>
13 <li><a href="#typesystem">Type System</a>
15 <li><a href="#t_primitive">Primitive Types</a>
17 <li><a href="#t_classifications">Type Classifications</a></li>
20 <li><a href="#t_derived">Derived Types</a>
22 <li><a href="#t_array">Array Type</a></li>
23 <li><a href="#t_function">Function Type</a></li>
24 <li><a href="#t_pointer">Pointer Type</a></li>
25 <li><a href="#t_struct">Structure Type</a></li>
26 <!-- <li><a href="#t_packed" >Packed Type</a> -->
31 <li><a href="#highlevel">High Level Structure</a>
33 <li><a href="#modulestructure">Module Structure</a></li>
34 <li><a href="#globalvars">Global Variables</a></li>
35 <li><a href="#functionstructure">Function Structure</a></li>
38 <li><a href="#instref">Instruction Reference</a>
40 <li><a href="#terminators">Terminator Instructions</a>
42 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
43 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
44 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
45 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
46 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
49 <li><a href="#binaryops">Binary Operations</a>
51 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
52 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
53 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
54 <li><a href="#i_div">'<tt>div</tt>' Instruction</a></li>
55 <li><a href="#i_rem">'<tt>rem</tt>' Instruction</a></li>
56 <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li>
59 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
61 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
62 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
63 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
64 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
65 <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a></li>
68 <li><a href="#memoryops">Memory Access Operations</a>
70 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
71 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
72 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
73 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
74 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
75 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
78 <li><a href="#otherops">Other Operations</a>
80 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
81 <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li>
82 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
83 <li><a href="#i_vanext">'<tt>vanext</tt>' Instruction</a></li>
84 <li><a href="#i_vaarg">'<tt>vaarg</tt>' Instruction</a></li>
89 <li><a href="#intrinsics">Intrinsic Functions</a>
91 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
93 <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
94 <li><a href="#i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
95 <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
98 <li><a href="#int_codegen">Code Generator Intrinsics</a>
100 <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
101 <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
104 <li><a href="#int_libc">Standard C Library Intrinsics</a>
106 <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li>
107 <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li>
108 <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li>
111 <li><a href="#int_debugger">Debugger intrinsics</a>
115 <div class="doc_text">
116 <p><b>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
117 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></b></p>
120 <!-- *********************************************************************** -->
121 <div class="doc_section"> <a name="abstract">Abstract </a></div>
122 <!-- *********************************************************************** -->
123 <div class="doc_text">
124 <p>This document is a reference manual for the LLVM assembly language.
125 LLVM is an SSA based representation that provides type safety,
126 low-level operations, flexibility, and the capability of representing
127 'all' high-level languages cleanly. It is the common code
128 representation used throughout all phases of the LLVM compilation
131 <!-- *********************************************************************** -->
132 <div class="doc_section"> <a name="introduction">Introduction</a> </div>
133 <!-- *********************************************************************** -->
134 <div class="doc_text">
135 <p>The LLVM code representation is designed to be used in three
136 different forms: as an in-memory compiler IR, as an on-disk bytecode
137 representation (suitable for fast loading by a Just-In-Time compiler),
138 and as a human readable assembly language representation. This allows
139 LLVM to provide a powerful intermediate representation for efficient
140 compiler transformations and analysis, while providing a natural means
141 to debug and visualize the transformations. The three different forms
142 of LLVM are all equivalent. This document describes the human readable
143 representation and notation.</p>
144 <p>The LLVM representation aims to be a light-weight and low-level
145 while being expressive, typed, and extensible at the same time. It
146 aims to be a "universal IR" of sorts, by being at a low enough level
147 that high-level ideas may be cleanly mapped to it (similar to how
148 microprocessors are "universal IR's", allowing many source languages to
149 be mapped to them). By providing type information, LLVM can be used as
150 the target of optimizations: for example, through pointer analysis, it
151 can be proven that a C automatic variable is never accessed outside of
152 the current function... allowing it to be promoted to a simple SSA
153 value instead of a memory location.</p>
155 <!-- _______________________________________________________________________ -->
156 <div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
157 <div class="doc_text">
158 <p>It is important to note that this document describes 'well formed'
159 LLVM assembly language. There is a difference between what the parser
160 accepts and what is considered 'well formed'. For example, the
161 following instruction is syntactically okay, but not well formed:</p>
162 <pre> %x = <a href="#i_add">add</a> int 1, %x<br></pre>
163 <p>...because the definition of <tt>%x</tt> does not dominate all of
164 its uses. The LLVM infrastructure provides a verification pass that may
165 be used to verify that an LLVM module is well formed. This pass is
166 automatically run by the parser after parsing input assembly, and by
167 the optimizer before it outputs bytecode. The violations pointed out
168 by the verifier pass indicate bugs in transformation passes or input to
170 <!-- Describe the typesetting conventions here. --> </div>
171 <!-- *********************************************************************** -->
172 <div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
173 <!-- *********************************************************************** -->
174 <div class="doc_text">
175 <p>LLVM uses three different forms of identifiers, for different
178 <li>Numeric constants are represented as you would expect: 12, -3
179 123.421, etc. Floating point constants have an optional hexidecimal
181 <li>Named values are represented as a string of characters with a '%'
182 prefix. For example, %foo, %DivisionByZero,
183 %a.really.long.identifier. The actual regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
184 Identifiers which require other characters in their names can be
185 surrounded with quotes. In this way, anything except a <tt>"</tt>
186 character can be used in a name.</li>
187 <li>Unnamed values are represented as an unsigned numeric value with
188 a '%' prefix. For example, %12, %2, %44.</li>
190 <p>LLVM requires the values start with a '%' sign for two reasons:
191 Compilers don't need to worry about name clashes with reserved words,
192 and the set of reserved words may be expanded in the future without
193 penalty. Additionally, unnamed identifiers allow a compiler to quickly
194 come up with a temporary variable without having to avoid symbol table
196 <p>Reserved words in LLVM are very similar to reserved words in other
197 languages. There are keywords for different opcodes ('<tt><a
198 href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
199 href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
200 href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>',
201 etc...), and others. These reserved words cannot conflict with
202 variable names, because none of them start with a '%' character.</p>
203 <p>Here is an example of LLVM code to multiply the integer variable '<tt>%X</tt>'
206 <pre> %result = <a href="#i_mul">mul</a> uint %X, 8<br></pre>
207 <p>After strength reduction:</p>
208 <pre> %result = <a href="#i_shl">shl</a> uint %X, ubyte 3<br></pre>
209 <p>And the hard way:</p>
210 <pre> <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
212 href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
214 href="#i_add">add</a> uint %1, %1<br></pre>
215 <p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
216 important lexical features of LLVM:</p>
218 <li>Comments are delimited with a '<tt>;</tt>' and go until the end
220 <li>Unnamed temporaries are created when the result of a computation
221 is not assigned to a named value.</li>
222 <li>Unnamed temporaries are numbered sequentially</li>
224 <p>...and it also show a convention that we follow in this document.
225 When demonstrating instructions, we will follow an instruction with a
226 comment that defines the type and name of value produced. Comments are
227 shown in italic text.</p>
228 <p>The one non-intuitive notation for constants is the optional
229 hexidecimal form of floating point constants. For example, the form '<tt>double
230 0x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
231 4.5e+15</tt>' which is also supported by the parser. The only time
232 hexadecimal floating point constants are useful (and the only time that
233 they are generated by the disassembler) is when an FP constant has to
234 be emitted that is not representable as a decimal floating point number
235 exactly. For example, NaN's, infinities, and other special cases are
236 represented in their IEEE hexadecimal format so that assembly and
237 disassembly do not cause any bits to change in the constants.</p>
239 <!-- *********************************************************************** -->
240 <div class="doc_section"> <a name="typesystem">Type System</a> </div>
241 <!-- *********************************************************************** -->
242 <div class="doc_text">
243 <p>The LLVM type system is one of the most important features of the
244 intermediate representation. Being typed enables a number of
245 optimizations to be performed on the IR directly, without having to do
246 extra analyses on the side before the transformation. A strong type
247 system makes it easier to read the generated code and enables novel
248 analyses and transformations that are not feasible to perform on normal
249 three address code representations.</p>
250 <!-- The written form for the type system was heavily influenced by the
251 syntactic problems with types in the C language<sup><a
252 href="#rw_stroustrup">1</a></sup>.<p> --> </div>
253 <!-- ======================================================================= -->
254 <div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
255 <div class="doc_text">
256 <p>The primitive types are the fundemental building blocks of the LLVM
257 system. The current set of primitive types are as follows:</p>
259 <table border="0" align="center">
263 <table border="1" cellspacing="0" cellpadding="4" align="center">
266 <td><tt>void</tt></td>
270 <td><tt>ubyte</tt></td>
271 <td>Unsigned 8 bit value</td>
274 <td><tt>ushort</tt></td>
275 <td>Unsigned 16 bit value</td>
278 <td><tt>uint</tt></td>
279 <td>Unsigned 32 bit value</td>
282 <td><tt>ulong</tt></td>
283 <td>Unsigned 64 bit value</td>
286 <td><tt>float</tt></td>
287 <td>32 bit floating point value</td>
290 <td><tt>label</tt></td>
291 <td>Branch destination</td>
297 <table border="1" cellspacing="0" cellpadding="4" align="center"">
300 <td><tt>bool</tt></td>
301 <td>True or False value</td>
304 <td><tt>sbyte</tt></td>
305 <td>Signed 8 bit value</td>
308 <td><tt>short</tt></td>
309 <td>Signed 16 bit value</td>
312 <td><tt>int</tt></td>
313 <td>Signed 32 bit value</td>
316 <td><tt>long</tt></td>
317 <td>Signed 64 bit value</td>
320 <td><tt>double</tt></td>
321 <td>64 bit floating point value</td>
331 <!-- _______________________________________________________________________ -->
332 <div class="doc_subsubsection"> <a name="t_classifications">Type
333 Classifications</a> </div>
334 <div class="doc_text">
335 <p>These different primitive types fall into a few useful
338 <table border="1" cellspacing="0" cellpadding="4" align="center">
341 <td><a name="t_signed">signed</a></td>
342 <td><tt>sbyte, short, int, long, float, double</tt></td>
345 <td><a name="t_unsigned">unsigned</a></td>
346 <td><tt>ubyte, ushort, uint, ulong</tt></td>
349 <td><a name="t_integer">integer</a></td>
350 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
353 <td><a name="t_integral">integral</a></td>
354 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
357 <td><a name="t_floating">floating point</a></td>
358 <td><tt>float, double</tt></td>
361 <td><a name="t_firstclass">first class</a></td>
362 <td><tt>bool, ubyte, sbyte, ushort, short,<br>
363 uint, int, ulong, long, float, double, <a href="#t_pointer">pointer</a></tt></td>
368 <p>The <a href="#t_firstclass">first class</a> types are perhaps the
369 most important. Values of these types are the only ones which can be
370 produced by instructions, passed as arguments, or used as operands to
371 instructions. This means that all structures and arrays must be
372 manipulated either by pointer or by component.</p>
374 <!-- ======================================================================= -->
375 <div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
376 <div class="doc_text">
377 <p>The real power in LLVM comes from the derived types in the system.
378 This is what allows a programmer to represent arrays, functions,
379 pointers, and other useful types. Note that these derived types may be
380 recursive: For example, it is possible to have a two dimensional array.</p>
382 <!-- _______________________________________________________________________ -->
383 <div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
384 <div class="doc_text">
386 <p>The array type is a very simple derived type that arranges elements
387 sequentially in memory. The array type requires a size (number of
388 elements) and an underlying data type.</p>
390 <pre> [<# elements> x <elementtype>]<br></pre>
391 <p>The number of elements is a constant integer value, elementtype may
392 be any type with a size.</p>
394 <p> <tt>[40 x int ]</tt>: Array of 40 integer values.<br>
395 <tt>[41 x int ]</tt>: Array of 41 integer values.<br>
396 <tt>[40 x uint]</tt>: Array of 40 unsigned integer values.</p>
398 <p>Here are some examples of multidimensional arrays:</p>
400 <table border="0" cellpadding="0" cellspacing="0">
403 <td><tt>[3 x [4 x int]]</tt></td>
404 <td>: 3x4 array integer values.</td>
407 <td><tt>[12 x [10 x float]]</tt></td>
408 <td>: 12x10 array of single precision floating point values.</td>
411 <td><tt>[2 x [3 x [4 x uint]]]</tt></td>
412 <td>: 2x3x4 array of unsigned integer values.</td>
418 <!-- _______________________________________________________________________ -->
419 <div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
420 <div class="doc_text">
422 <p>The function type can be thought of as a function signature. It
423 consists of a return type and a list of formal parameter types.
424 Function types are usually used to build virtual function tables
425 (which are structures of pointers to functions), for indirect function
426 calls, and when defining a function.</p>
428 The return type of a function type cannot be an aggregate type.
431 <pre> <returntype> (<parameter list>)<br></pre>
432 <p>Where '<tt><parameter list></tt>' is a comma-separated list of
433 type specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
434 which indicates that the function takes a variable number of arguments.
435 Variable argument functions can access their arguments with the <a
436 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
439 <table border="0" cellpadding="0" cellspacing="0">
442 <td><tt>int (int)</tt></td>
443 <td>: function taking an <tt>int</tt>, returning an <tt>int</tt></td>
446 <td><tt>float (int, int *) *</tt></td>
447 <td>: <a href="#t_pointer">Pointer</a> to a function that takes
448 an <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
449 returning <tt>float</tt>.</td>
452 <td><tt>int (sbyte *, ...)</tt></td>
453 <td>: A vararg function that takes at least one <a
454 href="#t_pointer">pointer</a> to <tt>sbyte</tt> (signed char in C),
455 which returns an integer. This is the signature for <tt>printf</tt>
462 <!-- _______________________________________________________________________ -->
463 <div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
464 <div class="doc_text">
466 <p>The structure type is used to represent a collection of data members
467 together in memory. The packing of the field types is defined to match
468 the ABI of the underlying processor. The elements of a structure may
469 be any type that has a size.</p>
470 <p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
471 and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
472 field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
475 <pre> { <type list> }<br></pre>
478 <table border="0" cellpadding="0" cellspacing="0">
481 <td><tt>{ int, int, int }</tt></td>
482 <td>: a triple of three <tt>int</tt> values</td>
485 <td><tt>{ float, int (int) * }</tt></td>
486 <td>: A pair, where the first element is a <tt>float</tt> and the
487 second element is a <a href="#t_pointer">pointer</a> to a <a
488 href="t_function">function</a> that takes an <tt>int</tt>, returning
489 an <tt>int</tt>.</td>
495 <!-- _______________________________________________________________________ -->
496 <div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
497 <div class="doc_text">
499 <p>As in many languages, the pointer type represents a pointer or
500 reference to another object, which must live in memory.</p>
502 <pre> <type> *<br></pre>
505 <table border="0" cellpadding="0" cellspacing="0">
508 <td><tt>[4x int]*</tt></td>
509 <td>: <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a>
510 of four <tt>int</tt> values</td>
513 <td><tt>int (int *) *</tt></td>
514 <td>: A <a href="#t_pointer">pointer</a> to a <a
515 href="t_function">function</a> that takes an <tt>int</tt>, returning
516 an <tt>int</tt>.</td>
522 <!-- _______________________________________________________________________ --><!--
523 <div class="doc_subsubsection">
524 <a name="t_packed">Packed Type</a>
527 <div class="doc_text">
529 Mention/decide that packed types work with saturation or not. Maybe have a packed+saturated type in addition to just a packed type.<p>
531 Packed types should be 'nonsaturated' because standard data types are not saturated. Maybe have a saturated packed type?<p>
535 --><!-- *********************************************************************** -->
536 <div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
537 <!-- *********************************************************************** --><!-- ======================================================================= -->
538 <div class="doc_subsection"> <a name="modulestructure">Module Structure</a> </div>
539 <div class="doc_text">
540 <p>LLVM programs are composed of "Module"s, each of which is a
541 translation unit of the input programs. Each module consists of
542 functions, global variables, and symbol table entries. Modules may be
543 combined together with the LLVM linker, which merges function (and
544 global variable) definitions, resolves forward declarations, and merges
545 symbol table entries. Here is an example of the "hello world" module:</p>
546 <pre><i>; Declare the string constant as a global constant...</i>
547 <a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
548 href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00" <i>; [13 x sbyte]*</i>
550 <i>; External declaration of the puts function</i>
551 <a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
553 <i>; Definition of main function</i>
554 int %main() { <i>; int()* </i>
555 <i>; Convert [13x sbyte]* to sbyte *...</i>
557 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
559 <i>; Call puts function to write out the string to stdout...</i>
561 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
563 href="#i_ret">ret</a> int 0<br>}<br></pre>
564 <p>This example is made up of a <a href="#globalvars">global variable</a>
565 named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
566 function, and a <a href="#functionstructure">function definition</a>
567 for "<tt>main</tt>".</p>
568 <a name="linkage"> In general, a module is made up of a list of global
569 values, where both functions and global variables are global values.
570 Global values are represented by a pointer to a memory location (in
571 this case, a pointer to an array of char, and a pointer to a function),
572 and have one of the following linkage types:</a>
575 <a name="linkage_internal"> <dt><tt><b>internal</b></tt> </dt>
576 <dd>Global values with internal linkage are only directly accessible
577 by objects in the current module. In particular, linking code into a
578 module with an internal global value may cause the internal to be
579 renamed as necessary to avoid collisions. Because the symbol is
580 internal to the module, all references can be updated. This
581 corresponds to the notion of the '<tt>static</tt>' keyword in C, or the
582 idea of "anonymous namespaces" in C++.
585 </a><a name="linkage_linkonce"> <dt><tt><b>linkonce</b></tt>: </dt>
586 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt>
587 linkage, with the twist that linking together two modules defining the
588 same <tt>linkonce</tt> globals will cause one of the globals to be
589 discarded. This is typically used to implement inline functions.
590 Unreferenced <tt>linkonce</tt> globals are allowed to be discarded.
593 </a><a name="linkage_weak"> <dt><tt><b>weak</b></tt>: </dt>
594 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt>
595 linkage, except that unreferenced <tt>weak</tt> globals may not be
596 discarded. This is used to implement constructs in C such as "<tt>int
597 X;</tt>" at global scope.
600 </a><a name="linkage_appending"> <dt><tt><b>appending</b></tt>: </dt>
601 <dd>"<tt>appending</tt>" linkage may only be applied to global
602 variables of pointer to array type. When two global variables with
603 appending linkage are linked together, the two global arrays are
604 appended together. This is the LLVM, typesafe, equivalent of having
605 the system linker append together "sections" with identical names when
609 </a><a name="linkage_external"> <dt><tt><b>externally visible</b></tt>:</dt>
610 <dd>If none of the above identifiers are used, the global is
611 externally visible, meaning that it participates in linkage and can be
612 used to resolve external symbol references.
618 <p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
619 variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
620 variable and was linked with this one, one of the two would be renamed,
621 preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
622 external (i.e., lacking any linkage declarations), they are accessible
623 outside of the current module. It is illegal for a function <i>declaration</i>
624 to have any linkage type other than "externally visible".</a></p>
626 <!-- ======================================================================= -->
627 <div class="doc_subsection"> <a name="globalvars">Global Variables</a> </div>
628 <div class="doc_text">
629 <p>Global variables define regions of memory allocated at compilation
630 time instead of run-time. Global variables may optionally be
631 initialized. A variable may be defined as a global "constant", which
632 indicates that the contents of the variable will never be modified
633 (opening options for optimization). Constants must always have an
635 <p>As SSA values, global variables define pointer values that are in
636 scope (i.e. they dominate) for all basic blocks in the program. Global
637 variables always define a pointer to their "content" type because they
638 describe a region of memory, and all memory objects in LLVM are
639 accessed through pointers.</p>
641 <!-- ======================================================================= -->
642 <div class="doc_subsection"> <a name="functionstructure">Functions</a> </div>
643 <div class="doc_text">
644 <p>LLVM function definitions are composed of a (possibly empty)
645 argument list, an opening curly brace, a list of basic blocks, and a
646 closing curly brace. LLVM function declarations are defined with the "<tt>declare</tt>"
647 keyword, a function name, and a function signature.</p>
648 <p>A function definition contains a list of basic blocks, forming the
649 CFG for the function. Each basic block may optionally start with a
650 label (giving the basic block a symbol table entry), contains a list of
651 instructions, and ends with a <a href="#terminators">terminator</a>
652 instruction (such as a branch or function return).</p>
653 <p>The first basic block in program is special in two ways: it is
654 immediately executed on entrance to the function, and it is not allowed
655 to have predecessor basic blocks (i.e. there can not be any branches to
656 the entry block of a function). Because the block can have no
657 predecessors, it also cannot have any <a href="#i_phi">PHI nodes</a>.</p>
659 LLVM functions are identified by their name and type signature. Hence, two
660 functions with the same name but different parameter lists or return values
661 are considered different functions, and LLVM will resolves references to each
665 <!-- *********************************************************************** -->
666 <div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
667 <!-- *********************************************************************** -->
668 <div class="doc_text">
669 <p>The LLVM instruction set consists of several different
670 classifications of instructions: <a href="#terminators">terminator
671 instructions</a>, <a href="#binaryops">binary instructions</a>, <a
672 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
673 instructions</a>.</p>
675 <!-- ======================================================================= -->
676 <div class="doc_subsection"> <a name="terminators">Terminator
677 Instructions</a> </div>
678 <div class="doc_text">
679 <p>As mentioned <a href="#functionstructure">previously</a>, every
680 basic block in a program ends with a "Terminator" instruction, which
681 indicates which block should be executed after the current block is
682 finished. These terminator instructions typically yield a '<tt>void</tt>'
683 value: they produce control flow, not values (the one exception being
684 the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
685 <p>There are five different terminator instructions: the '<a
686 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
687 instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
688 the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, and the '<a
689 href="#i_unwind"><tt>unwind</tt></a>' instruction.</p>
691 <!-- _______________________________________________________________________ -->
692 <div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
693 Instruction</a> </div>
694 <div class="doc_text">
696 <pre> ret <type> <value> <i>; Return a value from a non-void function</i>
697 ret void <i>; Return from void function</i>
700 <p>The '<tt>ret</tt>' instruction is used to return control flow (and a
701 value) from a function, back to the caller.</p>
702 <p>There are two forms of the '<tt>ret</tt>' instructruction: one that
703 returns a value and then causes control flow, and one that just causes
704 control flow to occur.</p>
706 <p>The '<tt>ret</tt>' instruction may return any '<a
707 href="#t_firstclass">first class</a>' type. Notice that a function is
708 not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
709 instruction inside of the function that returns a value that does not
710 match the return type of the function.</p>
712 <p>When the '<tt>ret</tt>' instruction is executed, control flow
713 returns back to the calling function's context. If the caller is a "<a
714 href="#i_call"><tt>call</tt></a> instruction, execution continues at
715 the instruction after the call. If the caller was an "<a
716 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
717 at the beginning "normal" of the destination block. If the instruction
718 returns a value, that value shall set the call or invoke instruction's
721 <pre> ret int 5 <i>; Return an integer value of 5</i>
722 ret void <i>; Return from a void function</i>
725 <!-- _______________________________________________________________________ -->
726 <div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
727 <div class="doc_text">
729 <pre> br bool <cond>, label <iftrue>, label <iffalse><br> br label <dest> <i>; Unconditional branch</i>
732 <p>The '<tt>br</tt>' instruction is used to cause control flow to
733 transfer to a different basic block in the current function. There are
734 two forms of this instruction, corresponding to a conditional branch
735 and an unconditional branch.</p>
737 <p>The conditional branch form of the '<tt>br</tt>' instruction takes a
738 single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
739 unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
740 value as a target.</p>
742 <p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
743 argument is evaluated. If the value is <tt>true</tt>, control flows
744 to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
745 control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
747 <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
748 href="#i_ret">ret</a> int 1<br>IfUnequal:<br> <a href="#i_ret">ret</a> int 0<br></pre>
750 <!-- _______________________________________________________________________ -->
751 <div class="doc_subsubsection"> <a name="i_switch">'<tt>switch</tt>'
752 Instruction</a> </div>
753 <div class="doc_text">
755 <pre> switch uint <value>, label <defaultdest> [ int <val>, label <dest>, ... ]<br></pre>
757 <p>The '<tt>switch</tt>' instruction is used to transfer control flow
758 to one of several different places. It is a generalization of the '<tt>br</tt>'
759 instruction, allowing a branch to occur to one of many possible
762 <p>The '<tt>switch</tt>' instruction uses three parameters: a '<tt>uint</tt>'
763 comparison value '<tt>value</tt>', a default '<tt>label</tt>'
764 destination, and an array of pairs of comparison value constants and '<tt>label</tt>'s.</p>
766 <p>The <tt>switch</tt> instruction specifies a table of values and
767 destinations. When the '<tt>switch</tt>' instruction is executed, this
768 table is searched for the given value. If the value is found, the
769 corresponding destination is branched to, otherwise the default value
770 it transfered to.</p>
771 <h5>Implementation:</h5>
772 <p>Depending on properties of the target machine and the particular <tt>switch</tt>
773 instruction, this instruction may be code generated as a series of
774 chained conditional branches, or with a lookup table.</p>
776 <pre> <i>; Emulate a conditional br instruction</i>
778 href="#i_cast">cast</a> bool %value to uint<br> switch uint %Val, label %truedest [int 0, label %falsedest ]<br><br> <i>; Emulate an unconditional br instruction</i>
779 switch uint 0, label %dest [ ]
781 <i>; Implement a jump table:</i>
782 switch uint %val, label %otherwise [ int 0, label %onzero,
784 int 2, label %ontwo ]
787 <!-- _______________________________________________________________________ -->
788 <div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>'
789 Instruction</a> </div>
790 <div class="doc_text">
792 <pre> <result> = invoke <ptr to function ty> %<function ptr val>(<function args>)<br> to label <normal label> except label <exception label><br></pre>
794 <p>The '<tt>invoke</tt>' instruction causes control to transfer to a
795 specified function, with the possibility of control flow transfer to
796 either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>.
797 If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>"
798 instruction, control flow will return to the "normal" label. If the
799 callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
800 instruction, control is interrupted, and continued at the dynamically
801 nearest "except" label.</p>
803 <p>This instruction requires several arguments:</p>
805 <li>'<tt>ptr to function ty</tt>': shall be the signature of the
806 pointer to function value being invoked. In most cases, this is a
807 direct function invocation, but indirect <tt>invoke</tt>s are just as
808 possible, branching off an arbitrary pointer to function value. </li>
809 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer
810 to a function to be invoked. </li>
811 <li>'<tt>function args</tt>': argument list whose types match the
812 function signature argument types. If the function signature indicates
813 the function accepts a variable number of arguments, the extra
814 arguments can be specified. </li>
815 <li>'<tt>normal label</tt>': the label reached when the called
816 function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
817 <li>'<tt>exception label</tt>': the label reached when a callee
818 returns with the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
821 <p>This instruction is designed to operate as a standard '<tt><a
822 href="#i_call">call</a></tt>' instruction in most regards. The
823 primary difference is that it establishes an association with a label,
824 which is used by the runtime library to unwind the stack.</p>
825 <p>This instruction is used in languages with destructors to ensure
826 that proper cleanup is performed in the case of either a <tt>longjmp</tt>
827 or a thrown exception. Additionally, this is important for
828 implementation of '<tt>catch</tt>' clauses in high-level languages that
831 <pre> %retval = invoke int %Test(int 15)<br> to label %Continue<br> except label %TestCleanup <i>; {int}:retval set</i>
834 <!-- _______________________________________________________________________ -->
835 <div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
836 Instruction</a> </div>
837 <div class="doc_text">
839 <pre> unwind<br></pre>
841 <p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing
842 control flow at the first callee in the dynamic call stack which used
843 an <a href="#i_invoke"><tt>invoke</tt></a> instruction to perform the
844 call. This is primarily used to implement exception handling.</p>
846 <p>The '<tt>unwind</tt>' intrinsic causes execution of the current
847 function to immediately halt. The dynamic call stack is then searched
848 for the first <a href="#i_invoke"><tt>invoke</tt></a> instruction on
849 the call stack. Once found, execution continues at the "exceptional"
850 destination block specified by the <tt>invoke</tt> instruction. If
851 there is no <tt>invoke</tt> instruction in the dynamic call chain,
852 undefined behavior results.</p>
854 <!-- ======================================================================= -->
855 <div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
856 <div class="doc_text">
857 <p>Binary operators are used to do most of the computation in a
858 program. They require two operands, execute an operation on them, and
859 produce a single value. The result value of a binary operator is not
860 necessarily the same type as its operands.</p>
861 <p>There are several different binary operators:</p>
863 <!-- _______________________________________________________________________ -->
864 <div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
865 Instruction</a> </div>
866 <div class="doc_text">
868 <pre> <result> = add <ty> <var1>, <var2> <i>; yields {ty}:result</i>
871 <p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
873 <p>The two arguments to the '<tt>add</tt>' instruction must be either <a
874 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
875 values. Both arguments must have identical types.</p>
877 <p>The value produced is the integer or floating point sum of the two
880 <pre> <result> = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
883 <!-- _______________________________________________________________________ -->
884 <div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
885 Instruction</a> </div>
886 <div class="doc_text">
888 <pre> <result> = sub <ty> <var1>, <var2> <i>; yields {ty}:result</i>
891 <p>The '<tt>sub</tt>' instruction returns the difference of its two
893 <p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
894 instruction present in most other intermediate representations.</p>
896 <p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
897 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
898 values. Both arguments must have identical types.</p>
900 <p>The value produced is the integer or floating point difference of
901 the two operands.</p>
903 <pre> <result> = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
904 <result> = sub int 0, %val <i>; yields {int}:result = -%var</i>
907 <!-- _______________________________________________________________________ -->
908 <div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
909 Instruction</a> </div>
910 <div class="doc_text">
912 <pre> <result> = mul <ty> <var1>, <var2> <i>; yields {ty}:result</i>
915 <p>The '<tt>mul</tt>' instruction returns the product of its two
918 <p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
919 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
920 values. Both arguments must have identical types.</p>
922 <p>The value produced is the integer or floating point product of the
924 <p>There is no signed vs unsigned multiplication. The appropriate
925 action is taken based on the type of the operand.</p>
927 <pre> <result> = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
930 <!-- _______________________________________________________________________ -->
931 <div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
932 Instruction</a> </div>
933 <div class="doc_text">
935 <pre> <result> = div <ty> <var1>, <var2> <i>; yields {ty}:result</i>
938 <p>The '<tt>div</tt>' instruction returns the quotient of its two
941 <p>The two arguments to the '<tt>div</tt>' instruction must be either <a
942 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
943 values. Both arguments must have identical types.</p>
945 <p>The value produced is the integer or floating point quotient of the
948 <pre> <result> = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
951 <!-- _______________________________________________________________________ -->
952 <div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
953 Instruction</a> </div>
954 <div class="doc_text">
956 <pre> <result> = rem <ty> <var1>, <var2> <i>; yields {ty}:result</i>
959 <p>The '<tt>rem</tt>' instruction returns the remainder from the
960 division of its two operands.</p>
962 <p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
963 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
964 values. Both arguments must have identical types.</p>
966 <p>This returns the <i>remainder</i> of a division (where the result
967 has the same sign as the divisor), not the <i>modulus</i> (where the
968 result has the same sign as the dividend) of a value. For more
969 information about the difference, see: <a
970 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
973 <pre> <result> = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
976 <!-- _______________________________________________________________________ -->
977 <div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
978 Instructions</a> </div>
979 <div class="doc_text">
981 <pre> <result> = seteq <ty> <var1>, <var2> <i>; yields {bool}:result</i>
982 <result> = setne <ty> <var1>, <var2> <i>; yields {bool}:result</i>
983 <result> = setlt <ty> <var1>, <var2> <i>; yields {bool}:result</i>
984 <result> = setgt <ty> <var1>, <var2> <i>; yields {bool}:result</i>
985 <result> = setle <ty> <var1>, <var2> <i>; yields {bool}:result</i>
986 <result> = setge <ty> <var1>, <var2> <i>; yields {bool}:result</i>
989 <p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
990 value based on a comparison of their two operands.</p>
992 <p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
993 be of <a href="#t_firstclass">first class</a> type (it is not possible
994 to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
995 or '<tt>void</tt>' values, etc...). Both arguments must have identical
998 <p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
999 value if both operands are equal.<br>
1000 The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1001 value if both operands are unequal.<br>
1002 The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1003 value if the first operand is less than the second operand.<br>
1004 The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1005 value if the first operand is greater than the second operand.<br>
1006 The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1007 value if the first operand is less than or equal to the second operand.<br>
1008 The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1009 value if the first operand is greater than or equal to the second
1012 <pre> <result> = seteq int 4, 5 <i>; yields {bool}:result = false</i>
1013 <result> = setne float 4, 5 <i>; yields {bool}:result = true</i>
1014 <result> = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1015 <result> = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1016 <result> = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1017 <result> = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1020 <!-- ======================================================================= -->
1021 <div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1022 Operations</a> </div>
1023 <div class="doc_text">
1024 <p>Bitwise binary operators are used to do various forms of
1025 bit-twiddling in a program. They are generally very efficient
1026 instructions, and can commonly be strength reduced from other
1027 instructions. They require two operands, execute an operation on them,
1028 and produce a single value. The resulting value of the bitwise binary
1029 operators is always the same type as its first operand.</p>
1031 <!-- _______________________________________________________________________ -->
1032 <div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1033 Instruction</a> </div>
1034 <div class="doc_text">
1036 <pre> <result> = and <ty> <var1>, <var2> <i>; yields {ty}:result</i>
1039 <p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1040 its two operands.</p>
1042 <p>The two arguments to the '<tt>and</tt>' instruction must be <a
1043 href="#t_integral">integral</a> values. Both arguments must have
1044 identical types.</p>
1046 <p>The truth table used for the '<tt>and</tt>' instruction is:</p>
1049 <table border="1" cellspacing="0" cellpadding="4">
1080 <pre> <result> = and int 4, %var <i>; yields {int}:result = 4 & %var</i>
1081 <result> = and int 15, 40 <i>; yields {int}:result = 8</i>
1082 <result> = and int 4, 8 <i>; yields {int}:result = 0</i>
1085 <!-- _______________________________________________________________________ -->
1086 <div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
1087 <div class="doc_text">
1089 <pre> <result> = or <ty> <var1>, <var2> <i>; yields {ty}:result</i>
1092 <p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1093 or of its two operands.</p>
1095 <p>The two arguments to the '<tt>or</tt>' instruction must be <a
1096 href="#t_integral">integral</a> values. Both arguments must have
1097 identical types.</p>
1099 <p>The truth table used for the '<tt>or</tt>' instruction is:</p>
1102 <table border="1" cellspacing="0" cellpadding="4">
1133 <pre> <result> = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
1134 <result> = or int 15, 40 <i>; yields {int}:result = 47</i>
1135 <result> = or int 4, 8 <i>; yields {int}:result = 12</i>
1138 <!-- _______________________________________________________________________ -->
1139 <div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1140 Instruction</a> </div>
1141 <div class="doc_text">
1143 <pre> <result> = xor <ty> <var1>, <var2> <i>; yields {ty}:result</i>
1146 <p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1147 or of its two operands. The <tt>xor</tt> is used to implement the
1148 "one's complement" operation, which is the "~" operator in C.</p>
1150 <p>The two arguments to the '<tt>xor</tt>' instruction must be <a
1151 href="#t_integral">integral</a> values. Both arguments must have
1152 identical types.</p>
1154 <p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
1157 <table border="1" cellspacing="0" cellpadding="4">
1189 <pre> <result> = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
1190 <result> = xor int 15, 40 <i>; yields {int}:result = 39</i>
1191 <result> = xor int 4, 8 <i>; yields {int}:result = 12</i>
1192 <result> = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
1195 <!-- _______________________________________________________________________ -->
1196 <div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1197 Instruction</a> </div>
1198 <div class="doc_text">
1200 <pre> <result> = shl <ty> <var1>, ubyte <var2> <i>; yields {ty}:result</i>
1203 <p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1204 the left a specified number of bits.</p>
1206 <p>The first argument to the '<tt>shl</tt>' instruction must be an <a
1207 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1210 <p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
1212 <pre> <result> = shl int 4, ubyte %var <i>; yields {int}:result = 4 << %var</i>
1213 <result> = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1214 <result> = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1217 <!-- _______________________________________________________________________ -->
1218 <div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1219 Instruction</a> </div>
1220 <div class="doc_text">
1222 <pre> <result> = shr <ty> <var1>, ubyte <var2> <i>; yields {ty}:result</i>
1225 <p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1226 the right a specified number of bits.</p>
1228 <p>The first argument to the '<tt>shr</tt>' instruction must be an <a
1229 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1232 <p>If the first argument is a <a href="#t_signed">signed</a> type, the
1233 most significant bit is duplicated in the newly free'd bit positions.
1234 If the first argument is unsigned, zero bits shall fill the empty
1237 <pre> <result> = shr int 4, ubyte %var <i>; yields {int}:result = 4 >> %var</i>
1238 <result> = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
1239 <result> = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
1240 <result> = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1241 <result> = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
1244 <!-- ======================================================================= -->
1245 <div class="doc_subsection"> <a name="memoryops">Memory Access
1246 Operations</a></div>
1247 <div class="doc_text">
1248 <p>A key design point of an SSA-based representation is how it
1249 represents memory. In LLVM, no memory locations are in SSA form, which
1250 makes things very simple. This section describes how to read, write,
1251 allocate and free memory in LLVM.</p>
1253 <!-- _______________________________________________________________________ -->
1254 <div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>'
1255 Instruction</a> </div>
1256 <div class="doc_text">
1258 <pre> <result> = malloc <type>, uint <NumElements> <i>; yields {type*}:result</i>
1259 <result> = malloc <type> <i>; yields {type*}:result</i>
1262 <p>The '<tt>malloc</tt>' instruction allocates memory from the system
1263 heap and returns a pointer to it.</p>
1265 <p>The the '<tt>malloc</tt>' instruction allocates <tt>sizeof(<type>)*NumElements</tt>
1266 bytes of memory from the operating system, and returns a pointer of the
1267 appropriate type to the program. The second form of the instruction is
1268 a shorter version of the first instruction that defaults to allocating
1270 <p>'<tt>type</tt>' must be a sized type.</p>
1272 <p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1273 a pointer is returned.</p>
1275 <pre> %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
1278 href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
1279 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1280 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
1283 <!-- _______________________________________________________________________ -->
1284 <div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>'
1285 Instruction</a> </div>
1286 <div class="doc_text">
1288 <pre> free <type> <value> <i>; yields {void}</i>
1291 <p>The '<tt>free</tt>' instruction returns memory back to the unused
1292 memory heap, to be reallocated in the future.</p>
1295 <p>'<tt>value</tt>' shall be a pointer value that points to a value
1296 that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1299 <p>Access to the memory pointed to by the pointer is not longer defined
1300 after this instruction executes.</p>
1302 <pre> %array = <a href="#i_malloc">malloc</a> [4 x ubyte] <i>; yields {[4 x ubyte]*}:array</i>
1303 free [4 x ubyte]* %array
1306 <!-- _______________________________________________________________________ -->
1307 <div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>'
1308 Instruction</a> </div>
1309 <div class="doc_text">
1311 <pre> <result> = alloca <type>, uint <NumElements> <i>; yields {type*}:result</i>
1312 <result> = alloca <type> <i>; yields {type*}:result</i>
1315 <p>The '<tt>alloca</tt>' instruction allocates memory on the current
1316 stack frame of the procedure that is live until the current function
1317 returns to its caller.</p>
1319 <p>The the '<tt>alloca</tt>' instruction allocates <tt>sizeof(<type>)*NumElements</tt>
1320 bytes of memory on the runtime stack, returning a pointer of the
1321 appropriate type to the program. The second form of the instruction is
1322 a shorter version of the first that defaults to allocating one element.</p>
1323 <p>'<tt>type</tt>' may be any sized type.</p>
1325 <p>Memory is allocated, a pointer is returned. '<tt>alloca</tt>'d
1326 memory is automatically released when the function returns. The '<tt>alloca</tt>'
1327 instruction is commonly used to represent automatic variables that must
1328 have an address available. When the function returns (either with the <tt><a
1329 href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt>
1330 instructions), the memory is reclaimed.</p>
1332 <pre> %ptr = alloca int <i>; yields {int*}:ptr</i>
1333 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
1336 <!-- _______________________________________________________________________ -->
1337 <div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1338 Instruction</a> </div>
1339 <div class="doc_text">
1341 <pre> <result> = load <ty>* <pointer><br> <result> = volatile load <ty>* <pointer><br></pre>
1343 <p>The '<tt>load</tt>' instruction is used to read from memory.</p>
1345 <p>The argument to the '<tt>load</tt>' instruction specifies the memory
1346 address to load from. The pointer must point to a <a
1347 href="t_firstclass">first class</a> type. If the <tt>load</tt> is
1348 marked as <tt>volatile</tt> then the optimizer is not allowed to modify
1349 the number or order of execution of this <tt>load</tt> with other
1350 volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1353 <p>The location of memory pointed to is loaded.</p>
1355 <pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1357 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
1358 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1361 <!-- _______________________________________________________________________ -->
1362 <div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1363 Instruction</a> </div>
1365 <pre> store <ty> <value>, <ty>* <pointer> <i>; yields {void}</i>
1366 volatile store <ty> <value>, <ty>* <pointer> <i>; yields {void}</i>
1369 <p>The '<tt>store</tt>' instruction is used to write to memory.</p>
1371 <p>There are two arguments to the '<tt>store</tt>' instruction: a value
1372 to store and an address to store it into. The type of the '<tt><pointer></tt>'
1373 operand must be a pointer to the type of the '<tt><value></tt>'
1374 operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the
1375 optimizer is not allowed to modify the number or order of execution of
1376 this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1377 href="#i_store">store</a></tt> instructions.</p>
1379 <p>The contents of memory are updated to contain '<tt><value></tt>'
1380 at the location specified by the '<tt><pointer></tt>' operand.</p>
1382 <pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1384 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
1385 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1387 <!-- _______________________________________________________________________ -->
1388 <div class="doc_subsubsection"> <a name="i_getelementptr">'<tt>getelementptr</tt>'
1389 Instruction</a> </div>
1390 <div class="doc_text">
1392 <pre> <result> = getelementptr <ty>* <ptrval>{, long <aidx>|, ubyte <sidx>}*<br></pre>
1394 <p>The '<tt>getelementptr</tt>' instruction is used to get the address
1395 of a subelement of an aggregate data structure.</p>
1397 <p>This instruction takes a list of <tt>long</tt> values and <tt>ubyte</tt>
1398 constants that indicate what form of addressing to perform. The actual
1399 types of the arguments provided depend on the type of the first pointer
1400 argument. The '<tt>getelementptr</tt>' instruction is used to index
1401 down through the type levels of a structure.</p>
1402 <p>For example, let's consider a C code fragment and how it gets
1403 compiled to LLVM:</p>
1404 <pre>struct RT {<br> char A;<br> int B[10][20];<br> char C;<br>};<br>struct ST {<br> int X;<br> double Y;<br> struct RT Z;<br>};<br><br>int *foo(struct ST *s) {<br> return &s[1].Z.B[5][13];<br>}<br></pre>
1405 <p>The LLVM code generated by the GCC frontend is:</p>
1406 <pre>%RT = type { sbyte, [10 x [20 x int]], sbyte }<br>%ST = type { int, double, %RT }<br><br>int* "foo"(%ST* %s) {<br> %reg = getelementptr %ST* %s, long 1, ubyte 2, ubyte 1, long 5, long 13<br> ret int* %reg<br>}<br></pre>
1408 <p>The index types specified for the '<tt>getelementptr</tt>'
1409 instruction depend on the pointer type that is being index into. <a
1410 href="t_pointer">Pointer</a> and <a href="t_array">array</a> types
1411 require '<tt>long</tt>' values, and <a href="t_struct">structure</a>
1412 types require '<tt>ubyte</tt>' <b>constants</b>.</p>
1413 <p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
1414 type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int,
1415 double, %RT }</tt>' type, a structure. The second index indexes into
1416 the third element of the structure, yielding a '<tt>%RT</tt>' = '<tt>{
1417 sbyte, [10 x [20 x int]], sbyte }</tt>' type, another structure. The
1418 third index indexes into the second element of the structure, yielding
1419 a '<tt>[10 x [20 x int]]</tt>' type, an array. The two dimensions of
1420 the array are subscripted into, yielding an '<tt>int</tt>' type. The '<tt>getelementptr</tt>'
1421 instruction return a pointer to this element, thus yielding a '<tt>int*</tt>'
1423 <p>Note that it is perfectly legal to index partially through a
1424 structure, returning a pointer to an inner element. Because of this,
1425 the LLVM code for the given testcase is equivalent to:</p>
1426 <pre>int* "foo"(%ST* %s) {<br> %t1 = getelementptr %ST* %s , long 1 <i>; yields %ST*:%t1</i>
1427 %t2 = getelementptr %ST* %t1, long 0, ubyte 2 <i>; yields %RT*:%t2</i>
1428 %t3 = getelementptr %RT* %t2, long 0, ubyte 1 <i>; yields [10 x [20 x int]]*:%t3</i>
1429 %t4 = getelementptr [10 x [20 x int]]* %t3, long 0, long 5 <i>; yields [20 x int]*:%t4</i>
1430 %t5 = getelementptr [20 x int]* %t4, long 0, long 13 <i>; yields int*:%t5</i>
1435 <pre> <i>; yields [12 x ubyte]*:aptr</i>
1436 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, ubyte 1<br></pre>
1437 <h5> Note To The Novice:</h5>
1438 When using indexing into global arrays with the '<tt>getelementptr</tt>'
1439 instruction, you must remember that the </div>
1440 <!-- ======================================================================= -->
1441 <div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
1442 <div class="doc_text">
1443 <p>The instructions in this catagory are the "miscellaneous"
1444 instructions, which defy better classification.</p>
1446 <!-- _______________________________________________________________________ -->
1447 <div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
1448 Instruction</a> </div>
1449 <div class="doc_text">
1451 <pre> <result> = phi <ty> [ <val0>, <label0>], ...<br></pre>
1453 <p>The '<tt>phi</tt>' instruction is used to implement the φ node in
1454 the SSA graph representing the function.</p>
1456 <p>The type of the incoming values are specified with the first type
1457 field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
1458 as arguments, with one pair for each predecessor basic block of the
1459 current block. Only values of <a href="#t_firstclass">first class</a>
1460 type may be used as the value arguments to the PHI node. Only labels
1461 may be used as the label arguments.</p>
1462 <p>There must be no non-phi instructions between the start of a basic
1463 block and the PHI instructions: i.e. PHI instructions must be first in
1466 <p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
1467 value specified by the parameter, depending on which basic block we
1468 came from in the last <a href="#terminators">terminator</a> instruction.</p>
1470 <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>
1472 <!-- _______________________________________________________________________ -->
1473 <div class="doc_subsubsection"> <a name="i_cast">'<tt>cast .. to</tt>'
1474 Instruction</a> </div>
1475 <div class="doc_text">
1477 <pre> <result> = cast <ty> <value> to <ty2> <i>; yields ty2</i>
1480 <p>The '<tt>cast</tt>' instruction is used as the primitive means to
1481 convert integers to floating point, change data type sizes, and break
1482 type safety (by casting pointers).</p>
1484 <p>The '<tt>cast</tt>' instruction takes a value to cast, which must be
1485 a first class value, and a type to cast it to, which must also be a <a
1486 href="#t_firstclass">first class</a> type.</p>
1488 <p>This instruction follows the C rules for explicit casts when
1489 determining how the data being cast must change to fit in its new
1491 <p>When casting to bool, any value that would be considered true in the
1492 context of a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>'
1493 values, all else are '<tt>false</tt>'.</p>
1494 <p>When extending an integral value from a type of one signness to
1495 another (for example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value
1496 is sign-extended if the <b>source</b> value is signed, and
1497 zero-extended if the source value is unsigned. <tt>bool</tt> values
1498 are always zero extended into either zero or one.</p>
1500 <pre> %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
1501 %Y = cast int 123 to bool <i>; yields bool:true</i>
1504 <!-- _______________________________________________________________________ -->
1505 <div class="doc_subsubsection"> <a name="i_call">'<tt>call</tt>'
1506 Instruction</a> </div>
1507 <div class="doc_text">
1509 <pre> <result> = call <ty>* <fnptrval>(<param list>)<br></pre>
1511 <p>The '<tt>call</tt>' instruction represents a simple function call.</p>
1513 <p>This instruction requires several arguments:</p>
1516 <p>'<tt>ty</tt>': shall be the signature of the pointer to function
1517 value being invoked. The argument types must match the types implied
1518 by this signature.</p>
1521 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a
1522 function to be invoked. In most cases, this is a direct function
1523 invocation, but indirect <tt>call</tt>s are just as possible,
1524 calling an arbitrary pointer to function values.</p>
1527 <p>'<tt>function args</tt>': argument list whose types match the
1528 function signature argument types. If the function signature
1529 indicates the function accepts a variable number of arguments, the
1530 extra arguments can be specified.</p>
1534 <p>The '<tt>call</tt>' instruction is used to cause control flow to
1535 transfer to a specified function, with its incoming arguments bound to
1536 the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
1537 instruction in the called function, control flow continues with the
1538 instruction after the function call, and the return value of the
1539 function is bound to the result argument. This is a simpler case of
1540 the <a href="#i_invoke">invoke</a> instruction.</p>
1542 <pre> %retval = call int %test(int %argc)<br> call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42);<br></pre>
1544 <!-- _______________________________________________________________________ -->
1545 <div class="doc_subsubsection"> <a name="i_vanext">'<tt>vanext</tt>'
1546 Instruction</a> </div>
1547 <div class="doc_text">
1549 <pre> <resultarglist> = vanext <va_list> <arglist>, <argty><br></pre>
1551 <p>The '<tt>vanext</tt>' instruction is used to access arguments passed
1552 through the "variable argument" area of a function call. It is used to
1553 implement the <tt>va_arg</tt> macro in C.</p>
1555 <p>This instruction takes a <tt>valist</tt> value and the type of the
1556 argument. It returns another <tt>valist</tt>.</p>
1558 <p>The '<tt>vanext</tt>' instruction advances the specified <tt>valist</tt>
1559 past an argument of the specified type. In conjunction with the <a
1560 href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement
1561 the <tt>va_arg</tt> macro available in C. For more information, see
1562 the variable argument handling <a href="#int_varargs">Intrinsic
1564 <p>It is legal for this instruction to be called in a function which
1565 does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
1567 <p><tt>vanext</tt> is an LLVM instruction instead of an <a
1568 href="#intrinsics">intrinsic function</a> because it takes an type as
1571 <p>See the <a href="#int_varargs">variable argument processing</a>
1574 <!-- _______________________________________________________________________ -->
1575 <div class="doc_subsubsection"> <a name="i_vaarg">'<tt>vaarg</tt>'
1576 Instruction</a> </div>
1577 <div class="doc_text">
1579 <pre> <resultval> = vaarg <va_list> <arglist>, <argty><br></pre>
1581 <p>The '<tt>vaarg</tt>' instruction is used to access arguments passed
1582 through the "variable argument" area of a function call. It is used to
1583 implement the <tt>va_arg</tt> macro in C.</p>
1585 <p>This instruction takes a <tt>valist</tt> value and the type of the
1586 argument. It returns a value of the specified argument type.</p>
1588 <p>The '<tt>vaarg</tt>' instruction loads an argument of the specified
1589 type from the specified <tt>va_list</tt>. In conjunction with the <a
1590 href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to
1591 implement the <tt>va_arg</tt> macro available in C. For more
1592 information, see the variable argument handling <a href="#int_varargs">Intrinsic
1594 <p>It is legal for this instruction to be called in a function which
1595 does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
1597 <p><tt>vaarg</tt> is an LLVM instruction instead of an <a
1598 href="#intrinsics">intrinsic function</a> because it takes an type as
1601 <p>See the <a href="#int_varargs">variable argument processing</a>
1605 <!-- *********************************************************************** -->
1606 <div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
1607 <!-- *********************************************************************** -->
1609 <div class="doc_text">
1611 <p>LLVM supports the notion of an "intrinsic function". These functions have
1612 well known names and semantics, and are required to follow certain
1613 restrictions. Overall, these instructions represent an extension mechanism for
1614 the LLVM language that does not require changing all of the transformations in
1615 LLVM to add to the language (or the bytecode reader/writer, the parser,
1618 <p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix, this
1619 prefix is reserved in LLVM for intrinsic names, thus functions may not be named
1620 this. Intrinsic functions must always be external functions: you cannot define
1621 the body of intrinsic functions. Intrinsic functions may only be used in call
1622 or invoke instructions: it is illegal to take the address of an intrinsic
1623 function. Additionally, because intrinsic functions are part of the LLVM
1624 language, it is required that they all be documented here if any are added.</p>
1628 Adding an intrinsic to LLVM is straight-forward if it is possible to express the
1629 concept in LLVM directly (ie, code generator support is not _required_). To do
1630 this, extend the default implementation of the IntrinsicLowering class to handle
1631 the intrinsic. Code generators use this class to lower intrinsics they do not
1632 understand to raw LLVM instructions that they do.
1637 <!-- ======================================================================= -->
1638 <div class="doc_subsection">
1639 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
1642 <div class="doc_text">
1643 <p>Variable argument support is defined in LLVM with the <a
1644 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
1645 intrinsic functions. These functions are related to the similarly
1646 named macros defined in the <tt><stdarg.h></tt> header file.</p>
1647 <p>All of these functions operate on arguments that use a
1648 target-specific value type "<tt>va_list</tt>". The LLVM assembly
1649 language reference manual does not define what this type is, so all
1650 transformations should be prepared to handle intrinsics with any type
1652 <p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
1653 instruction and the variable argument handling intrinsic functions are
1656 int %test(int %X, ...) {
1657 ; Initialize variable argument processing
1658 %ap = call sbyte* %<a href="#i_va_start">llvm.va_start</a>()
1660 ; Read a single integer argument
1661 %tmp = vaarg sbyte* %ap, int
1663 ; Advance to the next argument
1664 %ap2 = vanext sbyte* %ap, int
1666 ; Demonstrate usage of llvm.va_copy and llvm.va_end
1667 %aq = call sbyte* %<a href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2)
1668 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %aq)
1670 ; Stop processing of arguments.
1671 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %ap2)
1677 <!-- _______________________________________________________________________ -->
1678 <div class="doc_subsubsection">
1679 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
1683 <div class="doc_text">
1685 <pre> call va_list ()* %llvm.va_start()<br></pre>
1687 <p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt><arglist></tt>
1688 for subsequent use by the variable argument intrinsics.</p>
1690 <p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
1691 macro available in C. In a target-dependent way, it initializes and
1692 returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt>
1693 will produce the first variable argument passed to the function. Unlike
1694 the C <tt>va_start</tt> macro, this intrinsic does not need to know the
1695 last argument of the function, the compiler can figure that out.</p>
1696 <p>Note that this intrinsic function is only legal to be called from
1697 within the body of a variable argument function.</p>
1700 <!-- _______________________________________________________________________ -->
1701 <div class="doc_subsubsection">
1702 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
1705 <div class="doc_text">
1707 <pre> call void (va_list)* %llvm.va_end(va_list <arglist>)<br></pre>
1709 <p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt><arglist></tt>
1710 which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
1711 or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
1713 <p>The argument is a <tt>va_list</tt> to destroy.</p>
1715 <p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
1716 macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
1717 Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
1718 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
1719 with calls to <tt>llvm.va_end</tt>.</p>
1722 <!-- _______________________________________________________________________ -->
1723 <div class="doc_subsubsection">
1724 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
1727 <div class="doc_text">
1729 <pre> call va_list (va_list)* %llvm.va_copy(va_list <destarglist>)<br></pre>
1731 <p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument
1732 position from the source argument list to the destination argument list.</p>
1734 <p>The argument is the <tt>va_list</tt> to copy.</p>
1736 <p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
1737 macro available in C. In a target-dependent way, it copies the source <tt>va_list</tt>
1738 element into the returned list. This intrinsic is necessary because the <tt><a
1739 href="i_va_start">llvm.va_start</a></tt> intrinsic may be arbitrarily
1740 complex and require memory allocation, for example.</p>
1743 <!-- ======================================================================= -->
1744 <div class="doc_subsection">
1745 <a name="int_codegen">Code Generator Intrinsics</a>
1748 <div class="doc_text">
1750 These intrinsics are provided by LLVM to expose special features that may only
1751 be implemented with code generator support.
1756 <!-- _______________________________________________________________________ -->
1757 <div class="doc_subsubsection">
1758 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
1761 <div class="doc_text">
1765 call void* ()* %llvm.returnaddress(uint <level>)
1771 The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
1772 indicating the return address of the current function or one of its callers.
1778 The argument to this intrinsic indicates which function to return the address
1779 for. Zero indicates the calling function, one indicates its caller, etc. The
1780 argument is <b>required</b> to be a constant integer value.
1786 The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
1787 the return address of the specified call frame, or zero if it cannot be
1788 identified. The value returned by this intrinsic is likely to be incorrect or 0
1789 for arguments other than zero, so it should only be used for debugging purposes.
1793 Note that calling this intrinsic does not prevent function inlining or other
1794 aggressive transformations, so the value returned may not that of the obvious
1795 source-language caller.
1800 <!-- _______________________________________________________________________ -->
1801 <div class="doc_subsubsection">
1802 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
1805 <div class="doc_text">
1809 call void* ()* %llvm.frameaddress(uint <level>)
1815 The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
1816 pointer value for the specified stack frame.
1822 The argument to this intrinsic indicates which function to return the frame
1823 pointer for. Zero indicates the calling function, one indicates its caller,
1824 etc. The argument is <b>required</b> to be a constant integer value.
1830 The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
1831 the frame address of the specified call frame, or zero if it cannot be
1832 identified. The value returned by this intrinsic is likely to be incorrect or 0
1833 for arguments other than zero, so it should only be used for debugging purposes.
1837 Note that calling this intrinsic does not prevent function inlining or other
1838 aggressive transformations, so the value returned may not that of the obvious
1839 source-language caller.
1844 <!-- ======================================================================= -->
1845 <div class="doc_subsection">
1846 <a name="int_libc">Standard C Library Intrinsics</a>
1849 <div class="doc_text">
1851 LLVM provides intrinsics for a few important standard C library functions.
1852 These intrinsics allow source-language front-ends to pass information about the
1853 alignment of the pointer arguments to the code generator, providing opportunity
1854 for more efficient code generation.
1859 <!-- _______________________________________________________________________ -->
1860 <div class="doc_subsubsection">
1861 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
1864 <div class="doc_text">
1868 call void (sbyte*, sbyte*, uint, uint)* %llvm.memcpy(sbyte* <dest>, sbyte* <src>,
1869 uint <len>, uint <align>)
1875 The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
1876 location to the destination location.
1880 Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
1881 does not return a value, and takes an extra alignment argument.
1887 The first argument is a pointer to the destination, the second is a pointer to
1888 the source. The third argument is an (arbitrarily sized) integer argument
1889 specifying the number of bytes to copy, and the fourth argument is the alignment
1890 of the source and destination locations.
1894 If the call to this intrinisic has an alignment value that is not 0 or 1, then
1895 the caller guarantees that the size of the copy is a multiple of the alignment
1896 and that both the source and destination pointers are aligned to that boundary.
1902 The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
1903 location to the destination location, which are not allowed to overlap. It
1904 copies "len" bytes of memory over. If the argument is known to be aligned to
1905 some boundary, this can be specified as the fourth argument, otherwise it should
1911 <!-- _______________________________________________________________________ -->
1912 <div class="doc_subsubsection">
1913 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
1916 <div class="doc_text">
1920 call void (sbyte*, sbyte*, uint, uint)* %llvm.memmove(sbyte* <dest>, sbyte* <src>,
1921 uint <len>, uint <align>)
1927 The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
1928 location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>'
1929 intrinsic but allows the two memory locations to overlap.
1933 Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
1934 does not return a value, and takes an extra alignment argument.
1940 The first argument is a pointer to the destination, the second is a pointer to
1941 the source. The third argument is an (arbitrarily sized) integer argument
1942 specifying the number of bytes to copy, and the fourth argument is the alignment
1943 of the source and destination locations.
1947 If the call to this intrinisic has an alignment value that is not 0 or 1, then
1948 the caller guarantees that the size of the copy is a multiple of the alignment
1949 and that both the source and destination pointers are aligned to that boundary.
1955 The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
1956 location to the destination location, which may overlap. It
1957 copies "len" bytes of memory over. If the argument is known to be aligned to
1958 some boundary, this can be specified as the fourth argument, otherwise it should
1964 <!-- _______________________________________________________________________ -->
1965 <div class="doc_subsubsection">
1966 <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a>
1969 <div class="doc_text">
1973 call void (sbyte*, ubyte, uint, uint)* %llvm.memset(sbyte* <dest>, ubyte <val>,
1974 uint <len>, uint <align>)
1980 The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular
1985 Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
1986 does not return a value, and takes an extra alignment argument.
1992 The first argument is a pointer to the destination to fill, the second is the
1993 byte value to fill it with, the third argument is an (arbitrarily sized) integer
1994 argument specifying the number of bytes to fill, and the fourth argument is the
1995 known alignment of destination location.
1999 If the call to this intrinisic has an alignment value that is not 0 or 1, then
2000 the caller guarantees that the size of the copy is a multiple of the alignment
2001 and that the destination pointer is aligned to that boundary.
2007 The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the
2008 destination location. If the argument is known to be aligned to some boundary,
2009 this can be specified as the fourth argument, otherwise it should be set to 0 or
2015 <!-- ======================================================================= -->
2016 <div class="doc_subsection">
2017 <a name="int_debugger">Debugger Intrinsics</a>
2020 <div class="doc_text">
2022 The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
2023 are described in the <a
2024 href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
2025 Debugging</a> document.
2030 <!-- *********************************************************************** -->
2032 <div class="doc_footer">
2033 <address><a href="mailto:sabre@nondot.org">Chris Lattner</a></address>
2034 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a> <br>
2035 Last modified: $Date$ </div>