blob: 76655ad4fc85f563c709bf2fe0e5fcf9a18423a0 [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>
8<body>
Chris Lattner261efe92003-11-25 01:02:51 +00009<div class="doc_title"> LLVM Language Reference Manual </div>
Chris Lattner00950542001-06-06 20:29:01 +000010<ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000011 <li><a href="#abstract">Abstract</a></li>
12 <li><a href="#introduction">Introduction</a></li>
13 <li><a href="#identifiers">Identifiers</a></li>
Chris Lattner00950542001-06-06 20:29:01 +000014 <li><a href="#typesystem">Type System</a>
15 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000016 <li><a href="#t_primitive">Primitive Types</a>
17 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000018 <li><a href="#t_classifications">Type Classifications</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000019 </ol>
20 </li>
Chris Lattner00950542001-06-06 20:29:01 +000021 <li><a href="#t_derived">Derived Types</a>
22 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000023 <li><a href="#t_array">Array Type</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000024 <li><a href="#t_function">Function Type</a></li>
25 <li><a href="#t_pointer">Pointer Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000026 <li><a href="#t_struct">Structure Type</a></li>
27<!-- <li><a href="#t_packed" >Packed Type</a> -->
28 </ol>
29 </li>
30 </ol>
31 </li>
Chris Lattner00950542001-06-06 20:29:01 +000032 <li><a href="#highlevel">High Level Structure</a>
33 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000034 <li><a href="#modulestructure">Module Structure</a></li>
35 <li><a href="#globalvars">Global Variables</a></li>
36 <li><a href="#functionstructure">Function Structure</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000037 </ol>
38 </li>
Chris Lattner00950542001-06-06 20:29:01 +000039 <li><a href="#instref">Instruction Reference</a>
40 <ol>
41 <li><a href="#terminators">Terminator Instructions</a>
42 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000043 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
44 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000045 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
46 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000047 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
48 </ol>
49 </li>
Chris Lattner00950542001-06-06 20:29:01 +000050 <li><a href="#binaryops">Binary Operations</a>
51 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000052 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
53 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
54 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
55 <li><a href="#i_div">'<tt>div</tt>' Instruction</a></li>
56 <li><a href="#i_rem">'<tt>rem</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000057 <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000058 </ol>
59 </li>
Chris Lattner00950542001-06-06 20:29:01 +000060 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
61 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000062 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000063 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000064 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
65 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
66 <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000067 </ol>
68 </li>
Chris Lattner00950542001-06-06 20:29:01 +000069 <li><a href="#memoryops">Memory Access Operations</a>
70 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000071 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
72 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
73 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
74 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
75 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
76 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
77 </ol>
78 </li>
Chris Lattner00950542001-06-06 20:29:01 +000079 <li><a href="#otherops">Other Operations</a>
80 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000081 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000082 <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li>
Chris Lattnercc37aae2004-03-12 05:50:16 +000083 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000084 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000085 <li><a href="#i_vanext">'<tt>vanext</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000086 <li><a href="#i_vaarg">'<tt>vaarg</tt>' Instruction</a></li>
Chris Lattner00950542001-06-06 20:29:01 +000087 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +000088 </li>
Chris Lattner00950542001-06-06 20:29:01 +000089 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +000090 </li>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +000091 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +000092 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000093 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
94 <ol>
95 <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
96 <li><a href="#i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
97 <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
98 </ol>
99 </li>
Chris Lattner10610642004-02-14 04:08:35 +0000100 <li><a href="#int_codegen">Code Generator Intrinsics</a>
101 <ol>
102 <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
103 <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
John Criswell7123e272004-04-09 16:43:20 +0000104 </ol>
105 </li>
106 <li><a href="#int_os">Operating System Intrinsics</a>
107 <ol>
John Criswellcfd3bac2004-04-09 15:23:37 +0000108 <li><a href="#i_readport">'<tt>llvm.readport</tt>' Intrinsic</a></li>
109 <li><a href="#i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a></li>
John Criswell183402a2004-04-12 15:02:16 +0000110 <li><a href="#i_readio">'<tt>llvm.readio</tt>' Intrinsic</a></li>
111 <li><a href="#i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000112 </ol>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000113 <li><a href="#int_libc">Standard C Library Intrinsics</a>
114 <ol>
115 <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li>
Chris Lattner0eb51b42004-02-12 18:10:10 +0000116 <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000117 <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000118 </ol>
119 </li>
Chris Lattner8ff75902004-01-06 05:31:32 +0000120 <li><a href="#int_debugger">Debugger intrinsics</a>
Chris Lattner261efe92003-11-25 01:02:51 +0000121 </ol>
122 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000123</ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000124<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000125<p><b>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
126and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></b></p>
127<p> </p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000128</div>
Chris Lattner00950542001-06-06 20:29:01 +0000129<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000130<div class="doc_section"> <a name="abstract">Abstract </a></div>
131<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000132<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000133<p>This document is a reference manual for the LLVM assembly language.
134LLVM is an SSA based representation that provides type safety,
135low-level operations, flexibility, and the capability of representing
136'all' high-level languages cleanly. It is the common code
137representation used throughout all phases of the LLVM compilation
138strategy.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000139</div>
Chris Lattner00950542001-06-06 20:29:01 +0000140<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000141<div class="doc_section"> <a name="introduction">Introduction</a> </div>
142<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000143<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000144<p>The LLVM code representation is designed to be used in three
145different forms: as an in-memory compiler IR, as an on-disk bytecode
146representation (suitable for fast loading by a Just-In-Time compiler),
147and as a human readable assembly language representation. This allows
148LLVM to provide a powerful intermediate representation for efficient
149compiler transformations and analysis, while providing a natural means
150to debug and visualize the transformations. The three different forms
151of LLVM are all equivalent. This document describes the human readable
152representation and notation.</p>
153<p>The LLVM representation aims to be a light-weight and low-level
154while being expressive, typed, and extensible at the same time. It
155aims to be a "universal IR" of sorts, by being at a low enough level
156that high-level ideas may be cleanly mapped to it (similar to how
157microprocessors are "universal IR's", allowing many source languages to
158be mapped to them). By providing type information, LLVM can be used as
159the target of optimizations: for example, through pointer analysis, it
160can be proven that a C automatic variable is never accessed outside of
161the current function... allowing it to be promoted to a simple SSA
162value instead of a memory location.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000163</div>
Chris Lattner00950542001-06-06 20:29:01 +0000164<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000165<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000166<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000167<p>It is important to note that this document describes 'well formed'
168LLVM assembly language. There is a difference between what the parser
169accepts and what is considered 'well formed'. For example, the
170following instruction is syntactically okay, but not well formed:</p>
171<pre> %x = <a href="#i_add">add</a> int 1, %x<br></pre>
172<p>...because the definition of <tt>%x</tt> does not dominate all of
173its uses. The LLVM infrastructure provides a verification pass that may
174be used to verify that an LLVM module is well formed. This pass is
175automatically run by the parser after parsing input assembly, and by
176the optimizer before it outputs bytecode. The violations pointed out
177by the verifier pass indicate bugs in transformation passes or input to
178the parser.</p>
179<!-- Describe the typesetting conventions here. --> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000180<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000181<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000182<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000183<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000184<p>LLVM uses three different forms of identifiers, for different
185purposes:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000186<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000187 <li>Numeric constants are represented as you would expect: 12, -3
John Criswell4457dc92004-04-09 16:48:45 +0000188123.421, etc. Floating point constants have an optional hexadecimal
Chris Lattner261efe92003-11-25 01:02:51 +0000189notation.</li>
190 <li>Named values are represented as a string of characters with a '%'
191prefix. For example, %foo, %DivisionByZero,
192%a.really.long.identifier. The actual regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
193Identifiers which require other characters in their names can be
194surrounded with quotes. In this way, anything except a <tt>"</tt>
195character can be used in a name.</li>
196 <li>Unnamed values are represented as an unsigned numeric value with
197a '%' prefix. For example, %12, %2, %44.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000198</ol>
John Criswell6794d922004-03-12 21:19:06 +0000199<p>LLVM requires that values start with a '%' sign for two reasons:
Chris Lattner261efe92003-11-25 01:02:51 +0000200Compilers don't need to worry about name clashes with reserved words,
201and the set of reserved words may be expanded in the future without
202penalty. Additionally, unnamed identifiers allow a compiler to quickly
203come up with a temporary variable without having to avoid symbol table
204conflicts.</p>
205<p>Reserved words in LLVM are very similar to reserved words in other
206languages. There are keywords for different opcodes ('<tt><a
207 href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
208 href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
209 href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>',
210etc...), and others. These reserved words cannot conflict with
211variable names, because none of them start with a '%' character.</p>
212<p>Here is an example of LLVM code to multiply the integer variable '<tt>%X</tt>'
213by 8:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000214<p>The easy way:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000215<pre> %result = <a href="#i_mul">mul</a> uint %X, 8<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000216<p>After strength reduction:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000217<pre> %result = <a href="#i_shl">shl</a> uint %X, ubyte 3<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000218<p>And the hard way:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000219<pre> <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
220 <a
221 href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
222 %result = <a
223 href="#i_add">add</a> uint %1, %1<br></pre>
224<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
225important lexical features of LLVM:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000226<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000227 <li>Comments are delimited with a '<tt>;</tt>' and go until the end
228of line.</li>
229 <li>Unnamed temporaries are created when the result of a computation
230is not assigned to a named value.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000231 <li>Unnamed temporaries are numbered sequentially</li>
232</ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000233<p>...and it also show a convention that we follow in this document.
234When demonstrating instructions, we will follow an instruction with a
235comment that defines the type and name of value produced. Comments are
236shown in italic text.</p>
237<p>The one non-intuitive notation for constants is the optional
238hexidecimal form of floating point constants. For example, the form '<tt>double
Chris Lattner2b7d3202002-05-06 03:03:22 +00002390x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
Chris Lattner261efe92003-11-25 01:02:51 +00002404.5e+15</tt>' which is also supported by the parser. The only time
241hexadecimal floating point constants are useful (and the only time that
242they are generated by the disassembler) is when an FP constant has to
243be emitted that is not representable as a decimal floating point number
244exactly. For example, NaN's, infinities, and other special cases are
245represented in their IEEE hexadecimal format so that assembly and
246disassembly do not cause any bits to change in the constants.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000247</div>
Chris Lattner00950542001-06-06 20:29:01 +0000248<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000249<div class="doc_section"> <a name="typesystem">Type System</a> </div>
250<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000251<div class="doc_text">
Misha Brukman9d0919f2003-11-08 01:05:38 +0000252<p>The LLVM type system is one of the most important features of the
Chris Lattner261efe92003-11-25 01:02:51 +0000253intermediate representation. Being typed enables a number of
254optimizations to be performed on the IR directly, without having to do
255extra analyses on the side before the transformation. A strong type
256system makes it easier to read the generated code and enables novel
257analyses and transformations that are not feasible to perform on normal
258three address code representations.</p>
Chris Lattner7bae3952002-06-25 18:03:17 +0000259<!-- The written form for the type system was heavily influenced by the
260syntactic problems with types in the C language<sup><a
Chris Lattner261efe92003-11-25 01:02:51 +0000261href="#rw_stroustrup">1</a></sup>.<p> --> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000262<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000263<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000264<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +0000265<p>The primitive types are the fundamental building blocks of the LLVM
Chris Lattner261efe92003-11-25 01:02:51 +0000266system. The current set of primitive types are as follows:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000267
268<table border="0" style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +0000269 <tbody>
270 <tr>
271 <td>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000272 <table border="1" cellspacing="0" cellpadding="4" style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +0000273 <tbody>
274 <tr>
275 <td><tt>void</tt></td>
276 <td>No value</td>
277 </tr>
278 <tr>
279 <td><tt>ubyte</tt></td>
280 <td>Unsigned 8 bit value</td>
281 </tr>
282 <tr>
283 <td><tt>ushort</tt></td>
284 <td>Unsigned 16 bit value</td>
285 </tr>
286 <tr>
287 <td><tt>uint</tt></td>
288 <td>Unsigned 32 bit value</td>
289 </tr>
290 <tr>
291 <td><tt>ulong</tt></td>
292 <td>Unsigned 64 bit value</td>
293 </tr>
294 <tr>
295 <td><tt>float</tt></td>
296 <td>32 bit floating point value</td>
297 </tr>
298 <tr>
299 <td><tt>label</tt></td>
300 <td>Branch destination</td>
301 </tr>
302 </tbody>
303 </table>
304 </td>
305 <td valign="top">
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000306 <table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +0000307 <tbody>
308 <tr>
309 <td><tt>bool</tt></td>
310 <td>True or False value</td>
311 </tr>
312 <tr>
313 <td><tt>sbyte</tt></td>
314 <td>Signed 8 bit value</td>
315 </tr>
316 <tr>
317 <td><tt>short</tt></td>
318 <td>Signed 16 bit value</td>
319 </tr>
320 <tr>
321 <td><tt>int</tt></td>
322 <td>Signed 32 bit value</td>
323 </tr>
324 <tr>
325 <td><tt>long</tt></td>
326 <td>Signed 64 bit value</td>
327 </tr>
328 <tr>
329 <td><tt>double</tt></td>
330 <td>64 bit floating point value</td>
331 </tr>
332 </tbody>
333 </table>
334 </td>
335 </tr>
336 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000337</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000338
Misha Brukman9d0919f2003-11-08 01:05:38 +0000339</div>
Chris Lattner00950542001-06-06 20:29:01 +0000340<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000341<div class="doc_subsubsection"> <a name="t_classifications">Type
342Classifications</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000343<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000344<p>These different primitive types fall into a few useful
345classifications:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000346
347<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +0000348 <tbody>
349 <tr>
350 <td><a name="t_signed">signed</a></td>
351 <td><tt>sbyte, short, int, long, float, double</tt></td>
352 </tr>
353 <tr>
354 <td><a name="t_unsigned">unsigned</a></td>
355 <td><tt>ubyte, ushort, uint, ulong</tt></td>
356 </tr>
357 <tr>
358 <td><a name="t_integer">integer</a></td>
359 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
360 </tr>
361 <tr>
362 <td><a name="t_integral">integral</a></td>
363 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
364 </tr>
365 <tr>
366 <td><a name="t_floating">floating point</a></td>
367 <td><tt>float, double</tt></td>
368 </tr>
369 <tr>
370 <td><a name="t_firstclass">first class</a></td>
371 <td><tt>bool, ubyte, sbyte, ushort, short,<br>
372uint, int, ulong, long, float, double, <a href="#t_pointer">pointer</a></tt></td>
373 </tr>
374 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000375</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000376
Chris Lattner261efe92003-11-25 01:02:51 +0000377<p>The <a href="#t_firstclass">first class</a> types are perhaps the
378most important. Values of these types are the only ones which can be
379produced by instructions, passed as arguments, or used as operands to
380instructions. This means that all structures and arrays must be
381manipulated either by pointer or by component.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000382</div>
Chris Lattner00950542001-06-06 20:29:01 +0000383<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000384<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000385<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000386<p>The real power in LLVM comes from the derived types in the system.
387This is what allows a programmer to represent arrays, functions,
388pointers, and other useful types. Note that these derived types may be
389recursive: For example, it is possible to have a two dimensional array.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000390</div>
Chris Lattner00950542001-06-06 20:29:01 +0000391<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000392<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000393<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000394<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000395<p>The array type is a very simple derived type that arranges elements
Chris Lattner261efe92003-11-25 01:02:51 +0000396sequentially in memory. The array type requires a size (number of
397elements) and an underlying data type.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000398<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000399<pre> [&lt;# elements&gt; x &lt;elementtype&gt;]<br></pre>
400<p>The number of elements is a constant integer value, elementtype may
401be any type with a size.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000402<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000403<p> <tt>[40 x int ]</tt>: Array of 40 integer values.<br>
404<tt>[41 x int ]</tt>: Array of 41 integer values.<br>
405<tt>[40 x uint]</tt>: Array of 40 unsigned integer values.</p>
406<p> </p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000407<p>Here are some examples of multidimensional arrays:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000408
Misha Brukman9d0919f2003-11-08 01:05:38 +0000409<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000410 <tbody>
411 <tr>
412 <td><tt>[3 x [4 x int]]</tt></td>
413 <td>: 3x4 array integer values.</td>
414 </tr>
415 <tr>
416 <td><tt>[12 x [10 x float]]</tt></td>
417 <td>: 12x10 array of single precision floating point values.</td>
418 </tr>
419 <tr>
420 <td><tt>[2 x [3 x [4 x uint]]]</tt></td>
421 <td>: 2x3x4 array of unsigned integer values.</td>
422 </tr>
423 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000424</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000425
Misha Brukman9d0919f2003-11-08 01:05:38 +0000426</div>
Chris Lattner00950542001-06-06 20:29:01 +0000427<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000428<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000429<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000430<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000431<p>The function type can be thought of as a function signature. It
432consists of a return type and a list of formal parameter types.
John Criswell009900b2003-11-25 21:45:46 +0000433Function types are usually used to build virtual function tables
Chris Lattner261efe92003-11-25 01:02:51 +0000434(which are structures of pointers to functions), for indirect function
435calls, and when defining a function.</p>
John Criswell009900b2003-11-25 21:45:46 +0000436<p>
437The return type of a function type cannot be an aggregate type.
438</p>
Chris Lattner00950542001-06-06 20:29:01 +0000439<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000440<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
441<p>Where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of
442type specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner27f71f22003-09-03 00:41:47 +0000443which indicates that the function takes a variable number of arguments.
444Variable argument functions can access their arguments with the <a
Chris Lattner261efe92003-11-25 01:02:51 +0000445 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000446<h5>Examples:</h5>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000447
Misha Brukman9d0919f2003-11-08 01:05:38 +0000448<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000449 <tbody>
450 <tr>
451 <td><tt>int (int)</tt></td>
452 <td>: function taking an <tt>int</tt>, returning an <tt>int</tt></td>
453 </tr>
454 <tr>
455 <td><tt>float (int, int *) *</tt></td>
456 <td>: <a href="#t_pointer">Pointer</a> to a function that takes
457an <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
458returning <tt>float</tt>.</td>
459 </tr>
460 <tr>
461 <td><tt>int (sbyte *, ...)</tt></td>
462 <td>: A vararg function that takes at least one <a
463 href="#t_pointer">pointer</a> to <tt>sbyte</tt> (signed char in C),
464which returns an integer. This is the signature for <tt>printf</tt>
465in LLVM.</td>
466 </tr>
467 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000468</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000469
Misha Brukman9d0919f2003-11-08 01:05:38 +0000470</div>
Chris Lattner00950542001-06-06 20:29:01 +0000471<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000472<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000473<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000474<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000475<p>The structure type is used to represent a collection of data members
476together in memory. The packing of the field types is defined to match
477the ABI of the underlying processor. The elements of a structure may
478be any type that has a size.</p>
479<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
480and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
481field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
482instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000483<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000484<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +0000485<h5>Examples:</h5>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000486
Misha Brukman9d0919f2003-11-08 01:05:38 +0000487<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000488 <tbody>
489 <tr>
490 <td><tt>{ int, int, int }</tt></td>
491 <td>: a triple of three <tt>int</tt> values</td>
492 </tr>
493 <tr>
494 <td><tt>{ float, int (int) * }</tt></td>
495 <td>: A pair, where the first element is a <tt>float</tt> and the
496second element is a <a href="#t_pointer">pointer</a> to a <a
497 href="t_function">function</a> that takes an <tt>int</tt>, returning
498an <tt>int</tt>.</td>
499 </tr>
500 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000501</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000502
Misha Brukman9d0919f2003-11-08 01:05:38 +0000503</div>
Chris Lattner00950542001-06-06 20:29:01 +0000504<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000505<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000506<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +0000507<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000508<p>As in many languages, the pointer type represents a pointer or
509reference to another object, which must live in memory.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000510<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000511<pre> &lt;type&gt; *<br></pre>
Chris Lattner7faa8832002-04-14 06:13:44 +0000512<h5>Examples:</h5>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000513
Misha Brukman9d0919f2003-11-08 01:05:38 +0000514<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000515 <tbody>
516 <tr>
517 <td><tt>[4x int]*</tt></td>
518 <td>: <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a>
519of four <tt>int</tt> values</td>
520 </tr>
521 <tr>
522 <td><tt>int (int *) *</tt></td>
523 <td>: A <a href="#t_pointer">pointer</a> to a <a
524 href="t_function">function</a> that takes an <tt>int</tt>, returning
525an <tt>int</tt>.</td>
526 </tr>
527 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000528</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000529
Misha Brukman9d0919f2003-11-08 01:05:38 +0000530</div>
Chris Lattner261efe92003-11-25 01:02:51 +0000531<!-- _______________________________________________________________________ --><!--
Misha Brukman9d0919f2003-11-08 01:05:38 +0000532<div class="doc_subsubsection">
533 <a name="t_packed">Packed Type</a>
534</div>
535
536<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000537
538Mention/decide that packed types work with saturation or not. Maybe have a packed+saturated type in addition to just a packed type.<p>
539
540Packed types should be 'nonsaturated' because standard data types are not saturated. Maybe have a saturated packed type?<p>
541
Misha Brukman9d0919f2003-11-08 01:05:38 +0000542</div>
543
Chris Lattner261efe92003-11-25 01:02:51 +0000544--><!-- *********************************************************************** -->
545<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
546<!-- *********************************************************************** --><!-- ======================================================================= -->
547<div class="doc_subsection"> <a name="modulestructure">Module Structure</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000548<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000549<p>LLVM programs are composed of "Module"s, each of which is a
550translation unit of the input programs. Each module consists of
551functions, global variables, and symbol table entries. Modules may be
552combined together with the LLVM linker, which merges function (and
553global variable) definitions, resolves forward declarations, and merges
554symbol table entries. Here is an example of the "hello world" module:</p>
555<pre><i>; Declare the string constant as a global constant...</i>
556<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
557 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 +0000558
Chris Lattner27f71f22003-09-03 00:41:47 +0000559<i>; External declaration of the puts function</i>
560<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000561
562<i>; Definition of main function</i>
Chris Lattner27f71f22003-09-03 00:41:47 +0000563int %main() { <i>; int()* </i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000564 <i>; Convert [13x sbyte]* to sbyte *...</i>
Chris Lattner261efe92003-11-25 01:02:51 +0000565 %cast210 = <a
566 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000567
568 <i>; Call puts function to write out the string to stdout...</i>
Chris Lattner261efe92003-11-25 01:02:51 +0000569 <a
570 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
571 <a
572 href="#i_ret">ret</a> int 0<br>}<br></pre>
573<p>This example is made up of a <a href="#globalvars">global variable</a>
574named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
575function, and a <a href="#functionstructure">function definition</a>
576for "<tt>main</tt>".</p>
577<a name="linkage"> In general, a module is made up of a list of global
578values, where both functions and global variables are global values.
579Global values are represented by a pointer to a memory location (in
580this case, a pointer to an array of char, and a pointer to a function),
581and have one of the following linkage types:</a>
582<p> </p>
Chris Lattner27f71f22003-09-03 00:41:47 +0000583<dl>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000584 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000585 <dd>Global values with internal linkage are only directly accessible
586by objects in the current module. In particular, linking code into a
587module with an internal global value may cause the internal to be
588renamed as necessary to avoid collisions. Because the symbol is
589internal to the module, all references can be updated. This
590corresponds to the notion of the '<tt>static</tt>' keyword in C, or the
591idea of "anonymous namespaces" in C++.
592 <p> </p>
593 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000594 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000595 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt>
596linkage, with the twist that linking together two modules defining the
597same <tt>linkonce</tt> globals will cause one of the globals to be
598discarded. This is typically used to implement inline functions.
599Unreferenced <tt>linkonce</tt> globals are allowed to be discarded.
600 <p> </p>
601 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000602 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000603 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt>
604linkage, except that unreferenced <tt>weak</tt> globals may not be
605discarded. This is used to implement constructs in C such as "<tt>int
606X;</tt>" at global scope.
607 <p> </p>
608 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000609 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000610 <dd>"<tt>appending</tt>" linkage may only be applied to global
611variables of pointer to array type. When two global variables with
612appending linkage are linked together, the two global arrays are
613appended together. This is the LLVM, typesafe, equivalent of having
614the system linker append together "sections" with identical names when
615.o files are linked.
616 <p> </p>
617 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000618 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000619 <dd>If none of the above identifiers are used, the global is
620externally visible, meaning that it participates in linkage and can be
621used to resolve external symbol references.
622 <p> </p>
623 </dd>
Chris Lattner261efe92003-11-25 01:02:51 +0000624</dl>
625<p> </p>
626<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
627variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
628variable and was linked with this one, one of the two would be renamed,
629preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
630external (i.e., lacking any linkage declarations), they are accessible
631outside of the current module. It is illegal for a function <i>declaration</i>
632to have any linkage type other than "externally visible".</a></p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000633</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000634
Chris Lattner00950542001-06-06 20:29:01 +0000635<!-- ======================================================================= -->
Chris Lattner9ee5d222004-03-08 16:49:10 +0000636<div class="doc_subsection">
637 <a name="globalvars">Global Variables</a>
638</div>
639
Misha Brukman9d0919f2003-11-08 01:05:38 +0000640<div class="doc_text">
Chris Lattner9ee5d222004-03-08 16:49:10 +0000641
Chris Lattner261efe92003-11-25 01:02:51 +0000642<p>Global variables define regions of memory allocated at compilation
643time instead of run-time. Global variables may optionally be
644initialized. A variable may be defined as a global "constant", which
645indicates that the contents of the variable will never be modified
Chris Lattner9ee5d222004-03-08 16:49:10 +0000646(opening options for optimization).</p>
647
Chris Lattner261efe92003-11-25 01:02:51 +0000648<p>As SSA values, global variables define pointer values that are in
649scope (i.e. they dominate) for all basic blocks in the program. Global
650variables always define a pointer to their "content" type because they
651describe a region of memory, and all memory objects in LLVM are
652accessed through pointers.</p>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000653
Misha Brukman9d0919f2003-11-08 01:05:38 +0000654</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000655
656
Chris Lattner2b7d3202002-05-06 03:03:22 +0000657<!-- ======================================================================= -->
Chris Lattner9ee5d222004-03-08 16:49:10 +0000658<div class="doc_subsection">
659 <a name="functionstructure">Functions</a>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000660</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000661
662<div class="doc_text">
663
664<p>LLVM function definitions are composed of a (possibly empty) argument list,
665an opening curly brace, a list of basic blocks, and a closing curly brace. LLVM
666function declarations are defined with the "<tt>declare</tt>" keyword, a
667function name, and a function signature.</p>
668
669<p>A function definition contains a list of basic blocks, forming the CFG for
670the function. Each basic block may optionally start with a label (giving the
671basic block a symbol table entry), contains a list of instructions, and ends
672with a <a href="#terminators">terminator</a> instruction (such as a branch or
673function return).</p>
674
675<p>The first basic block in program is special in two ways: it is immediately
676executed on entrance to the function, and it is not allowed to have predecessor
677basic blocks (i.e. there can not be any branches to the entry block of a
678function). Because the block can have no predecessors, it also cannot have any
679<a href="#i_phi">PHI nodes</a>.</p>
680
681<p>LLVM functions are identified by their name and type signature. Hence, two
682functions with the same name but different parameter lists or return values are
683considered different functions, and LLVM will resolves references to each
684appropriately.</p>
685
686</div>
687
688
Chris Lattner00950542001-06-06 20:29:01 +0000689<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000690<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
691<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000692<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000693<p>The LLVM instruction set consists of several different
694classifications of instructions: <a href="#terminators">terminator
695instructions</a>, <a href="#binaryops">binary instructions</a>, <a
696 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
697instructions</a>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000698</div>
Chris Lattner00950542001-06-06 20:29:01 +0000699<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000700<div class="doc_subsection"> <a name="terminators">Terminator
701Instructions</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000702<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000703<p>As mentioned <a href="#functionstructure">previously</a>, every
704basic block in a program ends with a "Terminator" instruction, which
705indicates which block should be executed after the current block is
706finished. These terminator instructions typically yield a '<tt>void</tt>'
707value: they produce control flow, not values (the one exception being
708the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000709<p>There are five different terminator instructions: the '<a
Chris Lattner261efe92003-11-25 01:02:51 +0000710 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
711instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
712the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, and the '<a
713 href="#i_unwind"><tt>unwind</tt></a>' instruction.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000714</div>
Chris Lattner00950542001-06-06 20:29:01 +0000715<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000716<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
717Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000718<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000719<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000720<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 +0000721 ret void <i>; Return from void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000722</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000723<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000724<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
725value) from a function, back to the caller.</p>
John Criswell4457dc92004-04-09 16:48:45 +0000726<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner261efe92003-11-25 01:02:51 +0000727returns a value and then causes control flow, and one that just causes
728control flow to occur.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000729<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000730<p>The '<tt>ret</tt>' instruction may return any '<a
731 href="#t_firstclass">first class</a>' type. Notice that a function is
732not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
733instruction inside of the function that returns a value that does not
734match the return type of the function.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000735<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000736<p>When the '<tt>ret</tt>' instruction is executed, control flow
737returns back to the calling function's context. If the caller is a "<a
738 href="#i_call"><tt>call</tt></a> instruction, execution continues at
739the instruction after the call. If the caller was an "<a
740 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
741at the beginning "normal" of the destination block. If the instruction
742returns a value, that value shall set the call or invoke instruction's
743return value.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000744<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000745<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner7faa8832002-04-14 06:13:44 +0000746 ret void <i>; Return from a void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000747</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000748</div>
Chris Lattner00950542001-06-06 20:29:01 +0000749<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000750<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000751<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000752<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000753<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 +0000754</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000755<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000756<p>The '<tt>br</tt>' instruction is used to cause control flow to
757transfer to a different basic block in the current function. There are
758two forms of this instruction, corresponding to a conditional branch
759and an unconditional branch.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000760<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000761<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
762single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
763unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
764value as a target.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000765<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000766<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
767argument is evaluated. If the value is <tt>true</tt>, control flows
768to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
769control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000770<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000771<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
772 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 +0000773</div>
Chris Lattner00950542001-06-06 20:29:01 +0000774<!-- _______________________________________________________________________ -->
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000775<div class="doc_subsubsection">
776 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
777</div>
778
Misha Brukman9d0919f2003-11-08 01:05:38 +0000779<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000780<h5>Syntax:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000781
782<pre>
783 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
784</pre>
785
Chris Lattner00950542001-06-06 20:29:01 +0000786<h5>Overview:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000787
788<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
789several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +0000790instruction, allowing a branch to occur to one of many possible
791destinations.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000792
793
Chris Lattner00950542001-06-06 20:29:01 +0000794<h5>Arguments:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000795
796<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
797comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
798an array of pairs of comparison value constants and '<tt>label</tt>'s. The
799table is not allowed to contain duplicate constant entries.</p>
800
Chris Lattner00950542001-06-06 20:29:01 +0000801<h5>Semantics:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000802
Chris Lattner261efe92003-11-25 01:02:51 +0000803<p>The <tt>switch</tt> instruction specifies a table of values and
804destinations. When the '<tt>switch</tt>' instruction is executed, this
805table is searched for the given value. If the value is found, the
806corresponding destination is branched to, otherwise the default value
807it transfered to.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000808
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000809<h5>Implementation:</h5>
810
811<p>Depending on properties of the target machine and the particular
812<tt>switch</tt> instruction, this instruction may be code generated in different
813ways, for example as a series of chained conditional branches, or with a lookup
814table.</p>
815
816<h5>Example:</h5>
817
818<pre>
819 <i>; Emulate a conditional br instruction</i>
820 %Val = <a href="#i_cast">cast</a> bool %value to int
821 switch int %Val, label %truedest [int 0, label %falsedest ]
822
823 <i>; Emulate an unconditional br instruction</i>
824 switch uint 0, label %dest [ ]
825
826 <i>; Implement a jump table:</i>
827 switch uint %val, label %otherwise [ uint 0, label %onzero
828 uint 1, label %onone
829 uint 2, label %ontwo ]
Chris Lattner00950542001-06-06 20:29:01 +0000830</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000831</div>
Chris Lattner00950542001-06-06 20:29:01 +0000832<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000833<div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>'
834Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000835<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000836<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000837<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 +0000838<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000839<p>The '<tt>invoke</tt>' instruction causes control to transfer to a
840specified function, with the possibility of control flow transfer to
841either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>.
842If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>"
843instruction, control flow will return to the "normal" label. If the
844callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
845instruction, control is interrupted, and continued at the dynamically
846nearest "except" label.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000847<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000848<p>This instruction requires several arguments:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000849<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000850 <li>'<tt>ptr to function ty</tt>': shall be the signature of the
851pointer to function value being invoked. In most cases, this is a
852direct function invocation, but indirect <tt>invoke</tt>s are just as
853possible, branching off an arbitrary pointer to function value. </li>
854 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer
855to a function to be invoked. </li>
856 <li>'<tt>function args</tt>': argument list whose types match the
857function signature argument types. If the function signature indicates
858the function accepts a variable number of arguments, the extra
859arguments can be specified. </li>
860 <li>'<tt>normal label</tt>': the label reached when the called
861function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
862 <li>'<tt>exception label</tt>': the label reached when a callee
863returns with the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
Chris Lattner00950542001-06-06 20:29:01 +0000864</ol>
Chris Lattner00950542001-06-06 20:29:01 +0000865<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000866<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner261efe92003-11-25 01:02:51 +0000867 href="#i_call">call</a></tt>' instruction in most regards. The
868primary difference is that it establishes an association with a label,
869which is used by the runtime library to unwind the stack.</p>
870<p>This instruction is used in languages with destructors to ensure
871that proper cleanup is performed in the case of either a <tt>longjmp</tt>
872or a thrown exception. Additionally, this is important for
873implementation of '<tt>catch</tt>' clauses in high-level languages that
874support them.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000875<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000876<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 +0000877</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000878</div>
Chris Lattner27f71f22003-09-03 00:41:47 +0000879<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000880<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
881Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000882<div class="doc_text">
Chris Lattner27f71f22003-09-03 00:41:47 +0000883<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000884<pre> unwind<br></pre>
Chris Lattner27f71f22003-09-03 00:41:47 +0000885<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000886<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing
887control flow at the first callee in the dynamic call stack which used
888an <a href="#i_invoke"><tt>invoke</tt></a> instruction to perform the
889call. This is primarily used to implement exception handling.</p>
Chris Lattner27f71f22003-09-03 00:41:47 +0000890<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000891<p>The '<tt>unwind</tt>' intrinsic causes execution of the current
892function to immediately halt. The dynamic call stack is then searched
893for the first <a href="#i_invoke"><tt>invoke</tt></a> instruction on
894the call stack. Once found, execution continues at the "exceptional"
895destination block specified by the <tt>invoke</tt> instruction. If
896there is no <tt>invoke</tt> instruction in the dynamic call chain,
897undefined behavior results.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000898</div>
Chris Lattner00950542001-06-06 20:29:01 +0000899<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000900<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000901<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000902<p>Binary operators are used to do most of the computation in a
903program. They require two operands, execute an operation on them, and
904produce a single value. The result value of a binary operator is not
905necessarily the same type as its operands.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000906<p>There are several different binary operators:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000907</div>
Chris Lattner00950542001-06-06 20:29:01 +0000908<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000909<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
910Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000911<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000912<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000913<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 +0000914</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000915<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000916<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000917<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000918<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +0000919 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
920values. Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000921<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000922<p>The value produced is the integer or floating point sum of the two
923operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000924<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000925<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner00950542001-06-06 20:29:01 +0000926</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000927</div>
Chris Lattner00950542001-06-06 20:29:01 +0000928<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000929<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
930Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000931<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000932<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000933<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 +0000934</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000935<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000936<p>The '<tt>sub</tt>' instruction returns the difference of its two
937operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000938<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
939instruction present in most other intermediate representations.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000940<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000941<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +0000942 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
943values. Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000944<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000945<p>The value produced is the integer or floating point difference of
946the two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000947<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000948<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner00950542001-06-06 20:29:01 +0000949 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
950</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000951</div>
Chris Lattner00950542001-06-06 20:29:01 +0000952<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000953<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
954Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000955<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000956<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000957<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 +0000958</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000959<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000960<p>The '<tt>mul</tt>' instruction returns the product of its two
961operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000962<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000963<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +0000964 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
965values. Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000966<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000967<p>The value produced is the integer or floating point product of the
Misha Brukman9d0919f2003-11-08 01:05:38 +0000968two operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000969<p>There is no signed vs unsigned multiplication. The appropriate
970action is taken based on the type of the operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000971<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000972<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner00950542001-06-06 20:29:01 +0000973</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000974</div>
Chris Lattner00950542001-06-06 20:29:01 +0000975<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000976<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
977Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000978<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000979<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000980<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
981</pre>
982<h5>Overview:</h5>
983<p>The '<tt>div</tt>' instruction returns the quotient of its two
984operands.</p>
985<h5>Arguments:</h5>
986<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
987 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
988values. Both arguments must have identical types.</p>
989<h5>Semantics:</h5>
990<p>The value produced is the integer or floating point quotient of the
991two operands.</p>
992<h5>Example:</h5>
993<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
994</pre>
995</div>
996<!-- _______________________________________________________________________ -->
997<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
998Instruction</a> </div>
999<div class="doc_text">
1000<h5>Syntax:</h5>
1001<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1002</pre>
1003<h5>Overview:</h5>
1004<p>The '<tt>rem</tt>' instruction returns the remainder from the
1005division of its two operands.</p>
1006<h5>Arguments:</h5>
1007<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1008 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
1009values. Both arguments must have identical types.</p>
1010<h5>Semantics:</h5>
1011<p>This returns the <i>remainder</i> of a division (where the result
1012has the same sign as the divisor), not the <i>modulus</i> (where the
1013result has the same sign as the dividend) of a value. For more
1014information about the difference, see: <a
1015 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1016Math Forum</a>.</p>
1017<h5>Example:</h5>
1018<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1019</pre>
1020</div>
1021<!-- _______________________________________________________________________ -->
1022<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1023Instructions</a> </div>
1024<div class="doc_text">
1025<h5>Syntax:</h5>
1026<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 +00001027 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1028 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1029 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1030 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1031 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1032</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001033<h5>Overview:</h5>
1034<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1035value based on a comparison of their two operands.</p>
1036<h5>Arguments:</h5>
1037<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1038be of <a href="#t_firstclass">first class</a> type (it is not possible
1039to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1040or '<tt>void</tt>' values, etc...). Both arguments must have identical
1041types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001042<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001043<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1044value if both operands are equal.<br>
1045The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1046value if both operands are unequal.<br>
1047The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1048value if the first operand is less than the second operand.<br>
1049The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1050value if the first operand is greater than the second operand.<br>
1051The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1052value if the first operand is less than or equal to the second operand.<br>
1053The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1054value if the first operand is greater than or equal to the second
1055operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001056<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001057<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner00950542001-06-06 20:29:01 +00001058 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
1059 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1060 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1061 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1062 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1063</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001064</div>
Chris Lattner00950542001-06-06 20:29:01 +00001065<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001066<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1067Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001068<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001069<p>Bitwise binary operators are used to do various forms of
1070bit-twiddling in a program. They are generally very efficient
1071instructions, and can commonly be strength reduced from other
1072instructions. They require two operands, execute an operation on them,
1073and produce a single value. The resulting value of the bitwise binary
1074operators is always the same type as its first operand.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001075</div>
Chris Lattner00950542001-06-06 20:29:01 +00001076<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001077<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1078Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001079<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001080<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001081<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 +00001082</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001083<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001084<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1085its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001086<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001087<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001088 href="#t_integral">integral</a> values. Both arguments must have
1089identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001090<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001091<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001092<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001093<div style="align: center">
Misha Brukman9d0919f2003-11-08 01:05:38 +00001094<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +00001095 <tbody>
1096 <tr>
1097 <td>In0</td>
1098 <td>In1</td>
1099 <td>Out</td>
1100 </tr>
1101 <tr>
1102 <td>0</td>
1103 <td>0</td>
1104 <td>0</td>
1105 </tr>
1106 <tr>
1107 <td>0</td>
1108 <td>1</td>
1109 <td>0</td>
1110 </tr>
1111 <tr>
1112 <td>1</td>
1113 <td>0</td>
1114 <td>0</td>
1115 </tr>
1116 <tr>
1117 <td>1</td>
1118 <td>1</td>
1119 <td>1</td>
1120 </tr>
1121 </tbody>
1122</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001123</div>
Chris Lattner00950542001-06-06 20:29:01 +00001124<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001125<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001126 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1127 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1128</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001129</div>
Chris Lattner00950542001-06-06 20:29:01 +00001130<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001131<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001132<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001133<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001134<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 +00001135</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001136<h5>Overview:</h5>
1137<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1138or of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001139<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001140<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001141 href="#t_integral">integral</a> values. Both arguments must have
1142identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001143<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001144<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001145<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001146<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001147<table border="1" cellspacing="0" cellpadding="4">
1148 <tbody>
1149 <tr>
1150 <td>In0</td>
1151 <td>In1</td>
1152 <td>Out</td>
1153 </tr>
1154 <tr>
1155 <td>0</td>
1156 <td>0</td>
1157 <td>0</td>
1158 </tr>
1159 <tr>
1160 <td>0</td>
1161 <td>1</td>
1162 <td>1</td>
1163 </tr>
1164 <tr>
1165 <td>1</td>
1166 <td>0</td>
1167 <td>1</td>
1168 </tr>
1169 <tr>
1170 <td>1</td>
1171 <td>1</td>
1172 <td>1</td>
1173 </tr>
1174 </tbody>
1175</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001176</div>
Chris Lattner00950542001-06-06 20:29:01 +00001177<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001178<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001179 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1180 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1181</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001182</div>
Chris Lattner00950542001-06-06 20:29:01 +00001183<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001184<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1185Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001186<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001187<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001188<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 +00001189</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001190<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001191<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1192or of its two operands. The <tt>xor</tt> is used to implement the
1193"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001194<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001195<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001196 href="#t_integral">integral</a> values. Both arguments must have
1197identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001198<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001199<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001200<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001201<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001202<table border="1" cellspacing="0" cellpadding="4">
1203 <tbody>
1204 <tr>
1205 <td>In0</td>
1206 <td>In1</td>
1207 <td>Out</td>
1208 </tr>
1209 <tr>
1210 <td>0</td>
1211 <td>0</td>
1212 <td>0</td>
1213 </tr>
1214 <tr>
1215 <td>0</td>
1216 <td>1</td>
1217 <td>1</td>
1218 </tr>
1219 <tr>
1220 <td>1</td>
1221 <td>0</td>
1222 <td>1</td>
1223 </tr>
1224 <tr>
1225 <td>1</td>
1226 <td>1</td>
1227 <td>0</td>
1228 </tr>
1229 </tbody>
1230</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001231</div>
Chris Lattner261efe92003-11-25 01:02:51 +00001232<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001233<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001234<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001235 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1236 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner27f71f22003-09-03 00:41:47 +00001237 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner00950542001-06-06 20:29:01 +00001238</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001239</div>
Chris Lattner00950542001-06-06 20:29:01 +00001240<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001241<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1242Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001243<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001244<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001245<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 +00001246</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001247<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001248<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1249the left a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001250<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001251<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001252 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1253type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001254<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001255<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001256<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001257<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 +00001258 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1259 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1260</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001261</div>
Chris Lattner00950542001-06-06 20:29:01 +00001262<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001263<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1264Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001265<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001266<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001267<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 +00001268</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001269<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001270<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1271the right a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001272<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001273<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001274 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1275type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001276<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001277<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1278most significant bit is duplicated in the newly free'd bit positions.
1279If the first argument is unsigned, zero bits shall fill the empty
1280positions.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001281<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001282<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 +00001283 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001284 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner8c6bb902003-06-18 21:30:51 +00001285 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1286 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner00950542001-06-06 20:29:01 +00001287</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001288</div>
Chris Lattner00950542001-06-06 20:29:01 +00001289<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001290<div class="doc_subsection"> <a name="memoryops">Memory Access
1291Operations</a></div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001292<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001293<p>A key design point of an SSA-based representation is how it
1294represents memory. In LLVM, no memory locations are in SSA form, which
1295makes things very simple. This section describes how to read, write,
1296allocate and free memory in LLVM.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001297</div>
Chris Lattner00950542001-06-06 20:29:01 +00001298<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001299<div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>'
1300Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001301<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001302<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001303<pre> &lt;result&gt; = malloc &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001304 &lt;result&gt; = malloc &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001305</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001306<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001307<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1308heap and returns a pointer to it.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001309<h5>Arguments:</h5>
John Criswell6e4ca612004-02-24 16:13:56 +00001310<p>The '<tt>malloc</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1311bytes of memory from the operating system and returns a pointer of the
Chris Lattner261efe92003-11-25 01:02:51 +00001312appropriate type to the program. The second form of the instruction is
1313a shorter version of the first instruction that defaults to allocating
1314one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001315<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001316<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001317<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1318a pointer is returned.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001319<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001320<pre> %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001321
Chris Lattner261efe92003-11-25 01:02:51 +00001322 %size = <a
1323 href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001324 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1325 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001326</pre>
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_free">'<tt>free</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> free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner00950542001-06-06 20:29:01 +00001334</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001335<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001336<p>The '<tt>free</tt>' instruction returns memory back to the unused
1337memory heap, to be reallocated in the future.</p>
1338<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001339<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001340<p>'<tt>value</tt>' shall be a pointer value that points to a value
1341that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1342instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001343<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001344<p>Access to the memory pointed to by the pointer is not longer defined
1345after this instruction executes.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001346<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001347<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 +00001348 free [4 x ubyte]* %array
1349</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001350</div>
Chris Lattner00950542001-06-06 20:29:01 +00001351<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001352<div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>'
1353Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001354<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001355<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001356<pre> &lt;result&gt; = alloca &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001357 &lt;result&gt; = alloca &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001358</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001359<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001360<p>The '<tt>alloca</tt>' instruction allocates memory on the current
1361stack frame of the procedure that is live until the current function
1362returns to its caller.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001363<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001364<p>The the '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1365bytes of memory on the runtime stack, returning a pointer of the
1366appropriate type to the program. The second form of the instruction is
1367a shorter version of the first that defaults to allocating one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001368<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001369<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001370<p>Memory is allocated, a pointer is returned. '<tt>alloca</tt>'d
1371memory is automatically released when the function returns. The '<tt>alloca</tt>'
1372instruction is commonly used to represent automatic variables that must
1373have an address available. When the function returns (either with the <tt><a
1374 href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001375instructions), the memory is reclaimed.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001376<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001377<pre> %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001378 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner00950542001-06-06 20:29:01 +00001379</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_load">'<tt>load</tt>'
1383Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001384<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00001385<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001386<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 +00001387<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001388<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001389<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001390<p>The argument to the '<tt>load</tt>' instruction specifies the memory
1391address to load from. The pointer must point to a <a
1392 href="t_firstclass">first class</a> type. If the <tt>load</tt> is
1393marked as <tt>volatile</tt> then the optimizer is not allowed to modify
1394the number or order of execution of this <tt>load</tt> with other
1395volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1396instructions. </p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001397<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001398<p>The location of memory pointed to is loaded.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001399<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001400<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1401 <a
1402 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001403 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1404</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001405</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001406<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001407<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1408Instruction</a> </div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001409<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001410<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 +00001411 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 +00001412</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001413<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001414<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001415<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001416<p>There are two arguments to the '<tt>store</tt>' instruction: a value
1417to store and an address to store it into. The type of the '<tt>&lt;pointer&gt;</tt>'
1418operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
1419operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the
1420optimizer is not allowed to modify the number or order of execution of
1421this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1422 href="#i_store">store</a></tt> instructions.</p>
1423<h5>Semantics:</h5>
1424<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
1425at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001426<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001427<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1428 <a
1429 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001430 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1431</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001432<!-- _______________________________________________________________________ -->
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001433<div class="doc_subsubsection">
1434 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
1435</div>
1436
Misha Brukman9d0919f2003-11-08 01:05:38 +00001437<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00001438<h5>Syntax:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001439<pre>
1440 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
1441</pre>
1442
Chris Lattner7faa8832002-04-14 06:13:44 +00001443<h5>Overview:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001444
1445<p>
1446The '<tt>getelementptr</tt>' instruction is used to get the address of a
1447subelement of an aggregate data structure.</p>
1448
Chris Lattner7faa8832002-04-14 06:13:44 +00001449<h5>Arguments:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001450
1451<p>This instruction takes a list of integer constants that indicate what
1452elements of the aggregate object to index to. The actual types of the arguments
1453provided depend on the type of the first pointer argument. The
1454'<tt>getelementptr</tt>' instruction is used to index down through the type
1455levels of a structure. When indexing into a structure, only <tt>uint</tt>
1456integer constants are allowed. When indexing into an array or pointer
1457<tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
1458
Chris Lattner261efe92003-11-25 01:02:51 +00001459<p>For example, let's consider a C code fragment and how it gets
1460compiled to LLVM:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001461
1462<pre>
1463 struct RT {
1464 char A;
1465 int B[10][20];
1466 char C;
1467 };
1468 struct ST {
1469 int X;
1470 double Y;
1471 struct RT Z;
1472 };
1473
1474 int *foo(struct ST *s) {
1475 return &amp;s[1].Z.B[5][13];
1476 }
1477</pre>
1478
Misha Brukman9d0919f2003-11-08 01:05:38 +00001479<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001480
1481<pre>
1482 %RT = type { sbyte, [10 x [20 x int]], sbyte }
1483 %ST = type { int, double, %RT }
1484
1485 int* "foo"(%ST* %s) {
1486 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13<br>
1487 ret int* %reg
1488 }
1489</pre>
1490
Chris Lattner7faa8832002-04-14 06:13:44 +00001491<h5>Semantics:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001492
1493<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
1494on the pointer type that is being index into. <a href="t_pointer">Pointer</a>
1495and <a href="t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
1496<tt>ulong</tt>, or <tt>long</tt> values, and <a href="t_struct">structure</a>
1497types require <tt>uint</tt> <b>constants</b>.</p>
1498
Misha Brukman9d0919f2003-11-08 01:05:38 +00001499<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001500type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
1501}</tt>' type, a structure. The second index indexes into the third element of
1502the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
1503sbyte }</tt>' type, another structure. The third index indexes into the second
1504element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
1505array. The two dimensions of the array are subscripted into, yielding an
1506'<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction return a pointer
1507to this element, thus computing a value of '<tt>int*</tt>' type.</p>
1508
Chris Lattner261efe92003-11-25 01:02:51 +00001509<p>Note that it is perfectly legal to index partially through a
1510structure, returning a pointer to an inner element. Because of this,
1511the LLVM code for the given testcase is equivalent to:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001512
1513<pre>
1514 int* "foo"(%ST* %s) {
1515 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
1516 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
1517 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
1518 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
1519 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
1520 ret int* %t5
1521 }
Chris Lattner6536cfe2002-05-06 22:08:29 +00001522</pre>
Chris Lattner7faa8832002-04-14 06:13:44 +00001523<h5>Example:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001524<pre>
1525 <i>; yields [12 x ubyte]*:aptr</i>
1526 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
1527</pre>
1528
1529</div>
Chris Lattner00950542001-06-06 20:29:01 +00001530<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001531<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001532<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +00001533<p>The instructions in this category are the "miscellaneous"
Chris Lattner261efe92003-11-25 01:02:51 +00001534instructions, which defy better classification.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001535</div>
Chris Lattner00950542001-06-06 20:29:01 +00001536<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001537<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
1538Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001539<div class="doc_text">
Chris Lattner33ba0d92001-07-09 00:26:23 +00001540<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001541<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001542<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001543<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
1544the SSA graph representing the function.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001545<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001546<p>The type of the incoming values are specified with the first type
1547field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
1548as arguments, with one pair for each predecessor basic block of the
1549current block. Only values of <a href="#t_firstclass">first class</a>
1550type may be used as the value arguments to the PHI node. Only labels
1551may be used as the label arguments.</p>
1552<p>There must be no non-phi instructions between the start of a basic
1553block and the PHI instructions: i.e. PHI instructions must be first in
1554a basic block.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001555<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001556<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
1557value specified by the parameter, depending on which basic block we
1558came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001559<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001560<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 +00001561</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001562
Chris Lattner6536cfe2002-05-06 22:08:29 +00001563<!-- _______________________________________________________________________ -->
Chris Lattnercc37aae2004-03-12 05:50:16 +00001564<div class="doc_subsubsection">
1565 <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
1566</div>
1567
Misha Brukman9d0919f2003-11-08 01:05:38 +00001568<div class="doc_text">
Chris Lattnercc37aae2004-03-12 05:50:16 +00001569
Chris Lattner6536cfe2002-05-06 22:08:29 +00001570<h5>Syntax:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001571
1572<pre>
1573 &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 +00001574</pre>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001575
Chris Lattner6536cfe2002-05-06 22:08:29 +00001576<h5>Overview:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001577
1578<p>
1579The '<tt>cast</tt>' instruction is used as the primitive means to convert
1580integers to floating point, change data type sizes, and break type safety (by
1581casting pointers).
1582</p>
1583
1584
Chris Lattner6536cfe2002-05-06 22:08:29 +00001585<h5>Arguments:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001586
1587<p>
1588The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
1589class value, and a type to cast it to, which must also be a <a
1590href="#t_firstclass">first class</a> type.
1591</p>
1592
Chris Lattner6536cfe2002-05-06 22:08:29 +00001593<h5>Semantics:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001594
1595<p>
1596This instruction follows the C rules for explicit casts when determining how the
1597data being cast must change to fit in its new container.
1598</p>
1599
1600<p>
1601When casting to bool, any value that would be considered true in the context of
1602a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
1603all else are '<tt>false</tt>'.
1604</p>
1605
1606<p>
1607When extending an integral value from a type of one signness to another (for
1608example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
1609<b>source</b> value is signed, and zero-extended if the source value is
1610unsigned. <tt>bool</tt> values are always zero extended into either zero or
1611one.
1612</p>
1613
Chris Lattner33ba0d92001-07-09 00:26:23 +00001614<h5>Example:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001615
1616<pre>
1617 %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattner7bae3952002-06-25 18:03:17 +00001618 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001619</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001620</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001621
1622<!-- _______________________________________________________________________ -->
1623<div class="doc_subsubsection">
1624 <a name="i_select">'<tt>select</tt>' Instruction</a>
1625</div>
1626
1627<div class="doc_text">
1628
1629<h5>Syntax:</h5>
1630
1631<pre>
1632 &lt;result&gt; = select bool &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
1633</pre>
1634
1635<h5>Overview:</h5>
1636
1637<p>
1638The '<tt>select</tt>' instruction is used to choose one value based on a
1639condition, without branching.
1640</p>
1641
1642
1643<h5>Arguments:</h5>
1644
1645<p>
1646The '<tt>select</tt>' instruction requires a boolean value indicating the condition, and two values of the same <a href="#t_firstclass">first class</a> type.
1647</p>
1648
1649<h5>Semantics:</h5>
1650
1651<p>
1652If the boolean condition evaluates to true, the instruction returns the first
1653value argument, otherwise it returns the second value argument.
1654</p>
1655
1656<h5>Example:</h5>
1657
1658<pre>
1659 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
1660</pre>
1661</div>
1662
1663
1664
1665
1666
Chris Lattner33ba0d92001-07-09 00:26:23 +00001667<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001668<div class="doc_subsubsection"> <a name="i_call">'<tt>call</tt>'
1669Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001670<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001671<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001672<pre> &lt;result&gt; = call &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +00001673<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001674<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001675<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001676<p>This instruction requires several arguments:</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001677<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00001678 <li>
1679 <p>'<tt>ty</tt>': shall be the signature of the pointer to function
1680value being invoked. The argument types must match the types implied
1681by this signature.</p>
1682 </li>
1683 <li>
1684 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a
1685function to be invoked. In most cases, this is a direct function
1686invocation, but indirect <tt>call</tt>s are just as possible,
1687calling an arbitrary pointer to function values.</p>
1688 </li>
1689 <li>
1690 <p>'<tt>function args</tt>': argument list whose types match the
1691function signature argument types. If the function signature
1692indicates the function accepts a variable number of arguments, the
1693extra arguments can be specified.</p>
1694 </li>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001695</ol>
Chris Lattner00950542001-06-06 20:29:01 +00001696<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001697<p>The '<tt>call</tt>' instruction is used to cause control flow to
1698transfer to a specified function, with its incoming arguments bound to
1699the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
1700instruction in the called function, control flow continues with the
1701instruction after the function call, and the return value of the
1702function is bound to the result argument. This is a simpler case of
1703the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001704<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001705<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 +00001706</div>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001707<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001708<div class="doc_subsubsection"> <a name="i_vanext">'<tt>vanext</tt>'
1709Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001710<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001711<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001712<pre> &lt;resultarglist&gt; = vanext &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001713<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001714<p>The '<tt>vanext</tt>' instruction is used to access arguments passed
1715through the "variable argument" area of a function call. It is used to
1716implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001717<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001718<p>This instruction takes a <tt>valist</tt> value and the type of the
1719argument. It returns another <tt>valist</tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001720<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001721<p>The '<tt>vanext</tt>' instruction advances the specified <tt>valist</tt>
1722past an argument of the specified type. In conjunction with the <a
1723 href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement
1724the <tt>va_arg</tt> macro available in C. For more information, see
1725the variable argument handling <a href="#int_varargs">Intrinsic
1726Functions</a>.</p>
1727<p>It is legal for this instruction to be called in a function which
1728does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001729function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001730<p><tt>vanext</tt> is an LLVM instruction instead of an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001731 href="#intrinsics">intrinsic function</a> because it takes an type as
1732an argument.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001733<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001734<p>See the <a href="#int_varargs">variable argument processing</a>
1735section.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001736</div>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001737<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001738<div class="doc_subsubsection"> <a name="i_vaarg">'<tt>vaarg</tt>'
1739Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001740<div class="doc_text">
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001741<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001742<pre> &lt;resultval&gt; = vaarg &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;<br></pre>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001743<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001744<p>The '<tt>vaarg</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 Lattner8d1a81d2003-10-18 05:51: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 a value of the specified argument type.</p>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001750<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001751<p>The '<tt>vaarg</tt>' instruction loads an argument of the specified
1752type from the specified <tt>va_list</tt>. In conjunction with the <a
1753 href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to
1754implement the <tt>va_arg</tt> macro available in C. For more
1755information, see the 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>vaarg</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 Lattner8d1a81d2003-10-18 05:51: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 Lattner8ff75902004-01-06 05:31:32 +00001767
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001768<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00001769<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
1770<!-- *********************************************************************** -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001771
Misha Brukman9d0919f2003-11-08 01:05:38 +00001772<div class="doc_text">
Chris Lattner33aec9e2004-02-12 17:01:32 +00001773
1774<p>LLVM supports the notion of an "intrinsic function". These functions have
1775well known names and semantics, and are required to follow certain
1776restrictions. Overall, these instructions represent an extension mechanism for
1777the LLVM language that does not require changing all of the transformations in
1778LLVM to add to the language (or the bytecode reader/writer, the parser,
1779etc...).</p>
1780
1781<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix, this
1782prefix is reserved in LLVM for intrinsic names, thus functions may not be named
1783this. Intrinsic functions must always be external functions: you cannot define
1784the body of intrinsic functions. Intrinsic functions may only be used in call
1785or invoke instructions: it is illegal to take the address of an intrinsic
1786function. Additionally, because intrinsic functions are part of the LLVM
1787language, it is required that they all be documented here if any are added.</p>
1788
1789
1790<p>
1791Adding an intrinsic to LLVM is straight-forward if it is possible to express the
1792concept in LLVM directly (ie, code generator support is not _required_). To do
1793this, extend the default implementation of the IntrinsicLowering class to handle
1794the intrinsic. Code generators use this class to lower intrinsics they do not
1795understand to raw LLVM instructions that they do.
1796</p>
1797
Misha Brukman9d0919f2003-11-08 01:05:38 +00001798</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001799
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001800<!-- ======================================================================= -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001801<div class="doc_subsection">
1802 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
1803</div>
1804
Misha Brukman9d0919f2003-11-08 01:05:38 +00001805<div class="doc_text">
Misha Brukman9d0919f2003-11-08 01:05:38 +00001806<p>Variable argument support is defined in LLVM with the <a
Chris Lattner261efe92003-11-25 01:02:51 +00001807 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
1808intrinsic functions. These functions are related to the similarly
1809named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
1810<p>All of these functions operate on arguments that use a
1811target-specific value type "<tt>va_list</tt>". The LLVM assembly
1812language reference manual does not define what this type is, so all
1813transformations should be prepared to handle intrinsics with any type
1814used.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001815<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner261efe92003-11-25 01:02:51 +00001816instruction and the variable argument handling intrinsic functions are
1817used.</p>
Chris Lattner33aec9e2004-02-12 17:01:32 +00001818<pre>
1819int %test(int %X, ...) {
1820 ; Initialize variable argument processing
1821 %ap = call sbyte* %<a href="#i_va_start">llvm.va_start</a>()
1822
1823 ; Read a single integer argument
1824 %tmp = vaarg sbyte* %ap, int
1825
1826 ; Advance to the next argument
1827 %ap2 = vanext sbyte* %ap, int
1828
1829 ; Demonstrate usage of llvm.va_copy and llvm.va_end
1830 %aq = call sbyte* %<a href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2)
1831 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %aq)
1832
1833 ; Stop processing of arguments.
1834 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %ap2)
1835 ret int %tmp
1836}
1837</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001838</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001839
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001840<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001841<div class="doc_subsubsection">
1842 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
1843</div>
1844
1845
Misha Brukman9d0919f2003-11-08 01:05:38 +00001846<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001847<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001848<pre> call va_list ()* %llvm.va_start()<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001849<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001850<p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt>&lt;arglist&gt;</tt>
1851for subsequent use by the variable argument intrinsics.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001852<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001853<p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001854macro available in C. In a target-dependent way, it initializes and
1855returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt>
1856will produce the first variable argument passed to the function. Unlike
1857the C <tt>va_start</tt> macro, this intrinsic does not need to know the
1858last argument of the function, the compiler can figure that out.</p>
1859<p>Note that this intrinsic function is only legal to be called from
1860within the body of a variable argument function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001861</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001862
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001863<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001864<div class="doc_subsubsection">
1865 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
1866</div>
1867
Misha Brukman9d0919f2003-11-08 01:05:38 +00001868<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001869<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001870<pre> call void (va_list)* %llvm.va_end(va_list &lt;arglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001871<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001872<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
1873which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
1874or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001875<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001876<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001877<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001878<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001879macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
1880Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
1881 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
1882with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001883</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001884
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001885<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001886<div class="doc_subsubsection">
1887 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
1888</div>
1889
Misha Brukman9d0919f2003-11-08 01:05:38 +00001890<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001891<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001892<pre> call va_list (va_list)* %llvm.va_copy(va_list &lt;destarglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001893<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001894<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument
1895position from the source argument list to the destination argument list.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001896<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001897<p>The argument is the <tt>va_list</tt> to copy.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001898<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001899<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001900macro available in C. In a target-dependent way, it copies the source <tt>va_list</tt>
1901element into the returned list. This intrinsic is necessary because the <tt><a
1902 href="i_va_start">llvm.va_start</a></tt> intrinsic may be arbitrarily
1903complex and require memory allocation, for example.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001904</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001905
Chris Lattner33aec9e2004-02-12 17:01:32 +00001906<!-- ======================================================================= -->
1907<div class="doc_subsection">
Chris Lattner10610642004-02-14 04:08:35 +00001908 <a name="int_codegen">Code Generator Intrinsics</a>
1909</div>
1910
1911<div class="doc_text">
1912<p>
1913These intrinsics are provided by LLVM to expose special features that may only
1914be implemented with code generator support.
1915</p>
1916
1917</div>
1918
1919<!-- _______________________________________________________________________ -->
1920<div class="doc_subsubsection">
1921 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
1922</div>
1923
1924<div class="doc_text">
1925
1926<h5>Syntax:</h5>
1927<pre>
1928 call void* ()* %llvm.returnaddress(uint &lt;level&gt;)
1929</pre>
1930
1931<h5>Overview:</h5>
1932
1933<p>
1934The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
1935indicating the return address of the current function or one of its callers.
1936</p>
1937
1938<h5>Arguments:</h5>
1939
1940<p>
1941The argument to this intrinsic indicates which function to return the address
1942for. Zero indicates the calling function, one indicates its caller, etc. The
1943argument is <b>required</b> to be a constant integer value.
1944</p>
1945
1946<h5>Semantics:</h5>
1947
1948<p>
1949The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
1950the return address of the specified call frame, or zero if it cannot be
1951identified. The value returned by this intrinsic is likely to be incorrect or 0
1952for arguments other than zero, so it should only be used for debugging purposes.
1953</p>
1954
1955<p>
1956Note that calling this intrinsic does not prevent function inlining or other
1957aggressive transformations, so the value returned may not that of the obvious
1958source-language caller.
1959</p>
1960</div>
1961
1962
1963<!-- _______________________________________________________________________ -->
1964<div class="doc_subsubsection">
1965 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
1966</div>
1967
1968<div class="doc_text">
1969
1970<h5>Syntax:</h5>
1971<pre>
1972 call void* ()* %llvm.frameaddress(uint &lt;level&gt;)
1973</pre>
1974
1975<h5>Overview:</h5>
1976
1977<p>
1978The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
1979pointer value for the specified stack frame.
1980</p>
1981
1982<h5>Arguments:</h5>
1983
1984<p>
1985The argument to this intrinsic indicates which function to return the frame
1986pointer for. Zero indicates the calling function, one indicates its caller,
1987etc. The argument is <b>required</b> to be a constant integer value.
1988</p>
1989
1990<h5>Semantics:</h5>
1991
1992<p>
1993The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
1994the frame address of the specified call frame, or zero if it cannot be
1995identified. The value returned by this intrinsic is likely to be incorrect or 0
1996for arguments other than zero, so it should only be used for debugging purposes.
1997</p>
1998
1999<p>
2000Note that calling this intrinsic does not prevent function inlining or other
2001aggressive transformations, so the value returned may not that of the obvious
2002source-language caller.
2003</p>
2004</div>
2005
John Criswell7123e272004-04-09 16:43:20 +00002006<!-- ======================================================================= -->
2007<div class="doc_subsection">
2008 <a name="int_os">Operating System Intrinsics</a>
2009</div>
2010
2011<div class="doc_text">
2012<p>
2013These intrinsics are provided by LLVM to support the implementation of
2014operating system level code.
2015</p>
2016
2017</div>
John Criswell183402a2004-04-12 15:02:16 +00002018
John Criswellcfd3bac2004-04-09 15:23:37 +00002019<!-- _______________________________________________________________________ -->
2020<div class="doc_subsubsection">
2021 <a name="i_readport">'<tt>llvm.readport</tt>' Intrinsic</a>
2022</div>
2023
2024<div class="doc_text">
2025
2026<h5>Syntax:</h5>
2027<pre>
John Criswell7123e272004-04-09 16:43:20 +00002028 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 +00002029</pre>
2030
2031<h5>Overview:</h5>
2032
2033<p>
John Criswell7123e272004-04-09 16:43:20 +00002034The '<tt>llvm.readport</tt>' intrinsic reads data from the specified hardware
2035I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002036</p>
2037
2038<h5>Arguments:</h5>
2039
2040<p>
John Criswell7123e272004-04-09 16:43:20 +00002041The argument to this intrinsic indicates the hardware I/O address from which
2042to read the data. The address is in the hardware I/O address namespace (as
2043opposed to being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002044</p>
2045
2046<h5>Semantics:</h5>
2047
2048<p>
John Criswell7123e272004-04-09 16:43:20 +00002049The '<tt>llvm.readport</tt>' intrinsic reads data from the hardware I/O port
2050specified by <i>address</i> and returns the value. The address and return
2051value must be integers, but the size is dependent upon the platform upon which
2052the program is code generated. For example, on x86, the address must be an
2053unsigned 16 bit value, and the return value must be 8, 16, or 32 bits.
John Criswellcfd3bac2004-04-09 15:23:37 +00002054</p>
2055
2056</div>
2057
2058<!-- _______________________________________________________________________ -->
2059<div class="doc_subsubsection">
2060 <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a>
2061</div>
2062
2063<div class="doc_text">
2064
2065<h5>Syntax:</h5>
2066<pre>
John Criswell7123e272004-04-09 16:43:20 +00002067 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 +00002068</pre>
2069
2070<h5>Overview:</h5>
2071
2072<p>
John Criswell7123e272004-04-09 16:43:20 +00002073The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified hardware
2074I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002075</p>
2076
2077<h5>Arguments:</h5>
2078
2079<p>
John Criswell7123e272004-04-09 16:43:20 +00002080The first argument to this intrinsic indicates the hardware I/O address to
2081which data should be written. The address is in the hardware I/O address
2082namespace (as opposed to being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002083</p>
2084
2085<p>
2086The second argument is the value to write to the I/O port.
2087</p>
2088
2089<h5>Semantics:</h5>
2090
2091<p>
2092The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port
2093specified by <i>address</i>. The address and value must be integers, but the
2094size is dependent upon the platform upon which the program is code generated.
John Criswell7123e272004-04-09 16:43:20 +00002095For example, on x86, the address must be an unsigned 16 bit value, and the
2096value written must be 8, 16, or 32 bits in length.
John Criswellcfd3bac2004-04-09 15:23:37 +00002097</p>
2098
2099</div>
Chris Lattner10610642004-02-14 04:08:35 +00002100
John Criswell183402a2004-04-12 15:02:16 +00002101<!-- _______________________________________________________________________ -->
2102<div class="doc_subsubsection">
2103 <a name="i_readio">'<tt>llvm.readio</tt>' Intrinsic</a>
2104</div>
2105
2106<div class="doc_text">
2107
2108<h5>Syntax:</h5>
2109<pre>
2110 call &lt;integer type&gt; (&lt;integer type&gt;)* %llvm.readio (&lt;integer type&gt; &lt;address&gt;)
2111</pre>
2112
2113<h5>Overview:</h5>
2114
2115<p>
2116The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
2117address.
2118</p>
2119
2120<h5>Arguments:</h5>
2121
2122<p>
2123The argument to this intrinsic indicates the memory address from which to read
2124the data.
2125</p>
2126
2127<h5>Semantics:</h5>
2128
2129<p>
2130The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
2131location specified by <i>address</i> and returns the value. The address and
2132return value must be integers, but the size allowed for each is dependent upon
2133the platform upon which the program is code generated.
2134</p>
2135
2136<p>
2137This intrinsic ensures that the I/O data read occurs in instruction order in
2138relation to other I/O data reads and writes (as opposed to a normal load, where
2139hardware scheduling can re-arrange the actual memory accesses to occur out of
2140order).
2141</p>
2142
2143</div>
2144
2145<!-- _______________________________________________________________________ -->
2146<div class="doc_subsubsection">
2147 <a name="i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a>
2148</div>
2149
2150<div class="doc_text">
2151
2152<h5>Syntax:</h5>
2153<pre>
2154 call void (&lt;integer type&gt;, &lt;integer type&gt;)* %llvm.writeio (&lt;integer type&gt; &lt;value&gt;, &lt;integer type&gt; &lt;address&gt;)
2155</pre>
2156
2157<h5>Overview:</h5>
2158
2159<p>
2160The '<tt>llvm.writeio</tt>' intrinsic writes data to the specified memory
2161mapped I/O address.
2162</p>
2163
2164<h5>Arguments:</h5>
2165
2166<p>
2167The first argument to this intrinsic indicates the memory address to which data
2168should be written.
2169</p>
2170
2171<p>
2172The second argument is the value to write to the memory mapped I/O location.
2173</p>
2174
2175<h5>Semantics:</h5>
2176
2177<p>
2178The '<tt>llvm.writeio</tt>' intrinsic writes <i>value</i> to the memory mapped
2179I/O address specified by <i>address</i>. The address and value must be
2180integers, but the size is dependent upon the platform upon which the program is
2181code generated.
2182</p>
2183
2184<p>
2185This intrinsic ensures that the I/O data write occurs in instruction order in
2186relation to other I/O data reads and writes (as opposed to a normal store,
2187where hardware scheduling can re-arrange the actual memory accesses to occur
2188out of order).
2189</p>
2190
2191</div>
2192
2193
Chris Lattner10610642004-02-14 04:08:35 +00002194<!-- ======================================================================= -->
2195<div class="doc_subsection">
Chris Lattner33aec9e2004-02-12 17:01:32 +00002196 <a name="int_libc">Standard C Library Intrinsics</a>
2197</div>
2198
2199<div class="doc_text">
2200<p>
Chris Lattner10610642004-02-14 04:08:35 +00002201LLVM provides intrinsics for a few important standard C library functions.
2202These intrinsics allow source-language front-ends to pass information about the
2203alignment of the pointer arguments to the code generator, providing opportunity
2204for more efficient code generation.
Chris Lattner33aec9e2004-02-12 17:01:32 +00002205</p>
2206
2207</div>
2208
2209<!-- _______________________________________________________________________ -->
2210<div class="doc_subsubsection">
2211 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
2212</div>
2213
2214<div class="doc_text">
2215
2216<h5>Syntax:</h5>
2217<pre>
2218 call void (sbyte*, sbyte*, uint, uint)* %llvm.memcpy(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2219 uint &lt;len&gt;, uint &lt;align&gt;)
2220</pre>
2221
2222<h5>Overview:</h5>
2223
2224<p>
2225The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2226location to the destination location.
2227</p>
2228
2229<p>
2230Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
2231does not return a value, and takes an extra alignment argument.
2232</p>
2233
2234<h5>Arguments:</h5>
2235
2236<p>
2237The first argument is a pointer to the destination, the second is a pointer to
2238the source. The third argument is an (arbitrarily sized) integer argument
2239specifying the number of bytes to copy, and the fourth argument is the alignment
2240of the source and destination locations.
2241</p>
2242
Chris Lattner3301ced2004-02-12 21:18:15 +00002243<p>
2244If the call to this intrinisic has an alignment value that is not 0 or 1, then
2245the caller guarantees that the size of the copy is a multiple of the alignment
2246and that both the source and destination pointers are aligned to that boundary.
2247</p>
2248
Chris Lattner33aec9e2004-02-12 17:01:32 +00002249<h5>Semantics:</h5>
2250
2251<p>
2252The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2253location to the destination location, which are not allowed to overlap. It
2254copies "len" bytes of memory over. If the argument is known to be aligned to
2255some boundary, this can be specified as the fourth argument, otherwise it should
2256be set to 0 or 1.
2257</p>
2258</div>
2259
2260
Chris Lattner0eb51b42004-02-12 18:10:10 +00002261<!-- _______________________________________________________________________ -->
2262<div class="doc_subsubsection">
2263 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
2264</div>
2265
2266<div class="doc_text">
2267
2268<h5>Syntax:</h5>
2269<pre>
2270 call void (sbyte*, sbyte*, uint, uint)* %llvm.memmove(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2271 uint &lt;len&gt;, uint &lt;align&gt;)
2272</pre>
2273
2274<h5>Overview:</h5>
2275
2276<p>
2277The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
2278location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>'
2279intrinsic but allows the two memory locations to overlap.
2280</p>
2281
2282<p>
2283Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
2284does not return a value, and takes an extra alignment argument.
2285</p>
2286
2287<h5>Arguments:</h5>
2288
2289<p>
2290The first argument is a pointer to the destination, the second is a pointer to
2291the source. The third argument is an (arbitrarily sized) integer argument
2292specifying the number of bytes to copy, and the fourth argument is the alignment
2293of the source and destination locations.
2294</p>
2295
Chris Lattner3301ced2004-02-12 21:18:15 +00002296<p>
2297If the call to this intrinisic has an alignment value that is not 0 or 1, then
2298the caller guarantees that the size of the copy is a multiple of the alignment
2299and that both the source and destination pointers are aligned to that boundary.
2300</p>
2301
Chris Lattner0eb51b42004-02-12 18:10:10 +00002302<h5>Semantics:</h5>
2303
2304<p>
2305The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
2306location to the destination location, which may overlap. It
2307copies "len" bytes of memory over. If the argument is known to be aligned to
2308some boundary, this can be specified as the fourth argument, otherwise it should
2309be set to 0 or 1.
2310</p>
2311</div>
2312
Chris Lattner8ff75902004-01-06 05:31:32 +00002313
Chris Lattner10610642004-02-14 04:08:35 +00002314<!-- _______________________________________________________________________ -->
2315<div class="doc_subsubsection">
2316 <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a>
2317</div>
2318
2319<div class="doc_text">
2320
2321<h5>Syntax:</h5>
2322<pre>
2323 call void (sbyte*, ubyte, uint, uint)* %llvm.memset(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
2324 uint &lt;len&gt;, uint &lt;align&gt;)
2325</pre>
2326
2327<h5>Overview:</h5>
2328
2329<p>
2330The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular
2331byte value.
2332</p>
2333
2334<p>
2335Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
2336does not return a value, and takes an extra alignment argument.
2337</p>
2338
2339<h5>Arguments:</h5>
2340
2341<p>
2342The first argument is a pointer to the destination to fill, the second is the
2343byte value to fill it with, the third argument is an (arbitrarily sized) integer
2344argument specifying the number of bytes to fill, and the fourth argument is the
2345known alignment of destination location.
2346</p>
2347
2348<p>
2349If the call to this intrinisic has an alignment value that is not 0 or 1, then
2350the caller guarantees that the size of the copy is a multiple of the alignment
2351and that the destination pointer is aligned to that boundary.
2352</p>
2353
2354<h5>Semantics:</h5>
2355
2356<p>
2357The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the
2358destination location. If the argument is known to be aligned to some boundary,
2359this can be specified as the fourth argument, otherwise it should be set to 0 or
23601.
2361</p>
2362</div>
2363
2364
Chris Lattner8ff75902004-01-06 05:31:32 +00002365<!-- ======================================================================= -->
2366<div class="doc_subsection">
2367 <a name="int_debugger">Debugger Intrinsics</a>
2368</div>
2369
2370<div class="doc_text">
2371<p>
2372The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
2373are described in the <a
2374href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
2375Debugging</a> document.
2376</p>
2377</div>
2378
2379
Chris Lattner00950542001-06-06 20:29:01 +00002380<!-- *********************************************************************** -->
Chris Lattner00950542001-06-06 20:29:01 +00002381<hr>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002382<address>
2383 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
2384 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
2385 <a href="http://validator.w3.org/check/referer"><img
2386 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
2387
2388 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
2389 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
2390 Last modified: $Date$
2391</address>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002392</body>
2393</html>