blob: 33afe7e7e3b080e84825ab76084849b31f30cd50 [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 Lattner33aec9e2004-02-12 17:01:32 +000098 <li><a href="#int_libc">Standard C Library Intrinsics</a>
99 <ol>
100 <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li>
Chris Lattner0eb51b42004-02-12 18:10:10 +0000101 <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000102 </ol>
103 </li>
Chris Lattner8ff75902004-01-06 05:31:32 +0000104 <li><a href="#int_debugger">Debugger intrinsics</a>
Chris Lattner261efe92003-11-25 01:02:51 +0000105 </ol>
106 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000107</ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000108<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000109<p><b>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
110and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></b></p>
111<p> </p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000112</div>
Chris Lattner00950542001-06-06 20:29:01 +0000113<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000114<div class="doc_section"> <a name="abstract">Abstract </a></div>
115<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000116<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000117<p>This document is a reference manual for the LLVM assembly language.
118LLVM is an SSA based representation that provides type safety,
119low-level operations, flexibility, and the capability of representing
120'all' high-level languages cleanly. It is the common code
121representation used throughout all phases of the LLVM compilation
122strategy.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000123</div>
Chris Lattner00950542001-06-06 20:29:01 +0000124<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000125<div class="doc_section"> <a name="introduction">Introduction</a> </div>
126<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000127<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000128<p>The LLVM code representation is designed to be used in three
129different forms: as an in-memory compiler IR, as an on-disk bytecode
130representation (suitable for fast loading by a Just-In-Time compiler),
131and as a human readable assembly language representation. This allows
132LLVM to provide a powerful intermediate representation for efficient
133compiler transformations and analysis, while providing a natural means
134to debug and visualize the transformations. The three different forms
135of LLVM are all equivalent. This document describes the human readable
136representation and notation.</p>
137<p>The LLVM representation aims to be a light-weight and low-level
138while being expressive, typed, and extensible at the same time. It
139aims to be a "universal IR" of sorts, by being at a low enough level
140that high-level ideas may be cleanly mapped to it (similar to how
141microprocessors are "universal IR's", allowing many source languages to
142be mapped to them). By providing type information, LLVM can be used as
143the target of optimizations: for example, through pointer analysis, it
144can be proven that a C automatic variable is never accessed outside of
145the current function... allowing it to be promoted to a simple SSA
146value instead of a memory location.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000147</div>
Chris Lattner00950542001-06-06 20:29:01 +0000148<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000149<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000150<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000151<p>It is important to note that this document describes 'well formed'
152LLVM assembly language. There is a difference between what the parser
153accepts and what is considered 'well formed'. For example, the
154following instruction is syntactically okay, but not well formed:</p>
155<pre> %x = <a href="#i_add">add</a> int 1, %x<br></pre>
156<p>...because the definition of <tt>%x</tt> does not dominate all of
157its uses. The LLVM infrastructure provides a verification pass that may
158be used to verify that an LLVM module is well formed. This pass is
159automatically run by the parser after parsing input assembly, and by
160the optimizer before it outputs bytecode. The violations pointed out
161by the verifier pass indicate bugs in transformation passes or input to
162the parser.</p>
163<!-- Describe the typesetting conventions here. --> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000164<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000165<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000166<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000167<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000168<p>LLVM uses three different forms of identifiers, for different
169purposes:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000170<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000171 <li>Numeric constants are represented as you would expect: 12, -3
172123.421, etc. Floating point constants have an optional hexidecimal
173notation.</li>
174 <li>Named values are represented as a string of characters with a '%'
175prefix. For example, %foo, %DivisionByZero,
176%a.really.long.identifier. The actual regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
177Identifiers which require other characters in their names can be
178surrounded with quotes. In this way, anything except a <tt>"</tt>
179character can be used in a name.</li>
180 <li>Unnamed values are represented as an unsigned numeric value with
181a '%' prefix. For example, %12, %2, %44.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000182</ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000183<p>LLVM requires the values start with a '%' sign for two reasons:
184Compilers don't need to worry about name clashes with reserved words,
185and the set of reserved words may be expanded in the future without
186penalty. Additionally, unnamed identifiers allow a compiler to quickly
187come up with a temporary variable without having to avoid symbol table
188conflicts.</p>
189<p>Reserved words in LLVM are very similar to reserved words in other
190languages. There are keywords for different opcodes ('<tt><a
191 href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
192 href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
193 href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>',
194etc...), and others. These reserved words cannot conflict with
195variable names, because none of them start with a '%' character.</p>
196<p>Here is an example of LLVM code to multiply the integer variable '<tt>%X</tt>'
197by 8:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000198<p>The easy way:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000199<pre> %result = <a href="#i_mul">mul</a> uint %X, 8<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000200<p>After strength reduction:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000201<pre> %result = <a href="#i_shl">shl</a> uint %X, ubyte 3<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000202<p>And the hard way:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000203<pre> <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
204 <a
205 href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
206 %result = <a
207 href="#i_add">add</a> uint %1, %1<br></pre>
208<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
209important lexical features of LLVM:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000210<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000211 <li>Comments are delimited with a '<tt>;</tt>' and go until the end
212of line.</li>
213 <li>Unnamed temporaries are created when the result of a computation
214is not assigned to a named value.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000215 <li>Unnamed temporaries are numbered sequentially</li>
216</ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000217<p>...and it also show a convention that we follow in this document.
218When demonstrating instructions, we will follow an instruction with a
219comment that defines the type and name of value produced. Comments are
220shown in italic text.</p>
221<p>The one non-intuitive notation for constants is the optional
222hexidecimal form of floating point constants. For example, the form '<tt>double
Chris Lattner2b7d3202002-05-06 03:03:22 +00002230x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
Chris Lattner261efe92003-11-25 01:02:51 +00002244.5e+15</tt>' which is also supported by the parser. The only time
225hexadecimal floating point constants are useful (and the only time that
226they are generated by the disassembler) is when an FP constant has to
227be emitted that is not representable as a decimal floating point number
228exactly. For example, NaN's, infinities, and other special cases are
229represented in their IEEE hexadecimal format so that assembly and
230disassembly do not cause any bits to change in the constants.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000231</div>
Chris Lattner00950542001-06-06 20:29:01 +0000232<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000233<div class="doc_section"> <a name="typesystem">Type System</a> </div>
234<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000235<div class="doc_text">
Misha Brukman9d0919f2003-11-08 01:05:38 +0000236<p>The LLVM type system is one of the most important features of the
Chris Lattner261efe92003-11-25 01:02:51 +0000237intermediate representation. Being typed enables a number of
238optimizations to be performed on the IR directly, without having to do
239extra analyses on the side before the transformation. A strong type
240system makes it easier to read the generated code and enables novel
241analyses and transformations that are not feasible to perform on normal
242three address code representations.</p>
Chris Lattner7bae3952002-06-25 18:03:17 +0000243<!-- The written form for the type system was heavily influenced by the
244syntactic problems with types in the C language<sup><a
Chris Lattner261efe92003-11-25 01:02:51 +0000245href="#rw_stroustrup">1</a></sup>.<p> --> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000246<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000247<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000248<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000249<p>The primitive types are the fundemental building blocks of the LLVM
250system. The current set of primitive types are as follows:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000251<p>
252<table border="0" align="center">
Chris Lattner261efe92003-11-25 01:02:51 +0000253 <tbody>
254 <tr>
255 <td>
256 <table border="1" cellspacing="0" cellpadding="4" align="center">
257 <tbody>
258 <tr>
259 <td><tt>void</tt></td>
260 <td>No value</td>
261 </tr>
262 <tr>
263 <td><tt>ubyte</tt></td>
264 <td>Unsigned 8 bit value</td>
265 </tr>
266 <tr>
267 <td><tt>ushort</tt></td>
268 <td>Unsigned 16 bit value</td>
269 </tr>
270 <tr>
271 <td><tt>uint</tt></td>
272 <td>Unsigned 32 bit value</td>
273 </tr>
274 <tr>
275 <td><tt>ulong</tt></td>
276 <td>Unsigned 64 bit value</td>
277 </tr>
278 <tr>
279 <td><tt>float</tt></td>
280 <td>32 bit floating point value</td>
281 </tr>
282 <tr>
283 <td><tt>label</tt></td>
284 <td>Branch destination</td>
285 </tr>
286 </tbody>
287 </table>
288 </td>
289 <td valign="top">
290 <table border="1" cellspacing="0" cellpadding="4" align="center&quot;">
291 <tbody>
292 <tr>
293 <td><tt>bool</tt></td>
294 <td>True or False value</td>
295 </tr>
296 <tr>
297 <td><tt>sbyte</tt></td>
298 <td>Signed 8 bit value</td>
299 </tr>
300 <tr>
301 <td><tt>short</tt></td>
302 <td>Signed 16 bit value</td>
303 </tr>
304 <tr>
305 <td><tt>int</tt></td>
306 <td>Signed 32 bit value</td>
307 </tr>
308 <tr>
309 <td><tt>long</tt></td>
310 <td>Signed 64 bit value</td>
311 </tr>
312 <tr>
313 <td><tt>double</tt></td>
314 <td>64 bit floating point value</td>
315 </tr>
316 </tbody>
317 </table>
318 </td>
319 </tr>
320 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000321</table>
322</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000323</div>
Chris Lattner00950542001-06-06 20:29:01 +0000324<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000325<div class="doc_subsubsection"> <a name="t_classifications">Type
326Classifications</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000327<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000328<p>These different primitive types fall into a few useful
329classifications:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000330<p>
331<table border="1" cellspacing="0" cellpadding="4" align="center">
Chris Lattner261efe92003-11-25 01:02:51 +0000332 <tbody>
333 <tr>
334 <td><a name="t_signed">signed</a></td>
335 <td><tt>sbyte, short, int, long, float, double</tt></td>
336 </tr>
337 <tr>
338 <td><a name="t_unsigned">unsigned</a></td>
339 <td><tt>ubyte, ushort, uint, ulong</tt></td>
340 </tr>
341 <tr>
342 <td><a name="t_integer">integer</a></td>
343 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
344 </tr>
345 <tr>
346 <td><a name="t_integral">integral</a></td>
347 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
348 </tr>
349 <tr>
350 <td><a name="t_floating">floating point</a></td>
351 <td><tt>float, double</tt></td>
352 </tr>
353 <tr>
354 <td><a name="t_firstclass">first class</a></td>
355 <td><tt>bool, ubyte, sbyte, ushort, short,<br>
356uint, int, ulong, long, float, double, <a href="#t_pointer">pointer</a></tt></td>
357 </tr>
358 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000359</table>
360</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000361<p>The <a href="#t_firstclass">first class</a> types are perhaps the
362most important. Values of these types are the only ones which can be
363produced by instructions, passed as arguments, or used as operands to
364instructions. This means that all structures and arrays must be
365manipulated either by pointer or by component.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000366</div>
Chris Lattner00950542001-06-06 20:29:01 +0000367<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000368<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000369<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000370<p>The real power in LLVM comes from the derived types in the system.
371This is what allows a programmer to represent arrays, functions,
372pointers, and other useful types. Note that these derived types may be
373recursive: For example, it is possible to have a two dimensional array.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000374</div>
Chris Lattner00950542001-06-06 20:29:01 +0000375<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000376<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000377<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000378<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000379<p>The array type is a very simple derived type that arranges elements
Chris Lattner261efe92003-11-25 01:02:51 +0000380sequentially in memory. The array type requires a size (number of
381elements) and an underlying data type.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000382<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000383<pre> [&lt;# elements&gt; x &lt;elementtype&gt;]<br></pre>
384<p>The number of elements is a constant integer value, elementtype may
385be any type with a size.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000386<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000387<p> <tt>[40 x int ]</tt>: Array of 40 integer values.<br>
388<tt>[41 x int ]</tt>: Array of 41 integer values.<br>
389<tt>[40 x uint]</tt>: Array of 40 unsigned integer values.</p>
390<p> </p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000391<p>Here are some examples of multidimensional arrays:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000392<p>
393<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000394 <tbody>
395 <tr>
396 <td><tt>[3 x [4 x int]]</tt></td>
397 <td>: 3x4 array integer values.</td>
398 </tr>
399 <tr>
400 <td><tt>[12 x [10 x float]]</tt></td>
401 <td>: 12x10 array of single precision floating point values.</td>
402 </tr>
403 <tr>
404 <td><tt>[2 x [3 x [4 x uint]]]</tt></td>
405 <td>: 2x3x4 array of unsigned integer values.</td>
406 </tr>
407 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000408</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000409</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000410</div>
Chris Lattner00950542001-06-06 20:29:01 +0000411<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000412<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000413<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000414<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000415<p>The function type can be thought of as a function signature. It
416consists of a return type and a list of formal parameter types.
John Criswell009900b2003-11-25 21:45:46 +0000417Function types are usually used to build virtual function tables
Chris Lattner261efe92003-11-25 01:02:51 +0000418(which are structures of pointers to functions), for indirect function
419calls, and when defining a function.</p>
John Criswell009900b2003-11-25 21:45:46 +0000420<p>
421The return type of a function type cannot be an aggregate type.
422</p>
Chris Lattner00950542001-06-06 20:29:01 +0000423<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000424<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
425<p>Where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of
426type specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner27f71f22003-09-03 00:41:47 +0000427which indicates that the function takes a variable number of arguments.
428Variable argument functions can access their arguments with the <a
Chris Lattner261efe92003-11-25 01:02:51 +0000429 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000430<h5>Examples:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000431<p>
432<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000433 <tbody>
434 <tr>
435 <td><tt>int (int)</tt></td>
436 <td>: function taking an <tt>int</tt>, returning an <tt>int</tt></td>
437 </tr>
438 <tr>
439 <td><tt>float (int, int *) *</tt></td>
440 <td>: <a href="#t_pointer">Pointer</a> to a function that takes
441an <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
442returning <tt>float</tt>.</td>
443 </tr>
444 <tr>
445 <td><tt>int (sbyte *, ...)</tt></td>
446 <td>: A vararg function that takes at least one <a
447 href="#t_pointer">pointer</a> to <tt>sbyte</tt> (signed char in C),
448which returns an integer. This is the signature for <tt>printf</tt>
449in LLVM.</td>
450 </tr>
451 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000452</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000453</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000454</div>
Chris Lattner00950542001-06-06 20:29:01 +0000455<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000456<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000457<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000458<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000459<p>The structure type is used to represent a collection of data members
460together in memory. The packing of the field types is defined to match
461the ABI of the underlying processor. The elements of a structure may
462be any type that has a size.</p>
463<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
464and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
465field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
466instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000467<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000468<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +0000469<h5>Examples:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000470<p>
471<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000472 <tbody>
473 <tr>
474 <td><tt>{ int, int, int }</tt></td>
475 <td>: a triple of three <tt>int</tt> values</td>
476 </tr>
477 <tr>
478 <td><tt>{ float, int (int) * }</tt></td>
479 <td>: A pair, where the first element is a <tt>float</tt> and the
480second element is a <a href="#t_pointer">pointer</a> to a <a
481 href="t_function">function</a> that takes an <tt>int</tt>, returning
482an <tt>int</tt>.</td>
483 </tr>
484 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000485</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000486</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000487</div>
Chris Lattner00950542001-06-06 20:29:01 +0000488<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000489<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000490<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +0000491<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000492<p>As in many languages, the pointer type represents a pointer or
493reference to another object, which must live in memory.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000494<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000495<pre> &lt;type&gt; *<br></pre>
Chris Lattner7faa8832002-04-14 06:13:44 +0000496<h5>Examples:</h5>
Chris Lattner7faa8832002-04-14 06:13:44 +0000497<p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000498<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000499 <tbody>
500 <tr>
501 <td><tt>[4x int]*</tt></td>
502 <td>: <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a>
503of four <tt>int</tt> values</td>
504 </tr>
505 <tr>
506 <td><tt>int (int *) *</tt></td>
507 <td>: A <a href="#t_pointer">pointer</a> to a <a
508 href="t_function">function</a> that takes an <tt>int</tt>, returning
509an <tt>int</tt>.</td>
510 </tr>
511 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000512</table>
513</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000514</div>
Chris Lattner261efe92003-11-25 01:02:51 +0000515<!-- _______________________________________________________________________ --><!--
Misha Brukman9d0919f2003-11-08 01:05:38 +0000516<div class="doc_subsubsection">
517 <a name="t_packed">Packed Type</a>
518</div>
519
520<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000521
522Mention/decide that packed types work with saturation or not. Maybe have a packed+saturated type in addition to just a packed type.<p>
523
524Packed types should be 'nonsaturated' because standard data types are not saturated. Maybe have a saturated packed type?<p>
525
Misha Brukman9d0919f2003-11-08 01:05:38 +0000526</div>
527
Chris Lattner261efe92003-11-25 01:02:51 +0000528--><!-- *********************************************************************** -->
529<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
530<!-- *********************************************************************** --><!-- ======================================================================= -->
531<div class="doc_subsection"> <a name="modulestructure">Module Structure</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000532<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000533<p>LLVM programs are composed of "Module"s, each of which is a
534translation unit of the input programs. Each module consists of
535functions, global variables, and symbol table entries. Modules may be
536combined together with the LLVM linker, which merges function (and
537global variable) definitions, resolves forward declarations, and merges
538symbol table entries. Here is an example of the "hello world" module:</p>
539<pre><i>; Declare the string constant as a global constant...</i>
540<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
541 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 +0000542
Chris Lattner27f71f22003-09-03 00:41:47 +0000543<i>; External declaration of the puts function</i>
544<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000545
546<i>; Definition of main function</i>
Chris Lattner27f71f22003-09-03 00:41:47 +0000547int %main() { <i>; int()* </i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000548 <i>; Convert [13x sbyte]* to sbyte *...</i>
Chris Lattner261efe92003-11-25 01:02:51 +0000549 %cast210 = <a
550 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000551
552 <i>; Call puts function to write out the string to stdout...</i>
Chris Lattner261efe92003-11-25 01:02:51 +0000553 <a
554 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
555 <a
556 href="#i_ret">ret</a> int 0<br>}<br></pre>
557<p>This example is made up of a <a href="#globalvars">global variable</a>
558named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
559function, and a <a href="#functionstructure">function definition</a>
560for "<tt>main</tt>".</p>
561<a name="linkage"> In general, a module is made up of a list of global
562values, where both functions and global variables are global values.
563Global values are represented by a pointer to a memory location (in
564this case, a pointer to an array of char, and a pointer to a function),
565and have one of the following linkage types:</a>
566<p> </p>
Chris Lattner27f71f22003-09-03 00:41:47 +0000567<dl>
Chris Lattner261efe92003-11-25 01:02:51 +0000568 <a name="linkage_internal"> <dt><tt><b>internal</b></tt> </dt>
569 <dd>Global values with internal linkage are only directly accessible
570by objects in the current module. In particular, linking code into a
571module with an internal global value may cause the internal to be
572renamed as necessary to avoid collisions. Because the symbol is
573internal to the module, all references can be updated. This
574corresponds to the notion of the '<tt>static</tt>' keyword in C, or the
575idea of "anonymous namespaces" in C++.
576 <p> </p>
577 </dd>
578 </a><a name="linkage_linkonce"> <dt><tt><b>linkonce</b></tt>: </dt>
579 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt>
580linkage, with the twist that linking together two modules defining the
581same <tt>linkonce</tt> globals will cause one of the globals to be
582discarded. This is typically used to implement inline functions.
583Unreferenced <tt>linkonce</tt> globals are allowed to be discarded.
584 <p> </p>
585 </dd>
586 </a><a name="linkage_weak"> <dt><tt><b>weak</b></tt>: </dt>
587 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt>
588linkage, except that unreferenced <tt>weak</tt> globals may not be
589discarded. This is used to implement constructs in C such as "<tt>int
590X;</tt>" at global scope.
591 <p> </p>
592 </dd>
593 </a><a name="linkage_appending"> <dt><tt><b>appending</b></tt>: </dt>
594 <dd>"<tt>appending</tt>" linkage may only be applied to global
595variables of pointer to array type. When two global variables with
596appending linkage are linked together, the two global arrays are
597appended together. This is the LLVM, typesafe, equivalent of having
598the system linker append together "sections" with identical names when
599.o files are linked.
600 <p> </p>
601 </dd>
602 </a><a name="linkage_external"> <dt><tt><b>externally visible</b></tt>:</dt>
603 <dd>If none of the above identifiers are used, the global is
604externally visible, meaning that it participates in linkage and can be
605used to resolve external symbol references.
606 <p> </p>
607 </dd>
608 </a>
609</dl>
610<p> </p>
611<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
612variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
613variable and was linked with this one, one of the two would be renamed,
614preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
615external (i.e., lacking any linkage declarations), they are accessible
616outside of the current module. It is illegal for a function <i>declaration</i>
617to have any linkage type other than "externally visible".</a></p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000618</div>
Chris Lattner00950542001-06-06 20:29:01 +0000619<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000620<div class="doc_subsection"> <a name="globalvars">Global Variables</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000621<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000622<p>Global variables define regions of memory allocated at compilation
623time instead of run-time. Global variables may optionally be
624initialized. A variable may be defined as a global "constant", which
625indicates that the contents of the variable will never be modified
626(opening options for optimization). Constants must always have an
627initial value.</p>
628<p>As SSA values, global variables define pointer values that are in
629scope (i.e. they dominate) for all basic blocks in the program. Global
630variables always define a pointer to their "content" type because they
631describe a region of memory, and all memory objects in LLVM are
632accessed through pointers.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000633</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000634<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000635<div class="doc_subsection"> <a name="functionstructure">Functions</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000636<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000637<p>LLVM function definitions are composed of a (possibly empty)
638argument list, an opening curly brace, a list of basic blocks, and a
639closing curly brace. LLVM function declarations are defined with the "<tt>declare</tt>"
640keyword, a function name, and a function signature.</p>
641<p>A function definition contains a list of basic blocks, forming the
642CFG for the function. Each basic block may optionally start with a
643label (giving the basic block a symbol table entry), contains a list of
644instructions, and ends with a <a href="#terminators">terminator</a>
645instruction (such as a branch or function return).</p>
646<p>The first basic block in program is special in two ways: it is
647immediately executed on entrance to the function, and it is not allowed
648to have predecessor basic blocks (i.e. there can not be any branches to
649the entry block of a function). Because the block can have no
650predecessors, it also cannot have any <a href="#i_phi">PHI nodes</a>.</p>
John Criswell009900b2003-11-25 21:45:46 +0000651<p>
652LLVM functions are identified by their name and type signature. Hence, two
653functions with the same name but different parameter lists or return values
654are considered different functions, and LLVM will resolves references to each
655appropriately.
656</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000657</div>
Chris Lattner00950542001-06-06 20:29:01 +0000658<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000659<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
660<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000661<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000662<p>The LLVM instruction set consists of several different
663classifications of instructions: <a href="#terminators">terminator
664instructions</a>, <a href="#binaryops">binary instructions</a>, <a
665 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
666instructions</a>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000667</div>
Chris Lattner00950542001-06-06 20:29:01 +0000668<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000669<div class="doc_subsection"> <a name="terminators">Terminator
670Instructions</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000671<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000672<p>As mentioned <a href="#functionstructure">previously</a>, every
673basic block in a program ends with a "Terminator" instruction, which
674indicates which block should be executed after the current block is
675finished. These terminator instructions typically yield a '<tt>void</tt>'
676value: they produce control flow, not values (the one exception being
677the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000678<p>There are five different terminator instructions: the '<a
Chris Lattner261efe92003-11-25 01:02:51 +0000679 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
680instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
681the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, and the '<a
682 href="#i_unwind"><tt>unwind</tt></a>' instruction.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000683</div>
Chris Lattner00950542001-06-06 20:29:01 +0000684<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000685<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
686Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000687<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000688<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000689<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 +0000690 ret void <i>; Return from void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000691</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000692<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000693<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
694value) from a function, back to the caller.</p>
695<p>There are two forms of the '<tt>ret</tt>' instructruction: one that
696returns a value and then causes control flow, and one that just causes
697control flow to occur.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000698<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000699<p>The '<tt>ret</tt>' instruction may return any '<a
700 href="#t_firstclass">first class</a>' type. Notice that a function is
701not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
702instruction inside of the function that returns a value that does not
703match the return type of the function.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000704<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000705<p>When the '<tt>ret</tt>' instruction is executed, control flow
706returns back to the calling function's context. If the caller is a "<a
707 href="#i_call"><tt>call</tt></a> instruction, execution continues at
708the instruction after the call. If the caller was an "<a
709 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
710at the beginning "normal" of the destination block. If the instruction
711returns a value, that value shall set the call or invoke instruction's
712return value.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000713<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000714<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner7faa8832002-04-14 06:13:44 +0000715 ret void <i>; Return from a void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000716</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000717</div>
Chris Lattner00950542001-06-06 20:29:01 +0000718<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000719<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000720<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000721<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000722<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 +0000723</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000724<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000725<p>The '<tt>br</tt>' instruction is used to cause control flow to
726transfer to a different basic block in the current function. There are
727two forms of this instruction, corresponding to a conditional branch
728and an unconditional branch.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000729<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000730<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
731single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
732unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
733value as a target.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000734<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000735<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
736argument is evaluated. If the value is <tt>true</tt>, control flows
737to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
738control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000739<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000740<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
741 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 +0000742</div>
Chris Lattner00950542001-06-06 20:29:01 +0000743<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000744<div class="doc_subsubsection"> <a name="i_switch">'<tt>switch</tt>'
745Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000746<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000747<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000748<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 +0000749<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000750<p>The '<tt>switch</tt>' instruction is used to transfer control flow
751to one of several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +0000752instruction, allowing a branch to occur to one of many possible
753destinations.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000754<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000755<p>The '<tt>switch</tt>' instruction uses three parameters: a '<tt>uint</tt>'
Chris Lattner261efe92003-11-25 01:02:51 +0000756comparison value '<tt>value</tt>', a default '<tt>label</tt>'
757destination, and an array of pairs of comparison value constants and '<tt>label</tt>'s.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000758<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000759<p>The <tt>switch</tt> instruction specifies a table of values and
760destinations. When the '<tt>switch</tt>' instruction is executed, this
761table is searched for the given value. If the value is found, the
762corresponding destination is branched to, otherwise the default value
763it transfered to.</p>
Chris Lattnerc29b1252003-05-08 05:08:48 +0000764<h5>Implementation:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000765<p>Depending on properties of the target machine and the particular <tt>switch</tt>
766instruction, this instruction may be code generated as a series of
767chained conditional branches, or with a lookup table.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000768<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000769<pre> <i>; Emulate a conditional br instruction</i>
770 %Val = <a
771 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 +0000772 switch uint 0, label %dest [ ]
Chris Lattner00950542001-06-06 20:29:01 +0000773
Chris Lattner2b7d3202002-05-06 03:03:22 +0000774 <i>; Implement a jump table:</i>
Chris Lattner27f71f22003-09-03 00:41:47 +0000775 switch uint %val, label %otherwise [ int 0, label %onzero,
776 int 1, label %onone,
777 int 2, label %ontwo ]
Chris Lattner00950542001-06-06 20:29:01 +0000778</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000779</div>
Chris Lattner00950542001-06-06 20:29:01 +0000780<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000781<div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>'
782Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000783<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000784<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000785<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 +0000786<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000787<p>The '<tt>invoke</tt>' instruction causes control to transfer to a
788specified function, with the possibility of control flow transfer to
789either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>.
790If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>"
791instruction, control flow will return to the "normal" label. If the
792callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
793instruction, control is interrupted, and continued at the dynamically
794nearest "except" label.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000795<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000796<p>This instruction requires several arguments:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000797<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000798 <li>'<tt>ptr to function ty</tt>': shall be the signature of the
799pointer to function value being invoked. In most cases, this is a
800direct function invocation, but indirect <tt>invoke</tt>s are just as
801possible, branching off an arbitrary pointer to function value. </li>
802 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer
803to a function to be invoked. </li>
804 <li>'<tt>function args</tt>': argument list whose types match the
805function signature argument types. If the function signature indicates
806the function accepts a variable number of arguments, the extra
807arguments can be specified. </li>
808 <li>'<tt>normal label</tt>': the label reached when the called
809function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
810 <li>'<tt>exception label</tt>': the label reached when a callee
811returns with the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
Chris Lattner00950542001-06-06 20:29:01 +0000812</ol>
Chris Lattner00950542001-06-06 20:29:01 +0000813<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000814<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner261efe92003-11-25 01:02:51 +0000815 href="#i_call">call</a></tt>' instruction in most regards. The
816primary difference is that it establishes an association with a label,
817which is used by the runtime library to unwind the stack.</p>
818<p>This instruction is used in languages with destructors to ensure
819that proper cleanup is performed in the case of either a <tt>longjmp</tt>
820or a thrown exception. Additionally, this is important for
821implementation of '<tt>catch</tt>' clauses in high-level languages that
822support them.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000823<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000824<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 +0000825</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000826</div>
Chris Lattner27f71f22003-09-03 00:41:47 +0000827<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000828<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
829Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000830<div class="doc_text">
Chris Lattner27f71f22003-09-03 00:41:47 +0000831<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000832<pre> unwind<br></pre>
Chris Lattner27f71f22003-09-03 00:41:47 +0000833<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000834<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing
835control flow at the first callee in the dynamic call stack which used
836an <a href="#i_invoke"><tt>invoke</tt></a> instruction to perform the
837call. This is primarily used to implement exception handling.</p>
Chris Lattner27f71f22003-09-03 00:41:47 +0000838<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000839<p>The '<tt>unwind</tt>' intrinsic causes execution of the current
840function to immediately halt. The dynamic call stack is then searched
841for the first <a href="#i_invoke"><tt>invoke</tt></a> instruction on
842the call stack. Once found, execution continues at the "exceptional"
843destination block specified by the <tt>invoke</tt> instruction. If
844there is no <tt>invoke</tt> instruction in the dynamic call chain,
845undefined behavior results.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000846</div>
Chris Lattner00950542001-06-06 20:29:01 +0000847<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000848<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000849<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000850<p>Binary operators are used to do most of the computation in a
851program. They require two operands, execute an operation on them, and
852produce a single value. The result value of a binary operator is not
853necessarily the same type as its operands.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000854<p>There are several different binary operators:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000855</div>
Chris Lattner00950542001-06-06 20:29:01 +0000856<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000857<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
858Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000859<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000860<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000861<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 +0000862</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000863<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000864<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000865<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000866<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +0000867 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
868values. Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000869<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000870<p>The value produced is the integer or floating point sum of the two
871operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000872<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000873<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner00950542001-06-06 20:29:01 +0000874</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000875</div>
Chris Lattner00950542001-06-06 20:29:01 +0000876<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000877<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
878Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000879<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000880<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000881<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 +0000882</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000883<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000884<p>The '<tt>sub</tt>' instruction returns the difference of its two
885operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000886<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
887instruction present in most other intermediate representations.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000888<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000889<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +0000890 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
891values. Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000892<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000893<p>The value produced is the integer or floating point difference of
894the two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000895<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000896<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner00950542001-06-06 20:29:01 +0000897 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
898</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000899</div>
Chris Lattner00950542001-06-06 20:29:01 +0000900<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000901<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
902Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000903<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000904<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000905<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 +0000906</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000907<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000908<p>The '<tt>mul</tt>' instruction returns the product of its two
909operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000910<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000911<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +0000912 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
913values. Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000914<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000915<p>The value produced is the integer or floating point product of the
Misha Brukman9d0919f2003-11-08 01:05:38 +0000916two operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000917<p>There is no signed vs unsigned multiplication. The appropriate
918action is taken based on the type of the operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000919<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000920<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner00950542001-06-06 20:29:01 +0000921</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000922</div>
Chris Lattner00950542001-06-06 20:29:01 +0000923<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000924<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
925Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000926<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000927<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000928<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
929</pre>
930<h5>Overview:</h5>
931<p>The '<tt>div</tt>' instruction returns the quotient of its two
932operands.</p>
933<h5>Arguments:</h5>
934<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
935 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
936values. Both arguments must have identical types.</p>
937<h5>Semantics:</h5>
938<p>The value produced is the integer or floating point quotient of the
939two operands.</p>
940<h5>Example:</h5>
941<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
942</pre>
943</div>
944<!-- _______________________________________________________________________ -->
945<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
946Instruction</a> </div>
947<div class="doc_text">
948<h5>Syntax:</h5>
949<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
950</pre>
951<h5>Overview:</h5>
952<p>The '<tt>rem</tt>' instruction returns the remainder from the
953division of its two operands.</p>
954<h5>Arguments:</h5>
955<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
956 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
957values. Both arguments must have identical types.</p>
958<h5>Semantics:</h5>
959<p>This returns the <i>remainder</i> of a division (where the result
960has the same sign as the divisor), not the <i>modulus</i> (where the
961result has the same sign as the dividend) of a value. For more
962information about the difference, see: <a
963 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
964Math Forum</a>.</p>
965<h5>Example:</h5>
966<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
967</pre>
968</div>
969<!-- _______________________________________________________________________ -->
970<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
971Instructions</a> </div>
972<div class="doc_text">
973<h5>Syntax:</h5>
974<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 +0000975 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
976 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
977 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
978 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
979 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
980</pre>
Chris Lattner261efe92003-11-25 01:02:51 +0000981<h5>Overview:</h5>
982<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
983value based on a comparison of their two operands.</p>
984<h5>Arguments:</h5>
985<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
986be of <a href="#t_firstclass">first class</a> type (it is not possible
987to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
988or '<tt>void</tt>' values, etc...). Both arguments must have identical
989types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000990<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000991<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
992value if both operands are equal.<br>
993The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
994value if both operands are unequal.<br>
995The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
996value if the first operand is less than the second operand.<br>
997The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
998value if the first operand is greater than the second operand.<br>
999The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1000value if the first operand is less than or equal to the second operand.<br>
1001The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1002value if the first operand is greater than or equal to the second
1003operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001004<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001005<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner00950542001-06-06 20:29:01 +00001006 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
1007 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1008 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1009 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1010 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1011</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001012</div>
Chris Lattner00950542001-06-06 20:29:01 +00001013<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001014<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1015Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001016<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001017<p>Bitwise binary operators are used to do various forms of
1018bit-twiddling in a program. They are generally very efficient
1019instructions, and can commonly be strength reduced from other
1020instructions. They require two operands, execute an operation on them,
1021and produce a single value. The resulting value of the bitwise binary
1022operators is always the same type as its first operand.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001023</div>
Chris Lattner00950542001-06-06 20:29:01 +00001024<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001025<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1026Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001027<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001028<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001029<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 +00001030</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001031<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001032<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1033its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001034<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001035<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001036 href="#t_integral">integral</a> values. Both arguments must have
1037identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001038<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001039<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001040<p> </p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001041<center>
1042<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +00001043 <tbody>
1044 <tr>
1045 <td>In0</td>
1046 <td>In1</td>
1047 <td>Out</td>
1048 </tr>
1049 <tr>
1050 <td>0</td>
1051 <td>0</td>
1052 <td>0</td>
1053 </tr>
1054 <tr>
1055 <td>0</td>
1056 <td>1</td>
1057 <td>0</td>
1058 </tr>
1059 <tr>
1060 <td>1</td>
1061 <td>0</td>
1062 <td>0</td>
1063 </tr>
1064 <tr>
1065 <td>1</td>
1066 <td>1</td>
1067 <td>1</td>
1068 </tr>
1069 </tbody>
1070</table>
1071</center>
Chris Lattner00950542001-06-06 20:29:01 +00001072<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001073<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001074 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1075 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1076</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001077</div>
Chris Lattner00950542001-06-06 20:29:01 +00001078<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001079<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001080<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001081<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001082<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 +00001083</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001084<h5>Overview:</h5>
1085<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1086or of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001087<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001088<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001089 href="#t_integral">integral</a> values. Both arguments must have
1090identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001091<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001092<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001093<p> </p>
1094<center>
1095<table border="1" cellspacing="0" cellpadding="4">
1096 <tbody>
1097 <tr>
1098 <td>In0</td>
1099 <td>In1</td>
1100 <td>Out</td>
1101 </tr>
1102 <tr>
1103 <td>0</td>
1104 <td>0</td>
1105 <td>0</td>
1106 </tr>
1107 <tr>
1108 <td>0</td>
1109 <td>1</td>
1110 <td>1</td>
1111 </tr>
1112 <tr>
1113 <td>1</td>
1114 <td>0</td>
1115 <td>1</td>
1116 </tr>
1117 <tr>
1118 <td>1</td>
1119 <td>1</td>
1120 <td>1</td>
1121 </tr>
1122 </tbody>
1123</table>
1124</center>
Chris Lattner00950542001-06-06 20:29:01 +00001125<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001126<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001127 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1128 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1129</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001130</div>
Chris Lattner00950542001-06-06 20:29:01 +00001131<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001132<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1133Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001134<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001135<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001136<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 +00001137</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001138<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001139<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1140or of its two operands. The <tt>xor</tt> is used to implement the
1141"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001142<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001143<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001144 href="#t_integral">integral</a> values. Both arguments must have
1145identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001146<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001147<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001148<p> </p>
1149<center>
1150<table border="1" cellspacing="0" cellpadding="4">
1151 <tbody>
1152 <tr>
1153 <td>In0</td>
1154 <td>In1</td>
1155 <td>Out</td>
1156 </tr>
1157 <tr>
1158 <td>0</td>
1159 <td>0</td>
1160 <td>0</td>
1161 </tr>
1162 <tr>
1163 <td>0</td>
1164 <td>1</td>
1165 <td>1</td>
1166 </tr>
1167 <tr>
1168 <td>1</td>
1169 <td>0</td>
1170 <td>1</td>
1171 </tr>
1172 <tr>
1173 <td>1</td>
1174 <td>1</td>
1175 <td>0</td>
1176 </tr>
1177 </tbody>
1178</table>
1179</center>
1180<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001181<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001182<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001183 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1184 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner27f71f22003-09-03 00:41:47 +00001185 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner00950542001-06-06 20:29:01 +00001186</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001187</div>
Chris Lattner00950542001-06-06 20:29:01 +00001188<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001189<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1190Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001191<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001192<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001193<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 +00001194</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001195<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001196<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1197the left a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001198<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001199<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001200 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1201type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001202<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001203<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001204<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001205<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 +00001206 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1207 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1208</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001209</div>
Chris Lattner00950542001-06-06 20:29:01 +00001210<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001211<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1212Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001213<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001214<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001215<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 +00001216</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001217<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001218<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1219the right a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001220<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001221<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001222 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1223type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001224<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001225<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1226most significant bit is duplicated in the newly free'd bit positions.
1227If the first argument is unsigned, zero bits shall fill the empty
1228positions.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001229<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001230<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 +00001231 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001232 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner8c6bb902003-06-18 21:30:51 +00001233 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1234 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner00950542001-06-06 20:29:01 +00001235</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001236</div>
Chris Lattner00950542001-06-06 20:29:01 +00001237<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001238<div class="doc_subsection"> <a name="memoryops">Memory Access
1239Operations</a></div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001240<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001241<p>A key design point of an SSA-based representation is how it
1242represents memory. In LLVM, no memory locations are in SSA form, which
1243makes things very simple. This section describes how to read, write,
1244allocate and free memory in LLVM.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001245</div>
Chris Lattner00950542001-06-06 20:29:01 +00001246<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001247<div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>'
1248Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001249<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001250<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001251<pre> &lt;result&gt; = malloc &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001252 &lt;result&gt; = malloc &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001253</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001254<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001255<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1256heap and returns a pointer to it.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001257<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001258<p>The the '<tt>malloc</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1259bytes of memory from the operating system, and returns a pointer of the
1260appropriate type to the program. The second form of the instruction is
1261a shorter version of the first instruction that defaults to allocating
1262one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001263<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001264<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001265<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1266a pointer is returned.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001267<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001268<pre> %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001269
Chris Lattner261efe92003-11-25 01:02:51 +00001270 %size = <a
1271 href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001272 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1273 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001274</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001275</div>
Chris Lattner00950542001-06-06 20:29:01 +00001276<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001277<div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>'
1278Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001279<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001280<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001281<pre> free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner00950542001-06-06 20:29:01 +00001282</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001283<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001284<p>The '<tt>free</tt>' instruction returns memory back to the unused
1285memory heap, to be reallocated in the future.</p>
1286<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001287<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001288<p>'<tt>value</tt>' shall be a pointer value that points to a value
1289that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1290instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001291<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001292<p>Access to the memory pointed to by the pointer is not longer defined
1293after this instruction executes.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001294<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001295<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 +00001296 free [4 x ubyte]* %array
1297</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001298</div>
Chris Lattner00950542001-06-06 20:29:01 +00001299<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001300<div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>'
1301Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001302<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001303<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001304<pre> &lt;result&gt; = alloca &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001305 &lt;result&gt; = alloca &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001306</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001307<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001308<p>The '<tt>alloca</tt>' instruction allocates memory on the current
1309stack frame of the procedure that is live until the current function
1310returns to its caller.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001311<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001312<p>The the '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1313bytes of memory on the runtime stack, returning a pointer of the
1314appropriate type to the program. The second form of the instruction is
1315a shorter version of the first that defaults to allocating one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001316<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001317<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001318<p>Memory is allocated, a pointer is returned. '<tt>alloca</tt>'d
1319memory is automatically released when the function returns. The '<tt>alloca</tt>'
1320instruction is commonly used to represent automatic variables that must
1321have an address available. When the function returns (either with the <tt><a
1322 href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001323instructions), the memory is reclaimed.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001324<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001325<pre> %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001326 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner00950542001-06-06 20:29:01 +00001327</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001328</div>
Chris Lattner00950542001-06-06 20:29:01 +00001329<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001330<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1331Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001332<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00001333<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001334<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 +00001335<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001336<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001337<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001338<p>The argument to the '<tt>load</tt>' instruction specifies the memory
1339address to load from. The pointer must point to a <a
1340 href="t_firstclass">first class</a> type. If the <tt>load</tt> is
1341marked as <tt>volatile</tt> then the optimizer is not allowed to modify
1342the number or order of execution of this <tt>load</tt> with other
1343volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1344instructions. </p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001345<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001346<p>The location of memory pointed to is loaded.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001347<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001348<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1349 <a
1350 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001351 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1352</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001353</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001354<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001355<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1356Instruction</a> </div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001357<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001358<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 +00001359 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 +00001360</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001361<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001362<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001363<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001364<p>There are two arguments to the '<tt>store</tt>' instruction: a value
1365to store and an address to store it into. The type of the '<tt>&lt;pointer&gt;</tt>'
1366operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
1367operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the
1368optimizer is not allowed to modify the number or order of execution of
1369this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1370 href="#i_store">store</a></tt> instructions.</p>
1371<h5>Semantics:</h5>
1372<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
1373at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001374<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001375<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1376 <a
1377 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001378 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1379</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001380<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001381<div class="doc_subsubsection"> <a name="i_getelementptr">'<tt>getelementptr</tt>'
1382Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001383<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00001384<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001385<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 +00001386<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001387<p>The '<tt>getelementptr</tt>' instruction is used to get the address
1388of a subelement of an aggregate data structure.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +00001389<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001390<p>This instruction takes a list of <tt>long</tt> values and <tt>ubyte</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001391constants that indicate what form of addressing to perform. The actual
1392types of the arguments provided depend on the type of the first pointer
1393argument. The '<tt>getelementptr</tt>' instruction is used to index
1394down through the type levels of a structure.</p>
1395<p>For example, let's consider a C code fragment and how it gets
1396compiled to LLVM:</p>
1397<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 +00001398<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001399<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 +00001400<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001401<p>The index types specified for the '<tt>getelementptr</tt>'
1402instruction depend on the pointer type that is being index into. <a
1403 href="t_pointer">Pointer</a> and <a href="t_array">array</a> types
1404require '<tt>long</tt>' values, and <a href="t_struct">structure</a>
1405types require '<tt>ubyte</tt>' <b>constants</b>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001406<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattner261efe92003-11-25 01:02:51 +00001407type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int,
1408double, %RT }</tt>' type, a structure. The second index indexes into
1409the third element of the structure, yielding a '<tt>%RT</tt>' = '<tt>{
1410sbyte, [10 x [20 x int]], sbyte }</tt>' type, another structure. The
1411third index indexes into the second element of the structure, yielding
1412a '<tt>[10 x [20 x int]]</tt>' type, an array. The two dimensions of
1413the array are subscripted into, yielding an '<tt>int</tt>' type. The '<tt>getelementptr</tt>'
1414instruction return a pointer to this element, thus yielding a '<tt>int*</tt>'
1415type.</p>
1416<p>Note that it is perfectly legal to index partially through a
1417structure, returning a pointer to an inner element. Because of this,
1418the LLVM code for the given testcase is equivalent to:</p>
1419<pre>int* "foo"(%ST* %s) {<br> %t1 = getelementptr %ST* %s , long 1 <i>; yields %ST*:%t1</i>
Chris Lattner3dfa10b2002-12-13 06:01:21 +00001420 %t2 = getelementptr %ST* %t1, long 0, ubyte 2 <i>; yields %RT*:%t2</i>
1421 %t3 = getelementptr %RT* %t2, long 0, ubyte 1 <i>; yields [10 x [20 x int]]*:%t3</i>
1422 %t4 = getelementptr [10 x [20 x int]]* %t3, long 0, long 5 <i>; yields [20 x int]*:%t4</i>
1423 %t5 = getelementptr [20 x int]* %t4, long 0, long 13 <i>; yields int*:%t5</i>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001424 ret int* %t5
1425}
1426</pre>
Chris Lattner7faa8832002-04-14 06:13:44 +00001427<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001428<pre> <i>; yields [12 x ubyte]*:aptr</i>
1429 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, ubyte 1<br></pre>
1430<h5>&nbsp;Note To The Novice:</h5>
1431When using indexing into global arrays with the '<tt>getelementptr</tt>'
1432instruction, you must remember that the&nbsp; </div>
Chris Lattner00950542001-06-06 20:29:01 +00001433<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001434<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001435<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001436<p>The instructions in this catagory are the "miscellaneous"
1437instructions, which defy better classification.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001438</div>
Chris Lattner00950542001-06-06 20:29:01 +00001439<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001440<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
1441Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001442<div class="doc_text">
Chris Lattner33ba0d92001-07-09 00:26:23 +00001443<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001444<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001445<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001446<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
1447the SSA graph representing the function.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001448<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001449<p>The type of the incoming values are specified with the first type
1450field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
1451as arguments, with one pair for each predecessor basic block of the
1452current block. Only values of <a href="#t_firstclass">first class</a>
1453type may be used as the value arguments to the PHI node. Only labels
1454may be used as the label arguments.</p>
1455<p>There must be no non-phi instructions between the start of a basic
1456block and the PHI instructions: i.e. PHI instructions must be first in
1457a basic block.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001458<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001459<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
1460value specified by the parameter, depending on which basic block we
1461came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001462<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001463<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 +00001464</div>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001465<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001466<div class="doc_subsubsection"> <a name="i_cast">'<tt>cast .. to</tt>'
1467Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001468<div class="doc_text">
Chris Lattner6536cfe2002-05-06 22:08:29 +00001469<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001470<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 +00001471</pre>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001472<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001473<p>The '<tt>cast</tt>' instruction is used as the primitive means to
1474convert integers to floating point, change data type sizes, and break
1475type safety (by casting pointers).</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001476<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001477<p>The '<tt>cast</tt>' instruction takes a value to cast, which must be
1478a first class value, and a type to cast it to, which must also be a <a
1479 href="#t_firstclass">first class</a> type.</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001480<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001481<p>This instruction follows the C rules for explicit casts when
1482determining how the data being cast must change to fit in its new
1483container.</p>
1484<p>When casting to bool, any value that would be considered true in the
1485context of a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +00001486values, all else are '<tt>false</tt>'.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001487<p>When extending an integral value from a type of one signness to
1488another (for example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value
1489is sign-extended if the <b>source</b> value is signed, and
1490zero-extended if the source value is unsigned. <tt>bool</tt> values
1491are always zero extended into either zero or one.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001492<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001493<pre> %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattner7bae3952002-06-25 18:03:17 +00001494 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001495</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001496</div>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001497<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001498<div class="doc_subsubsection"> <a name="i_call">'<tt>call</tt>'
1499Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001500<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001501<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001502<pre> &lt;result&gt; = call &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +00001503<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001504<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001505<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001506<p>This instruction requires several arguments:</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001507<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00001508 <li>
1509 <p>'<tt>ty</tt>': shall be the signature of the pointer to function
1510value being invoked. The argument types must match the types implied
1511by this signature.</p>
1512 </li>
1513 <li>
1514 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a
1515function to be invoked. In most cases, this is a direct function
1516invocation, but indirect <tt>call</tt>s are just as possible,
1517calling an arbitrary pointer to function values.</p>
1518 </li>
1519 <li>
1520 <p>'<tt>function args</tt>': argument list whose types match the
1521function signature argument types. If the function signature
1522indicates the function accepts a variable number of arguments, the
1523extra arguments can be specified.</p>
1524 </li>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001525</ol>
Chris Lattner00950542001-06-06 20:29:01 +00001526<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001527<p>The '<tt>call</tt>' instruction is used to cause control flow to
1528transfer to a specified function, with its incoming arguments bound to
1529the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
1530instruction in the called function, control flow continues with the
1531instruction after the function call, and the return value of the
1532function is bound to the result argument. This is a simpler case of
1533the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001534<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001535<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 +00001536</div>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001537<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001538<div class="doc_subsubsection"> <a name="i_vanext">'<tt>vanext</tt>'
1539Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001540<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001541<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001542<pre> &lt;resultarglist&gt; = vanext &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001543<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001544<p>The '<tt>vanext</tt>' instruction is used to access arguments passed
1545through the "variable argument" area of a function call. It is used to
1546implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001547<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001548<p>This instruction takes a <tt>valist</tt> value and the type of the
1549argument. It returns another <tt>valist</tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001550<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001551<p>The '<tt>vanext</tt>' instruction advances the specified <tt>valist</tt>
1552past an argument of the specified type. In conjunction with the <a
1553 href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement
1554the <tt>va_arg</tt> macro available in C. For more information, see
1555the variable argument handling <a href="#int_varargs">Intrinsic
1556Functions</a>.</p>
1557<p>It is legal for this instruction to be called in a function which
1558does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001559function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001560<p><tt>vanext</tt> is an LLVM instruction instead of an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001561 href="#intrinsics">intrinsic function</a> because it takes an type as
1562an argument.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001563<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001564<p>See the <a href="#int_varargs">variable argument processing</a>
1565section.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001566</div>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001567<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001568<div class="doc_subsubsection"> <a name="i_vaarg">'<tt>vaarg</tt>'
1569Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001570<div class="doc_text">
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001571<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001572<pre> &lt;resultval&gt; = vaarg &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;<br></pre>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001573<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001574<p>The '<tt>vaarg</tt>' instruction is used to access arguments passed
1575through the "variable argument" area of a function call. It is used to
1576implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001577<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001578<p>This instruction takes a <tt>valist</tt> value and the type of the
1579argument. It returns a value of the specified argument type.</p>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001580<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001581<p>The '<tt>vaarg</tt>' instruction loads an argument of the specified
1582type from the specified <tt>va_list</tt>. In conjunction with the <a
1583 href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to
1584implement the <tt>va_arg</tt> macro available in C. For more
1585information, see the variable argument handling <a href="#int_varargs">Intrinsic
1586Functions</a>.</p>
1587<p>It is legal for this instruction to be called in a function which
1588does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001589function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001590<p><tt>vaarg</tt> is an LLVM instruction instead of an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001591 href="#intrinsics">intrinsic function</a> because it takes an type as
1592an argument.</p>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001593<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001594<p>See the <a href="#int_varargs">variable argument processing</a>
1595section.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001596</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001597
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001598<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00001599<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
1600<!-- *********************************************************************** -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001601
Misha Brukman9d0919f2003-11-08 01:05:38 +00001602<div class="doc_text">
Chris Lattner33aec9e2004-02-12 17:01:32 +00001603
1604<p>LLVM supports the notion of an "intrinsic function". These functions have
1605well known names and semantics, and are required to follow certain
1606restrictions. Overall, these instructions represent an extension mechanism for
1607the LLVM language that does not require changing all of the transformations in
1608LLVM to add to the language (or the bytecode reader/writer, the parser,
1609etc...).</p>
1610
1611<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix, this
1612prefix is reserved in LLVM for intrinsic names, thus functions may not be named
1613this. Intrinsic functions must always be external functions: you cannot define
1614the body of intrinsic functions. Intrinsic functions may only be used in call
1615or invoke instructions: it is illegal to take the address of an intrinsic
1616function. Additionally, because intrinsic functions are part of the LLVM
1617language, it is required that they all be documented here if any are added.</p>
1618
1619
1620<p>
1621Adding an intrinsic to LLVM is straight-forward if it is possible to express the
1622concept in LLVM directly (ie, code generator support is not _required_). To do
1623this, extend the default implementation of the IntrinsicLowering class to handle
1624the intrinsic. Code generators use this class to lower intrinsics they do not
1625understand to raw LLVM instructions that they do.
1626</p>
1627
Misha Brukman9d0919f2003-11-08 01:05:38 +00001628</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001629
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001630<!-- ======================================================================= -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001631<div class="doc_subsection">
1632 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
1633</div>
1634
Misha Brukman9d0919f2003-11-08 01:05:38 +00001635<div class="doc_text">
Misha Brukman9d0919f2003-11-08 01:05:38 +00001636<p>Variable argument support is defined in LLVM with the <a
Chris Lattner261efe92003-11-25 01:02:51 +00001637 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
1638intrinsic functions. These functions are related to the similarly
1639named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
1640<p>All of these functions operate on arguments that use a
1641target-specific value type "<tt>va_list</tt>". The LLVM assembly
1642language reference manual does not define what this type is, so all
1643transformations should be prepared to handle intrinsics with any type
1644used.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001645<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner261efe92003-11-25 01:02:51 +00001646instruction and the variable argument handling intrinsic functions are
1647used.</p>
Chris Lattner33aec9e2004-02-12 17:01:32 +00001648<pre>
1649int %test(int %X, ...) {
1650 ; Initialize variable argument processing
1651 %ap = call sbyte* %<a href="#i_va_start">llvm.va_start</a>()
1652
1653 ; Read a single integer argument
1654 %tmp = vaarg sbyte* %ap, int
1655
1656 ; Advance to the next argument
1657 %ap2 = vanext sbyte* %ap, int
1658
1659 ; Demonstrate usage of llvm.va_copy and llvm.va_end
1660 %aq = call sbyte* %<a href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2)
1661 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %aq)
1662
1663 ; Stop processing of arguments.
1664 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %ap2)
1665 ret int %tmp
1666}
1667</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001668</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001669
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001670<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001671<div class="doc_subsubsection">
1672 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
1673</div>
1674
1675
Misha Brukman9d0919f2003-11-08 01:05:38 +00001676<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001677<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001678<pre> call va_list ()* %llvm.va_start()<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001679<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001680<p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt>&lt;arglist&gt;</tt>
1681for subsequent use by the variable argument intrinsics.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001682<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001683<p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001684macro available in C. In a target-dependent way, it initializes and
1685returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt>
1686will produce the first variable argument passed to the function. Unlike
1687the C <tt>va_start</tt> macro, this intrinsic does not need to know the
1688last argument of the function, the compiler can figure that out.</p>
1689<p>Note that this intrinsic function is only legal to be called from
1690within the body of a variable argument function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001691</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001692
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001693<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001694<div class="doc_subsubsection">
1695 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
1696</div>
1697
Misha Brukman9d0919f2003-11-08 01:05:38 +00001698<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001699<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001700<pre> call void (va_list)* %llvm.va_end(va_list &lt;arglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001701<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001702<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
1703which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
1704or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001705<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001706<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001707<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001708<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001709macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
1710Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
1711 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
1712with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001713</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001714
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001715<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001716<div class="doc_subsubsection">
1717 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
1718</div>
1719
Misha Brukman9d0919f2003-11-08 01:05:38 +00001720<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001721<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001722<pre> call va_list (va_list)* %llvm.va_copy(va_list &lt;destarglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001723<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001724<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument
1725position from the source argument list to the destination argument list.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001726<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001727<p>The argument is the <tt>va_list</tt> to copy.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001728<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001729<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001730macro available in C. In a target-dependent way, it copies the source <tt>va_list</tt>
1731element into the returned list. This intrinsic is necessary because the <tt><a
1732 href="i_va_start">llvm.va_start</a></tt> intrinsic may be arbitrarily
1733complex and require memory allocation, for example.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001734</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001735
Chris Lattner33aec9e2004-02-12 17:01:32 +00001736<!-- ======================================================================= -->
1737<div class="doc_subsection">
1738 <a name="int_libc">Standard C Library Intrinsics</a>
1739</div>
1740
1741<div class="doc_text">
1742<p>
1743
1744</p>
1745
1746</div>
1747
1748<!-- _______________________________________________________________________ -->
1749<div class="doc_subsubsection">
1750 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
1751</div>
1752
1753<div class="doc_text">
1754
1755<h5>Syntax:</h5>
1756<pre>
1757 call void (sbyte*, sbyte*, uint, uint)* %llvm.memcpy(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
1758 uint &lt;len&gt;, uint &lt;align&gt;)
1759</pre>
1760
1761<h5>Overview:</h5>
1762
1763<p>
1764The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
1765location to the destination location.
1766</p>
1767
1768<p>
1769Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
1770does not return a value, and takes an extra alignment argument.
1771</p>
1772
1773<h5>Arguments:</h5>
1774
1775<p>
1776The first argument is a pointer to the destination, the second is a pointer to
1777the source. The third argument is an (arbitrarily sized) integer argument
1778specifying the number of bytes to copy, and the fourth argument is the alignment
1779of the source and destination locations.
1780</p>
1781
Chris Lattner3301ced2004-02-12 21:18:15 +00001782<p>
1783If the call to this intrinisic has an alignment value that is not 0 or 1, then
1784the caller guarantees that the size of the copy is a multiple of the alignment
1785and that both the source and destination pointers are aligned to that boundary.
1786</p>
1787
Chris Lattner33aec9e2004-02-12 17:01:32 +00001788<h5>Semantics:</h5>
1789
1790<p>
1791The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
1792location to the destination location, which are not allowed to overlap. It
1793copies "len" bytes of memory over. If the argument is known to be aligned to
1794some boundary, this can be specified as the fourth argument, otherwise it should
1795be set to 0 or 1.
1796</p>
1797</div>
1798
1799
Chris Lattner0eb51b42004-02-12 18:10:10 +00001800<!-- _______________________________________________________________________ -->
1801<div class="doc_subsubsection">
1802 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
1803</div>
1804
1805<div class="doc_text">
1806
1807<h5>Syntax:</h5>
1808<pre>
1809 call void (sbyte*, sbyte*, uint, uint)* %llvm.memmove(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
1810 uint &lt;len&gt;, uint &lt;align&gt;)
1811</pre>
1812
1813<h5>Overview:</h5>
1814
1815<p>
1816The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
1817location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>'
1818intrinsic but allows the two memory locations to overlap.
1819</p>
1820
1821<p>
1822Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
1823does not return a value, and takes an extra alignment argument.
1824</p>
1825
1826<h5>Arguments:</h5>
1827
1828<p>
1829The first argument is a pointer to the destination, the second is a pointer to
1830the source. The third argument is an (arbitrarily sized) integer argument
1831specifying the number of bytes to copy, and the fourth argument is the alignment
1832of the source and destination locations.
1833</p>
1834
Chris Lattner3301ced2004-02-12 21:18:15 +00001835<p>
1836If the call to this intrinisic has an alignment value that is not 0 or 1, then
1837the caller guarantees that the size of the copy is a multiple of the alignment
1838and that both the source and destination pointers are aligned to that boundary.
1839</p>
1840
Chris Lattner0eb51b42004-02-12 18:10:10 +00001841<h5>Semantics:</h5>
1842
1843<p>
1844The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
1845location to the destination location, which may overlap. It
1846copies "len" bytes of memory over. If the argument is known to be aligned to
1847some boundary, this can be specified as the fourth argument, otherwise it should
1848be set to 0 or 1.
1849</p>
1850</div>
1851
Chris Lattner8ff75902004-01-06 05:31:32 +00001852
1853<!-- ======================================================================= -->
1854<div class="doc_subsection">
1855 <a name="int_debugger">Debugger Intrinsics</a>
1856</div>
1857
1858<div class="doc_text">
1859<p>
1860The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
1861are described in the <a
1862href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
1863Debugging</a> document.
1864</p>
1865</div>
1866
1867
Chris Lattner00950542001-06-06 20:29:01 +00001868<!-- *********************************************************************** -->
Chris Lattner00950542001-06-06 20:29:01 +00001869<hr>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001870<div class="doc_footer">
Chris Lattner261efe92003-11-25 01:02:51 +00001871<address><a href="mailto:sabre@nondot.org">Chris Lattner</a></address>
1872<a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a> <br>
1873Last modified: $Date$ </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001874</body>
1875</html>