blob: 05de0bd4cfbb032ddfebb061c5badc6f4eb953b6 [file] [log] [blame]
Chris Lattner261efe92003-11-25 01:02:51 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
Misha Brukman9d0919f2003-11-08 01:05:38 +00002<html>
3<head>
4 <title>LLVM Assembly Language Reference Manual</title>
5 <link rel="stylesheet" href="llvm.css" type="text/css">
6</head>
7<body>
Chris Lattner261efe92003-11-25 01:02:51 +00008<div class="doc_title"> LLVM Language Reference Manual </div>
Chris Lattner00950542001-06-06 20:29:01 +00009<ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000010 <li><a href="#abstract">Abstract</a></li>
11 <li><a href="#introduction">Introduction</a></li>
12 <li><a href="#identifiers">Identifiers</a></li>
Chris Lattner00950542001-06-06 20:29:01 +000013 <li><a href="#typesystem">Type System</a>
14 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000015 <li><a href="#t_primitive">Primitive Types</a>
16 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000017 <li><a href="#t_classifications">Type Classifications</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000018 </ol>
19 </li>
Chris Lattner00950542001-06-06 20:29:01 +000020 <li><a href="#t_derived">Derived Types</a>
21 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000022 <li><a href="#t_array">Array Type</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000023 <li><a href="#t_function">Function Type</a></li>
24 <li><a href="#t_pointer">Pointer Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000025 <li><a href="#t_struct">Structure Type</a></li>
26<!-- <li><a href="#t_packed" >Packed Type</a> -->
27 </ol>
28 </li>
29 </ol>
30 </li>
Chris Lattner00950542001-06-06 20:29:01 +000031 <li><a href="#highlevel">High Level Structure</a>
32 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000033 <li><a href="#modulestructure">Module Structure</a></li>
34 <li><a href="#globalvars">Global Variables</a></li>
35 <li><a href="#functionstructure">Function Structure</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000036 </ol>
37 </li>
Chris Lattner00950542001-06-06 20:29:01 +000038 <li><a href="#instref">Instruction Reference</a>
39 <ol>
40 <li><a href="#terminators">Terminator Instructions</a>
41 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000042 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
43 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000044 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
45 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000046 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
47 </ol>
48 </li>
Chris Lattner00950542001-06-06 20:29:01 +000049 <li><a href="#binaryops">Binary Operations</a>
50 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000051 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
52 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
53 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
54 <li><a href="#i_div">'<tt>div</tt>' Instruction</a></li>
55 <li><a href="#i_rem">'<tt>rem</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000056 <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000057 </ol>
58 </li>
Chris Lattner00950542001-06-06 20:29:01 +000059 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
60 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000061 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000062 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000063 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
64 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
65 <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000066 </ol>
67 </li>
Chris Lattner00950542001-06-06 20:29:01 +000068 <li><a href="#memoryops">Memory Access Operations</a>
69 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000070 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
71 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
72 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
73 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
74 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
75 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
76 </ol>
77 </li>
Chris Lattner00950542001-06-06 20:29:01 +000078 <li><a href="#otherops">Other Operations</a>
79 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000080 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000081 <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000082 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000083 <li><a href="#i_vanext">'<tt>vanext</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000084 <li><a href="#i_vaarg">'<tt>vaarg</tt>' Instruction</a></li>
Chris Lattner00950542001-06-06 20:29:01 +000085 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +000086 </li>
Chris Lattner00950542001-06-06 20:29:01 +000087 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +000088 </li>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +000089 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +000090 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000091 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
92 <ol>
93 <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
94 <li><a href="#i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
95 <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
96 </ol>
97 </li>
98 </ol>
99 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000100</ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000101<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000102<p><b>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
103and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></b></p>
104<p> </p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000105</div>
Chris Lattner00950542001-06-06 20:29:01 +0000106<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000107<div class="doc_section"> <a name="abstract">Abstract </a></div>
108<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000109<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000110<p>This document is a reference manual for the LLVM assembly language.
111LLVM is an SSA based representation that provides type safety,
112low-level operations, flexibility, and the capability of representing
113'all' high-level languages cleanly. It is the common code
114representation used throughout all phases of the LLVM compilation
115strategy.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000116</div>
Chris Lattner00950542001-06-06 20:29:01 +0000117<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000118<div class="doc_section"> <a name="introduction">Introduction</a> </div>
119<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000120<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000121<p>The LLVM code representation is designed to be used in three
122different forms: as an in-memory compiler IR, as an on-disk bytecode
123representation (suitable for fast loading by a Just-In-Time compiler),
124and as a human readable assembly language representation. This allows
125LLVM to provide a powerful intermediate representation for efficient
126compiler transformations and analysis, while providing a natural means
127to debug and visualize the transformations. The three different forms
128of LLVM are all equivalent. This document describes the human readable
129representation and notation.</p>
130<p>The LLVM representation aims to be a light-weight and low-level
131while being expressive, typed, and extensible at the same time. It
132aims to be a "universal IR" of sorts, by being at a low enough level
133that high-level ideas may be cleanly mapped to it (similar to how
134microprocessors are "universal IR's", allowing many source languages to
135be mapped to them). By providing type information, LLVM can be used as
136the target of optimizations: for example, through pointer analysis, it
137can be proven that a C automatic variable is never accessed outside of
138the current function... allowing it to be promoted to a simple SSA
139value instead of a memory location.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000140</div>
Chris Lattner00950542001-06-06 20:29:01 +0000141<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000142<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000143<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000144<p>It is important to note that this document describes 'well formed'
145LLVM assembly language. There is a difference between what the parser
146accepts and what is considered 'well formed'. For example, the
147following instruction is syntactically okay, but not well formed:</p>
148<pre> %x = <a href="#i_add">add</a> int 1, %x<br></pre>
149<p>...because the definition of <tt>%x</tt> does not dominate all of
150its uses. The LLVM infrastructure provides a verification pass that may
151be used to verify that an LLVM module is well formed. This pass is
152automatically run by the parser after parsing input assembly, and by
153the optimizer before it outputs bytecode. The violations pointed out
154by the verifier pass indicate bugs in transformation passes or input to
155the parser.</p>
156<!-- Describe the typesetting conventions here. --> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000157<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000158<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000159<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000160<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000161<p>LLVM uses three different forms of identifiers, for different
162purposes:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000163<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000164 <li>Numeric constants are represented as you would expect: 12, -3
165123.421, etc. Floating point constants have an optional hexidecimal
166notation.</li>
167 <li>Named values are represented as a string of characters with a '%'
168prefix. For example, %foo, %DivisionByZero,
169%a.really.long.identifier. The actual regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
170Identifiers which require other characters in their names can be
171surrounded with quotes. In this way, anything except a <tt>"</tt>
172character can be used in a name.</li>
173 <li>Unnamed values are represented as an unsigned numeric value with
174a '%' prefix. For example, %12, %2, %44.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000175</ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000176<p>LLVM requires the values start with a '%' sign for two reasons:
177Compilers don't need to worry about name clashes with reserved words,
178and the set of reserved words may be expanded in the future without
179penalty. Additionally, unnamed identifiers allow a compiler to quickly
180come up with a temporary variable without having to avoid symbol table
181conflicts.</p>
182<p>Reserved words in LLVM are very similar to reserved words in other
183languages. There are keywords for different opcodes ('<tt><a
184 href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
185 href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
186 href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>',
187etc...), and others. These reserved words cannot conflict with
188variable names, because none of them start with a '%' character.</p>
189<p>Here is an example of LLVM code to multiply the integer variable '<tt>%X</tt>'
190by 8:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000191<p>The easy way:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000192<pre> %result = <a href="#i_mul">mul</a> uint %X, 8<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000193<p>After strength reduction:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000194<pre> %result = <a href="#i_shl">shl</a> uint %X, ubyte 3<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000195<p>And the hard way:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000196<pre> <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
197 <a
198 href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
199 %result = <a
200 href="#i_add">add</a> uint %1, %1<br></pre>
201<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
202important lexical features of LLVM:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000203<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000204 <li>Comments are delimited with a '<tt>;</tt>' and go until the end
205of line.</li>
206 <li>Unnamed temporaries are created when the result of a computation
207is not assigned to a named value.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000208 <li>Unnamed temporaries are numbered sequentially</li>
209</ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000210<p>...and it also show a convention that we follow in this document.
211When demonstrating instructions, we will follow an instruction with a
212comment that defines the type and name of value produced. Comments are
213shown in italic text.</p>
214<p>The one non-intuitive notation for constants is the optional
215hexidecimal form of floating point constants. For example, the form '<tt>double
Chris Lattner2b7d3202002-05-06 03:03:22 +00002160x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
Chris Lattner261efe92003-11-25 01:02:51 +00002174.5e+15</tt>' which is also supported by the parser. The only time
218hexadecimal floating point constants are useful (and the only time that
219they are generated by the disassembler) is when an FP constant has to
220be emitted that is not representable as a decimal floating point number
221exactly. For example, NaN's, infinities, and other special cases are
222represented in their IEEE hexadecimal format so that assembly and
223disassembly do not cause any bits to change in the constants.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000224</div>
Chris Lattner00950542001-06-06 20:29:01 +0000225<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000226<div class="doc_section"> <a name="typesystem">Type System</a> </div>
227<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000228<div class="doc_text">
Misha Brukman9d0919f2003-11-08 01:05:38 +0000229<p>The LLVM type system is one of the most important features of the
Chris Lattner261efe92003-11-25 01:02:51 +0000230intermediate representation. Being typed enables a number of
231optimizations to be performed on the IR directly, without having to do
232extra analyses on the side before the transformation. A strong type
233system makes it easier to read the generated code and enables novel
234analyses and transformations that are not feasible to perform on normal
235three address code representations.</p>
Chris Lattner7bae3952002-06-25 18:03:17 +0000236<!-- The written form for the type system was heavily influenced by the
237syntactic problems with types in the C language<sup><a
Chris Lattner261efe92003-11-25 01:02:51 +0000238href="#rw_stroustrup">1</a></sup>.<p> --> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000239<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000240<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000241<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000242<p>The primitive types are the fundemental building blocks of the LLVM
243system. The current set of primitive types are as follows:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000244<p>
245<table border="0" align="center">
Chris Lattner261efe92003-11-25 01:02:51 +0000246 <tbody>
247 <tr>
248 <td>
249 <table border="1" cellspacing="0" cellpadding="4" align="center">
250 <tbody>
251 <tr>
252 <td><tt>void</tt></td>
253 <td>No value</td>
254 </tr>
255 <tr>
256 <td><tt>ubyte</tt></td>
257 <td>Unsigned 8 bit value</td>
258 </tr>
259 <tr>
260 <td><tt>ushort</tt></td>
261 <td>Unsigned 16 bit value</td>
262 </tr>
263 <tr>
264 <td><tt>uint</tt></td>
265 <td>Unsigned 32 bit value</td>
266 </tr>
267 <tr>
268 <td><tt>ulong</tt></td>
269 <td>Unsigned 64 bit value</td>
270 </tr>
271 <tr>
272 <td><tt>float</tt></td>
273 <td>32 bit floating point value</td>
274 </tr>
275 <tr>
276 <td><tt>label</tt></td>
277 <td>Branch destination</td>
278 </tr>
279 </tbody>
280 </table>
281 </td>
282 <td valign="top">
283 <table border="1" cellspacing="0" cellpadding="4" align="center&quot;">
284 <tbody>
285 <tr>
286 <td><tt>bool</tt></td>
287 <td>True or False value</td>
288 </tr>
289 <tr>
290 <td><tt>sbyte</tt></td>
291 <td>Signed 8 bit value</td>
292 </tr>
293 <tr>
294 <td><tt>short</tt></td>
295 <td>Signed 16 bit value</td>
296 </tr>
297 <tr>
298 <td><tt>int</tt></td>
299 <td>Signed 32 bit value</td>
300 </tr>
301 <tr>
302 <td><tt>long</tt></td>
303 <td>Signed 64 bit value</td>
304 </tr>
305 <tr>
306 <td><tt>double</tt></td>
307 <td>64 bit floating point value</td>
308 </tr>
309 </tbody>
310 </table>
311 </td>
312 </tr>
313 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000314</table>
315</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000316</div>
Chris Lattner00950542001-06-06 20:29:01 +0000317<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000318<div class="doc_subsubsection"> <a name="t_classifications">Type
319Classifications</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000320<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000321<p>These different primitive types fall into a few useful
322classifications:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000323<p>
324<table border="1" cellspacing="0" cellpadding="4" align="center">
Chris Lattner261efe92003-11-25 01:02:51 +0000325 <tbody>
326 <tr>
327 <td><a name="t_signed">signed</a></td>
328 <td><tt>sbyte, short, int, long, float, double</tt></td>
329 </tr>
330 <tr>
331 <td><a name="t_unsigned">unsigned</a></td>
332 <td><tt>ubyte, ushort, uint, ulong</tt></td>
333 </tr>
334 <tr>
335 <td><a name="t_integer">integer</a></td>
336 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
337 </tr>
338 <tr>
339 <td><a name="t_integral">integral</a></td>
340 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
341 </tr>
342 <tr>
343 <td><a name="t_floating">floating point</a></td>
344 <td><tt>float, double</tt></td>
345 </tr>
346 <tr>
347 <td><a name="t_firstclass">first class</a></td>
348 <td><tt>bool, ubyte, sbyte, ushort, short,<br>
349uint, int, ulong, long, float, double, <a href="#t_pointer">pointer</a></tt></td>
350 </tr>
351 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000352</table>
353</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000354<p>The <a href="#t_firstclass">first class</a> types are perhaps the
355most important. Values of these types are the only ones which can be
356produced by instructions, passed as arguments, or used as operands to
357instructions. This means that all structures and arrays must be
358manipulated either by pointer or by component.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000359</div>
Chris Lattner00950542001-06-06 20:29:01 +0000360<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000361<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000362<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000363<p>The real power in LLVM comes from the derived types in the system.
364This is what allows a programmer to represent arrays, functions,
365pointers, and other useful types. Note that these derived types may be
366recursive: For example, it is possible to have a two dimensional array.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000367</div>
Chris Lattner00950542001-06-06 20:29:01 +0000368<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000369<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000370<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000371<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000372<p>The array type is a very simple derived type that arranges elements
Chris Lattner261efe92003-11-25 01:02:51 +0000373sequentially in memory. The array type requires a size (number of
374elements) and an underlying data type.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000375<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000376<pre> [&lt;# elements&gt; x &lt;elementtype&gt;]<br></pre>
377<p>The number of elements is a constant integer value, elementtype may
378be any type with a size.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000379<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000380<p> <tt>[40 x int ]</tt>: Array of 40 integer values.<br>
381<tt>[41 x int ]</tt>: Array of 41 integer values.<br>
382<tt>[40 x uint]</tt>: Array of 40 unsigned integer values.</p>
383<p> </p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000384<p>Here are some examples of multidimensional arrays:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000385<p>
386<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000387 <tbody>
388 <tr>
389 <td><tt>[3 x [4 x int]]</tt></td>
390 <td>: 3x4 array integer values.</td>
391 </tr>
392 <tr>
393 <td><tt>[12 x [10 x float]]</tt></td>
394 <td>: 12x10 array of single precision floating point values.</td>
395 </tr>
396 <tr>
397 <td><tt>[2 x [3 x [4 x uint]]]</tt></td>
398 <td>: 2x3x4 array of unsigned integer values.</td>
399 </tr>
400 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000401</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000402</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000403</div>
Chris Lattner00950542001-06-06 20:29:01 +0000404<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000405<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000406<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000407<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000408<p>The function type can be thought of as a function signature. It
409consists of a return type and a list of formal parameter types.
410Function types are usually used when to build virtual function tables
411(which are structures of pointers to functions), for indirect function
412calls, and when defining a function.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000413<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000414<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
415<p>Where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of
416type specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner27f71f22003-09-03 00:41:47 +0000417which indicates that the function takes a variable number of arguments.
418Variable argument functions can access their arguments with the <a
Chris Lattner261efe92003-11-25 01:02:51 +0000419 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000420<h5>Examples:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000421<p>
422<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000423 <tbody>
424 <tr>
425 <td><tt>int (int)</tt></td>
426 <td>: function taking an <tt>int</tt>, returning an <tt>int</tt></td>
427 </tr>
428 <tr>
429 <td><tt>float (int, int *) *</tt></td>
430 <td>: <a href="#t_pointer">Pointer</a> to a function that takes
431an <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
432returning <tt>float</tt>.</td>
433 </tr>
434 <tr>
435 <td><tt>int (sbyte *, ...)</tt></td>
436 <td>: A vararg function that takes at least one <a
437 href="#t_pointer">pointer</a> to <tt>sbyte</tt> (signed char in C),
438which returns an integer. This is the signature for <tt>printf</tt>
439in LLVM.</td>
440 </tr>
441 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000442</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000443</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000444</div>
Chris Lattner00950542001-06-06 20:29:01 +0000445<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000446<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000447<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000448<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000449<p>The structure type is used to represent a collection of data members
450together in memory. The packing of the field types is defined to match
451the ABI of the underlying processor. The elements of a structure may
452be any type that has a size.</p>
453<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
454and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
455field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
456instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000457<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000458<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +0000459<h5>Examples:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000460<p>
461<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000462 <tbody>
463 <tr>
464 <td><tt>{ int, int, int }</tt></td>
465 <td>: a triple of three <tt>int</tt> values</td>
466 </tr>
467 <tr>
468 <td><tt>{ float, int (int) * }</tt></td>
469 <td>: A pair, where the first element is a <tt>float</tt> and the
470second element is a <a href="#t_pointer">pointer</a> to a <a
471 href="t_function">function</a> that takes an <tt>int</tt>, returning
472an <tt>int</tt>.</td>
473 </tr>
474 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000475</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000476</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000477</div>
Chris Lattner00950542001-06-06 20:29:01 +0000478<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000479<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000480<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +0000481<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000482<p>As in many languages, the pointer type represents a pointer or
483reference to another object, which must live in memory.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000484<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000485<pre> &lt;type&gt; *<br></pre>
Chris Lattner7faa8832002-04-14 06:13:44 +0000486<h5>Examples:</h5>
Chris Lattner7faa8832002-04-14 06:13:44 +0000487<p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000488<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000489 <tbody>
490 <tr>
491 <td><tt>[4x int]*</tt></td>
492 <td>: <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a>
493of four <tt>int</tt> values</td>
494 </tr>
495 <tr>
496 <td><tt>int (int *) *</tt></td>
497 <td>: A <a href="#t_pointer">pointer</a> to a <a
498 href="t_function">function</a> that takes an <tt>int</tt>, returning
499an <tt>int</tt>.</td>
500 </tr>
501 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000502</table>
503</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000504</div>
Chris Lattner261efe92003-11-25 01:02:51 +0000505<!-- _______________________________________________________________________ --><!--
Misha Brukman9d0919f2003-11-08 01:05:38 +0000506<div class="doc_subsubsection">
507 <a name="t_packed">Packed Type</a>
508</div>
509
510<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000511
512Mention/decide that packed types work with saturation or not. Maybe have a packed+saturated type in addition to just a packed type.<p>
513
514Packed types should be 'nonsaturated' because standard data types are not saturated. Maybe have a saturated packed type?<p>
515
Misha Brukman9d0919f2003-11-08 01:05:38 +0000516</div>
517
Chris Lattner261efe92003-11-25 01:02:51 +0000518--><!-- *********************************************************************** -->
519<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
520<!-- *********************************************************************** --><!-- ======================================================================= -->
521<div class="doc_subsection"> <a name="modulestructure">Module Structure</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000522<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000523<p>LLVM programs are composed of "Module"s, each of which is a
524translation unit of the input programs. Each module consists of
525functions, global variables, and symbol table entries. Modules may be
526combined together with the LLVM linker, which merges function (and
527global variable) definitions, resolves forward declarations, and merges
528symbol table entries. Here is an example of the "hello world" module:</p>
529<pre><i>; Declare the string constant as a global constant...</i>
530<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
531 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 +0000532
Chris Lattner27f71f22003-09-03 00:41:47 +0000533<i>; External declaration of the puts function</i>
534<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000535
536<i>; Definition of main function</i>
Chris Lattner27f71f22003-09-03 00:41:47 +0000537int %main() { <i>; int()* </i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000538 <i>; Convert [13x sbyte]* to sbyte *...</i>
Chris Lattner261efe92003-11-25 01:02:51 +0000539 %cast210 = <a
540 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000541
542 <i>; Call puts function to write out the string to stdout...</i>
Chris Lattner261efe92003-11-25 01:02:51 +0000543 <a
544 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
545 <a
546 href="#i_ret">ret</a> int 0<br>}<br></pre>
547<p>This example is made up of a <a href="#globalvars">global variable</a>
548named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
549function, and a <a href="#functionstructure">function definition</a>
550for "<tt>main</tt>".</p>
551<a name="linkage"> In general, a module is made up of a list of global
552values, where both functions and global variables are global values.
553Global values are represented by a pointer to a memory location (in
554this case, a pointer to an array of char, and a pointer to a function),
555and have one of the following linkage types:</a>
556<p> </p>
Chris Lattner27f71f22003-09-03 00:41:47 +0000557<dl>
Chris Lattner261efe92003-11-25 01:02:51 +0000558 <a name="linkage_internal"> <dt><tt><b>internal</b></tt> </dt>
559 <dd>Global values with internal linkage are only directly accessible
560by objects in the current module. In particular, linking code into a
561module with an internal global value may cause the internal to be
562renamed as necessary to avoid collisions. Because the symbol is
563internal to the module, all references can be updated. This
564corresponds to the notion of the '<tt>static</tt>' keyword in C, or the
565idea of "anonymous namespaces" in C++.
566 <p> </p>
567 </dd>
568 </a><a name="linkage_linkonce"> <dt><tt><b>linkonce</b></tt>: </dt>
569 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt>
570linkage, with the twist that linking together two modules defining the
571same <tt>linkonce</tt> globals will cause one of the globals to be
572discarded. This is typically used to implement inline functions.
573Unreferenced <tt>linkonce</tt> globals are allowed to be discarded.
574 <p> </p>
575 </dd>
576 </a><a name="linkage_weak"> <dt><tt><b>weak</b></tt>: </dt>
577 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt>
578linkage, except that unreferenced <tt>weak</tt> globals may not be
579discarded. This is used to implement constructs in C such as "<tt>int
580X;</tt>" at global scope.
581 <p> </p>
582 </dd>
583 </a><a name="linkage_appending"> <dt><tt><b>appending</b></tt>: </dt>
584 <dd>"<tt>appending</tt>" linkage may only be applied to global
585variables of pointer to array type. When two global variables with
586appending linkage are linked together, the two global arrays are
587appended together. This is the LLVM, typesafe, equivalent of having
588the system linker append together "sections" with identical names when
589.o files are linked.
590 <p> </p>
591 </dd>
592 </a><a name="linkage_external"> <dt><tt><b>externally visible</b></tt>:</dt>
593 <dd>If none of the above identifiers are used, the global is
594externally visible, meaning that it participates in linkage and can be
595used to resolve external symbol references.
596 <p> </p>
597 </dd>
598 </a>
599</dl>
600<p> </p>
601<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
602variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
603variable and was linked with this one, one of the two would be renamed,
604preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
605external (i.e., lacking any linkage declarations), they are accessible
606outside of the current module. It is illegal for a function <i>declaration</i>
607to have any linkage type other than "externally visible".</a></p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000608</div>
Chris Lattner00950542001-06-06 20:29:01 +0000609<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000610<div class="doc_subsection"> <a name="globalvars">Global Variables</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000611<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000612<p>Global variables define regions of memory allocated at compilation
613time instead of run-time. Global variables may optionally be
614initialized. A variable may be defined as a global "constant", which
615indicates that the contents of the variable will never be modified
616(opening options for optimization). Constants must always have an
617initial value.</p>
618<p>As SSA values, global variables define pointer values that are in
619scope (i.e. they dominate) for all basic blocks in the program. Global
620variables always define a pointer to their "content" type because they
621describe a region of memory, and all memory objects in LLVM are
622accessed through pointers.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000623</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000624<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000625<div class="doc_subsection"> <a name="functionstructure">Functions</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000626<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000627<p>LLVM function definitions are composed of a (possibly empty)
628argument list, an opening curly brace, a list of basic blocks, and a
629closing curly brace. LLVM function declarations are defined with the "<tt>declare</tt>"
630keyword, a function name, and a function signature.</p>
631<p>A function definition contains a list of basic blocks, forming the
632CFG for the function. Each basic block may optionally start with a
633label (giving the basic block a symbol table entry), contains a list of
634instructions, and ends with a <a href="#terminators">terminator</a>
635instruction (such as a branch or function return).</p>
636<p>The first basic block in program is special in two ways: it is
637immediately executed on entrance to the function, and it is not allowed
638to have predecessor basic blocks (i.e. there can not be any branches to
639the entry block of a function). Because the block can have no
640predecessors, it also cannot have any <a href="#i_phi">PHI nodes</a>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000641</div>
Chris Lattner00950542001-06-06 20:29:01 +0000642<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000643<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
644<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000645<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000646<p>The LLVM instruction set consists of several different
647classifications of instructions: <a href="#terminators">terminator
648instructions</a>, <a href="#binaryops">binary instructions</a>, <a
649 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
650instructions</a>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000651</div>
Chris Lattner00950542001-06-06 20:29:01 +0000652<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000653<div class="doc_subsection"> <a name="terminators">Terminator
654Instructions</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000655<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000656<p>As mentioned <a href="#functionstructure">previously</a>, every
657basic block in a program ends with a "Terminator" instruction, which
658indicates which block should be executed after the current block is
659finished. These terminator instructions typically yield a '<tt>void</tt>'
660value: they produce control flow, not values (the one exception being
661the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000662<p>There are five different terminator instructions: the '<a
Chris Lattner261efe92003-11-25 01:02:51 +0000663 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
664instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
665the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, and the '<a
666 href="#i_unwind"><tt>unwind</tt></a>' instruction.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000667</div>
Chris Lattner00950542001-06-06 20:29:01 +0000668<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000669<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
670Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000671<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000672<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000673<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 +0000674 ret void <i>; Return from void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000675</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000676<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000677<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
678value) from a function, back to the caller.</p>
679<p>There are two forms of the '<tt>ret</tt>' instructruction: one that
680returns a value and then causes control flow, and one that just causes
681control flow to occur.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000682<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000683<p>The '<tt>ret</tt>' instruction may return any '<a
684 href="#t_firstclass">first class</a>' type. Notice that a function is
685not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
686instruction inside of the function that returns a value that does not
687match the return type of the function.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000688<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000689<p>When the '<tt>ret</tt>' instruction is executed, control flow
690returns back to the calling function's context. If the caller is a "<a
691 href="#i_call"><tt>call</tt></a> instruction, execution continues at
692the instruction after the call. If the caller was an "<a
693 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
694at the beginning "normal" of the destination block. If the instruction
695returns a value, that value shall set the call or invoke instruction's
696return value.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000697<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000698<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner7faa8832002-04-14 06:13:44 +0000699 ret void <i>; Return from a void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000700</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000701</div>
Chris Lattner00950542001-06-06 20:29:01 +0000702<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000703<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000704<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000705<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000706<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 +0000707</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000708<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000709<p>The '<tt>br</tt>' instruction is used to cause control flow to
710transfer to a different basic block in the current function. There are
711two forms of this instruction, corresponding to a conditional branch
712and an unconditional branch.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000713<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000714<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
715single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
716unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
717value as a target.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000718<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000719<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
720argument is evaluated. If the value is <tt>true</tt>, control flows
721to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
722control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000723<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000724<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
725 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 +0000726</div>
Chris Lattner00950542001-06-06 20:29:01 +0000727<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000728<div class="doc_subsubsection"> <a name="i_switch">'<tt>switch</tt>'
729Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000730<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000731<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000732<pre> switch uint &lt;value&gt;, label &lt;defaultdest&gt; [ int &lt;val&gt;, label &amp;dest&gt;, ... ]<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +0000733<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000734<p>The '<tt>switch</tt>' instruction is used to transfer control flow
735to one of several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +0000736instruction, allowing a branch to occur to one of many possible
737destinations.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000738<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000739<p>The '<tt>switch</tt>' instruction uses three parameters: a '<tt>uint</tt>'
Chris Lattner261efe92003-11-25 01:02:51 +0000740comparison value '<tt>value</tt>', a default '<tt>label</tt>'
741destination, and an array of pairs of comparison value constants and '<tt>label</tt>'s.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000742<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000743<p>The <tt>switch</tt> instruction specifies a table of values and
744destinations. When the '<tt>switch</tt>' instruction is executed, this
745table is searched for the given value. If the value is found, the
746corresponding destination is branched to, otherwise the default value
747it transfered to.</p>
Chris Lattnerc29b1252003-05-08 05:08:48 +0000748<h5>Implementation:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000749<p>Depending on properties of the target machine and the particular <tt>switch</tt>
750instruction, this instruction may be code generated as a series of
751chained conditional branches, or with a lookup table.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000752<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000753<pre> <i>; Emulate a conditional br instruction</i>
754 %Val = <a
755 href="#i_cast">cast</a> bool %value to uint<br> switch uint %Val, label %truedest [int 0, label %falsedest ]<br><br> <i>; Emulate an unconditional br instruction</i>
Chris Lattner27f71f22003-09-03 00:41:47 +0000756 switch uint 0, label %dest [ ]
Chris Lattner00950542001-06-06 20:29:01 +0000757
Chris Lattner2b7d3202002-05-06 03:03:22 +0000758 <i>; Implement a jump table:</i>
Chris Lattner27f71f22003-09-03 00:41:47 +0000759 switch uint %val, label %otherwise [ int 0, label %onzero,
760 int 1, label %onone,
761 int 2, label %ontwo ]
Chris Lattner00950542001-06-06 20:29:01 +0000762</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000763</div>
Chris Lattner00950542001-06-06 20:29:01 +0000764<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000765<div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>'
766Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000767<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000768<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000769<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 +0000770<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000771<p>The '<tt>invoke</tt>' instruction causes control to transfer to a
772specified function, with the possibility of control flow transfer to
773either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>.
774If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>"
775instruction, control flow will return to the "normal" label. If the
776callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
777instruction, control is interrupted, and continued at the dynamically
778nearest "except" label.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000779<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000780<p>This instruction requires several arguments:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000781<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000782 <li>'<tt>ptr to function ty</tt>': shall be the signature of the
783pointer to function value being invoked. In most cases, this is a
784direct function invocation, but indirect <tt>invoke</tt>s are just as
785possible, branching off an arbitrary pointer to function value. </li>
786 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer
787to a function to be invoked. </li>
788 <li>'<tt>function args</tt>': argument list whose types match the
789function signature argument types. If the function signature indicates
790the function accepts a variable number of arguments, the extra
791arguments can be specified. </li>
792 <li>'<tt>normal label</tt>': the label reached when the called
793function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
794 <li>'<tt>exception label</tt>': the label reached when a callee
795returns with the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
Chris Lattner00950542001-06-06 20:29:01 +0000796</ol>
Chris Lattner00950542001-06-06 20:29:01 +0000797<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000798<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner261efe92003-11-25 01:02:51 +0000799 href="#i_call">call</a></tt>' instruction in most regards. The
800primary difference is that it establishes an association with a label,
801which is used by the runtime library to unwind the stack.</p>
802<p>This instruction is used in languages with destructors to ensure
803that proper cleanup is performed in the case of either a <tt>longjmp</tt>
804or a thrown exception. Additionally, this is important for
805implementation of '<tt>catch</tt>' clauses in high-level languages that
806support them.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000807<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000808<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 +0000809</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000810</div>
Chris Lattner27f71f22003-09-03 00:41:47 +0000811<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000812<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
813Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000814<div class="doc_text">
Chris Lattner27f71f22003-09-03 00:41:47 +0000815<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000816<pre> unwind<br></pre>
Chris Lattner27f71f22003-09-03 00:41:47 +0000817<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000818<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing
819control flow at the first callee in the dynamic call stack which used
820an <a href="#i_invoke"><tt>invoke</tt></a> instruction to perform the
821call. This is primarily used to implement exception handling.</p>
Chris Lattner27f71f22003-09-03 00:41:47 +0000822<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000823<p>The '<tt>unwind</tt>' intrinsic causes execution of the current
824function to immediately halt. The dynamic call stack is then searched
825for the first <a href="#i_invoke"><tt>invoke</tt></a> instruction on
826the call stack. Once found, execution continues at the "exceptional"
827destination block specified by the <tt>invoke</tt> instruction. If
828there is no <tt>invoke</tt> instruction in the dynamic call chain,
829undefined behavior results.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000830</div>
Chris Lattner00950542001-06-06 20:29:01 +0000831<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000832<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000833<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000834<p>Binary operators are used to do most of the computation in a
835program. They require two operands, execute an operation on them, and
836produce a single value. The result value of a binary operator is not
837necessarily the same type as its operands.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000838<p>There are several different binary operators:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000839</div>
Chris Lattner00950542001-06-06 20:29:01 +0000840<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000841<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
842Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000843<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000844<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000845<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 +0000846</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000847<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000848<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000849<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000850<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +0000851 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
852values. Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000853<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000854<p>The value produced is the integer or floating point sum of the two
855operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000856<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000857<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner00950542001-06-06 20:29:01 +0000858</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000859</div>
Chris Lattner00950542001-06-06 20:29:01 +0000860<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000861<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
862Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000863<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000864<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000865<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 +0000866</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000867<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000868<p>The '<tt>sub</tt>' instruction returns the difference of its two
869operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000870<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
871instruction present in most other intermediate representations.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000872<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000873<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +0000874 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
875values. Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000876<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000877<p>The value produced is the integer or floating point difference of
878the two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000879<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000880<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner00950542001-06-06 20:29:01 +0000881 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
882</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000883</div>
Chris Lattner00950542001-06-06 20:29:01 +0000884<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000885<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
886Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000887<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000888<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000889<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 +0000890</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000891<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000892<p>The '<tt>mul</tt>' instruction returns the product of its two
893operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000894<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000895<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +0000896 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
897values. Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000898<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000899<p>The value produced is the integer or floating point product of the
Misha Brukman9d0919f2003-11-08 01:05:38 +0000900two operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000901<p>There is no signed vs unsigned multiplication. The appropriate
902action is taken based on the type of the operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000903<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000904<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner00950542001-06-06 20:29:01 +0000905</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000906</div>
Chris Lattner00950542001-06-06 20:29:01 +0000907<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000908<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
909Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000910<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000911<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000912<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
913</pre>
914<h5>Overview:</h5>
915<p>The '<tt>div</tt>' instruction returns the quotient of its two
916operands.</p>
917<h5>Arguments:</h5>
918<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
919 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
920values. Both arguments must have identical types.</p>
921<h5>Semantics:</h5>
922<p>The value produced is the integer or floating point quotient of the
923two operands.</p>
924<h5>Example:</h5>
925<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
926</pre>
927</div>
928<!-- _______________________________________________________________________ -->
929<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
930Instruction</a> </div>
931<div class="doc_text">
932<h5>Syntax:</h5>
933<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
934</pre>
935<h5>Overview:</h5>
936<p>The '<tt>rem</tt>' instruction returns the remainder from the
937division of its two operands.</p>
938<h5>Arguments:</h5>
939<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
940 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
941values. Both arguments must have identical types.</p>
942<h5>Semantics:</h5>
943<p>This returns the <i>remainder</i> of a division (where the result
944has the same sign as the divisor), not the <i>modulus</i> (where the
945result has the same sign as the dividend) of a value. For more
946information about the difference, see: <a
947 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
948Math Forum</a>.</p>
949<h5>Example:</h5>
950<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
951</pre>
952</div>
953<!-- _______________________________________________________________________ -->
954<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
955Instructions</a> </div>
956<div class="doc_text">
957<h5>Syntax:</h5>
958<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 +0000959 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
960 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
961 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
962 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
963 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
964</pre>
Chris Lattner261efe92003-11-25 01:02:51 +0000965<h5>Overview:</h5>
966<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
967value based on a comparison of their two operands.</p>
968<h5>Arguments:</h5>
969<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
970be of <a href="#t_firstclass">first class</a> type (it is not possible
971to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
972or '<tt>void</tt>' values, etc...). Both arguments must have identical
973types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000974<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000975<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
976value if both operands are equal.<br>
977The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
978value if both operands are unequal.<br>
979The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
980value if the first operand is less than the second operand.<br>
981The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
982value if the first operand is greater than the second operand.<br>
983The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
984value if the first operand is less than or equal to the second operand.<br>
985The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
986value if the first operand is greater than or equal to the second
987operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000988<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000989<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner00950542001-06-06 20:29:01 +0000990 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
991 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
992 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
993 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
994 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
995</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000996</div>
Chris Lattner00950542001-06-06 20:29:01 +0000997<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000998<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
999Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001000<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001001<p>Bitwise binary operators are used to do various forms of
1002bit-twiddling in a program. They are generally very efficient
1003instructions, and can commonly be strength reduced from other
1004instructions. They require two operands, execute an operation on them,
1005and produce a single value. The resulting value of the bitwise binary
1006operators is always the same type as its first operand.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001007</div>
Chris Lattner00950542001-06-06 20:29:01 +00001008<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001009<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1010Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001011<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001012<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001013<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 +00001014</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001015<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001016<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1017its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001018<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001019<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001020 href="#t_integral">integral</a> values. Both arguments must have
1021identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001022<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001023<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001024<p> </p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001025<center>
1026<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +00001027 <tbody>
1028 <tr>
1029 <td>In0</td>
1030 <td>In1</td>
1031 <td>Out</td>
1032 </tr>
1033 <tr>
1034 <td>0</td>
1035 <td>0</td>
1036 <td>0</td>
1037 </tr>
1038 <tr>
1039 <td>0</td>
1040 <td>1</td>
1041 <td>0</td>
1042 </tr>
1043 <tr>
1044 <td>1</td>
1045 <td>0</td>
1046 <td>0</td>
1047 </tr>
1048 <tr>
1049 <td>1</td>
1050 <td>1</td>
1051 <td>1</td>
1052 </tr>
1053 </tbody>
1054</table>
1055</center>
Chris Lattner00950542001-06-06 20:29:01 +00001056<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001057<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001058 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1059 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1060</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001061</div>
Chris Lattner00950542001-06-06 20:29:01 +00001062<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001063<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001064<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001065<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001066<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 +00001067</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001068<h5>Overview:</h5>
1069<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1070or of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001071<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001072<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001073 href="#t_integral">integral</a> values. Both arguments must have
1074identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001075<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001076<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001077<p> </p>
1078<center>
1079<table border="1" cellspacing="0" cellpadding="4">
1080 <tbody>
1081 <tr>
1082 <td>In0</td>
1083 <td>In1</td>
1084 <td>Out</td>
1085 </tr>
1086 <tr>
1087 <td>0</td>
1088 <td>0</td>
1089 <td>0</td>
1090 </tr>
1091 <tr>
1092 <td>0</td>
1093 <td>1</td>
1094 <td>1</td>
1095 </tr>
1096 <tr>
1097 <td>1</td>
1098 <td>0</td>
1099 <td>1</td>
1100 </tr>
1101 <tr>
1102 <td>1</td>
1103 <td>1</td>
1104 <td>1</td>
1105 </tr>
1106 </tbody>
1107</table>
1108</center>
Chris Lattner00950542001-06-06 20:29:01 +00001109<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001110<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001111 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1112 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1113</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001114</div>
Chris Lattner00950542001-06-06 20:29:01 +00001115<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001116<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1117Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001118<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001119<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001120<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 +00001121</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001122<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001123<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1124or of its two operands. The <tt>xor</tt> is used to implement the
1125"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001126<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001127<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001128 href="#t_integral">integral</a> values. Both arguments must have
1129identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001130<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001131<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001132<p> </p>
1133<center>
1134<table border="1" cellspacing="0" cellpadding="4">
1135 <tbody>
1136 <tr>
1137 <td>In0</td>
1138 <td>In1</td>
1139 <td>Out</td>
1140 </tr>
1141 <tr>
1142 <td>0</td>
1143 <td>0</td>
1144 <td>0</td>
1145 </tr>
1146 <tr>
1147 <td>0</td>
1148 <td>1</td>
1149 <td>1</td>
1150 </tr>
1151 <tr>
1152 <td>1</td>
1153 <td>0</td>
1154 <td>1</td>
1155 </tr>
1156 <tr>
1157 <td>1</td>
1158 <td>1</td>
1159 <td>0</td>
1160 </tr>
1161 </tbody>
1162</table>
1163</center>
1164<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001165<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001166<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001167 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1168 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner27f71f22003-09-03 00:41:47 +00001169 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner00950542001-06-06 20:29:01 +00001170</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001171</div>
Chris Lattner00950542001-06-06 20:29:01 +00001172<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001173<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1174Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001175<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001176<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001177<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 +00001178</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001179<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001180<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1181the left a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001182<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001183<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001184 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1185type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001186<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001187<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001188<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001189<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 +00001190 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1191 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1192</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001193</div>
Chris Lattner00950542001-06-06 20:29:01 +00001194<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001195<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1196Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001197<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001198<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001199<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 +00001200</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001201<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001202<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1203the right a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001204<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001205<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001206 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1207type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001208<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001209<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1210most significant bit is duplicated in the newly free'd bit positions.
1211If the first argument is unsigned, zero bits shall fill the empty
1212positions.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001213<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001214<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 +00001215 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001216 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner8c6bb902003-06-18 21:30:51 +00001217 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1218 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner00950542001-06-06 20:29:01 +00001219</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001220</div>
Chris Lattner00950542001-06-06 20:29:01 +00001221<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001222<div class="doc_subsection"> <a name="memoryops">Memory Access
1223Operations</a></div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001224<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001225<p>A key design point of an SSA-based representation is how it
1226represents memory. In LLVM, no memory locations are in SSA form, which
1227makes things very simple. This section describes how to read, write,
1228allocate and free memory in LLVM.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001229</div>
Chris Lattner00950542001-06-06 20:29:01 +00001230<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001231<div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>'
1232Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001233<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001234<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001235<pre> &lt;result&gt; = malloc &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001236 &lt;result&gt; = malloc &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001237</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001238<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001239<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1240heap and returns a pointer to it.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001241<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001242<p>The the '<tt>malloc</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1243bytes of memory from the operating system, and returns a pointer of the
1244appropriate type to the program. The second form of the instruction is
1245a shorter version of the first instruction that defaults to allocating
1246one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001247<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001248<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001249<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1250a pointer is returned.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001251<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001252<pre> %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001253
Chris Lattner261efe92003-11-25 01:02:51 +00001254 %size = <a
1255 href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001256 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1257 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001258</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001259</div>
Chris Lattner00950542001-06-06 20:29:01 +00001260<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001261<div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>'
1262Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001263<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001264<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001265<pre> free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner00950542001-06-06 20:29:01 +00001266</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001267<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001268<p>The '<tt>free</tt>' instruction returns memory back to the unused
1269memory heap, to be reallocated in the future.</p>
1270<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001271<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001272<p>'<tt>value</tt>' shall be a pointer value that points to a value
1273that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1274instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001275<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001276<p>Access to the memory pointed to by the pointer is not longer defined
1277after this instruction executes.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001278<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001279<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 +00001280 free [4 x ubyte]* %array
1281</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001282</div>
Chris Lattner00950542001-06-06 20:29:01 +00001283<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001284<div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>'
1285Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001286<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001287<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001288<pre> &lt;result&gt; = alloca &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001289 &lt;result&gt; = alloca &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001290</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001291<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001292<p>The '<tt>alloca</tt>' instruction allocates memory on the current
1293stack frame of the procedure that is live until the current function
1294returns to its caller.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001295<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001296<p>The the '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1297bytes of memory on the runtime stack, returning a pointer of the
1298appropriate type to the program. The second form of the instruction is
1299a shorter version of the first that defaults to allocating one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001300<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001301<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001302<p>Memory is allocated, a pointer is returned. '<tt>alloca</tt>'d
1303memory is automatically released when the function returns. The '<tt>alloca</tt>'
1304instruction is commonly used to represent automatic variables that must
1305have an address available. When the function returns (either with the <tt><a
1306 href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001307instructions), the memory is reclaimed.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001308<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001309<pre> %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001310 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner00950542001-06-06 20:29:01 +00001311</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001312</div>
Chris Lattner00950542001-06-06 20:29:01 +00001313<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001314<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1315Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001316<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00001317<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001318<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 +00001319<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001320<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001321<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001322<p>The argument to the '<tt>load</tt>' instruction specifies the memory
1323address to load from. The pointer must point to a <a
1324 href="t_firstclass">first class</a> type. If the <tt>load</tt> is
1325marked as <tt>volatile</tt> then the optimizer is not allowed to modify
1326the number or order of execution of this <tt>load</tt> with other
1327volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1328instructions. </p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001329<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001330<p>The location of memory pointed to is loaded.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001331<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001332<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1333 <a
1334 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001335 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1336</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001337</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001338<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001339<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1340Instruction</a> </div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001341<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001342<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 +00001343 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 +00001344</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001345<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001346<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001347<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001348<p>There are two arguments to the '<tt>store</tt>' instruction: a value
1349to store and an address to store it into. The type of the '<tt>&lt;pointer&gt;</tt>'
1350operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
1351operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the
1352optimizer is not allowed to modify the number or order of execution of
1353this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1354 href="#i_store">store</a></tt> instructions.</p>
1355<h5>Semantics:</h5>
1356<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
1357at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001358<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001359<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1360 <a
1361 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001362 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1363</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001364<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001365<div class="doc_subsubsection"> <a name="i_getelementptr">'<tt>getelementptr</tt>'
1366Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001367<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00001368<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001369<pre> &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, long &lt;aidx&gt;|, ubyte &lt;sidx&gt;}*<br></pre>
Chris Lattner7faa8832002-04-14 06:13:44 +00001370<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001371<p>The '<tt>getelementptr</tt>' instruction is used to get the address
1372of a subelement of an aggregate data structure.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +00001373<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001374<p>This instruction takes a list of <tt>long</tt> values and <tt>ubyte</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001375constants that indicate what form of addressing to perform. The actual
1376types of the arguments provided depend on the type of the first pointer
1377argument. The '<tt>getelementptr</tt>' instruction is used to index
1378down through the type levels of a structure.</p>
1379<p>For example, let's consider a C code fragment and how it gets
1380compiled to LLVM:</p>
1381<pre>struct RT {<br> char A;<br> int B[10][20];<br> char C;<br>};<br>struct ST {<br> int X;<br> double Y;<br> struct RT Z;<br>};<br><br>int *foo(struct ST *s) {<br> return &amp;s[1].Z.B[5][13];<br>}<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001382<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001383<pre>%RT = type { sbyte, [10 x [20 x int]], sbyte }<br>%ST = type { int, double, %RT }<br><br>int* "foo"(%ST* %s) {<br> %reg = getelementptr %ST* %s, long 1, ubyte 2, ubyte 1, long 5, long 13<br> ret int* %reg<br>}<br></pre>
Chris Lattner7faa8832002-04-14 06:13:44 +00001384<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001385<p>The index types specified for the '<tt>getelementptr</tt>'
1386instruction depend on the pointer type that is being index into. <a
1387 href="t_pointer">Pointer</a> and <a href="t_array">array</a> types
1388require '<tt>long</tt>' values, and <a href="t_struct">structure</a>
1389types require '<tt>ubyte</tt>' <b>constants</b>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001390<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattner261efe92003-11-25 01:02:51 +00001391type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int,
1392double, %RT }</tt>' type, a structure. The second index indexes into
1393the third element of the structure, yielding a '<tt>%RT</tt>' = '<tt>{
1394sbyte, [10 x [20 x int]], sbyte }</tt>' type, another structure. The
1395third index indexes into the second element of the structure, yielding
1396a '<tt>[10 x [20 x int]]</tt>' type, an array. The two dimensions of
1397the array are subscripted into, yielding an '<tt>int</tt>' type. The '<tt>getelementptr</tt>'
1398instruction return a pointer to this element, thus yielding a '<tt>int*</tt>'
1399type.</p>
1400<p>Note that it is perfectly legal to index partially through a
1401structure, returning a pointer to an inner element. Because of this,
1402the LLVM code for the given testcase is equivalent to:</p>
1403<pre>int* "foo"(%ST* %s) {<br> %t1 = getelementptr %ST* %s , long 1 <i>; yields %ST*:%t1</i>
Chris Lattner3dfa10b2002-12-13 06:01:21 +00001404 %t2 = getelementptr %ST* %t1, long 0, ubyte 2 <i>; yields %RT*:%t2</i>
1405 %t3 = getelementptr %RT* %t2, long 0, ubyte 1 <i>; yields [10 x [20 x int]]*:%t3</i>
1406 %t4 = getelementptr [10 x [20 x int]]* %t3, long 0, long 5 <i>; yields [20 x int]*:%t4</i>
1407 %t5 = getelementptr [20 x int]* %t4, long 0, long 13 <i>; yields int*:%t5</i>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001408 ret int* %t5
1409}
1410</pre>
Chris Lattner7faa8832002-04-14 06:13:44 +00001411<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001412<pre> <i>; yields [12 x ubyte]*:aptr</i>
1413 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, ubyte 1<br></pre>
1414<h5>&nbsp;Note To The Novice:</h5>
1415When using indexing into global arrays with the '<tt>getelementptr</tt>'
1416instruction, you must remember that the&nbsp; </div>
Chris Lattner00950542001-06-06 20:29:01 +00001417<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001418<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001419<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001420<p>The instructions in this catagory are the "miscellaneous"
1421instructions, which defy better classification.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001422</div>
Chris Lattner00950542001-06-06 20:29:01 +00001423<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001424<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
1425Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001426<div class="doc_text">
Chris Lattner33ba0d92001-07-09 00:26:23 +00001427<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001428<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001429<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001430<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
1431the SSA graph representing the function.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001432<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001433<p>The type of the incoming values are specified with the first type
1434field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
1435as arguments, with one pair for each predecessor basic block of the
1436current block. Only values of <a href="#t_firstclass">first class</a>
1437type may be used as the value arguments to the PHI node. Only labels
1438may be used as the label arguments.</p>
1439<p>There must be no non-phi instructions between the start of a basic
1440block and the PHI instructions: i.e. PHI instructions must be first in
1441a basic block.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001442<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001443<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
1444value specified by the parameter, depending on which basic block we
1445came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001446<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001447<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 +00001448</div>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001449<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001450<div class="doc_subsubsection"> <a name="i_cast">'<tt>cast .. to</tt>'
1451Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001452<div class="doc_text">
Chris Lattner6536cfe2002-05-06 22:08:29 +00001453<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001454<pre> &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 +00001455</pre>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001456<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001457<p>The '<tt>cast</tt>' instruction is used as the primitive means to
1458convert integers to floating point, change data type sizes, and break
1459type safety (by casting pointers).</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001460<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001461<p>The '<tt>cast</tt>' instruction takes a value to cast, which must be
1462a first class value, and a type to cast it to, which must also be a <a
1463 href="#t_firstclass">first class</a> type.</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001464<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001465<p>This instruction follows the C rules for explicit casts when
1466determining how the data being cast must change to fit in its new
1467container.</p>
1468<p>When casting to bool, any value that would be considered true in the
1469context of a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +00001470values, all else are '<tt>false</tt>'.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001471<p>When extending an integral value from a type of one signness to
1472another (for example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value
1473is sign-extended if the <b>source</b> value is signed, and
1474zero-extended if the source value is unsigned. <tt>bool</tt> values
1475are always zero extended into either zero or one.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001476<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001477<pre> %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattner7bae3952002-06-25 18:03:17 +00001478 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001479</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001480</div>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001481<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001482<div class="doc_subsubsection"> <a name="i_call">'<tt>call</tt>'
1483Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001484<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001485<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001486<pre> &lt;result&gt; = call &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +00001487<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001488<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001489<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001490<p>This instruction requires several arguments:</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001491<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00001492 <li>
1493 <p>'<tt>ty</tt>': shall be the signature of the pointer to function
1494value being invoked. The argument types must match the types implied
1495by this signature.</p>
1496 </li>
1497 <li>
1498 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a
1499function to be invoked. In most cases, this is a direct function
1500invocation, but indirect <tt>call</tt>s are just as possible,
1501calling an arbitrary pointer to function values.</p>
1502 </li>
1503 <li>
1504 <p>'<tt>function args</tt>': argument list whose types match the
1505function signature argument types. If the function signature
1506indicates the function accepts a variable number of arguments, the
1507extra arguments can be specified.</p>
1508 </li>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001509</ol>
Chris Lattner00950542001-06-06 20:29:01 +00001510<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001511<p>The '<tt>call</tt>' instruction is used to cause control flow to
1512transfer to a specified function, with its incoming arguments bound to
1513the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
1514instruction in the called function, control flow continues with the
1515instruction after the function call, and the return value of the
1516function is bound to the result argument. This is a simpler case of
1517the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001518<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001519<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 +00001520</div>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001521<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001522<div class="doc_subsubsection"> <a name="i_vanext">'<tt>vanext</tt>'
1523Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001524<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001525<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001526<pre> &lt;resultarglist&gt; = vanext &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001527<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001528<p>The '<tt>vanext</tt>' instruction is used to access arguments passed
1529through the "variable argument" area of a function call. It is used to
1530implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001531<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001532<p>This instruction takes a <tt>valist</tt> value and the type of the
1533argument. It returns another <tt>valist</tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001534<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001535<p>The '<tt>vanext</tt>' instruction advances the specified <tt>valist</tt>
1536past an argument of the specified type. In conjunction with the <a
1537 href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement
1538the <tt>va_arg</tt> macro available in C. For more information, see
1539the variable argument handling <a href="#int_varargs">Intrinsic
1540Functions</a>.</p>
1541<p>It is legal for this instruction to be called in a function which
1542does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001543function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001544<p><tt>vanext</tt> is an LLVM instruction instead of an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001545 href="#intrinsics">intrinsic function</a> because it takes an type as
1546an argument.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001547<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001548<p>See the <a href="#int_varargs">variable argument processing</a>
1549section.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001550</div>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001551<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001552<div class="doc_subsubsection"> <a name="i_vaarg">'<tt>vaarg</tt>'
1553Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001554<div class="doc_text">
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001555<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001556<pre> &lt;resultval&gt; = vaarg &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;<br></pre>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001557<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001558<p>The '<tt>vaarg</tt>' instruction is used to access arguments passed
1559through the "variable argument" area of a function call. It is used to
1560implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001561<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001562<p>This instruction takes a <tt>valist</tt> value and the type of the
1563argument. It returns a value of the specified argument type.</p>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001564<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001565<p>The '<tt>vaarg</tt>' instruction loads an argument of the specified
1566type from the specified <tt>va_list</tt>. In conjunction with the <a
1567 href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to
1568implement the <tt>va_arg</tt> macro available in C. For more
1569information, see the variable argument handling <a href="#int_varargs">Intrinsic
1570Functions</a>.</p>
1571<p>It is legal for this instruction to be called in a function which
1572does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001573function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001574<p><tt>vaarg</tt> is an LLVM instruction instead of an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001575 href="#intrinsics">intrinsic function</a> because it takes an type as
1576an argument.</p>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001577<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001578<p>See the <a href="#int_varargs">variable argument processing</a>
1579section.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001580</div>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001581<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00001582<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
1583<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +00001584<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001585<p>LLVM supports the notion of an "intrinsic function". These
1586functions have well known names and semantics, and are required to
1587follow certain restrictions. Overall, these instructions represent an
1588extension mechanism for the LLVM language that does not require
1589changing all of the transformations in LLVM to add to the language (or
1590the bytecode reader/writer, the parser, etc...).</p>
1591<p>Intrinsic function names must all start with an "<tt>llvm.</tt>"
1592prefix, this prefix is reserved in LLVM for intrinsic names, thus
1593functions may not be named this. Intrinsic functions must always be
1594external functions: you cannot define the body of intrinsic functions.
1595Intrinsic functions may only be used in call or invoke instructions: it
1596is illegal to take the address of an intrinsic function. Additionally,
1597because intrinsic functions are part of the LLVM language, it is
1598required that they all be documented here if any are added.</p>
1599<p>Unless an intrinsic function is target-specific, there must be a
1600lowering pass to eliminate the intrinsic or all backends must support
1601the intrinsic function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001602</div>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001603<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001604<div class="doc_subsection"> <a name="int_varargs">Variable Argument
1605Handling Intrinsics</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001606<div class="doc_text">
Misha Brukman9d0919f2003-11-08 01:05:38 +00001607<p>Variable argument support is defined in LLVM with the <a
Chris Lattner261efe92003-11-25 01:02:51 +00001608 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
1609intrinsic functions. These functions are related to the similarly
1610named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
1611<p>All of these functions operate on arguments that use a
1612target-specific value type "<tt>va_list</tt>". The LLVM assembly
1613language reference manual does not define what this type is, so all
1614transformations should be prepared to handle intrinsics with any type
1615used.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001616<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner261efe92003-11-25 01:02:51 +00001617instruction and the variable argument handling intrinsic functions are
1618used.</p>
1619<pre>int %test(int %X, ...) {<br> ; Initialize variable argument processing<br> %ap = call sbyte*()* %<a
1620 href="#i_va_start">llvm.va_start</a>()<br><br> ; Read a single integer argument<br> %tmp = vaarg sbyte* %ap, int<br><br> ; Advance to the next argument<br> %ap2 = vanext sbyte* %ap, int<br><br> ; Demonstrate usage of llvm.va_copy and llvm.va_end<br> %aq = call sbyte* (sbyte*)* %<a
1621 href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2)<br> call void %<a
1622 href="#i_va_end">llvm.va_end</a>(sbyte* %aq)<br><br> ; Stop processing of arguments.<br> call void %<a
1623 href="#i_va_end">llvm.va_end</a>(sbyte* %ap2)<br> ret int %tmp<br>}<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001624</div>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001625<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001626<div class="doc_subsubsection"> <a name="i_va_start">'<tt>llvm.va_start</tt>'
1627Intrinsic</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001628<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001629<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001630<pre> call va_list ()* %llvm.va_start()<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001631<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001632<p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt>&lt;arglist&gt;</tt>
1633for subsequent use by the variable argument intrinsics.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001634<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001635<p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001636macro available in C. In a target-dependent way, it initializes and
1637returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt>
1638will produce the first variable argument passed to the function. Unlike
1639the C <tt>va_start</tt> macro, this intrinsic does not need to know the
1640last argument of the function, the compiler can figure that out.</p>
1641<p>Note that this intrinsic function is only legal to be called from
1642within the body of a variable argument function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001643</div>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001644<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001645<div class="doc_subsubsection"> <a name="i_va_end">'<tt>llvm.va_end</tt>'
1646Intrinsic</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001647<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001648<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001649<pre> call void (va_list)* %llvm.va_end(va_list &lt;arglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001650<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001651<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
1652which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
1653or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001654<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001655<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001656<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001657<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001658macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
1659Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
1660 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
1661with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001662</div>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001663<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001664<div class="doc_subsubsection"> <a name="i_va_copy">'<tt>llvm.va_copy</tt>'
1665Intrinsic</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001666<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001667<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001668<pre> call va_list (va_list)* %llvm.va_copy(va_list &lt;destarglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001669<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001670<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument
1671position from the source argument list to the destination argument list.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001672<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001673<p>The argument is the <tt>va_list</tt> to copy.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001674<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001675<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001676macro available in C. In a target-dependent way, it copies the source <tt>va_list</tt>
1677element into the returned list. This intrinsic is necessary because the <tt><a
1678 href="i_va_start">llvm.va_start</a></tt> intrinsic may be arbitrarily
1679complex and require memory allocation, for example.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001680</div>
Chris Lattner00950542001-06-06 20:29:01 +00001681<!-- *********************************************************************** -->
Chris Lattner00950542001-06-06 20:29:01 +00001682<hr>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001683<div class="doc_footer">
Chris Lattner261efe92003-11-25 01:02:51 +00001684<address><a href="mailto:sabre@nondot.org">Chris Lattner</a></address>
1685<a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a> <br>
1686Last modified: $Date$ </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001687</body>
1688</html>