blob: 7cd6765b674813c9b409612c0401e4862e13ce02 [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>
Chris Lattner8ff75902004-01-06 05:31:32 +000098 <li><a href="#int_debugger">Debugger intrinsics</a>
Chris Lattner261efe92003-11-25 01:02:51 +000099 </ol>
100 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000101</ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000102<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000103<p><b>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
104and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></b></p>
105<p> </p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000106</div>
Chris Lattner00950542001-06-06 20:29:01 +0000107<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000108<div class="doc_section"> <a name="abstract">Abstract </a></div>
109<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000110<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000111<p>This document is a reference manual for the LLVM assembly language.
112LLVM is an SSA based representation that provides type safety,
113low-level operations, flexibility, and the capability of representing
114'all' high-level languages cleanly. It is the common code
115representation used throughout all phases of the LLVM compilation
116strategy.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000117</div>
Chris Lattner00950542001-06-06 20:29:01 +0000118<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000119<div class="doc_section"> <a name="introduction">Introduction</a> </div>
120<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000121<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000122<p>The LLVM code representation is designed to be used in three
123different forms: as an in-memory compiler IR, as an on-disk bytecode
124representation (suitable for fast loading by a Just-In-Time compiler),
125and as a human readable assembly language representation. This allows
126LLVM to provide a powerful intermediate representation for efficient
127compiler transformations and analysis, while providing a natural means
128to debug and visualize the transformations. The three different forms
129of LLVM are all equivalent. This document describes the human readable
130representation and notation.</p>
131<p>The LLVM representation aims to be a light-weight and low-level
132while being expressive, typed, and extensible at the same time. It
133aims to be a "universal IR" of sorts, by being at a low enough level
134that high-level ideas may be cleanly mapped to it (similar to how
135microprocessors are "universal IR's", allowing many source languages to
136be mapped to them). By providing type information, LLVM can be used as
137the target of optimizations: for example, through pointer analysis, it
138can be proven that a C automatic variable is never accessed outside of
139the current function... allowing it to be promoted to a simple SSA
140value instead of a memory location.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000141</div>
Chris Lattner00950542001-06-06 20:29:01 +0000142<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000143<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000144<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000145<p>It is important to note that this document describes 'well formed'
146LLVM assembly language. There is a difference between what the parser
147accepts and what is considered 'well formed'. For example, the
148following instruction is syntactically okay, but not well formed:</p>
149<pre> %x = <a href="#i_add">add</a> int 1, %x<br></pre>
150<p>...because the definition of <tt>%x</tt> does not dominate all of
151its uses. The LLVM infrastructure provides a verification pass that may
152be used to verify that an LLVM module is well formed. This pass is
153automatically run by the parser after parsing input assembly, and by
154the optimizer before it outputs bytecode. The violations pointed out
155by the verifier pass indicate bugs in transformation passes or input to
156the parser.</p>
157<!-- Describe the typesetting conventions here. --> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000158<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000159<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000160<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000161<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000162<p>LLVM uses three different forms of identifiers, for different
163purposes:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000164<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000165 <li>Numeric constants are represented as you would expect: 12, -3
166123.421, etc. Floating point constants have an optional hexidecimal
167notation.</li>
168 <li>Named values are represented as a string of characters with a '%'
169prefix. For example, %foo, %DivisionByZero,
170%a.really.long.identifier. The actual regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
171Identifiers which require other characters in their names can be
172surrounded with quotes. In this way, anything except a <tt>"</tt>
173character can be used in a name.</li>
174 <li>Unnamed values are represented as an unsigned numeric value with
175a '%' prefix. For example, %12, %2, %44.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000176</ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000177<p>LLVM requires the values start with a '%' sign for two reasons:
178Compilers don't need to worry about name clashes with reserved words,
179and the set of reserved words may be expanded in the future without
180penalty. Additionally, unnamed identifiers allow a compiler to quickly
181come up with a temporary variable without having to avoid symbol table
182conflicts.</p>
183<p>Reserved words in LLVM are very similar to reserved words in other
184languages. There are keywords for different opcodes ('<tt><a
185 href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
186 href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
187 href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>',
188etc...), and others. These reserved words cannot conflict with
189variable names, because none of them start with a '%' character.</p>
190<p>Here is an example of LLVM code to multiply the integer variable '<tt>%X</tt>'
191by 8:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000192<p>The easy way:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000193<pre> %result = <a href="#i_mul">mul</a> uint %X, 8<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000194<p>After strength reduction:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000195<pre> %result = <a href="#i_shl">shl</a> uint %X, ubyte 3<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000196<p>And the hard way:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000197<pre> <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
198 <a
199 href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
200 %result = <a
201 href="#i_add">add</a> uint %1, %1<br></pre>
202<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
203important lexical features of LLVM:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000204<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000205 <li>Comments are delimited with a '<tt>;</tt>' and go until the end
206of line.</li>
207 <li>Unnamed temporaries are created when the result of a computation
208is not assigned to a named value.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000209 <li>Unnamed temporaries are numbered sequentially</li>
210</ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000211<p>...and it also show a convention that we follow in this document.
212When demonstrating instructions, we will follow an instruction with a
213comment that defines the type and name of value produced. Comments are
214shown in italic text.</p>
215<p>The one non-intuitive notation for constants is the optional
216hexidecimal form of floating point constants. For example, the form '<tt>double
Chris Lattner2b7d3202002-05-06 03:03:22 +00002170x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
Chris Lattner261efe92003-11-25 01:02:51 +00002184.5e+15</tt>' which is also supported by the parser. The only time
219hexadecimal floating point constants are useful (and the only time that
220they are generated by the disassembler) is when an FP constant has to
221be emitted that is not representable as a decimal floating point number
222exactly. For example, NaN's, infinities, and other special cases are
223represented in their IEEE hexadecimal format so that assembly and
224disassembly do not cause any bits to change in the constants.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000225</div>
Chris Lattner00950542001-06-06 20:29:01 +0000226<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000227<div class="doc_section"> <a name="typesystem">Type System</a> </div>
228<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000229<div class="doc_text">
Misha Brukman9d0919f2003-11-08 01:05:38 +0000230<p>The LLVM type system is one of the most important features of the
Chris Lattner261efe92003-11-25 01:02:51 +0000231intermediate representation. Being typed enables a number of
232optimizations to be performed on the IR directly, without having to do
233extra analyses on the side before the transformation. A strong type
234system makes it easier to read the generated code and enables novel
235analyses and transformations that are not feasible to perform on normal
236three address code representations.</p>
Chris Lattner7bae3952002-06-25 18:03:17 +0000237<!-- The written form for the type system was heavily influenced by the
238syntactic problems with types in the C language<sup><a
Chris Lattner261efe92003-11-25 01:02:51 +0000239href="#rw_stroustrup">1</a></sup>.<p> --> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000240<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000241<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000242<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000243<p>The primitive types are the fundemental building blocks of the LLVM
244system. The current set of primitive types are as follows:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000245<p>
246<table border="0" align="center">
Chris Lattner261efe92003-11-25 01:02:51 +0000247 <tbody>
248 <tr>
249 <td>
250 <table border="1" cellspacing="0" cellpadding="4" align="center">
251 <tbody>
252 <tr>
253 <td><tt>void</tt></td>
254 <td>No value</td>
255 </tr>
256 <tr>
257 <td><tt>ubyte</tt></td>
258 <td>Unsigned 8 bit value</td>
259 </tr>
260 <tr>
261 <td><tt>ushort</tt></td>
262 <td>Unsigned 16 bit value</td>
263 </tr>
264 <tr>
265 <td><tt>uint</tt></td>
266 <td>Unsigned 32 bit value</td>
267 </tr>
268 <tr>
269 <td><tt>ulong</tt></td>
270 <td>Unsigned 64 bit value</td>
271 </tr>
272 <tr>
273 <td><tt>float</tt></td>
274 <td>32 bit floating point value</td>
275 </tr>
276 <tr>
277 <td><tt>label</tt></td>
278 <td>Branch destination</td>
279 </tr>
280 </tbody>
281 </table>
282 </td>
283 <td valign="top">
284 <table border="1" cellspacing="0" cellpadding="4" align="center&quot;">
285 <tbody>
286 <tr>
287 <td><tt>bool</tt></td>
288 <td>True or False value</td>
289 </tr>
290 <tr>
291 <td><tt>sbyte</tt></td>
292 <td>Signed 8 bit value</td>
293 </tr>
294 <tr>
295 <td><tt>short</tt></td>
296 <td>Signed 16 bit value</td>
297 </tr>
298 <tr>
299 <td><tt>int</tt></td>
300 <td>Signed 32 bit value</td>
301 </tr>
302 <tr>
303 <td><tt>long</tt></td>
304 <td>Signed 64 bit value</td>
305 </tr>
306 <tr>
307 <td><tt>double</tt></td>
308 <td>64 bit floating point value</td>
309 </tr>
310 </tbody>
311 </table>
312 </td>
313 </tr>
314 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000315</table>
316</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000317</div>
Chris Lattner00950542001-06-06 20:29:01 +0000318<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000319<div class="doc_subsubsection"> <a name="t_classifications">Type
320Classifications</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000321<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000322<p>These different primitive types fall into a few useful
323classifications:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000324<p>
325<table border="1" cellspacing="0" cellpadding="4" align="center">
Chris Lattner261efe92003-11-25 01:02:51 +0000326 <tbody>
327 <tr>
328 <td><a name="t_signed">signed</a></td>
329 <td><tt>sbyte, short, int, long, float, double</tt></td>
330 </tr>
331 <tr>
332 <td><a name="t_unsigned">unsigned</a></td>
333 <td><tt>ubyte, ushort, uint, ulong</tt></td>
334 </tr>
335 <tr>
336 <td><a name="t_integer">integer</a></td>
337 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
338 </tr>
339 <tr>
340 <td><a name="t_integral">integral</a></td>
341 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
342 </tr>
343 <tr>
344 <td><a name="t_floating">floating point</a></td>
345 <td><tt>float, double</tt></td>
346 </tr>
347 <tr>
348 <td><a name="t_firstclass">first class</a></td>
349 <td><tt>bool, ubyte, sbyte, ushort, short,<br>
350uint, int, ulong, long, float, double, <a href="#t_pointer">pointer</a></tt></td>
351 </tr>
352 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000353</table>
354</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000355<p>The <a href="#t_firstclass">first class</a> types are perhaps the
356most important. Values of these types are the only ones which can be
357produced by instructions, passed as arguments, or used as operands to
358instructions. This means that all structures and arrays must be
359manipulated either by pointer or by component.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000360</div>
Chris Lattner00950542001-06-06 20:29:01 +0000361<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000362<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000363<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000364<p>The real power in LLVM comes from the derived types in the system.
365This is what allows a programmer to represent arrays, functions,
366pointers, and other useful types. Note that these derived types may be
367recursive: For example, it is possible to have a two dimensional array.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000368</div>
Chris Lattner00950542001-06-06 20:29:01 +0000369<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000370<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000371<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000372<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000373<p>The array type is a very simple derived type that arranges elements
Chris Lattner261efe92003-11-25 01:02:51 +0000374sequentially in memory. The array type requires a size (number of
375elements) and an underlying data type.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000376<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000377<pre> [&lt;# elements&gt; x &lt;elementtype&gt;]<br></pre>
378<p>The number of elements is a constant integer value, elementtype may
379be any type with a size.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000380<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000381<p> <tt>[40 x int ]</tt>: Array of 40 integer values.<br>
382<tt>[41 x int ]</tt>: Array of 41 integer values.<br>
383<tt>[40 x uint]</tt>: Array of 40 unsigned integer values.</p>
384<p> </p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000385<p>Here are some examples of multidimensional arrays:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000386<p>
387<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000388 <tbody>
389 <tr>
390 <td><tt>[3 x [4 x int]]</tt></td>
391 <td>: 3x4 array integer values.</td>
392 </tr>
393 <tr>
394 <td><tt>[12 x [10 x float]]</tt></td>
395 <td>: 12x10 array of single precision floating point values.</td>
396 </tr>
397 <tr>
398 <td><tt>[2 x [3 x [4 x uint]]]</tt></td>
399 <td>: 2x3x4 array of unsigned integer values.</td>
400 </tr>
401 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000402</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000403</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000404</div>
Chris Lattner00950542001-06-06 20:29:01 +0000405<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000406<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000407<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000408<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000409<p>The function type can be thought of as a function signature. It
410consists of a return type and a list of formal parameter types.
John Criswell009900b2003-11-25 21:45:46 +0000411Function types are usually used to build virtual function tables
Chris Lattner261efe92003-11-25 01:02:51 +0000412(which are structures of pointers to functions), for indirect function
413calls, and when defining a function.</p>
John Criswell009900b2003-11-25 21:45:46 +0000414<p>
415The return type of a function type cannot be an aggregate type.
416</p>
Chris Lattner00950542001-06-06 20:29:01 +0000417<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000418<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
419<p>Where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of
420type specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner27f71f22003-09-03 00:41:47 +0000421which indicates that the function takes a variable number of arguments.
422Variable argument functions can access their arguments with the <a
Chris Lattner261efe92003-11-25 01:02:51 +0000423 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000424<h5>Examples:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000425<p>
426<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000427 <tbody>
428 <tr>
429 <td><tt>int (int)</tt></td>
430 <td>: function taking an <tt>int</tt>, returning an <tt>int</tt></td>
431 </tr>
432 <tr>
433 <td><tt>float (int, int *) *</tt></td>
434 <td>: <a href="#t_pointer">Pointer</a> to a function that takes
435an <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
436returning <tt>float</tt>.</td>
437 </tr>
438 <tr>
439 <td><tt>int (sbyte *, ...)</tt></td>
440 <td>: A vararg function that takes at least one <a
441 href="#t_pointer">pointer</a> to <tt>sbyte</tt> (signed char in C),
442which returns an integer. This is the signature for <tt>printf</tt>
443in LLVM.</td>
444 </tr>
445 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000446</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000447</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000448</div>
Chris Lattner00950542001-06-06 20:29:01 +0000449<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000450<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000451<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000452<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000453<p>The structure type is used to represent a collection of data members
454together in memory. The packing of the field types is defined to match
455the ABI of the underlying processor. The elements of a structure may
456be any type that has a size.</p>
457<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
458and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
459field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
460instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000461<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000462<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +0000463<h5>Examples:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000464<p>
465<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000466 <tbody>
467 <tr>
468 <td><tt>{ int, int, int }</tt></td>
469 <td>: a triple of three <tt>int</tt> values</td>
470 </tr>
471 <tr>
472 <td><tt>{ float, int (int) * }</tt></td>
473 <td>: A pair, where the first element is a <tt>float</tt> and the
474second element is a <a href="#t_pointer">pointer</a> to a <a
475 href="t_function">function</a> that takes an <tt>int</tt>, returning
476an <tt>int</tt>.</td>
477 </tr>
478 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000479</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000480</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000481</div>
Chris Lattner00950542001-06-06 20:29:01 +0000482<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000483<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000484<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +0000485<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000486<p>As in many languages, the pointer type represents a pointer or
487reference to another object, which must live in memory.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000488<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000489<pre> &lt;type&gt; *<br></pre>
Chris Lattner7faa8832002-04-14 06:13:44 +0000490<h5>Examples:</h5>
Chris Lattner7faa8832002-04-14 06:13:44 +0000491<p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000492<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000493 <tbody>
494 <tr>
495 <td><tt>[4x int]*</tt></td>
496 <td>: <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a>
497of four <tt>int</tt> values</td>
498 </tr>
499 <tr>
500 <td><tt>int (int *) *</tt></td>
501 <td>: A <a href="#t_pointer">pointer</a> to a <a
502 href="t_function">function</a> that takes an <tt>int</tt>, returning
503an <tt>int</tt>.</td>
504 </tr>
505 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000506</table>
507</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000508</div>
Chris Lattner261efe92003-11-25 01:02:51 +0000509<!-- _______________________________________________________________________ --><!--
Misha Brukman9d0919f2003-11-08 01:05:38 +0000510<div class="doc_subsubsection">
511 <a name="t_packed">Packed Type</a>
512</div>
513
514<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000515
516Mention/decide that packed types work with saturation or not. Maybe have a packed+saturated type in addition to just a packed type.<p>
517
518Packed types should be 'nonsaturated' because standard data types are not saturated. Maybe have a saturated packed type?<p>
519
Misha Brukman9d0919f2003-11-08 01:05:38 +0000520</div>
521
Chris Lattner261efe92003-11-25 01:02:51 +0000522--><!-- *********************************************************************** -->
523<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
524<!-- *********************************************************************** --><!-- ======================================================================= -->
525<div class="doc_subsection"> <a name="modulestructure">Module Structure</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000526<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000527<p>LLVM programs are composed of "Module"s, each of which is a
528translation unit of the input programs. Each module consists of
529functions, global variables, and symbol table entries. Modules may be
530combined together with the LLVM linker, which merges function (and
531global variable) definitions, resolves forward declarations, and merges
532symbol table entries. Here is an example of the "hello world" module:</p>
533<pre><i>; Declare the string constant as a global constant...</i>
534<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
535 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 +0000536
Chris Lattner27f71f22003-09-03 00:41:47 +0000537<i>; External declaration of the puts function</i>
538<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000539
540<i>; Definition of main function</i>
Chris Lattner27f71f22003-09-03 00:41:47 +0000541int %main() { <i>; int()* </i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000542 <i>; Convert [13x sbyte]* to sbyte *...</i>
Chris Lattner261efe92003-11-25 01:02:51 +0000543 %cast210 = <a
544 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000545
546 <i>; Call puts function to write out the string to stdout...</i>
Chris Lattner261efe92003-11-25 01:02:51 +0000547 <a
548 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
549 <a
550 href="#i_ret">ret</a> int 0<br>}<br></pre>
551<p>This example is made up of a <a href="#globalvars">global variable</a>
552named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
553function, and a <a href="#functionstructure">function definition</a>
554for "<tt>main</tt>".</p>
555<a name="linkage"> In general, a module is made up of a list of global
556values, where both functions and global variables are global values.
557Global values are represented by a pointer to a memory location (in
558this case, a pointer to an array of char, and a pointer to a function),
559and have one of the following linkage types:</a>
560<p> </p>
Chris Lattner27f71f22003-09-03 00:41:47 +0000561<dl>
Chris Lattner261efe92003-11-25 01:02:51 +0000562 <a name="linkage_internal"> <dt><tt><b>internal</b></tt> </dt>
563 <dd>Global values with internal linkage are only directly accessible
564by objects in the current module. In particular, linking code into a
565module with an internal global value may cause the internal to be
566renamed as necessary to avoid collisions. Because the symbol is
567internal to the module, all references can be updated. This
568corresponds to the notion of the '<tt>static</tt>' keyword in C, or the
569idea of "anonymous namespaces" in C++.
570 <p> </p>
571 </dd>
572 </a><a name="linkage_linkonce"> <dt><tt><b>linkonce</b></tt>: </dt>
573 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt>
574linkage, with the twist that linking together two modules defining the
575same <tt>linkonce</tt> globals will cause one of the globals to be
576discarded. This is typically used to implement inline functions.
577Unreferenced <tt>linkonce</tt> globals are allowed to be discarded.
578 <p> </p>
579 </dd>
580 </a><a name="linkage_weak"> <dt><tt><b>weak</b></tt>: </dt>
581 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt>
582linkage, except that unreferenced <tt>weak</tt> globals may not be
583discarded. This is used to implement constructs in C such as "<tt>int
584X;</tt>" at global scope.
585 <p> </p>
586 </dd>
587 </a><a name="linkage_appending"> <dt><tt><b>appending</b></tt>: </dt>
588 <dd>"<tt>appending</tt>" linkage may only be applied to global
589variables of pointer to array type. When two global variables with
590appending linkage are linked together, the two global arrays are
591appended together. This is the LLVM, typesafe, equivalent of having
592the system linker append together "sections" with identical names when
593.o files are linked.
594 <p> </p>
595 </dd>
596 </a><a name="linkage_external"> <dt><tt><b>externally visible</b></tt>:</dt>
597 <dd>If none of the above identifiers are used, the global is
598externally visible, meaning that it participates in linkage and can be
599used to resolve external symbol references.
600 <p> </p>
601 </dd>
602 </a>
603</dl>
604<p> </p>
605<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
606variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
607variable and was linked with this one, one of the two would be renamed,
608preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
609external (i.e., lacking any linkage declarations), they are accessible
610outside of the current module. It is illegal for a function <i>declaration</i>
611to have any linkage type other than "externally visible".</a></p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000612</div>
Chris Lattner00950542001-06-06 20:29:01 +0000613<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000614<div class="doc_subsection"> <a name="globalvars">Global Variables</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000615<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000616<p>Global variables define regions of memory allocated at compilation
617time instead of run-time. Global variables may optionally be
618initialized. A variable may be defined as a global "constant", which
619indicates that the contents of the variable will never be modified
620(opening options for optimization). Constants must always have an
621initial value.</p>
622<p>As SSA values, global variables define pointer values that are in
623scope (i.e. they dominate) for all basic blocks in the program. Global
624variables always define a pointer to their "content" type because they
625describe a region of memory, and all memory objects in LLVM are
626accessed through pointers.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000627</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000628<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000629<div class="doc_subsection"> <a name="functionstructure">Functions</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000630<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000631<p>LLVM function definitions are composed of a (possibly empty)
632argument list, an opening curly brace, a list of basic blocks, and a
633closing curly brace. LLVM function declarations are defined with the "<tt>declare</tt>"
634keyword, a function name, and a function signature.</p>
635<p>A function definition contains a list of basic blocks, forming the
636CFG for the function. Each basic block may optionally start with a
637label (giving the basic block a symbol table entry), contains a list of
638instructions, and ends with a <a href="#terminators">terminator</a>
639instruction (such as a branch or function return).</p>
640<p>The first basic block in program is special in two ways: it is
641immediately executed on entrance to the function, and it is not allowed
642to have predecessor basic blocks (i.e. there can not be any branches to
643the entry block of a function). Because the block can have no
644predecessors, it also cannot have any <a href="#i_phi">PHI nodes</a>.</p>
John Criswell009900b2003-11-25 21:45:46 +0000645<p>
646LLVM functions are identified by their name and type signature. Hence, two
647functions with the same name but different parameter lists or return values
648are considered different functions, and LLVM will resolves references to each
649appropriately.
650</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_section"> <a name="instref">Instruction Reference</a> </div>
654<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000655<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000656<p>The LLVM instruction set consists of several different
657classifications of instructions: <a href="#terminators">terminator
658instructions</a>, <a href="#binaryops">binary instructions</a>, <a
659 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
660instructions</a>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000661</div>
Chris Lattner00950542001-06-06 20:29:01 +0000662<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000663<div class="doc_subsection"> <a name="terminators">Terminator
664Instructions</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000665<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000666<p>As mentioned <a href="#functionstructure">previously</a>, every
667basic block in a program ends with a "Terminator" instruction, which
668indicates which block should be executed after the current block is
669finished. These terminator instructions typically yield a '<tt>void</tt>'
670value: they produce control flow, not values (the one exception being
671the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000672<p>There are five different terminator instructions: the '<a
Chris Lattner261efe92003-11-25 01:02:51 +0000673 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
674instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
675the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, and the '<a
676 href="#i_unwind"><tt>unwind</tt></a>' instruction.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000677</div>
Chris Lattner00950542001-06-06 20:29:01 +0000678<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000679<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
680Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000681<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000682<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000683<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 +0000684 ret void <i>; Return from void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000685</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000686<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000687<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
688value) from a function, back to the caller.</p>
689<p>There are two forms of the '<tt>ret</tt>' instructruction: one that
690returns a value and then causes control flow, and one that just causes
691control flow to occur.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000692<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000693<p>The '<tt>ret</tt>' instruction may return any '<a
694 href="#t_firstclass">first class</a>' type. Notice that a function is
695not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
696instruction inside of the function that returns a value that does not
697match the return type of the function.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000698<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000699<p>When the '<tt>ret</tt>' instruction is executed, control flow
700returns back to the calling function's context. If the caller is a "<a
701 href="#i_call"><tt>call</tt></a> instruction, execution continues at
702the instruction after the call. If the caller was an "<a
703 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
704at the beginning "normal" of the destination block. If the instruction
705returns a value, that value shall set the call or invoke instruction's
706return value.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000707<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000708<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner7faa8832002-04-14 06:13:44 +0000709 ret void <i>; Return from a void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000710</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000711</div>
Chris Lattner00950542001-06-06 20:29:01 +0000712<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000713<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000714<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000715<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000716<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 +0000717</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000718<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000719<p>The '<tt>br</tt>' instruction is used to cause control flow to
720transfer to a different basic block in the current function. There are
721two forms of this instruction, corresponding to a conditional branch
722and an unconditional branch.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000723<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000724<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
725single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
726unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
727value as a target.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000728<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000729<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
730argument is evaluated. If the value is <tt>true</tt>, control flows
731to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
732control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000733<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000734<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
735 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 +0000736</div>
Chris Lattner00950542001-06-06 20:29:01 +0000737<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000738<div class="doc_subsubsection"> <a name="i_switch">'<tt>switch</tt>'
739Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000740<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000741<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000742<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 +0000743<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000744<p>The '<tt>switch</tt>' instruction is used to transfer control flow
745to one of several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +0000746instruction, allowing a branch to occur to one of many possible
747destinations.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000748<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000749<p>The '<tt>switch</tt>' instruction uses three parameters: a '<tt>uint</tt>'
Chris Lattner261efe92003-11-25 01:02:51 +0000750comparison value '<tt>value</tt>', a default '<tt>label</tt>'
751destination, and an array of pairs of comparison value constants and '<tt>label</tt>'s.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000752<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000753<p>The <tt>switch</tt> instruction specifies a table of values and
754destinations. When the '<tt>switch</tt>' instruction is executed, this
755table is searched for the given value. If the value is found, the
756corresponding destination is branched to, otherwise the default value
757it transfered to.</p>
Chris Lattnerc29b1252003-05-08 05:08:48 +0000758<h5>Implementation:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000759<p>Depending on properties of the target machine and the particular <tt>switch</tt>
760instruction, this instruction may be code generated as a series of
761chained conditional branches, or with a lookup table.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000762<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000763<pre> <i>; Emulate a conditional br instruction</i>
764 %Val = <a
765 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 +0000766 switch uint 0, label %dest [ ]
Chris Lattner00950542001-06-06 20:29:01 +0000767
Chris Lattner2b7d3202002-05-06 03:03:22 +0000768 <i>; Implement a jump table:</i>
Chris Lattner27f71f22003-09-03 00:41:47 +0000769 switch uint %val, label %otherwise [ int 0, label %onzero,
770 int 1, label %onone,
771 int 2, label %ontwo ]
Chris Lattner00950542001-06-06 20:29:01 +0000772</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000773</div>
Chris Lattner00950542001-06-06 20:29:01 +0000774<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000775<div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>'
776Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000777<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000778<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000779<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 +0000780<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000781<p>The '<tt>invoke</tt>' instruction causes control to transfer to a
782specified function, with the possibility of control flow transfer to
783either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>.
784If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>"
785instruction, control flow will return to the "normal" label. If the
786callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
787instruction, control is interrupted, and continued at the dynamically
788nearest "except" label.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000789<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000790<p>This instruction requires several arguments:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000791<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000792 <li>'<tt>ptr to function ty</tt>': shall be the signature of the
793pointer to function value being invoked. In most cases, this is a
794direct function invocation, but indirect <tt>invoke</tt>s are just as
795possible, branching off an arbitrary pointer to function value. </li>
796 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer
797to a function to be invoked. </li>
798 <li>'<tt>function args</tt>': argument list whose types match the
799function signature argument types. If the function signature indicates
800the function accepts a variable number of arguments, the extra
801arguments can be specified. </li>
802 <li>'<tt>normal label</tt>': the label reached when the called
803function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
804 <li>'<tt>exception label</tt>': the label reached when a callee
805returns with the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
Chris Lattner00950542001-06-06 20:29:01 +0000806</ol>
Chris Lattner00950542001-06-06 20:29:01 +0000807<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000808<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner261efe92003-11-25 01:02:51 +0000809 href="#i_call">call</a></tt>' instruction in most regards. The
810primary difference is that it establishes an association with a label,
811which is used by the runtime library to unwind the stack.</p>
812<p>This instruction is used in languages with destructors to ensure
813that proper cleanup is performed in the case of either a <tt>longjmp</tt>
814or a thrown exception. Additionally, this is important for
815implementation of '<tt>catch</tt>' clauses in high-level languages that
816support them.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000817<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000818<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 +0000819</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000820</div>
Chris Lattner27f71f22003-09-03 00:41:47 +0000821<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000822<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
823Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000824<div class="doc_text">
Chris Lattner27f71f22003-09-03 00:41:47 +0000825<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000826<pre> unwind<br></pre>
Chris Lattner27f71f22003-09-03 00:41:47 +0000827<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000828<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing
829control flow at the first callee in the dynamic call stack which used
830an <a href="#i_invoke"><tt>invoke</tt></a> instruction to perform the
831call. This is primarily used to implement exception handling.</p>
Chris Lattner27f71f22003-09-03 00:41:47 +0000832<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000833<p>The '<tt>unwind</tt>' intrinsic causes execution of the current
834function to immediately halt. The dynamic call stack is then searched
835for the first <a href="#i_invoke"><tt>invoke</tt></a> instruction on
836the call stack. Once found, execution continues at the "exceptional"
837destination block specified by the <tt>invoke</tt> instruction. If
838there is no <tt>invoke</tt> instruction in the dynamic call chain,
839undefined behavior results.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000840</div>
Chris Lattner00950542001-06-06 20:29:01 +0000841<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000842<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000843<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000844<p>Binary operators are used to do most of the computation in a
845program. They require two operands, execute an operation on them, and
846produce a single value. The result value of a binary operator is not
847necessarily the same type as its operands.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000848<p>There are several different binary operators:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000849</div>
Chris Lattner00950542001-06-06 20:29:01 +0000850<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000851<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
852Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000853<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000854<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000855<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 +0000856</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000857<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000858<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000859<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000860<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +0000861 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
862values. Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000863<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000864<p>The value produced is the integer or floating point sum of the two
865operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000866<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000867<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner00950542001-06-06 20:29:01 +0000868</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000869</div>
Chris Lattner00950542001-06-06 20:29:01 +0000870<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000871<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
872Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000873<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000874<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000875<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 +0000876</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000877<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000878<p>The '<tt>sub</tt>' instruction returns the difference of its two
879operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000880<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
881instruction present in most other intermediate representations.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000882<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000883<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +0000884 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
885values. Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000886<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000887<p>The value produced is the integer or floating point difference of
888the two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000889<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000890<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner00950542001-06-06 20:29:01 +0000891 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
892</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000893</div>
Chris Lattner00950542001-06-06 20:29:01 +0000894<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000895<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
896Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000897<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000898<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000899<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 +0000900</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000901<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000902<p>The '<tt>mul</tt>' instruction returns the product of its two
903operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000904<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000905<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +0000906 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
907values. Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000908<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000909<p>The value produced is the integer or floating point product of the
Misha Brukman9d0919f2003-11-08 01:05:38 +0000910two operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000911<p>There is no signed vs unsigned multiplication. The appropriate
912action is taken based on the type of the operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000913<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000914<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner00950542001-06-06 20:29:01 +0000915</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000916</div>
Chris Lattner00950542001-06-06 20:29:01 +0000917<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000918<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
919Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000920<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000921<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000922<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
923</pre>
924<h5>Overview:</h5>
925<p>The '<tt>div</tt>' instruction returns the quotient of its two
926operands.</p>
927<h5>Arguments:</h5>
928<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
929 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
930values. Both arguments must have identical types.</p>
931<h5>Semantics:</h5>
932<p>The value produced is the integer or floating point quotient of the
933two operands.</p>
934<h5>Example:</h5>
935<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
936</pre>
937</div>
938<!-- _______________________________________________________________________ -->
939<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
940Instruction</a> </div>
941<div class="doc_text">
942<h5>Syntax:</h5>
943<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
944</pre>
945<h5>Overview:</h5>
946<p>The '<tt>rem</tt>' instruction returns the remainder from the
947division of its two operands.</p>
948<h5>Arguments:</h5>
949<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
950 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
951values. Both arguments must have identical types.</p>
952<h5>Semantics:</h5>
953<p>This returns the <i>remainder</i> of a division (where the result
954has the same sign as the divisor), not the <i>modulus</i> (where the
955result has the same sign as the dividend) of a value. For more
956information about the difference, see: <a
957 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
958Math Forum</a>.</p>
959<h5>Example:</h5>
960<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
961</pre>
962</div>
963<!-- _______________________________________________________________________ -->
964<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
965Instructions</a> </div>
966<div class="doc_text">
967<h5>Syntax:</h5>
968<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 +0000969 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
970 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
971 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
972 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
973 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
974</pre>
Chris Lattner261efe92003-11-25 01:02:51 +0000975<h5>Overview:</h5>
976<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
977value based on a comparison of their two operands.</p>
978<h5>Arguments:</h5>
979<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
980be of <a href="#t_firstclass">first class</a> type (it is not possible
981to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
982or '<tt>void</tt>' values, etc...). Both arguments must have identical
983types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000984<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000985<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
986value if both operands are equal.<br>
987The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
988value if both operands are unequal.<br>
989The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
990value if the first operand is less than the second operand.<br>
991The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
992value if the first operand is greater than the second operand.<br>
993The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
994value if the first operand is less than or equal to the second operand.<br>
995The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
996value if the first operand is greater than or equal to the second
997operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000998<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000999<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner00950542001-06-06 20:29:01 +00001000 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
1001 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1002 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1003 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1004 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1005</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001006</div>
Chris Lattner00950542001-06-06 20:29:01 +00001007<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001008<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1009Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001010<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001011<p>Bitwise binary operators are used to do various forms of
1012bit-twiddling in a program. They are generally very efficient
1013instructions, and can commonly be strength reduced from other
1014instructions. They require two operands, execute an operation on them,
1015and produce a single value. The resulting value of the bitwise binary
1016operators is always the same type as its first operand.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001017</div>
Chris Lattner00950542001-06-06 20:29:01 +00001018<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001019<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1020Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001021<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001022<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001023<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 +00001024</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001025<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001026<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1027its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001028<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001029<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001030 href="#t_integral">integral</a> values. Both arguments must have
1031identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001032<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001033<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001034<p> </p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001035<center>
1036<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +00001037 <tbody>
1038 <tr>
1039 <td>In0</td>
1040 <td>In1</td>
1041 <td>Out</td>
1042 </tr>
1043 <tr>
1044 <td>0</td>
1045 <td>0</td>
1046 <td>0</td>
1047 </tr>
1048 <tr>
1049 <td>0</td>
1050 <td>1</td>
1051 <td>0</td>
1052 </tr>
1053 <tr>
1054 <td>1</td>
1055 <td>0</td>
1056 <td>0</td>
1057 </tr>
1058 <tr>
1059 <td>1</td>
1060 <td>1</td>
1061 <td>1</td>
1062 </tr>
1063 </tbody>
1064</table>
1065</center>
Chris Lattner00950542001-06-06 20:29:01 +00001066<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001067<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001068 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1069 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1070</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001071</div>
Chris Lattner00950542001-06-06 20:29:01 +00001072<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001073<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001074<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001075<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001076<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 +00001077</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001078<h5>Overview:</h5>
1079<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1080or of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001081<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001082<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001083 href="#t_integral">integral</a> values. Both arguments must have
1084identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001085<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001086<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001087<p> </p>
1088<center>
1089<table border="1" cellspacing="0" cellpadding="4">
1090 <tbody>
1091 <tr>
1092 <td>In0</td>
1093 <td>In1</td>
1094 <td>Out</td>
1095 </tr>
1096 <tr>
1097 <td>0</td>
1098 <td>0</td>
1099 <td>0</td>
1100 </tr>
1101 <tr>
1102 <td>0</td>
1103 <td>1</td>
1104 <td>1</td>
1105 </tr>
1106 <tr>
1107 <td>1</td>
1108 <td>0</td>
1109 <td>1</td>
1110 </tr>
1111 <tr>
1112 <td>1</td>
1113 <td>1</td>
1114 <td>1</td>
1115 </tr>
1116 </tbody>
1117</table>
1118</center>
Chris Lattner00950542001-06-06 20:29:01 +00001119<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001120<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001121 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1122 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1123</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001124</div>
Chris Lattner00950542001-06-06 20:29:01 +00001125<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001126<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1127Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001128<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001129<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001130<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 +00001131</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001132<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001133<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1134or of its two operands. The <tt>xor</tt> is used to implement the
1135"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001136<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001137<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001138 href="#t_integral">integral</a> values. Both arguments must have
1139identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001140<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001141<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001142<p> </p>
1143<center>
1144<table border="1" cellspacing="0" cellpadding="4">
1145 <tbody>
1146 <tr>
1147 <td>In0</td>
1148 <td>In1</td>
1149 <td>Out</td>
1150 </tr>
1151 <tr>
1152 <td>0</td>
1153 <td>0</td>
1154 <td>0</td>
1155 </tr>
1156 <tr>
1157 <td>0</td>
1158 <td>1</td>
1159 <td>1</td>
1160 </tr>
1161 <tr>
1162 <td>1</td>
1163 <td>0</td>
1164 <td>1</td>
1165 </tr>
1166 <tr>
1167 <td>1</td>
1168 <td>1</td>
1169 <td>0</td>
1170 </tr>
1171 </tbody>
1172</table>
1173</center>
1174<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001175<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001176<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001177 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1178 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner27f71f22003-09-03 00:41:47 +00001179 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner00950542001-06-06 20:29:01 +00001180</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001181</div>
Chris Lattner00950542001-06-06 20:29:01 +00001182<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001183<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1184Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001185<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001186<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001187<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 +00001188</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001189<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001190<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1191the left a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001192<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001193<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001194 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1195type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001196<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001197<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001198<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001199<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 +00001200 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1201 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1202</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001203</div>
Chris Lattner00950542001-06-06 20:29:01 +00001204<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001205<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1206Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001207<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001208<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001209<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 +00001210</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001211<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001212<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1213the right a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001214<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001215<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001216 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1217type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001218<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001219<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1220most significant bit is duplicated in the newly free'd bit positions.
1221If the first argument is unsigned, zero bits shall fill the empty
1222positions.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001223<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001224<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 +00001225 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001226 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner8c6bb902003-06-18 21:30:51 +00001227 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1228 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner00950542001-06-06 20:29:01 +00001229</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001230</div>
Chris Lattner00950542001-06-06 20:29:01 +00001231<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001232<div class="doc_subsection"> <a name="memoryops">Memory Access
1233Operations</a></div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001234<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001235<p>A key design point of an SSA-based representation is how it
1236represents memory. In LLVM, no memory locations are in SSA form, which
1237makes things very simple. This section describes how to read, write,
1238allocate and free memory in LLVM.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001239</div>
Chris Lattner00950542001-06-06 20:29:01 +00001240<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001241<div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>'
1242Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001243<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001244<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001245<pre> &lt;result&gt; = malloc &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001246 &lt;result&gt; = malloc &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001247</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001248<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001249<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1250heap and returns a pointer to it.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001251<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001252<p>The the '<tt>malloc</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1253bytes of memory from the operating system, and returns a pointer of the
1254appropriate type to the program. The second form of the instruction is
1255a shorter version of the first instruction that defaults to allocating
1256one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001257<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001258<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001259<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1260a pointer is returned.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001261<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001262<pre> %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001263
Chris Lattner261efe92003-11-25 01:02:51 +00001264 %size = <a
1265 href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001266 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1267 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001268</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001269</div>
Chris Lattner00950542001-06-06 20:29:01 +00001270<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001271<div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>'
1272Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001273<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001274<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001275<pre> free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner00950542001-06-06 20:29:01 +00001276</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001277<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001278<p>The '<tt>free</tt>' instruction returns memory back to the unused
1279memory heap, to be reallocated in the future.</p>
1280<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001281<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001282<p>'<tt>value</tt>' shall be a pointer value that points to a value
1283that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1284instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001285<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001286<p>Access to the memory pointed to by the pointer is not longer defined
1287after this instruction executes.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001288<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001289<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 +00001290 free [4 x ubyte]* %array
1291</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001292</div>
Chris Lattner00950542001-06-06 20:29:01 +00001293<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001294<div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>'
1295Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001296<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001297<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001298<pre> &lt;result&gt; = alloca &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001299 &lt;result&gt; = alloca &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001300</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001301<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001302<p>The '<tt>alloca</tt>' instruction allocates memory on the current
1303stack frame of the procedure that is live until the current function
1304returns to its caller.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001305<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001306<p>The the '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1307bytes of memory on the runtime stack, returning a pointer of the
1308appropriate type to the program. The second form of the instruction is
1309a shorter version of the first that defaults to allocating one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001310<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001311<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001312<p>Memory is allocated, a pointer is returned. '<tt>alloca</tt>'d
1313memory is automatically released when the function returns. The '<tt>alloca</tt>'
1314instruction is commonly used to represent automatic variables that must
1315have an address available. When the function returns (either with the <tt><a
1316 href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001317instructions), the memory is reclaimed.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001318<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001319<pre> %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001320 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner00950542001-06-06 20:29:01 +00001321</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001322</div>
Chris Lattner00950542001-06-06 20:29:01 +00001323<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001324<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1325Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001326<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00001327<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001328<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 +00001329<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001330<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001331<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001332<p>The argument to the '<tt>load</tt>' instruction specifies the memory
1333address to load from. The pointer must point to a <a
1334 href="t_firstclass">first class</a> type. If the <tt>load</tt> is
1335marked as <tt>volatile</tt> then the optimizer is not allowed to modify
1336the number or order of execution of this <tt>load</tt> with other
1337volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1338instructions. </p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001339<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001340<p>The location of memory pointed to is loaded.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001341<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001342<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1343 <a
1344 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001345 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1346</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001347</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001348<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001349<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1350Instruction</a> </div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001351<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001352<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 +00001353 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 +00001354</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001355<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001356<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001357<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001358<p>There are two arguments to the '<tt>store</tt>' instruction: a value
1359to store and an address to store it into. The type of the '<tt>&lt;pointer&gt;</tt>'
1360operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
1361operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the
1362optimizer is not allowed to modify the number or order of execution of
1363this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1364 href="#i_store">store</a></tt> instructions.</p>
1365<h5>Semantics:</h5>
1366<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
1367at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001368<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001369<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1370 <a
1371 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001372 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1373</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001374<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001375<div class="doc_subsubsection"> <a name="i_getelementptr">'<tt>getelementptr</tt>'
1376Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001377<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00001378<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001379<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 +00001380<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001381<p>The '<tt>getelementptr</tt>' instruction is used to get the address
1382of a subelement of an aggregate data structure.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +00001383<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001384<p>This instruction takes a list of <tt>long</tt> values and <tt>ubyte</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001385constants that indicate what form of addressing to perform. The actual
1386types of the arguments provided depend on the type of the first pointer
1387argument. The '<tt>getelementptr</tt>' instruction is used to index
1388down through the type levels of a structure.</p>
1389<p>For example, let's consider a C code fragment and how it gets
1390compiled to LLVM:</p>
1391<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 +00001392<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001393<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 +00001394<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001395<p>The index types specified for the '<tt>getelementptr</tt>'
1396instruction depend on the pointer type that is being index into. <a
1397 href="t_pointer">Pointer</a> and <a href="t_array">array</a> types
1398require '<tt>long</tt>' values, and <a href="t_struct">structure</a>
1399types require '<tt>ubyte</tt>' <b>constants</b>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001400<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattner261efe92003-11-25 01:02:51 +00001401type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int,
1402double, %RT }</tt>' type, a structure. The second index indexes into
1403the third element of the structure, yielding a '<tt>%RT</tt>' = '<tt>{
1404sbyte, [10 x [20 x int]], sbyte }</tt>' type, another structure. The
1405third index indexes into the second element of the structure, yielding
1406a '<tt>[10 x [20 x int]]</tt>' type, an array. The two dimensions of
1407the array are subscripted into, yielding an '<tt>int</tt>' type. The '<tt>getelementptr</tt>'
1408instruction return a pointer to this element, thus yielding a '<tt>int*</tt>'
1409type.</p>
1410<p>Note that it is perfectly legal to index partially through a
1411structure, returning a pointer to an inner element. Because of this,
1412the LLVM code for the given testcase is equivalent to:</p>
1413<pre>int* "foo"(%ST* %s) {<br> %t1 = getelementptr %ST* %s , long 1 <i>; yields %ST*:%t1</i>
Chris Lattner3dfa10b2002-12-13 06:01:21 +00001414 %t2 = getelementptr %ST* %t1, long 0, ubyte 2 <i>; yields %RT*:%t2</i>
1415 %t3 = getelementptr %RT* %t2, long 0, ubyte 1 <i>; yields [10 x [20 x int]]*:%t3</i>
1416 %t4 = getelementptr [10 x [20 x int]]* %t3, long 0, long 5 <i>; yields [20 x int]*:%t4</i>
1417 %t5 = getelementptr [20 x int]* %t4, long 0, long 13 <i>; yields int*:%t5</i>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001418 ret int* %t5
1419}
1420</pre>
Chris Lattner7faa8832002-04-14 06:13:44 +00001421<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001422<pre> <i>; yields [12 x ubyte]*:aptr</i>
1423 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, ubyte 1<br></pre>
1424<h5>&nbsp;Note To The Novice:</h5>
1425When using indexing into global arrays with the '<tt>getelementptr</tt>'
1426instruction, you must remember that the&nbsp; </div>
Chris Lattner00950542001-06-06 20:29:01 +00001427<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001428<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001429<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001430<p>The instructions in this catagory are the "miscellaneous"
1431instructions, which defy better classification.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001432</div>
Chris Lattner00950542001-06-06 20:29:01 +00001433<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001434<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
1435Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001436<div class="doc_text">
Chris Lattner33ba0d92001-07-09 00:26:23 +00001437<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001438<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001439<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001440<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
1441the SSA graph representing the function.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001442<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001443<p>The type of the incoming values are specified with the first type
1444field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
1445as arguments, with one pair for each predecessor basic block of the
1446current block. Only values of <a href="#t_firstclass">first class</a>
1447type may be used as the value arguments to the PHI node. Only labels
1448may be used as the label arguments.</p>
1449<p>There must be no non-phi instructions between the start of a basic
1450block and the PHI instructions: i.e. PHI instructions must be first in
1451a basic block.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001452<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001453<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
1454value specified by the parameter, depending on which basic block we
1455came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001456<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001457<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 +00001458</div>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001459<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001460<div class="doc_subsubsection"> <a name="i_cast">'<tt>cast .. to</tt>'
1461Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001462<div class="doc_text">
Chris Lattner6536cfe2002-05-06 22:08:29 +00001463<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001464<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 +00001465</pre>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001466<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001467<p>The '<tt>cast</tt>' instruction is used as the primitive means to
1468convert integers to floating point, change data type sizes, and break
1469type safety (by casting pointers).</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001470<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001471<p>The '<tt>cast</tt>' instruction takes a value to cast, which must be
1472a first class value, and a type to cast it to, which must also be a <a
1473 href="#t_firstclass">first class</a> type.</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001474<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001475<p>This instruction follows the C rules for explicit casts when
1476determining how the data being cast must change to fit in its new
1477container.</p>
1478<p>When casting to bool, any value that would be considered true in the
1479context of a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +00001480values, all else are '<tt>false</tt>'.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001481<p>When extending an integral value from a type of one signness to
1482another (for example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value
1483is sign-extended if the <b>source</b> value is signed, and
1484zero-extended if the source value is unsigned. <tt>bool</tt> values
1485are always zero extended into either zero or one.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001486<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001487<pre> %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattner7bae3952002-06-25 18:03:17 +00001488 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001489</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001490</div>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001491<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001492<div class="doc_subsubsection"> <a name="i_call">'<tt>call</tt>'
1493Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001494<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001495<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001496<pre> &lt;result&gt; = call &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +00001497<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001498<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001499<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001500<p>This instruction requires several arguments:</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001501<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00001502 <li>
1503 <p>'<tt>ty</tt>': shall be the signature of the pointer to function
1504value being invoked. The argument types must match the types implied
1505by this signature.</p>
1506 </li>
1507 <li>
1508 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a
1509function to be invoked. In most cases, this is a direct function
1510invocation, but indirect <tt>call</tt>s are just as possible,
1511calling an arbitrary pointer to function values.</p>
1512 </li>
1513 <li>
1514 <p>'<tt>function args</tt>': argument list whose types match the
1515function signature argument types. If the function signature
1516indicates the function accepts a variable number of arguments, the
1517extra arguments can be specified.</p>
1518 </li>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001519</ol>
Chris Lattner00950542001-06-06 20:29:01 +00001520<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001521<p>The '<tt>call</tt>' instruction is used to cause control flow to
1522transfer to a specified function, with its incoming arguments bound to
1523the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
1524instruction in the called function, control flow continues with the
1525instruction after the function call, and the return value of the
1526function is bound to the result argument. This is a simpler case of
1527the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001528<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001529<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 +00001530</div>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001531<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001532<div class="doc_subsubsection"> <a name="i_vanext">'<tt>vanext</tt>'
1533Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001534<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001535<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001536<pre> &lt;resultarglist&gt; = vanext &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001537<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001538<p>The '<tt>vanext</tt>' instruction is used to access arguments passed
1539through the "variable argument" area of a function call. It is used to
1540implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001541<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001542<p>This instruction takes a <tt>valist</tt> value and the type of the
1543argument. It returns another <tt>valist</tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001544<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001545<p>The '<tt>vanext</tt>' instruction advances the specified <tt>valist</tt>
1546past an argument of the specified type. In conjunction with the <a
1547 href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement
1548the <tt>va_arg</tt> macro available in C. For more information, see
1549the variable argument handling <a href="#int_varargs">Intrinsic
1550Functions</a>.</p>
1551<p>It is legal for this instruction to be called in a function which
1552does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001553function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001554<p><tt>vanext</tt> is an LLVM instruction instead of an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001555 href="#intrinsics">intrinsic function</a> because it takes an type as
1556an argument.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001557<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001558<p>See the <a href="#int_varargs">variable argument processing</a>
1559section.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001560</div>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001561<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001562<div class="doc_subsubsection"> <a name="i_vaarg">'<tt>vaarg</tt>'
1563Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001564<div class="doc_text">
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001565<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001566<pre> &lt;resultval&gt; = vaarg &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;<br></pre>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001567<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001568<p>The '<tt>vaarg</tt>' instruction is used to access arguments passed
1569through the "variable argument" area of a function call. It is used to
1570implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001571<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001572<p>This instruction takes a <tt>valist</tt> value and the type of the
1573argument. It returns a value of the specified argument type.</p>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001574<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001575<p>The '<tt>vaarg</tt>' instruction loads an argument of the specified
1576type from the specified <tt>va_list</tt>. In conjunction with the <a
1577 href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to
1578implement the <tt>va_arg</tt> macro available in C. For more
1579information, see the variable argument handling <a href="#int_varargs">Intrinsic
1580Functions</a>.</p>
1581<p>It is legal for this instruction to be called in a function which
1582does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001583function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001584<p><tt>vaarg</tt> is an LLVM instruction instead of an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001585 href="#intrinsics">intrinsic function</a> because it takes an type as
1586an argument.</p>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001587<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001588<p>See the <a href="#int_varargs">variable argument processing</a>
1589section.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001590</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001591
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001592<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00001593<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
1594<!-- *********************************************************************** -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001595
Misha Brukman9d0919f2003-11-08 01:05:38 +00001596<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001597<p>LLVM supports the notion of an "intrinsic function". These
1598functions have well known names and semantics, and are required to
1599follow certain restrictions. Overall, these instructions represent an
1600extension mechanism for the LLVM language that does not require
1601changing all of the transformations in LLVM to add to the language (or
1602the bytecode reader/writer, the parser, etc...).</p>
1603<p>Intrinsic function names must all start with an "<tt>llvm.</tt>"
1604prefix, this prefix is reserved in LLVM for intrinsic names, thus
1605functions may not be named this. Intrinsic functions must always be
1606external functions: you cannot define the body of intrinsic functions.
1607Intrinsic functions may only be used in call or invoke instructions: it
1608is illegal to take the address of an intrinsic function. Additionally,
1609because intrinsic functions are part of the LLVM language, it is
1610required that they all be documented here if any are added.</p>
1611<p>Unless an intrinsic function is target-specific, there must be a
1612lowering pass to eliminate the intrinsic or all backends must support
1613the intrinsic function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001614</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001615
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001616<!-- ======================================================================= -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001617<div class="doc_subsection">
1618 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
1619</div>
1620
Misha Brukman9d0919f2003-11-08 01:05:38 +00001621<div class="doc_text">
Misha Brukman9d0919f2003-11-08 01:05:38 +00001622<p>Variable argument support is defined in LLVM with the <a
Chris Lattner261efe92003-11-25 01:02:51 +00001623 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
1624intrinsic functions. These functions are related to the similarly
1625named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
1626<p>All of these functions operate on arguments that use a
1627target-specific value type "<tt>va_list</tt>". The LLVM assembly
1628language reference manual does not define what this type is, so all
1629transformations should be prepared to handle intrinsics with any type
1630used.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001631<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner261efe92003-11-25 01:02:51 +00001632instruction and the variable argument handling intrinsic functions are
1633used.</p>
1634<pre>int %test(int %X, ...) {<br> ; Initialize variable argument processing<br> %ap = call sbyte*()* %<a
1635 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
1636 href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2)<br> call void %<a
1637 href="#i_va_end">llvm.va_end</a>(sbyte* %aq)<br><br> ; Stop processing of arguments.<br> call void %<a
1638 href="#i_va_end">llvm.va_end</a>(sbyte* %ap2)<br> ret int %tmp<br>}<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001639</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001640
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001641<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001642<div class="doc_subsubsection">
1643 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
1644</div>
1645
1646
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 va_list ()* %llvm.va_start()<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001650<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001651<p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt>&lt;arglist&gt;</tt>
1652for subsequent use by the variable argument intrinsics.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001653<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001654<p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001655macro available in C. In a target-dependent way, it initializes and
1656returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt>
1657will produce the first variable argument passed to the function. Unlike
1658the C <tt>va_start</tt> macro, this intrinsic does not need to know the
1659last argument of the function, the compiler can figure that out.</p>
1660<p>Note that this intrinsic function is only legal to be called from
1661within the body of a variable argument function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001662</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001663
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001664<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001665<div class="doc_subsubsection">
1666 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
1667</div>
1668
Misha Brukman9d0919f2003-11-08 01:05:38 +00001669<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001670<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001671<pre> call void (va_list)* %llvm.va_end(va_list &lt;arglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001672<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001673<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
1674which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
1675or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001676<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001677<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001678<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001679<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001680macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
1681Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
1682 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
1683with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001684</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001685
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001686<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001687<div class="doc_subsubsection">
1688 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
1689</div>
1690
Misha Brukman9d0919f2003-11-08 01:05:38 +00001691<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001692<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001693<pre> call va_list (va_list)* %llvm.va_copy(va_list &lt;destarglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001694<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001695<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument
1696position from the source argument list to the destination argument list.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001697<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001698<p>The argument is the <tt>va_list</tt> to copy.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001699<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001700<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001701macro available in C. In a target-dependent way, it copies the source <tt>va_list</tt>
1702element into the returned list. This intrinsic is necessary because the <tt><a
1703 href="i_va_start">llvm.va_start</a></tt> intrinsic may be arbitrarily
1704complex and require memory allocation, for example.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001705</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001706
1707
1708<!-- ======================================================================= -->
1709<div class="doc_subsection">
1710 <a name="int_debugger">Debugger Intrinsics</a>
1711</div>
1712
1713<div class="doc_text">
1714<p>
1715The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
1716are described in the <a
1717href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
1718Debugging</a> document.
1719</p>
1720</div>
1721
1722
Chris Lattner00950542001-06-06 20:29:01 +00001723<!-- *********************************************************************** -->
Chris Lattner00950542001-06-06 20:29:01 +00001724<hr>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001725<div class="doc_footer">
Chris Lattner261efe92003-11-25 01:02:51 +00001726<address><a href="mailto:sabre@nondot.org">Chris Lattner</a></address>
1727<a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a> <br>
1728Last modified: $Date$ </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001729</body>
1730</html>