blob: 38307cb094e8e2ff2bdc5355d0149dcf5366349a [file] [log] [blame]
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
Misha Brukman9d0919f2003-11-08 01:05:38 +00003<html>
4<head>
5 <title>LLVM Assembly Language Reference Manual</title>
6 <link rel="stylesheet" href="llvm.css" type="text/css">
7</head>
Chris Lattnerd7923912004-05-23 21:06:01 +00008
Misha Brukman9d0919f2003-11-08 01:05:38 +00009<body>
Chris Lattnerd7923912004-05-23 21:06:01 +000010
Chris Lattner261efe92003-11-25 01:02:51 +000011<div class="doc_title"> LLVM Language Reference Manual </div>
Chris Lattner00950542001-06-06 20:29:01 +000012<ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000013 <li><a href="#abstract">Abstract</a></li>
14 <li><a href="#introduction">Introduction</a></li>
15 <li><a href="#identifiers">Identifiers</a></li>
Chris Lattner00950542001-06-06 20:29:01 +000016 <li><a href="#typesystem">Type System</a>
17 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000018 <li><a href="#t_primitive">Primitive Types</a>
19 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000020 <li><a href="#t_classifications">Type Classifications</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000021 </ol>
22 </li>
Chris Lattner00950542001-06-06 20:29:01 +000023 <li><a href="#t_derived">Derived Types</a>
24 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000025 <li><a href="#t_array">Array Type</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000026 <li><a href="#t_function">Function Type</a></li>
27 <li><a href="#t_pointer">Pointer Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000028 <li><a href="#t_struct">Structure Type</a></li>
29<!-- <li><a href="#t_packed" >Packed Type</a> -->
30 </ol>
31 </li>
32 </ol>
33 </li>
Chris Lattner00950542001-06-06 20:29:01 +000034 <li><a href="#highlevel">High Level Structure</a>
35 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000036 <li><a href="#modulestructure">Module Structure</a></li>
37 <li><a href="#globalvars">Global Variables</a></li>
38 <li><a href="#functionstructure">Function Structure</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000039 </ol>
40 </li>
Chris Lattner00950542001-06-06 20:29:01 +000041 <li><a href="#instref">Instruction Reference</a>
42 <ol>
43 <li><a href="#terminators">Terminator Instructions</a>
44 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000045 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
46 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000047 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
48 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000049 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
50 </ol>
51 </li>
Chris Lattner00950542001-06-06 20:29:01 +000052 <li><a href="#binaryops">Binary Operations</a>
53 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000054 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
55 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
56 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
57 <li><a href="#i_div">'<tt>div</tt>' Instruction</a></li>
58 <li><a href="#i_rem">'<tt>rem</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000059 <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000060 </ol>
61 </li>
Chris Lattner00950542001-06-06 20:29:01 +000062 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
63 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000064 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000065 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000066 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
67 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
68 <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000069 </ol>
70 </li>
Chris Lattner00950542001-06-06 20:29:01 +000071 <li><a href="#memoryops">Memory Access Operations</a>
72 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000073 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
74 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
75 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
76 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
77 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
78 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
79 </ol>
80 </li>
Chris Lattner00950542001-06-06 20:29:01 +000081 <li><a href="#otherops">Other Operations</a>
82 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000083 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000084 <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li>
Chris Lattnercc37aae2004-03-12 05:50:16 +000085 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000086 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000087 <li><a href="#i_vanext">'<tt>vanext</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000088 <li><a href="#i_vaarg">'<tt>vaarg</tt>' Instruction</a></li>
Chris Lattner00950542001-06-06 20:29:01 +000089 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +000090 </li>
Chris Lattner00950542001-06-06 20:29:01 +000091 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +000092 </li>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +000093 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +000094 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000095 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
96 <ol>
97 <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
98 <li><a href="#i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
99 <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
100 </ol>
101 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000102 <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
103 <ol>
104 <li><a href="#i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li>
105 <li><a href="#i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li>
106 <li><a href="#i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li>
107 </ol>
108 </li>
Chris Lattner10610642004-02-14 04:08:35 +0000109 <li><a href="#int_codegen">Code Generator Intrinsics</a>
110 <ol>
111 <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
112 <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
John Criswell7123e272004-04-09 16:43:20 +0000113 </ol>
114 </li>
115 <li><a href="#int_os">Operating System Intrinsics</a>
116 <ol>
Chris Lattner32006282004-06-11 02:28:03 +0000117 <li><a href="#i_readport">'<tt>llvm.readport</tt>' Intrinsic</a></li>
118 <li><a href="#i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a></li>
John Criswell183402a2004-04-12 15:02:16 +0000119 <li><a href="#i_readio">'<tt>llvm.readio</tt>' Intrinsic</a></li>
120 <li><a href="#i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000121 </ol>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000122 <li><a href="#int_libc">Standard C Library Intrinsics</a>
123 <ol>
124 <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li>
Chris Lattner0eb51b42004-02-12 18:10:10 +0000125 <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000126 <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li>
Chris Lattner32006282004-06-11 02:28:03 +0000127 <li><a href="#i_isnan">'<tt>llvm.isnan</tt>' Intrinsic</a></li>
Alkis Evlogimenos96853722004-06-12 19:19:14 +0000128 <li><a href="#i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a></li>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000129 </ol>
130 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000131 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000132 </ol>
133 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000134</ol>
Chris Lattnerd7923912004-05-23 21:06:01 +0000135
136<div class="doc_author">
137 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
138 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000139</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000140
Chris Lattner00950542001-06-06 20:29:01 +0000141<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000142<div class="doc_section"> <a name="abstract">Abstract </a></div>
143<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000144
Misha Brukman9d0919f2003-11-08 01:05:38 +0000145<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000146<p>This document is a reference manual for the LLVM assembly language.
147LLVM is an SSA based representation that provides type safety,
148low-level operations, flexibility, and the capability of representing
149'all' high-level languages cleanly. It is the common code
150representation used throughout all phases of the LLVM compilation
151strategy.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000152</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000153
Chris Lattner00950542001-06-06 20:29:01 +0000154<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000155<div class="doc_section"> <a name="introduction">Introduction</a> </div>
156<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000157
Misha Brukman9d0919f2003-11-08 01:05:38 +0000158<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000159
Chris Lattner261efe92003-11-25 01:02:51 +0000160<p>The LLVM code representation is designed to be used in three
161different forms: as an in-memory compiler IR, as an on-disk bytecode
162representation (suitable for fast loading by a Just-In-Time compiler),
163and as a human readable assembly language representation. This allows
164LLVM to provide a powerful intermediate representation for efficient
165compiler transformations and analysis, while providing a natural means
166to debug and visualize the transformations. The three different forms
167of LLVM are all equivalent. This document describes the human readable
168representation and notation.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000169
Chris Lattner261efe92003-11-25 01:02:51 +0000170<p>The LLVM representation aims to be a light-weight and low-level
171while being expressive, typed, and extensible at the same time. It
172aims to be a "universal IR" of sorts, by being at a low enough level
173that high-level ideas may be cleanly mapped to it (similar to how
174microprocessors are "universal IR's", allowing many source languages to
175be mapped to them). By providing type information, LLVM can be used as
176the target of optimizations: for example, through pointer analysis, it
177can be proven that a C automatic variable is never accessed outside of
178the current function... allowing it to be promoted to a simple SSA
179value instead of a memory location.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000180
Misha Brukman9d0919f2003-11-08 01:05:38 +0000181</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000182
Chris Lattner00950542001-06-06 20:29:01 +0000183<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000184<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000185
Misha Brukman9d0919f2003-11-08 01:05:38 +0000186<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000187
Chris Lattner261efe92003-11-25 01:02:51 +0000188<p>It is important to note that this document describes 'well formed'
189LLVM assembly language. There is a difference between what the parser
190accepts and what is considered 'well formed'. For example, the
191following instruction is syntactically okay, but not well formed:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000192
193<pre>
194 %x = <a href="#i_add">add</a> int 1, %x
195</pre>
196
Chris Lattner261efe92003-11-25 01:02:51 +0000197<p>...because the definition of <tt>%x</tt> does not dominate all of
198its uses. The LLVM infrastructure provides a verification pass that may
199be used to verify that an LLVM module is well formed. This pass is
200automatically run by the parser after parsing input assembly, and by
201the optimizer before it outputs bytecode. The violations pointed out
202by the verifier pass indicate bugs in transformation passes or input to
203the parser.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000204
Chris Lattner261efe92003-11-25 01:02:51 +0000205<!-- Describe the typesetting conventions here. --> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000206
Chris Lattner00950542001-06-06 20:29:01 +0000207<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000208<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000209<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000210
Misha Brukman9d0919f2003-11-08 01:05:38 +0000211<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000212
Chris Lattner261efe92003-11-25 01:02:51 +0000213<p>LLVM uses three different forms of identifiers, for different
214purposes:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000215
Chris Lattner00950542001-06-06 20:29:01 +0000216<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000217 <li>Numeric constants are represented as you would expect: 12, -3
John Criswell4457dc92004-04-09 16:48:45 +0000218123.421, etc. Floating point constants have an optional hexadecimal
Chris Lattner261efe92003-11-25 01:02:51 +0000219notation.</li>
220 <li>Named values are represented as a string of characters with a '%'
221prefix. For example, %foo, %DivisionByZero,
222%a.really.long.identifier. The actual regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
223Identifiers which require other characters in their names can be
224surrounded with quotes. In this way, anything except a <tt>"</tt>
225character can be used in a name.</li>
226 <li>Unnamed values are represented as an unsigned numeric value with
227a '%' prefix. For example, %12, %2, %44.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000228</ol>
John Criswell6794d922004-03-12 21:19:06 +0000229<p>LLVM requires that values start with a '%' sign for two reasons:
Chris Lattner261efe92003-11-25 01:02:51 +0000230Compilers don't need to worry about name clashes with reserved words,
231and the set of reserved words may be expanded in the future without
232penalty. Additionally, unnamed identifiers allow a compiler to quickly
233come up with a temporary variable without having to avoid symbol table
234conflicts.</p>
235<p>Reserved words in LLVM are very similar to reserved words in other
236languages. There are keywords for different opcodes ('<tt><a
237 href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
238 href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
239 href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>',
240etc...), and others. These reserved words cannot conflict with
241variable names, because none of them start with a '%' character.</p>
242<p>Here is an example of LLVM code to multiply the integer variable '<tt>%X</tt>'
243by 8:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000244<p>The easy way:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000245<pre> %result = <a href="#i_mul">mul</a> uint %X, 8<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000246<p>After strength reduction:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000247<pre> %result = <a href="#i_shl">shl</a> uint %X, ubyte 3<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000248<p>And the hard way:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000249<pre> <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
250 <a
251 href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
252 %result = <a
253 href="#i_add">add</a> uint %1, %1<br></pre>
254<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
255important lexical features of LLVM:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000256<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000257 <li>Comments are delimited with a '<tt>;</tt>' and go until the end
258of line.</li>
259 <li>Unnamed temporaries are created when the result of a computation
260is not assigned to a named value.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000261 <li>Unnamed temporaries are numbered sequentially</li>
262</ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000263<p>...and it also show a convention that we follow in this document.
264When demonstrating instructions, we will follow an instruction with a
265comment that defines the type and name of value produced. Comments are
266shown in italic text.</p>
267<p>The one non-intuitive notation for constants is the optional
268hexidecimal form of floating point constants. For example, the form '<tt>double
Chris Lattner2b7d3202002-05-06 03:03:22 +00002690x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
Chris Lattner261efe92003-11-25 01:02:51 +00002704.5e+15</tt>' which is also supported by the parser. The only time
271hexadecimal floating point constants are useful (and the only time that
272they are generated by the disassembler) is when an FP constant has to
273be emitted that is not representable as a decimal floating point number
274exactly. For example, NaN's, infinities, and other special cases are
275represented in their IEEE hexadecimal format so that assembly and
276disassembly do not cause any bits to change in the constants.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000277</div>
Chris Lattner00950542001-06-06 20:29:01 +0000278<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000279<div class="doc_section"> <a name="typesystem">Type System</a> </div>
280<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000281<div class="doc_text">
Misha Brukman9d0919f2003-11-08 01:05:38 +0000282<p>The LLVM type system is one of the most important features of the
Chris Lattner261efe92003-11-25 01:02:51 +0000283intermediate representation. Being typed enables a number of
284optimizations to be performed on the IR directly, without having to do
285extra analyses on the side before the transformation. A strong type
286system makes it easier to read the generated code and enables novel
287analyses and transformations that are not feasible to perform on normal
288three address code representations.</p>
Chris Lattner7bae3952002-06-25 18:03:17 +0000289<!-- The written form for the type system was heavily influenced by the
290syntactic problems with types in the C language<sup><a
Chris Lattner261efe92003-11-25 01:02:51 +0000291href="#rw_stroustrup">1</a></sup>.<p> --> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000292<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000293<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000294<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +0000295<p>The primitive types are the fundamental building blocks of the LLVM
Chris Lattner261efe92003-11-25 01:02:51 +0000296system. The current set of primitive types are as follows:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000297
298<table border="0" style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +0000299 <tbody>
300 <tr>
301 <td>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000302 <table border="1" cellspacing="0" cellpadding="4" style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +0000303 <tbody>
304 <tr>
305 <td><tt>void</tt></td>
306 <td>No value</td>
307 </tr>
308 <tr>
309 <td><tt>ubyte</tt></td>
310 <td>Unsigned 8 bit value</td>
311 </tr>
312 <tr>
313 <td><tt>ushort</tt></td>
314 <td>Unsigned 16 bit value</td>
315 </tr>
316 <tr>
317 <td><tt>uint</tt></td>
318 <td>Unsigned 32 bit value</td>
319 </tr>
320 <tr>
321 <td><tt>ulong</tt></td>
322 <td>Unsigned 64 bit value</td>
323 </tr>
324 <tr>
325 <td><tt>float</tt></td>
326 <td>32 bit floating point value</td>
327 </tr>
328 <tr>
329 <td><tt>label</tt></td>
330 <td>Branch destination</td>
331 </tr>
332 </tbody>
333 </table>
334 </td>
335 <td valign="top">
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000336 <table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +0000337 <tbody>
338 <tr>
339 <td><tt>bool</tt></td>
340 <td>True or False value</td>
341 </tr>
342 <tr>
343 <td><tt>sbyte</tt></td>
344 <td>Signed 8 bit value</td>
345 </tr>
346 <tr>
347 <td><tt>short</tt></td>
348 <td>Signed 16 bit value</td>
349 </tr>
350 <tr>
351 <td><tt>int</tt></td>
352 <td>Signed 32 bit value</td>
353 </tr>
354 <tr>
355 <td><tt>long</tt></td>
356 <td>Signed 64 bit value</td>
357 </tr>
358 <tr>
359 <td><tt>double</tt></td>
360 <td>64 bit floating point value</td>
361 </tr>
362 </tbody>
363 </table>
364 </td>
365 </tr>
366 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000367</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000368
Misha Brukman9d0919f2003-11-08 01:05:38 +0000369</div>
Chris Lattner00950542001-06-06 20:29:01 +0000370<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000371<div class="doc_subsubsection"> <a name="t_classifications">Type
372Classifications</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000373<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000374<p>These different primitive types fall into a few useful
375classifications:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000376
377<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +0000378 <tbody>
379 <tr>
380 <td><a name="t_signed">signed</a></td>
381 <td><tt>sbyte, short, int, long, float, double</tt></td>
382 </tr>
383 <tr>
384 <td><a name="t_unsigned">unsigned</a></td>
385 <td><tt>ubyte, ushort, uint, ulong</tt></td>
386 </tr>
387 <tr>
388 <td><a name="t_integer">integer</a></td>
389 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
390 </tr>
391 <tr>
392 <td><a name="t_integral">integral</a></td>
393 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
394 </tr>
395 <tr>
396 <td><a name="t_floating">floating point</a></td>
397 <td><tt>float, double</tt></td>
398 </tr>
399 <tr>
400 <td><a name="t_firstclass">first class</a></td>
401 <td><tt>bool, ubyte, sbyte, ushort, short,<br>
402uint, int, ulong, long, float, double, <a href="#t_pointer">pointer</a></tt></td>
403 </tr>
404 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000405</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000406
Chris Lattner261efe92003-11-25 01:02:51 +0000407<p>The <a href="#t_firstclass">first class</a> types are perhaps the
408most important. Values of these types are the only ones which can be
409produced by instructions, passed as arguments, or used as operands to
410instructions. This means that all structures and arrays must be
411manipulated either by pointer or by component.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000412</div>
Chris Lattner00950542001-06-06 20:29:01 +0000413<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000414<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000415<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000416<p>The real power in LLVM comes from the derived types in the system.
417This is what allows a programmer to represent arrays, functions,
418pointers, and other useful types. Note that these derived types may be
419recursive: For example, it is possible to have a two dimensional array.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000420</div>
Chris Lattner00950542001-06-06 20:29:01 +0000421<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000422<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000423<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000424<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000425<p>The array type is a very simple derived type that arranges elements
Chris Lattner261efe92003-11-25 01:02:51 +0000426sequentially in memory. The array type requires a size (number of
427elements) and an underlying data type.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000428<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000429<pre> [&lt;# elements&gt; x &lt;elementtype&gt;]<br></pre>
430<p>The number of elements is a constant integer value, elementtype may
431be any type with a size.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000432<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000433<p> <tt>[40 x int ]</tt>: Array of 40 integer values.<br>
434<tt>[41 x int ]</tt>: Array of 41 integer values.<br>
435<tt>[40 x uint]</tt>: Array of 40 unsigned integer values.</p>
436<p> </p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000437<p>Here are some examples of multidimensional arrays:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000438
Misha Brukman9d0919f2003-11-08 01:05:38 +0000439<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000440 <tbody>
441 <tr>
442 <td><tt>[3 x [4 x int]]</tt></td>
443 <td>: 3x4 array integer values.</td>
444 </tr>
445 <tr>
446 <td><tt>[12 x [10 x float]]</tt></td>
447 <td>: 12x10 array of single precision floating point values.</td>
448 </tr>
449 <tr>
450 <td><tt>[2 x [3 x [4 x uint]]]</tt></td>
451 <td>: 2x3x4 array of unsigned integer values.</td>
452 </tr>
453 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000454</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000455
Misha Brukman9d0919f2003-11-08 01:05:38 +0000456</div>
Chris Lattner00950542001-06-06 20:29:01 +0000457<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000458<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000459<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000460<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000461<p>The function type can be thought of as a function signature. It
462consists of a return type and a list of formal parameter types.
John Criswell009900b2003-11-25 21:45:46 +0000463Function types are usually used to build virtual function tables
Chris Lattner261efe92003-11-25 01:02:51 +0000464(which are structures of pointers to functions), for indirect function
465calls, and when defining a function.</p>
John Criswell009900b2003-11-25 21:45:46 +0000466<p>
467The return type of a function type cannot be an aggregate type.
468</p>
Chris Lattner00950542001-06-06 20:29:01 +0000469<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000470<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
471<p>Where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of
472type specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner27f71f22003-09-03 00:41:47 +0000473which indicates that the function takes a variable number of arguments.
474Variable argument functions can access their arguments with the <a
Chris Lattner261efe92003-11-25 01:02:51 +0000475 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000476<h5>Examples:</h5>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000477
Misha Brukman9d0919f2003-11-08 01:05:38 +0000478<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000479 <tbody>
480 <tr>
481 <td><tt>int (int)</tt></td>
482 <td>: function taking an <tt>int</tt>, returning an <tt>int</tt></td>
483 </tr>
484 <tr>
485 <td><tt>float (int, int *) *</tt></td>
486 <td>: <a href="#t_pointer">Pointer</a> to a function that takes
487an <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
488returning <tt>float</tt>.</td>
489 </tr>
490 <tr>
491 <td><tt>int (sbyte *, ...)</tt></td>
492 <td>: A vararg function that takes at least one <a
493 href="#t_pointer">pointer</a> to <tt>sbyte</tt> (signed char in C),
494which returns an integer. This is the signature for <tt>printf</tt>
495in LLVM.</td>
496 </tr>
497 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000498</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000499
Misha Brukman9d0919f2003-11-08 01:05:38 +0000500</div>
Chris Lattner00950542001-06-06 20:29:01 +0000501<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000502<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000503<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000504<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000505<p>The structure type is used to represent a collection of data members
506together in memory. The packing of the field types is defined to match
507the ABI of the underlying processor. The elements of a structure may
508be any type that has a size.</p>
509<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
510and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
511field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
512instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000513<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000514<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +0000515<h5>Examples:</h5>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000516
Misha Brukman9d0919f2003-11-08 01:05:38 +0000517<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000518 <tbody>
519 <tr>
520 <td><tt>{ int, int, int }</tt></td>
521 <td>: a triple of three <tt>int</tt> values</td>
522 </tr>
523 <tr>
524 <td><tt>{ float, int (int) * }</tt></td>
525 <td>: A pair, where the first element is a <tt>float</tt> and the
526second element is a <a href="#t_pointer">pointer</a> to a <a
Chris Lattnere53e5082004-06-03 22:57:15 +0000527 href="#t_function">function</a> that takes an <tt>int</tt>, returning
Chris Lattner261efe92003-11-25 01:02:51 +0000528an <tt>int</tt>.</td>
529 </tr>
530 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000531</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000532
Misha Brukman9d0919f2003-11-08 01:05:38 +0000533</div>
Chris Lattner00950542001-06-06 20:29:01 +0000534<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000535<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000536<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +0000537<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000538<p>As in many languages, the pointer type represents a pointer or
539reference to another object, which must live in memory.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000540<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000541<pre> &lt;type&gt; *<br></pre>
Chris Lattner7faa8832002-04-14 06:13:44 +0000542<h5>Examples:</h5>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000543
Misha Brukman9d0919f2003-11-08 01:05:38 +0000544<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000545 <tbody>
546 <tr>
547 <td><tt>[4x int]*</tt></td>
548 <td>: <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a>
549of four <tt>int</tt> values</td>
550 </tr>
551 <tr>
552 <td><tt>int (int *) *</tt></td>
553 <td>: A <a href="#t_pointer">pointer</a> to a <a
Chris Lattnere53e5082004-06-03 22:57:15 +0000554 href="#t_function">function</a> that takes an <tt>int</tt>, returning
Chris Lattner261efe92003-11-25 01:02:51 +0000555an <tt>int</tt>.</td>
556 </tr>
557 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000558</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000559
Misha Brukman9d0919f2003-11-08 01:05:38 +0000560</div>
Chris Lattner261efe92003-11-25 01:02:51 +0000561<!-- _______________________________________________________________________ --><!--
Misha Brukman9d0919f2003-11-08 01:05:38 +0000562<div class="doc_subsubsection">
563 <a name="t_packed">Packed Type</a>
564</div>
565
566<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000567
568Mention/decide that packed types work with saturation or not. Maybe have a packed+saturated type in addition to just a packed type.<p>
569
570Packed types should be 'nonsaturated' because standard data types are not saturated. Maybe have a saturated packed type?<p>
571
Misha Brukman9d0919f2003-11-08 01:05:38 +0000572</div>
573
Chris Lattner261efe92003-11-25 01:02:51 +0000574--><!-- *********************************************************************** -->
575<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
576<!-- *********************************************************************** --><!-- ======================================================================= -->
577<div class="doc_subsection"> <a name="modulestructure">Module Structure</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000578<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000579<p>LLVM programs are composed of "Module"s, each of which is a
580translation unit of the input programs. Each module consists of
581functions, global variables, and symbol table entries. Modules may be
582combined together with the LLVM linker, which merges function (and
583global variable) definitions, resolves forward declarations, and merges
584symbol table entries. Here is an example of the "hello world" module:</p>
585<pre><i>; Declare the string constant as a global constant...</i>
586<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
587 href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00" <i>; [13 x sbyte]*</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000588
Chris Lattner27f71f22003-09-03 00:41:47 +0000589<i>; External declaration of the puts function</i>
590<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000591
592<i>; Definition of main function</i>
Chris Lattner27f71f22003-09-03 00:41:47 +0000593int %main() { <i>; int()* </i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000594 <i>; Convert [13x sbyte]* to sbyte *...</i>
Chris Lattner261efe92003-11-25 01:02:51 +0000595 %cast210 = <a
596 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000597
598 <i>; Call puts function to write out the string to stdout...</i>
Chris Lattner261efe92003-11-25 01:02:51 +0000599 <a
600 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
601 <a
602 href="#i_ret">ret</a> int 0<br>}<br></pre>
603<p>This example is made up of a <a href="#globalvars">global variable</a>
604named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
605function, and a <a href="#functionstructure">function definition</a>
606for "<tt>main</tt>".</p>
607<a name="linkage"> In general, a module is made up of a list of global
608values, where both functions and global variables are global values.
609Global values are represented by a pointer to a memory location (in
610this case, a pointer to an array of char, and a pointer to a function),
611and have one of the following linkage types:</a>
612<p> </p>
Chris Lattner27f71f22003-09-03 00:41:47 +0000613<dl>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000614 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000615 <dd>Global values with internal linkage are only directly accessible
616by objects in the current module. In particular, linking code into a
617module with an internal global value may cause the internal to be
618renamed as necessary to avoid collisions. Because the symbol is
619internal to the module, all references can be updated. This
620corresponds to the notion of the '<tt>static</tt>' keyword in C, or the
621idea of "anonymous namespaces" in C++.
622 <p> </p>
623 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000624 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000625 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt>
626linkage, with the twist that linking together two modules defining the
627same <tt>linkonce</tt> globals will cause one of the globals to be
628discarded. This is typically used to implement inline functions.
629Unreferenced <tt>linkonce</tt> globals are allowed to be discarded.
630 <p> </p>
631 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000632 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000633 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt>
634linkage, except that unreferenced <tt>weak</tt> globals may not be
635discarded. This is used to implement constructs in C such as "<tt>int
636X;</tt>" at global scope.
637 <p> </p>
638 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000639 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000640 <dd>"<tt>appending</tt>" linkage may only be applied to global
641variables of pointer to array type. When two global variables with
642appending linkage are linked together, the two global arrays are
643appended together. This is the LLVM, typesafe, equivalent of having
644the system linker append together "sections" with identical names when
645.o files are linked.
646 <p> </p>
647 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000648 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000649 <dd>If none of the above identifiers are used, the global is
650externally visible, meaning that it participates in linkage and can be
651used to resolve external symbol references.
652 <p> </p>
653 </dd>
Chris Lattner261efe92003-11-25 01:02:51 +0000654</dl>
655<p> </p>
656<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
657variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
658variable and was linked with this one, one of the two would be renamed,
659preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
660external (i.e., lacking any linkage declarations), they are accessible
661outside of the current module. It is illegal for a function <i>declaration</i>
662to have any linkage type other than "externally visible".</a></p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000663</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000664
Chris Lattner00950542001-06-06 20:29:01 +0000665<!-- ======================================================================= -->
Chris Lattner9ee5d222004-03-08 16:49:10 +0000666<div class="doc_subsection">
667 <a name="globalvars">Global Variables</a>
668</div>
669
Misha Brukman9d0919f2003-11-08 01:05:38 +0000670<div class="doc_text">
Chris Lattner9ee5d222004-03-08 16:49:10 +0000671
Chris Lattner261efe92003-11-25 01:02:51 +0000672<p>Global variables define regions of memory allocated at compilation
673time instead of run-time. Global variables may optionally be
674initialized. A variable may be defined as a global "constant", which
675indicates that the contents of the variable will never be modified
Chris Lattner9ee5d222004-03-08 16:49:10 +0000676(opening options for optimization).</p>
677
Chris Lattner261efe92003-11-25 01:02:51 +0000678<p>As SSA values, global variables define pointer values that are in
679scope (i.e. they dominate) for all basic blocks in the program. Global
680variables always define a pointer to their "content" type because they
681describe a region of memory, and all memory objects in LLVM are
682accessed through pointers.</p>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000683
Misha Brukman9d0919f2003-11-08 01:05:38 +0000684</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000685
686
Chris Lattner2b7d3202002-05-06 03:03:22 +0000687<!-- ======================================================================= -->
Chris Lattner9ee5d222004-03-08 16:49:10 +0000688<div class="doc_subsection">
689 <a name="functionstructure">Functions</a>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000690</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000691
692<div class="doc_text">
693
694<p>LLVM function definitions are composed of a (possibly empty) argument list,
695an opening curly brace, a list of basic blocks, and a closing curly brace. LLVM
696function declarations are defined with the "<tt>declare</tt>" keyword, a
697function name, and a function signature.</p>
698
699<p>A function definition contains a list of basic blocks, forming the CFG for
700the function. Each basic block may optionally start with a label (giving the
701basic block a symbol table entry), contains a list of instructions, and ends
702with a <a href="#terminators">terminator</a> instruction (such as a branch or
703function return).</p>
704
705<p>The first basic block in program is special in two ways: it is immediately
706executed on entrance to the function, and it is not allowed to have predecessor
707basic blocks (i.e. there can not be any branches to the entry block of a
708function). Because the block can have no predecessors, it also cannot have any
709<a href="#i_phi">PHI nodes</a>.</p>
710
711<p>LLVM functions are identified by their name and type signature. Hence, two
712functions with the same name but different parameter lists or return values are
713considered different functions, and LLVM will resolves references to each
714appropriately.</p>
715
716</div>
717
718
Chris Lattner00950542001-06-06 20:29:01 +0000719<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000720<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
721<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000722<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000723<p>The LLVM instruction set consists of several different
724classifications of instructions: <a href="#terminators">terminator
725instructions</a>, <a href="#binaryops">binary instructions</a>, <a
726 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
727instructions</a>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000728</div>
Chris Lattner00950542001-06-06 20:29:01 +0000729<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000730<div class="doc_subsection"> <a name="terminators">Terminator
731Instructions</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000732<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000733<p>As mentioned <a href="#functionstructure">previously</a>, every
734basic block in a program ends with a "Terminator" instruction, which
735indicates which block should be executed after the current block is
736finished. These terminator instructions typically yield a '<tt>void</tt>'
737value: they produce control flow, not values (the one exception being
738the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000739<p>There are five different terminator instructions: the '<a
Chris Lattner261efe92003-11-25 01:02:51 +0000740 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
741instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
742the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, and the '<a
743 href="#i_unwind"><tt>unwind</tt></a>' instruction.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000744</div>
Chris Lattner00950542001-06-06 20:29:01 +0000745<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000746<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
747Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000748<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000749<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000750<pre> ret &lt;type&gt; &lt;value&gt; <i>; Return a value from a non-void function</i>
Chris Lattner7faa8832002-04-14 06:13:44 +0000751 ret void <i>; Return from void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000752</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000753<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000754<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
755value) from a function, back to the caller.</p>
John Criswell4457dc92004-04-09 16:48:45 +0000756<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner261efe92003-11-25 01:02:51 +0000757returns a value and then causes control flow, and one that just causes
758control flow to occur.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000759<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000760<p>The '<tt>ret</tt>' instruction may return any '<a
761 href="#t_firstclass">first class</a>' type. Notice that a function is
762not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
763instruction inside of the function that returns a value that does not
764match the return type of the function.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000765<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000766<p>When the '<tt>ret</tt>' instruction is executed, control flow
767returns back to the calling function's context. If the caller is a "<a
768 href="#i_call"><tt>call</tt></a> instruction, execution continues at
769the instruction after the call. If the caller was an "<a
770 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
771at the beginning "normal" of the destination block. If the instruction
772returns a value, that value shall set the call or invoke instruction's
773return value.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000774<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000775<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner7faa8832002-04-14 06:13:44 +0000776 ret void <i>; Return from a void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000777</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000778</div>
Chris Lattner00950542001-06-06 20:29:01 +0000779<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000780<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000781<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000782<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000783<pre> br bool &lt;cond&gt;, label &lt;iftrue&gt;, label &lt;iffalse&gt;<br> br label &lt;dest&gt; <i>; Unconditional branch</i>
Chris Lattner00950542001-06-06 20:29:01 +0000784</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000785<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000786<p>The '<tt>br</tt>' instruction is used to cause control flow to
787transfer to a different basic block in the current function. There are
788two forms of this instruction, corresponding to a conditional branch
789and an unconditional branch.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000790<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000791<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
792single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
793unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
794value as a target.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000795<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000796<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
797argument is evaluated. If the value is <tt>true</tt>, control flows
798to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
799control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000800<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000801<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
802 href="#i_ret">ret</a> int 1<br>IfUnequal:<br> <a href="#i_ret">ret</a> int 0<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000803</div>
Chris Lattner00950542001-06-06 20:29:01 +0000804<!-- _______________________________________________________________________ -->
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000805<div class="doc_subsubsection">
806 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
807</div>
808
Misha Brukman9d0919f2003-11-08 01:05:38 +0000809<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000810<h5>Syntax:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000811
812<pre>
813 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
814</pre>
815
Chris Lattner00950542001-06-06 20:29:01 +0000816<h5>Overview:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000817
818<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
819several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +0000820instruction, allowing a branch to occur to one of many possible
821destinations.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000822
823
Chris Lattner00950542001-06-06 20:29:01 +0000824<h5>Arguments:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000825
826<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
827comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
828an array of pairs of comparison value constants and '<tt>label</tt>'s. The
829table is not allowed to contain duplicate constant entries.</p>
830
Chris Lattner00950542001-06-06 20:29:01 +0000831<h5>Semantics:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000832
Chris Lattner261efe92003-11-25 01:02:51 +0000833<p>The <tt>switch</tt> instruction specifies a table of values and
834destinations. When the '<tt>switch</tt>' instruction is executed, this
835table is searched for the given value. If the value is found, the
836corresponding destination is branched to, otherwise the default value
837it transfered to.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000838
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000839<h5>Implementation:</h5>
840
841<p>Depending on properties of the target machine and the particular
842<tt>switch</tt> instruction, this instruction may be code generated in different
843ways, for example as a series of chained conditional branches, or with a lookup
844table.</p>
845
846<h5>Example:</h5>
847
848<pre>
849 <i>; Emulate a conditional br instruction</i>
850 %Val = <a href="#i_cast">cast</a> bool %value to int
851 switch int %Val, label %truedest [int 0, label %falsedest ]
852
853 <i>; Emulate an unconditional br instruction</i>
854 switch uint 0, label %dest [ ]
855
856 <i>; Implement a jump table:</i>
857 switch uint %val, label %otherwise [ uint 0, label %onzero
858 uint 1, label %onone
859 uint 2, label %ontwo ]
Chris Lattner00950542001-06-06 20:29:01 +0000860</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000861</div>
Chris Lattner00950542001-06-06 20:29:01 +0000862<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000863<div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>'
864Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000865<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000866<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000867<pre> &lt;result&gt; = invoke &lt;ptr to function ty&gt; %&lt;function ptr val&gt;(&lt;function args&gt;)<br> to label &lt;normal label&gt; except label &lt;exception label&gt;<br></pre>
Chris Lattner6536cfe2002-05-06 22:08:29 +0000868<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000869<p>The '<tt>invoke</tt>' instruction causes control to transfer to a
870specified function, with the possibility of control flow transfer to
871either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>.
872If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>"
873instruction, control flow will return to the "normal" label. If the
874callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
875instruction, control is interrupted, and continued at the dynamically
876nearest "except" label.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000877<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000878<p>This instruction requires several arguments:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000879<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000880 <li>'<tt>ptr to function ty</tt>': shall be the signature of the
881pointer to function value being invoked. In most cases, this is a
882direct function invocation, but indirect <tt>invoke</tt>s are just as
883possible, branching off an arbitrary pointer to function value. </li>
884 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer
885to a function to be invoked. </li>
886 <li>'<tt>function args</tt>': argument list whose types match the
887function signature argument types. If the function signature indicates
888the function accepts a variable number of arguments, the extra
889arguments can be specified. </li>
890 <li>'<tt>normal label</tt>': the label reached when the called
891function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
892 <li>'<tt>exception label</tt>': the label reached when a callee
893returns with the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
Chris Lattner00950542001-06-06 20:29:01 +0000894</ol>
Chris Lattner00950542001-06-06 20:29:01 +0000895<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000896<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner261efe92003-11-25 01:02:51 +0000897 href="#i_call">call</a></tt>' instruction in most regards. The
898primary difference is that it establishes an association with a label,
899which is used by the runtime library to unwind the stack.</p>
900<p>This instruction is used in languages with destructors to ensure
901that proper cleanup is performed in the case of either a <tt>longjmp</tt>
902or a thrown exception. Additionally, this is important for
903implementation of '<tt>catch</tt>' clauses in high-level languages that
904support them.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000905<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000906<pre> %retval = invoke int %Test(int 15)<br> to label %Continue<br> except label %TestCleanup <i>; {int}:retval set</i>
Chris Lattner00950542001-06-06 20:29:01 +0000907</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000908</div>
Chris Lattner27f71f22003-09-03 00:41:47 +0000909<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000910<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
911Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000912<div class="doc_text">
Chris Lattner27f71f22003-09-03 00:41:47 +0000913<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000914<pre> unwind<br></pre>
Chris Lattner27f71f22003-09-03 00:41:47 +0000915<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000916<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing
917control flow at the first callee in the dynamic call stack which used
918an <a href="#i_invoke"><tt>invoke</tt></a> instruction to perform the
919call. This is primarily used to implement exception handling.</p>
Chris Lattner27f71f22003-09-03 00:41:47 +0000920<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000921<p>The '<tt>unwind</tt>' intrinsic causes execution of the current
922function to immediately halt. The dynamic call stack is then searched
923for the first <a href="#i_invoke"><tt>invoke</tt></a> instruction on
924the call stack. Once found, execution continues at the "exceptional"
925destination block specified by the <tt>invoke</tt> instruction. If
926there is no <tt>invoke</tt> instruction in the dynamic call chain,
927undefined behavior results.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000928</div>
Chris Lattner00950542001-06-06 20:29:01 +0000929<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000930<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000931<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000932<p>Binary operators are used to do most of the computation in a
933program. They require two operands, execute an operation on them, and
934produce a single value. The result value of a binary operator is not
935necessarily the same type as its operands.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000936<p>There are several different binary operators:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000937</div>
Chris Lattner00950542001-06-06 20:29:01 +0000938<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000939<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
940Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000941<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000942<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000943<pre> &lt;result&gt; = add &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +0000944</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000945<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000946<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000947<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000948<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +0000949 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
950values. Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000951<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000952<p>The value produced is the integer or floating point sum of the two
953operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000954<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000955<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner00950542001-06-06 20:29:01 +0000956</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000957</div>
Chris Lattner00950542001-06-06 20:29:01 +0000958<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000959<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
960Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000961<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000962<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000963<pre> &lt;result&gt; = sub &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +0000964</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000965<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000966<p>The '<tt>sub</tt>' instruction returns the difference of its two
967operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000968<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
969instruction present in most other intermediate representations.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000970<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000971<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +0000972 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
973values. Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000974<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000975<p>The value produced is the integer or floating point difference of
976the two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000977<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000978<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner00950542001-06-06 20:29:01 +0000979 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
980</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000981</div>
Chris Lattner00950542001-06-06 20:29:01 +0000982<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000983<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
984Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000985<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000986<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000987<pre> &lt;result&gt; = mul &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +0000988</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000989<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000990<p>The '<tt>mul</tt>' instruction returns the product of its two
991operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000992<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000993<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +0000994 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
995values. Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000996<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000997<p>The value produced is the integer or floating point product of the
Misha Brukman9d0919f2003-11-08 01:05:38 +0000998two operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000999<p>There is no signed vs unsigned multiplication. The appropriate
1000action is taken based on the type of the operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001001<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001002<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001003</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001004</div>
Chris Lattner00950542001-06-06 20:29:01 +00001005<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001006<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
1007Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001008<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001009<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001010<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1011</pre>
1012<h5>Overview:</h5>
1013<p>The '<tt>div</tt>' instruction returns the quotient of its two
1014operands.</p>
1015<h5>Arguments:</h5>
1016<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
1017 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
1018values. Both arguments must have identical types.</p>
1019<h5>Semantics:</h5>
1020<p>The value produced is the integer or floating point quotient of the
1021two operands.</p>
1022<h5>Example:</h5>
1023<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
1024</pre>
1025</div>
1026<!-- _______________________________________________________________________ -->
1027<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
1028Instruction</a> </div>
1029<div class="doc_text">
1030<h5>Syntax:</h5>
1031<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1032</pre>
1033<h5>Overview:</h5>
1034<p>The '<tt>rem</tt>' instruction returns the remainder from the
1035division of its two operands.</p>
1036<h5>Arguments:</h5>
1037<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1038 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
1039values. Both arguments must have identical types.</p>
1040<h5>Semantics:</h5>
1041<p>This returns the <i>remainder</i> of a division (where the result
1042has the same sign as the divisor), not the <i>modulus</i> (where the
1043result has the same sign as the dividend) of a value. For more
1044information about the difference, see: <a
1045 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1046Math Forum</a>.</p>
1047<h5>Example:</h5>
1048<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1049</pre>
1050</div>
1051<!-- _______________________________________________________________________ -->
1052<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1053Instructions</a> </div>
1054<div class="doc_text">
1055<h5>Syntax:</h5>
1056<pre> &lt;result&gt; = seteq &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001057 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1058 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1059 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1060 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1061 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1062</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001063<h5>Overview:</h5>
1064<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1065value based on a comparison of their two operands.</p>
1066<h5>Arguments:</h5>
1067<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1068be of <a href="#t_firstclass">first class</a> type (it is not possible
1069to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1070or '<tt>void</tt>' values, etc...). Both arguments must have identical
1071types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001072<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001073<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1074value if both operands are equal.<br>
1075The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1076value if both operands are unequal.<br>
1077The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1078value if the first operand is less than the second operand.<br>
1079The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1080value if the first operand is greater than the second operand.<br>
1081The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1082value if the first operand is less than or equal to the second operand.<br>
1083The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1084value if the first operand is greater than or equal to the second
1085operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001086<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001087<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner00950542001-06-06 20:29:01 +00001088 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
1089 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1090 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1091 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1092 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1093</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001094</div>
Chris Lattner00950542001-06-06 20:29:01 +00001095<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001096<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1097Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001098<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001099<p>Bitwise binary operators are used to do various forms of
1100bit-twiddling in a program. They are generally very efficient
1101instructions, and can commonly be strength reduced from other
1102instructions. They require two operands, execute an operation on them,
1103and produce a single value. The resulting value of the bitwise binary
1104operators is always the same type as its first operand.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001105</div>
Chris Lattner00950542001-06-06 20:29:01 +00001106<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001107<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1108Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001109<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001110<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001111<pre> &lt;result&gt; = and &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001112</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001113<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001114<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1115its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001116<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001117<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001118 href="#t_integral">integral</a> values. Both arguments must have
1119identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001120<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001121<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001122<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001123<div style="align: center">
Misha Brukman9d0919f2003-11-08 01:05:38 +00001124<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +00001125 <tbody>
1126 <tr>
1127 <td>In0</td>
1128 <td>In1</td>
1129 <td>Out</td>
1130 </tr>
1131 <tr>
1132 <td>0</td>
1133 <td>0</td>
1134 <td>0</td>
1135 </tr>
1136 <tr>
1137 <td>0</td>
1138 <td>1</td>
1139 <td>0</td>
1140 </tr>
1141 <tr>
1142 <td>1</td>
1143 <td>0</td>
1144 <td>0</td>
1145 </tr>
1146 <tr>
1147 <td>1</td>
1148 <td>1</td>
1149 <td>1</td>
1150 </tr>
1151 </tbody>
1152</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001153</div>
Chris Lattner00950542001-06-06 20:29:01 +00001154<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001155<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001156 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1157 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1158</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001159</div>
Chris Lattner00950542001-06-06 20:29:01 +00001160<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001161<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001162<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001163<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001164<pre> &lt;result&gt; = or &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001165</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001166<h5>Overview:</h5>
1167<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1168or of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001169<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001170<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001171 href="#t_integral">integral</a> values. Both arguments must have
1172identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001173<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001174<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001175<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001176<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001177<table border="1" cellspacing="0" cellpadding="4">
1178 <tbody>
1179 <tr>
1180 <td>In0</td>
1181 <td>In1</td>
1182 <td>Out</td>
1183 </tr>
1184 <tr>
1185 <td>0</td>
1186 <td>0</td>
1187 <td>0</td>
1188 </tr>
1189 <tr>
1190 <td>0</td>
1191 <td>1</td>
1192 <td>1</td>
1193 </tr>
1194 <tr>
1195 <td>1</td>
1196 <td>0</td>
1197 <td>1</td>
1198 </tr>
1199 <tr>
1200 <td>1</td>
1201 <td>1</td>
1202 <td>1</td>
1203 </tr>
1204 </tbody>
1205</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001206</div>
Chris Lattner00950542001-06-06 20:29:01 +00001207<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001208<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001209 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1210 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1211</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001212</div>
Chris Lattner00950542001-06-06 20:29:01 +00001213<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001214<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1215Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001216<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001217<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001218<pre> &lt;result&gt; = xor &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001219</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001220<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001221<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1222or of its two operands. The <tt>xor</tt> is used to implement the
1223"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001224<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001225<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001226 href="#t_integral">integral</a> values. Both arguments must have
1227identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001228<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001229<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001230<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001231<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001232<table border="1" cellspacing="0" cellpadding="4">
1233 <tbody>
1234 <tr>
1235 <td>In0</td>
1236 <td>In1</td>
1237 <td>Out</td>
1238 </tr>
1239 <tr>
1240 <td>0</td>
1241 <td>0</td>
1242 <td>0</td>
1243 </tr>
1244 <tr>
1245 <td>0</td>
1246 <td>1</td>
1247 <td>1</td>
1248 </tr>
1249 <tr>
1250 <td>1</td>
1251 <td>0</td>
1252 <td>1</td>
1253 </tr>
1254 <tr>
1255 <td>1</td>
1256 <td>1</td>
1257 <td>0</td>
1258 </tr>
1259 </tbody>
1260</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001261</div>
Chris Lattner261efe92003-11-25 01:02:51 +00001262<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001263<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001264<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001265 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1266 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner27f71f22003-09-03 00:41:47 +00001267 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner00950542001-06-06 20:29:01 +00001268</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001269</div>
Chris Lattner00950542001-06-06 20:29:01 +00001270<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001271<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1272Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001273<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001274<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001275<pre> &lt;result&gt; = shl &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001276</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001277<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001278<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1279the left a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001280<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001281<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001282 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1283type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001284<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001285<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001286<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001287<pre> &lt;result&gt; = shl int 4, ubyte %var <i>; yields {int}:result = 4 &lt;&lt; %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001288 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1289 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1290</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001291</div>
Chris Lattner00950542001-06-06 20:29:01 +00001292<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001293<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1294Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001295<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001296<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001297<pre> &lt;result&gt; = shr &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001298</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001299<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001300<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1301the right a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001302<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001303<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001304 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1305type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001306<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001307<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1308most significant bit is duplicated in the newly free'd bit positions.
1309If the first argument is unsigned, zero bits shall fill the empty
1310positions.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001311<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001312<pre> &lt;result&gt; = shr int 4, ubyte %var <i>; yields {int}:result = 4 &gt;&gt; %var</i>
Chris Lattner8c6bb902003-06-18 21:30:51 +00001313 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001314 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner8c6bb902003-06-18 21:30:51 +00001315 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1316 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner00950542001-06-06 20:29:01 +00001317</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001318</div>
Chris Lattner00950542001-06-06 20:29:01 +00001319<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001320<div class="doc_subsection"> <a name="memoryops">Memory Access
1321Operations</a></div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001322<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001323<p>A key design point of an SSA-based representation is how it
1324represents memory. In LLVM, no memory locations are in SSA form, which
1325makes things very simple. This section describes how to read, write,
1326allocate and free memory in LLVM.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001327</div>
Chris Lattner00950542001-06-06 20:29:01 +00001328<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001329<div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>'
1330Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001331<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001332<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001333<pre> &lt;result&gt; = malloc &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001334 &lt;result&gt; = malloc &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001335</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001336<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001337<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1338heap and returns a pointer to it.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001339<h5>Arguments:</h5>
John Criswell6e4ca612004-02-24 16:13:56 +00001340<p>The '<tt>malloc</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1341bytes of memory from the operating system and returns a pointer of the
Chris Lattner261efe92003-11-25 01:02:51 +00001342appropriate type to the program. The second form of the instruction is
1343a shorter version of the first instruction that defaults to allocating
1344one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001345<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001346<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001347<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1348a pointer is returned.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001349<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001350<pre> %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001351
Chris Lattner261efe92003-11-25 01:02:51 +00001352 %size = <a
1353 href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001354 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1355 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001356</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001357</div>
Chris Lattner00950542001-06-06 20:29:01 +00001358<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001359<div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>'
1360Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001361<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001362<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001363<pre> free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner00950542001-06-06 20:29:01 +00001364</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001365<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001366<p>The '<tt>free</tt>' instruction returns memory back to the unused
1367memory heap, to be reallocated in the future.</p>
1368<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001369<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001370<p>'<tt>value</tt>' shall be a pointer value that points to a value
1371that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1372instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001373<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001374<p>Access to the memory pointed to by the pointer is not longer defined
1375after this instruction executes.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001376<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001377<pre> %array = <a href="#i_malloc">malloc</a> [4 x ubyte] <i>; yields {[4 x ubyte]*}:array</i>
Chris Lattner00950542001-06-06 20:29:01 +00001378 free [4 x ubyte]* %array
1379</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001380</div>
Chris Lattner00950542001-06-06 20:29:01 +00001381<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001382<div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>'
1383Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001384<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001385<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001386<pre> &lt;result&gt; = alloca &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001387 &lt;result&gt; = alloca &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001388</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001389<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001390<p>The '<tt>alloca</tt>' instruction allocates memory on the current
1391stack frame of the procedure that is live until the current function
1392returns to its caller.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001393<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001394<p>The the '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1395bytes of memory on the runtime stack, returning a pointer of the
1396appropriate type to the program. The second form of the instruction is
1397a shorter version of the first that defaults to allocating one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001398<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001399<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001400<p>Memory is allocated, a pointer is returned. '<tt>alloca</tt>'d
1401memory is automatically released when the function returns. The '<tt>alloca</tt>'
1402instruction is commonly used to represent automatic variables that must
1403have an address available. When the function returns (either with the <tt><a
1404 href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001405instructions), the memory is reclaimed.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001406<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001407<pre> %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001408 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner00950542001-06-06 20:29:01 +00001409</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001410</div>
Chris Lattner00950542001-06-06 20:29:01 +00001411<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001412<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1413Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001414<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00001415<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001416<pre> &lt;result&gt; = load &lt;ty&gt;* &lt;pointer&gt;<br> &lt;result&gt; = volatile load &lt;ty&gt;* &lt;pointer&gt;<br></pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001417<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001418<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001419<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001420<p>The argument to the '<tt>load</tt>' instruction specifies the memory
1421address to load from. The pointer must point to a <a
Chris Lattnere53e5082004-06-03 22:57:15 +00001422 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
Chris Lattner261efe92003-11-25 01:02:51 +00001423marked as <tt>volatile</tt> then the optimizer is not allowed to modify
1424the number or order of execution of this <tt>load</tt> with other
1425volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1426instructions. </p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001427<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001428<p>The location of memory pointed to is loaded.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001429<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001430<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1431 <a
1432 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001433 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1434</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001435</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001436<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001437<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1438Instruction</a> </div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001439<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001440<pre> store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt; <i>; yields {void}</i>
Chris Lattnerf0651072003-09-08 18:27:49 +00001441 volatile store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt; <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001442</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001443<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001444<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001445<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001446<p>There are two arguments to the '<tt>store</tt>' instruction: a value
1447to store and an address to store it into. The type of the '<tt>&lt;pointer&gt;</tt>'
1448operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
1449operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the
1450optimizer is not allowed to modify the number or order of execution of
1451this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1452 href="#i_store">store</a></tt> instructions.</p>
1453<h5>Semantics:</h5>
1454<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
1455at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001456<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001457<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1458 <a
1459 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001460 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1461</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001462<!-- _______________________________________________________________________ -->
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001463<div class="doc_subsubsection">
1464 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
1465</div>
1466
Misha Brukman9d0919f2003-11-08 01:05:38 +00001467<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00001468<h5>Syntax:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001469<pre>
1470 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
1471</pre>
1472
Chris Lattner7faa8832002-04-14 06:13:44 +00001473<h5>Overview:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001474
1475<p>
1476The '<tt>getelementptr</tt>' instruction is used to get the address of a
1477subelement of an aggregate data structure.</p>
1478
Chris Lattner7faa8832002-04-14 06:13:44 +00001479<h5>Arguments:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001480
1481<p>This instruction takes a list of integer constants that indicate what
1482elements of the aggregate object to index to. The actual types of the arguments
1483provided depend on the type of the first pointer argument. The
1484'<tt>getelementptr</tt>' instruction is used to index down through the type
1485levels of a structure. When indexing into a structure, only <tt>uint</tt>
1486integer constants are allowed. When indexing into an array or pointer
1487<tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
1488
Chris Lattner261efe92003-11-25 01:02:51 +00001489<p>For example, let's consider a C code fragment and how it gets
1490compiled to LLVM:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001491
1492<pre>
1493 struct RT {
1494 char A;
1495 int B[10][20];
1496 char C;
1497 };
1498 struct ST {
1499 int X;
1500 double Y;
1501 struct RT Z;
1502 };
1503
1504 int *foo(struct ST *s) {
1505 return &amp;s[1].Z.B[5][13];
1506 }
1507</pre>
1508
Misha Brukman9d0919f2003-11-08 01:05:38 +00001509<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001510
1511<pre>
1512 %RT = type { sbyte, [10 x [20 x int]], sbyte }
1513 %ST = type { int, double, %RT }
1514
1515 int* "foo"(%ST* %s) {
1516 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13<br>
1517 ret int* %reg
1518 }
1519</pre>
1520
Chris Lattner7faa8832002-04-14 06:13:44 +00001521<h5>Semantics:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001522
1523<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
Chris Lattnere53e5082004-06-03 22:57:15 +00001524on the pointer type that is being index into. <a href="#t_pointer">Pointer</a>
1525and <a href="#t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
1526<tt>ulong</tt>, or <tt>long</tt> values, and <a href="#t_struct">structure</a>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001527types require <tt>uint</tt> <b>constants</b>.</p>
1528
Misha Brukman9d0919f2003-11-08 01:05:38 +00001529<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001530type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
1531}</tt>' type, a structure. The second index indexes into the third element of
1532the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
1533sbyte }</tt>' type, another structure. The third index indexes into the second
1534element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
1535array. The two dimensions of the array are subscripted into, yielding an
1536'<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction return a pointer
1537to this element, thus computing a value of '<tt>int*</tt>' type.</p>
1538
Chris Lattner261efe92003-11-25 01:02:51 +00001539<p>Note that it is perfectly legal to index partially through a
1540structure, returning a pointer to an inner element. Because of this,
1541the LLVM code for the given testcase is equivalent to:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001542
1543<pre>
1544 int* "foo"(%ST* %s) {
1545 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
1546 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
1547 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
1548 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
1549 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
1550 ret int* %t5
1551 }
Chris Lattner6536cfe2002-05-06 22:08:29 +00001552</pre>
Chris Lattner7faa8832002-04-14 06:13:44 +00001553<h5>Example:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001554<pre>
1555 <i>; yields [12 x ubyte]*:aptr</i>
1556 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
1557</pre>
1558
1559</div>
Chris Lattner00950542001-06-06 20:29:01 +00001560<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001561<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001562<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +00001563<p>The instructions in this category are the "miscellaneous"
Chris Lattner261efe92003-11-25 01:02:51 +00001564instructions, which defy better classification.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001565</div>
Chris Lattner00950542001-06-06 20:29:01 +00001566<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001567<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
1568Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001569<div class="doc_text">
Chris Lattner33ba0d92001-07-09 00:26:23 +00001570<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001571<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001572<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001573<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
1574the SSA graph representing the function.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001575<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001576<p>The type of the incoming values are specified with the first type
1577field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
1578as arguments, with one pair for each predecessor basic block of the
1579current block. Only values of <a href="#t_firstclass">first class</a>
1580type may be used as the value arguments to the PHI node. Only labels
1581may be used as the label arguments.</p>
1582<p>There must be no non-phi instructions between the start of a basic
1583block and the PHI instructions: i.e. PHI instructions must be first in
1584a basic block.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001585<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001586<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
1587value specified by the parameter, depending on which basic block we
1588came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001589<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001590<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>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001591</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001592
Chris Lattner6536cfe2002-05-06 22:08:29 +00001593<!-- _______________________________________________________________________ -->
Chris Lattnercc37aae2004-03-12 05:50:16 +00001594<div class="doc_subsubsection">
1595 <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
1596</div>
1597
Misha Brukman9d0919f2003-11-08 01:05:38 +00001598<div class="doc_text">
Chris Lattnercc37aae2004-03-12 05:50:16 +00001599
Chris Lattner6536cfe2002-05-06 22:08:29 +00001600<h5>Syntax:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001601
1602<pre>
1603 &lt;result&gt; = cast &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001604</pre>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001605
Chris Lattner6536cfe2002-05-06 22:08:29 +00001606<h5>Overview:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001607
1608<p>
1609The '<tt>cast</tt>' instruction is used as the primitive means to convert
1610integers to floating point, change data type sizes, and break type safety (by
1611casting pointers).
1612</p>
1613
1614
Chris Lattner6536cfe2002-05-06 22:08:29 +00001615<h5>Arguments:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001616
1617<p>
1618The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
1619class value, and a type to cast it to, which must also be a <a
1620href="#t_firstclass">first class</a> type.
1621</p>
1622
Chris Lattner6536cfe2002-05-06 22:08:29 +00001623<h5>Semantics:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001624
1625<p>
1626This instruction follows the C rules for explicit casts when determining how the
1627data being cast must change to fit in its new container.
1628</p>
1629
1630<p>
1631When casting to bool, any value that would be considered true in the context of
1632a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
1633all else are '<tt>false</tt>'.
1634</p>
1635
1636<p>
1637When extending an integral value from a type of one signness to another (for
1638example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
1639<b>source</b> value is signed, and zero-extended if the source value is
1640unsigned. <tt>bool</tt> values are always zero extended into either zero or
1641one.
1642</p>
1643
Chris Lattner33ba0d92001-07-09 00:26:23 +00001644<h5>Example:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001645
1646<pre>
1647 %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattner7bae3952002-06-25 18:03:17 +00001648 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001649</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001650</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001651
1652<!-- _______________________________________________________________________ -->
1653<div class="doc_subsubsection">
1654 <a name="i_select">'<tt>select</tt>' Instruction</a>
1655</div>
1656
1657<div class="doc_text">
1658
1659<h5>Syntax:</h5>
1660
1661<pre>
1662 &lt;result&gt; = select bool &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
1663</pre>
1664
1665<h5>Overview:</h5>
1666
1667<p>
1668The '<tt>select</tt>' instruction is used to choose one value based on a
1669condition, without branching.
1670</p>
1671
1672
1673<h5>Arguments:</h5>
1674
1675<p>
1676The '<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.
1677</p>
1678
1679<h5>Semantics:</h5>
1680
1681<p>
1682If the boolean condition evaluates to true, the instruction returns the first
1683value argument, otherwise it returns the second value argument.
1684</p>
1685
1686<h5>Example:</h5>
1687
1688<pre>
1689 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
1690</pre>
1691</div>
1692
1693
1694
1695
1696
Chris Lattner33ba0d92001-07-09 00:26:23 +00001697<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001698<div class="doc_subsubsection"> <a name="i_call">'<tt>call</tt>'
1699Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001700<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001701<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001702<pre> &lt;result&gt; = call &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +00001703<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001704<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001705<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001706<p>This instruction requires several arguments:</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001707<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00001708 <li>
1709 <p>'<tt>ty</tt>': shall be the signature of the pointer to function
1710value being invoked. The argument types must match the types implied
1711by this signature.</p>
1712 </li>
1713 <li>
1714 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a
1715function to be invoked. In most cases, this is a direct function
1716invocation, but indirect <tt>call</tt>s are just as possible,
1717calling an arbitrary pointer to function values.</p>
1718 </li>
1719 <li>
1720 <p>'<tt>function args</tt>': argument list whose types match the
1721function signature argument types. If the function signature
1722indicates the function accepts a variable number of arguments, the
1723extra arguments can be specified.</p>
1724 </li>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001725</ol>
Chris Lattner00950542001-06-06 20:29:01 +00001726<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001727<p>The '<tt>call</tt>' instruction is used to cause control flow to
1728transfer to a specified function, with its incoming arguments bound to
1729the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
1730instruction in the called function, control flow continues with the
1731instruction after the function call, and the return value of the
1732function is bound to the result argument. This is a simpler case of
1733the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001734<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001735<pre> %retval = call int %test(int %argc)<br> call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42);<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001736</div>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001737<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001738<div class="doc_subsubsection"> <a name="i_vanext">'<tt>vanext</tt>'
1739Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001740<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001741<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001742<pre> &lt;resultarglist&gt; = vanext &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001743<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001744<p>The '<tt>vanext</tt>' instruction is used to access arguments passed
1745through the "variable argument" area of a function call. It is used to
1746implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001747<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001748<p>This instruction takes a <tt>valist</tt> value and the type of the
1749argument. It returns another <tt>valist</tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001750<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001751<p>The '<tt>vanext</tt>' instruction advances the specified <tt>valist</tt>
1752past an argument of the specified type. In conjunction with the <a
1753 href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement
1754the <tt>va_arg</tt> macro available in C. For more information, see
1755the variable argument handling <a href="#int_varargs">Intrinsic
1756Functions</a>.</p>
1757<p>It is legal for this instruction to be called in a function which
1758does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001759function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001760<p><tt>vanext</tt> is an LLVM instruction instead of an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001761 href="#intrinsics">intrinsic function</a> because it takes an type as
1762an argument.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001763<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001764<p>See the <a href="#int_varargs">variable argument processing</a>
1765section.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001766</div>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001767<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001768<div class="doc_subsubsection"> <a name="i_vaarg">'<tt>vaarg</tt>'
1769Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001770<div class="doc_text">
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001771<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001772<pre> &lt;resultval&gt; = vaarg &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;<br></pre>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001773<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001774<p>The '<tt>vaarg</tt>' instruction is used to access arguments passed
1775through the "variable argument" area of a function call. It is used to
1776implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001777<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001778<p>This instruction takes a <tt>valist</tt> value and the type of the
1779argument. It returns a value of the specified argument type.</p>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001780<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001781<p>The '<tt>vaarg</tt>' instruction loads an argument of the specified
1782type from the specified <tt>va_list</tt>. In conjunction with the <a
1783 href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to
1784implement the <tt>va_arg</tt> macro available in C. For more
1785information, see the variable argument handling <a href="#int_varargs">Intrinsic
1786Functions</a>.</p>
1787<p>It is legal for this instruction to be called in a function which
1788does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001789function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001790<p><tt>vaarg</tt> is an LLVM instruction instead of an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001791 href="#intrinsics">intrinsic function</a> because it takes an type as
1792an argument.</p>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001793<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001794<p>See the <a href="#int_varargs">variable argument processing</a>
1795section.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001796</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001797
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001798<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00001799<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
1800<!-- *********************************************************************** -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001801
Misha Brukman9d0919f2003-11-08 01:05:38 +00001802<div class="doc_text">
Chris Lattner33aec9e2004-02-12 17:01:32 +00001803
1804<p>LLVM supports the notion of an "intrinsic function". These functions have
1805well known names and semantics, and are required to follow certain
1806restrictions. Overall, these instructions represent an extension mechanism for
1807the LLVM language that does not require changing all of the transformations in
1808LLVM to add to the language (or the bytecode reader/writer, the parser,
1809etc...).</p>
1810
1811<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix, this
1812prefix is reserved in LLVM for intrinsic names, thus functions may not be named
1813this. Intrinsic functions must always be external functions: you cannot define
1814the body of intrinsic functions. Intrinsic functions may only be used in call
1815or invoke instructions: it is illegal to take the address of an intrinsic
1816function. Additionally, because intrinsic functions are part of the LLVM
1817language, it is required that they all be documented here if any are added.</p>
1818
1819
1820<p>
1821Adding an intrinsic to LLVM is straight-forward if it is possible to express the
1822concept in LLVM directly (ie, code generator support is not _required_). To do
1823this, extend the default implementation of the IntrinsicLowering class to handle
1824the intrinsic. Code generators use this class to lower intrinsics they do not
1825understand to raw LLVM instructions that they do.
1826</p>
1827
Misha Brukman9d0919f2003-11-08 01:05:38 +00001828</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001829
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001830<!-- ======================================================================= -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001831<div class="doc_subsection">
1832 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
1833</div>
1834
Misha Brukman9d0919f2003-11-08 01:05:38 +00001835<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00001836
Misha Brukman9d0919f2003-11-08 01:05:38 +00001837<p>Variable argument support is defined in LLVM with the <a
Chris Lattner261efe92003-11-25 01:02:51 +00001838 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
1839intrinsic functions. These functions are related to the similarly
1840named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00001841
Chris Lattner261efe92003-11-25 01:02:51 +00001842<p>All of these functions operate on arguments that use a
1843target-specific value type "<tt>va_list</tt>". The LLVM assembly
1844language reference manual does not define what this type is, so all
1845transformations should be prepared to handle intrinsics with any type
1846used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00001847
Misha Brukman9d0919f2003-11-08 01:05:38 +00001848<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner261efe92003-11-25 01:02:51 +00001849instruction and the variable argument handling intrinsic functions are
1850used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00001851
Chris Lattner33aec9e2004-02-12 17:01:32 +00001852<pre>
1853int %test(int %X, ...) {
1854 ; Initialize variable argument processing
1855 %ap = call sbyte* %<a href="#i_va_start">llvm.va_start</a>()
1856
1857 ; Read a single integer argument
1858 %tmp = vaarg sbyte* %ap, int
1859
1860 ; Advance to the next argument
1861 %ap2 = vanext sbyte* %ap, int
1862
1863 ; Demonstrate usage of llvm.va_copy and llvm.va_end
1864 %aq = call sbyte* %<a href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2)
1865 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %aq)
1866
1867 ; Stop processing of arguments.
1868 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %ap2)
1869 ret int %tmp
1870}
1871</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001872</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001873
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001874<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001875<div class="doc_subsubsection">
1876 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
1877</div>
1878
1879
Misha Brukman9d0919f2003-11-08 01:05:38 +00001880<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001881<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001882<pre> call va_list ()* %llvm.va_start()<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001883<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001884<p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt>&lt;arglist&gt;</tt>
1885for subsequent use by the variable argument intrinsics.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001886<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001887<p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001888macro available in C. In a target-dependent way, it initializes and
1889returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt>
1890will produce the first variable argument passed to the function. Unlike
1891the C <tt>va_start</tt> macro, this intrinsic does not need to know the
1892last argument of the function, the compiler can figure that out.</p>
1893<p>Note that this intrinsic function is only legal to be called from
1894within the body of a variable argument function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001895</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001896
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001897<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001898<div class="doc_subsubsection">
1899 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
1900</div>
1901
Misha Brukman9d0919f2003-11-08 01:05:38 +00001902<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001903<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001904<pre> call void (va_list)* %llvm.va_end(va_list &lt;arglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001905<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001906<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
1907which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
1908or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001909<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001910<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001911<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001912<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001913macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
1914Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
1915 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
1916with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001917</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001918
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001919<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001920<div class="doc_subsubsection">
1921 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
1922</div>
1923
Misha Brukman9d0919f2003-11-08 01:05:38 +00001924<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00001925
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001926<h5>Syntax:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00001927
1928<pre>
1929 call va_list (va_list)* %llvm.va_copy(va_list &lt;destarglist&gt;)
1930</pre>
1931
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001932<h5>Overview:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00001933
1934<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position
1935from the source argument list to the destination argument list.</p>
1936
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001937<h5>Arguments:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00001938
Misha Brukman9d0919f2003-11-08 01:05:38 +00001939<p>The argument is the <tt>va_list</tt> to copy.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00001940
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001941<h5>Semantics:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00001942
Misha Brukman9d0919f2003-11-08 01:05:38 +00001943<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
Chris Lattnerd7923912004-05-23 21:06:01 +00001944macro available in C. In a target-dependent way, it copies the source
1945<tt>va_list</tt> element into the returned list. This intrinsic is necessary
1946because the <tt><a href="i_va_start">llvm.va_start</a></tt> intrinsic may be
1947arbitrarily complex and require memory allocation, for example.</p>
1948
Misha Brukman9d0919f2003-11-08 01:05:38 +00001949</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001950
Chris Lattner33aec9e2004-02-12 17:01:32 +00001951<!-- ======================================================================= -->
1952<div class="doc_subsection">
Chris Lattnerd7923912004-05-23 21:06:01 +00001953 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
1954</div>
1955
1956<div class="doc_text">
1957
1958<p>
1959LLVM support for <a href="GarbageCollection.html">Accurate Garbage
1960Collection</a> requires the implementation and generation of these intrinsics.
1961These intrinsics allow identification of <a href="#i_gcroot">GC roots on the
1962stack</a>, as well as garbage collector implementations that require <a
1963href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers.
1964Front-ends for type-safe garbage collected languages should generate these
1965intrinsics to make use of the LLVM garbage collectors. For more details, see <a
1966href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
1967</p>
1968</div>
1969
1970<!-- _______________________________________________________________________ -->
1971<div class="doc_subsubsection">
1972 <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
1973</div>
1974
1975<div class="doc_text">
1976
1977<h5>Syntax:</h5>
1978
1979<pre>
1980 call void (&lt;ty&gt;**, &lt;ty2&gt;*)* %llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
1981</pre>
1982
1983<h5>Overview:</h5>
1984
1985<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existance of a GC root to
1986the code generator, and allows some metadata to be associated with it.</p>
1987
1988<h5>Arguments:</h5>
1989
1990<p>The first argument specifies the address of a stack object that contains the
1991root pointer. The second pointer (which must be either a constant or a global
1992value address) contains the meta-data to be associated with the root.</p>
1993
1994<h5>Semantics:</h5>
1995
1996<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
1997location. At compile-time, the code generator generates information to allow
1998the runtime to find the pointer at GC safe points.
1999</p>
2000
2001</div>
2002
2003
2004<!-- _______________________________________________________________________ -->
2005<div class="doc_subsubsection">
2006 <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
2007</div>
2008
2009<div class="doc_text">
2010
2011<h5>Syntax:</h5>
2012
2013<pre>
2014 call sbyte* (sbyte**)* %llvm.gcread(sbyte** %Ptr)
2015</pre>
2016
2017<h5>Overview:</h5>
2018
2019<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
2020locations, allowing garbage collector implementations that require read
2021barriers.</p>
2022
2023<h5>Arguments:</h5>
2024
2025<p>The argument is the address to read from, which should be an address
2026allocated from the garbage collector.</p>
2027
2028<h5>Semantics:</h5>
2029
2030<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
2031instruction, but may be replaced with substantially more complex code by the
2032garbage collector runtime, as needed.</p>
2033
2034</div>
2035
2036
2037<!-- _______________________________________________________________________ -->
2038<div class="doc_subsubsection">
2039 <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
2040</div>
2041
2042<div class="doc_text">
2043
2044<h5>Syntax:</h5>
2045
2046<pre>
2047 call void (sbyte*, sbyte**)* %llvm.gcwrite(sbyte* %P1, sbyte** %P2)
2048</pre>
2049
2050<h5>Overview:</h5>
2051
2052<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
2053locations, allowing garbage collector implementations that require write
2054barriers (such as generational or reference counting collectors).</p>
2055
2056<h5>Arguments:</h5>
2057
2058<p>The first argument is the reference to store, and the second is the heap
2059location to store to.</p>
2060
2061<h5>Semantics:</h5>
2062
2063<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
2064instruction, but may be replaced with substantially more complex code by the
2065garbage collector runtime, as needed.</p>
2066
2067</div>
2068
2069
2070
2071<!-- ======================================================================= -->
2072<div class="doc_subsection">
Chris Lattner10610642004-02-14 04:08:35 +00002073 <a name="int_codegen">Code Generator Intrinsics</a>
2074</div>
2075
2076<div class="doc_text">
2077<p>
2078These intrinsics are provided by LLVM to expose special features that may only
2079be implemented with code generator support.
2080</p>
2081
2082</div>
2083
2084<!-- _______________________________________________________________________ -->
2085<div class="doc_subsubsection">
2086 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
2087</div>
2088
2089<div class="doc_text">
2090
2091<h5>Syntax:</h5>
2092<pre>
2093 call void* ()* %llvm.returnaddress(uint &lt;level&gt;)
2094</pre>
2095
2096<h5>Overview:</h5>
2097
2098<p>
2099The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
2100indicating the return address of the current function or one of its callers.
2101</p>
2102
2103<h5>Arguments:</h5>
2104
2105<p>
2106The argument to this intrinsic indicates which function to return the address
2107for. Zero indicates the calling function, one indicates its caller, etc. The
2108argument is <b>required</b> to be a constant integer value.
2109</p>
2110
2111<h5>Semantics:</h5>
2112
2113<p>
2114The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
2115the return address of the specified call frame, or zero if it cannot be
2116identified. The value returned by this intrinsic is likely to be incorrect or 0
2117for arguments other than zero, so it should only be used for debugging purposes.
2118</p>
2119
2120<p>
2121Note that calling this intrinsic does not prevent function inlining or other
2122aggressive transformations, so the value returned may not that of the obvious
2123source-language caller.
2124</p>
2125</div>
2126
2127
2128<!-- _______________________________________________________________________ -->
2129<div class="doc_subsubsection">
2130 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
2131</div>
2132
2133<div class="doc_text">
2134
2135<h5>Syntax:</h5>
2136<pre>
2137 call void* ()* %llvm.frameaddress(uint &lt;level&gt;)
2138</pre>
2139
2140<h5>Overview:</h5>
2141
2142<p>
2143The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
2144pointer value for the specified stack frame.
2145</p>
2146
2147<h5>Arguments:</h5>
2148
2149<p>
2150The argument to this intrinsic indicates which function to return the frame
2151pointer for. Zero indicates the calling function, one indicates its caller,
2152etc. The argument is <b>required</b> to be a constant integer value.
2153</p>
2154
2155<h5>Semantics:</h5>
2156
2157<p>
2158The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
2159the frame address of the specified call frame, or zero if it cannot be
2160identified. The value returned by this intrinsic is likely to be incorrect or 0
2161for arguments other than zero, so it should only be used for debugging purposes.
2162</p>
2163
2164<p>
2165Note that calling this intrinsic does not prevent function inlining or other
2166aggressive transformations, so the value returned may not that of the obvious
2167source-language caller.
2168</p>
2169</div>
2170
John Criswell7123e272004-04-09 16:43:20 +00002171<!-- ======================================================================= -->
2172<div class="doc_subsection">
2173 <a name="int_os">Operating System Intrinsics</a>
2174</div>
2175
2176<div class="doc_text">
2177<p>
2178These intrinsics are provided by LLVM to support the implementation of
2179operating system level code.
2180</p>
2181
2182</div>
John Criswell183402a2004-04-12 15:02:16 +00002183
John Criswellcfd3bac2004-04-09 15:23:37 +00002184<!-- _______________________________________________________________________ -->
2185<div class="doc_subsubsection">
2186 <a name="i_readport">'<tt>llvm.readport</tt>' Intrinsic</a>
2187</div>
2188
2189<div class="doc_text">
2190
2191<h5>Syntax:</h5>
2192<pre>
John Criswell7123e272004-04-09 16:43:20 +00002193 call &lt;integer type&gt; (&lt;integer type&gt;)* %llvm.readport (&lt;integer type&gt; &lt;address&gt;)
John Criswellcfd3bac2004-04-09 15:23:37 +00002194</pre>
2195
2196<h5>Overview:</h5>
2197
2198<p>
John Criswell7123e272004-04-09 16:43:20 +00002199The '<tt>llvm.readport</tt>' intrinsic reads data from the specified hardware
2200I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002201</p>
2202
2203<h5>Arguments:</h5>
2204
2205<p>
John Criswell7123e272004-04-09 16:43:20 +00002206The argument to this intrinsic indicates the hardware I/O address from which
2207to read the data. The address is in the hardware I/O address namespace (as
2208opposed to being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002209</p>
2210
2211<h5>Semantics:</h5>
2212
2213<p>
John Criswell7123e272004-04-09 16:43:20 +00002214The '<tt>llvm.readport</tt>' intrinsic reads data from the hardware I/O port
2215specified by <i>address</i> and returns the value. The address and return
2216value must be integers, but the size is dependent upon the platform upon which
2217the program is code generated. For example, on x86, the address must be an
2218unsigned 16 bit value, and the return value must be 8, 16, or 32 bits.
John Criswellcfd3bac2004-04-09 15:23:37 +00002219</p>
2220
2221</div>
2222
2223<!-- _______________________________________________________________________ -->
2224<div class="doc_subsubsection">
2225 <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a>
2226</div>
2227
2228<div class="doc_text">
2229
2230<h5>Syntax:</h5>
2231<pre>
John Criswell7123e272004-04-09 16:43:20 +00002232 call void (&lt;integer type&gt;, &lt;integer type&gt;)* %llvm.writeport (&lt;integer type&gt; &lt;value&gt;, &lt;integer type&gt; &lt;address&gt;)
John Criswellcfd3bac2004-04-09 15:23:37 +00002233</pre>
2234
2235<h5>Overview:</h5>
2236
2237<p>
John Criswell7123e272004-04-09 16:43:20 +00002238The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified hardware
2239I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002240</p>
2241
2242<h5>Arguments:</h5>
2243
2244<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002245The first argument is the value to write to the I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002246</p>
2247
2248<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002249The second argument indicates the hardware I/O address to which data should be
2250written. The address is in the hardware I/O address namespace (as opposed to
2251being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002252</p>
2253
2254<h5>Semantics:</h5>
2255
2256<p>
2257The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port
2258specified by <i>address</i>. The address and value must be integers, but the
2259size is dependent upon the platform upon which the program is code generated.
John Criswell7123e272004-04-09 16:43:20 +00002260For example, on x86, the address must be an unsigned 16 bit value, and the
2261value written must be 8, 16, or 32 bits in length.
John Criswellcfd3bac2004-04-09 15:23:37 +00002262</p>
2263
2264</div>
Chris Lattner10610642004-02-14 04:08:35 +00002265
John Criswell183402a2004-04-12 15:02:16 +00002266<!-- _______________________________________________________________________ -->
2267<div class="doc_subsubsection">
2268 <a name="i_readio">'<tt>llvm.readio</tt>' Intrinsic</a>
2269</div>
2270
2271<div class="doc_text">
2272
2273<h5>Syntax:</h5>
2274<pre>
John Criswell96db6fc2004-04-12 16:33:19 +00002275 call &lt;result&gt; (&lt;ty&gt;*)* %llvm.readio (&lt;ty&gt; * &lt;pointer&gt;)
John Criswell183402a2004-04-12 15:02:16 +00002276</pre>
2277
2278<h5>Overview:</h5>
2279
2280<p>
2281The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
2282address.
2283</p>
2284
2285<h5>Arguments:</h5>
2286
2287<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002288The argument to this intrinsic is a pointer indicating the memory address from
2289which to read the data. The data must be a
2290<a href="#t_firstclass">first class</a> type.
John Criswell183402a2004-04-12 15:02:16 +00002291</p>
2292
2293<h5>Semantics:</h5>
2294
2295<p>
2296The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
John Criswell96db6fc2004-04-12 16:33:19 +00002297location specified by <i>pointer</i> and returns the value. The argument must
2298be a pointer, and the return value must be a
2299<a href="#t_firstclass">first class</a> type. However, certain architectures
2300may not support I/O on all first class types. For example, 32 bit processors
2301may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00002302</p>
2303
2304<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002305This intrinsic enforces an in-order memory model for llvm.readio and
2306llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2307scheduled processors may execute loads and stores out of order, re-ordering at
2308run time accesses to memory mapped I/O registers. Using these intrinsics
2309ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00002310</p>
2311
2312</div>
2313
2314<!-- _______________________________________________________________________ -->
2315<div class="doc_subsubsection">
2316 <a name="i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a>
2317</div>
2318
2319<div class="doc_text">
2320
2321<h5>Syntax:</h5>
2322<pre>
John Criswell96db6fc2004-04-12 16:33:19 +00002323 call void (&lt;ty1&gt;, &lt;ty2&gt;*)* %llvm.writeio (&lt;ty1&gt; &lt;value&gt;, &lt;ty2&gt; * &lt;pointer&gt;)
John Criswell183402a2004-04-12 15:02:16 +00002324</pre>
2325
2326<h5>Overview:</h5>
2327
2328<p>
2329The '<tt>llvm.writeio</tt>' intrinsic writes data to the specified memory
2330mapped I/O address.
2331</p>
2332
2333<h5>Arguments:</h5>
2334
2335<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002336The first argument is the value to write to the memory mapped I/O location.
2337The second argument is a pointer indicating the memory address to which the
2338data should be written.
John Criswell183402a2004-04-12 15:02:16 +00002339</p>
2340
2341<h5>Semantics:</h5>
2342
2343<p>
2344The '<tt>llvm.writeio</tt>' intrinsic writes <i>value</i> to the memory mapped
John Criswell96db6fc2004-04-12 16:33:19 +00002345I/O address specified by <i>pointer</i>. The value must be a
2346<a href="#t_firstclass">first class</a> type. However, certain architectures
2347may not support I/O on all first class types. For example, 32 bit processors
2348may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00002349</p>
2350
2351<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002352This intrinsic enforces an in-order memory model for llvm.readio and
2353llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2354scheduled processors may execute loads and stores out of order, re-ordering at
2355run time accesses to memory mapped I/O registers. Using these intrinsics
2356ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00002357</p>
2358
2359</div>
2360
2361
Chris Lattner10610642004-02-14 04:08:35 +00002362<!-- ======================================================================= -->
2363<div class="doc_subsection">
Chris Lattner33aec9e2004-02-12 17:01:32 +00002364 <a name="int_libc">Standard C Library Intrinsics</a>
2365</div>
2366
2367<div class="doc_text">
2368<p>
Chris Lattner10610642004-02-14 04:08:35 +00002369LLVM provides intrinsics for a few important standard C library functions.
2370These intrinsics allow source-language front-ends to pass information about the
2371alignment of the pointer arguments to the code generator, providing opportunity
2372for more efficient code generation.
Chris Lattner33aec9e2004-02-12 17:01:32 +00002373</p>
2374
2375</div>
2376
2377<!-- _______________________________________________________________________ -->
2378<div class="doc_subsubsection">
2379 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
2380</div>
2381
2382<div class="doc_text">
2383
2384<h5>Syntax:</h5>
2385<pre>
2386 call void (sbyte*, sbyte*, uint, uint)* %llvm.memcpy(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2387 uint &lt;len&gt;, uint &lt;align&gt;)
2388</pre>
2389
2390<h5>Overview:</h5>
2391
2392<p>
2393The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2394location to the destination location.
2395</p>
2396
2397<p>
2398Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
2399does not return a value, and takes an extra alignment argument.
2400</p>
2401
2402<h5>Arguments:</h5>
2403
2404<p>
2405The first argument is a pointer to the destination, the second is a pointer to
2406the source. The third argument is an (arbitrarily sized) integer argument
2407specifying the number of bytes to copy, and the fourth argument is the alignment
2408of the source and destination locations.
2409</p>
2410
Chris Lattner3301ced2004-02-12 21:18:15 +00002411<p>
2412If the call to this intrinisic has an alignment value that is not 0 or 1, then
2413the caller guarantees that the size of the copy is a multiple of the alignment
2414and that both the source and destination pointers are aligned to that boundary.
2415</p>
2416
Chris Lattner33aec9e2004-02-12 17:01:32 +00002417<h5>Semantics:</h5>
2418
2419<p>
2420The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2421location to the destination location, which are not allowed to overlap. It
2422copies "len" bytes of memory over. If the argument is known to be aligned to
2423some boundary, this can be specified as the fourth argument, otherwise it should
2424be set to 0 or 1.
2425</p>
2426</div>
2427
2428
Chris Lattner0eb51b42004-02-12 18:10:10 +00002429<!-- _______________________________________________________________________ -->
2430<div class="doc_subsubsection">
2431 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
2432</div>
2433
2434<div class="doc_text">
2435
2436<h5>Syntax:</h5>
2437<pre>
2438 call void (sbyte*, sbyte*, uint, uint)* %llvm.memmove(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2439 uint &lt;len&gt;, uint &lt;align&gt;)
2440</pre>
2441
2442<h5>Overview:</h5>
2443
2444<p>
2445The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
2446location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>'
2447intrinsic but allows the two memory locations to overlap.
2448</p>
2449
2450<p>
2451Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
2452does not return a value, and takes an extra alignment argument.
2453</p>
2454
2455<h5>Arguments:</h5>
2456
2457<p>
2458The first argument is a pointer to the destination, the second is a pointer to
2459the source. The third argument is an (arbitrarily sized) integer argument
2460specifying the number of bytes to copy, and the fourth argument is the alignment
2461of the source and destination locations.
2462</p>
2463
Chris Lattner3301ced2004-02-12 21:18:15 +00002464<p>
2465If the call to this intrinisic has an alignment value that is not 0 or 1, then
2466the caller guarantees that the size of the copy is a multiple of the alignment
2467and that both the source and destination pointers are aligned to that boundary.
2468</p>
2469
Chris Lattner0eb51b42004-02-12 18:10:10 +00002470<h5>Semantics:</h5>
2471
2472<p>
2473The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
2474location to the destination location, which may overlap. It
2475copies "len" bytes of memory over. If the argument is known to be aligned to
2476some boundary, this can be specified as the fourth argument, otherwise it should
2477be set to 0 or 1.
2478</p>
2479</div>
2480
Chris Lattner8ff75902004-01-06 05:31:32 +00002481
Chris Lattner10610642004-02-14 04:08:35 +00002482<!-- _______________________________________________________________________ -->
2483<div class="doc_subsubsection">
2484 <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a>
2485</div>
2486
2487<div class="doc_text">
2488
2489<h5>Syntax:</h5>
2490<pre>
2491 call void (sbyte*, ubyte, uint, uint)* %llvm.memset(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
2492 uint &lt;len&gt;, uint &lt;align&gt;)
2493</pre>
2494
2495<h5>Overview:</h5>
2496
2497<p>
2498The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular
2499byte value.
2500</p>
2501
2502<p>
2503Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
2504does not return a value, and takes an extra alignment argument.
2505</p>
2506
2507<h5>Arguments:</h5>
2508
2509<p>
2510The first argument is a pointer to the destination to fill, the second is the
2511byte value to fill it with, the third argument is an (arbitrarily sized) integer
2512argument specifying the number of bytes to fill, and the fourth argument is the
2513known alignment of destination location.
2514</p>
2515
2516<p>
2517If the call to this intrinisic has an alignment value that is not 0 or 1, then
2518the caller guarantees that the size of the copy is a multiple of the alignment
2519and that the destination pointer is aligned to that boundary.
2520</p>
2521
2522<h5>Semantics:</h5>
2523
2524<p>
2525The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the
2526destination location. If the argument is known to be aligned to some boundary,
2527this can be specified as the fourth argument, otherwise it should be set to 0 or
25281.
2529</p>
2530</div>
2531
2532
Chris Lattner32006282004-06-11 02:28:03 +00002533<!-- _______________________________________________________________________ -->
2534<div class="doc_subsubsection">
2535 <a name="i_isnan">'<tt>llvm.isnan</tt>' Intrinsic</a>
2536</div>
2537
2538<div class="doc_text">
2539
2540<h5>Syntax:</h5>
2541<pre>
2542 call bool (&lt;float or double&gt;)* %llvm.isnan(&lt;float or double&gt; Val)
2543</pre>
2544
2545<h5>Overview:</h5>
2546
2547<p>
2548The '<tt>llvm.isnan</tt>' intrinsic returns true if the specific floating point
2549value is a NAN.
2550</p>
2551
2552<h5>Arguments:</h5>
2553
2554<p>
2555The argument is a floating point number.
2556</p>
2557
2558<h5>Semantics:</h5>
2559
2560<p>
2561If the argument is a SNAN or QNAN, it returns true, otherwise false.
2562</p>
2563</div>
2564
2565
Alkis Evlogimenos26bbe932004-06-13 01:16:15 +00002566<!-- _______________________________________________________________________ -->
2567<div class="doc_subsubsection">
2568 <a name="i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a>
2569</div>
2570
2571<div class="doc_text">
2572
2573<h5>Syntax:</h5>
2574<pre>
2575 call bool (&lt;float or double&gt;, &lt;float or double&gt;)* %llvm.isunordered(&lt;float or double&gt; Val1,
2576 &lt;float or double&gt; Val2)
2577</pre>
2578
2579<h5>Overview:</h5>
2580
2581<p>
2582The '<tt>llvm.isunordered</tt>' intrinsic returns true if either or both of the
2583specified floating point values is a NAN.
2584</p>
2585
2586<h5>Arguments:</h5>
2587
2588<p>
2589The arguments are floating point numbers of the same type.
2590</p>
2591
2592<h5>Semantics:</h5>
2593
2594<p>
2595If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise
2596false.
2597</p>
2598</div>
2599
2600
Chris Lattner32006282004-06-11 02:28:03 +00002601
2602
Chris Lattner8ff75902004-01-06 05:31:32 +00002603<!-- ======================================================================= -->
2604<div class="doc_subsection">
2605 <a name="int_debugger">Debugger Intrinsics</a>
2606</div>
2607
2608<div class="doc_text">
2609<p>
2610The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
2611are described in the <a
2612href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
2613Debugging</a> document.
2614</p>
2615</div>
2616
2617
Chris Lattner00950542001-06-06 20:29:01 +00002618<!-- *********************************************************************** -->
Chris Lattner00950542001-06-06 20:29:01 +00002619<hr>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002620<address>
2621 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
2622 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
2623 <a href="http://validator.w3.org/check/referer"><img
2624 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
2625
2626 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
2627 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
2628 Last modified: $Date$
2629</address>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002630</body>
2631</html>