blob: e6cd7947a24d018360e8f31743f2868c9c95f4c4 [file] [log] [blame]
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
Misha Brukman9d0919f2003-11-08 01:05:38 +00003<html>
4<head>
5 <title>LLVM Assembly Language Reference Manual</title>
6 <link rel="stylesheet" href="llvm.css" type="text/css">
7</head>
8<body>
Chris Lattner261efe92003-11-25 01:02:51 +00009<div class="doc_title"> LLVM Language Reference Manual </div>
Chris Lattner00950542001-06-06 20:29:01 +000010<ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000011 <li><a href="#abstract">Abstract</a></li>
12 <li><a href="#introduction">Introduction</a></li>
13 <li><a href="#identifiers">Identifiers</a></li>
Chris Lattner00950542001-06-06 20:29:01 +000014 <li><a href="#typesystem">Type System</a>
15 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000016 <li><a href="#t_primitive">Primitive Types</a>
17 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000018 <li><a href="#t_classifications">Type Classifications</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000019 </ol>
20 </li>
Chris Lattner00950542001-06-06 20:29:01 +000021 <li><a href="#t_derived">Derived Types</a>
22 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000023 <li><a href="#t_array">Array Type</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000024 <li><a href="#t_function">Function Type</a></li>
25 <li><a href="#t_pointer">Pointer Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000026 <li><a href="#t_struct">Structure Type</a></li>
27<!-- <li><a href="#t_packed" >Packed Type</a> -->
28 </ol>
29 </li>
30 </ol>
31 </li>
Chris Lattner00950542001-06-06 20:29:01 +000032 <li><a href="#highlevel">High Level Structure</a>
33 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000034 <li><a href="#modulestructure">Module Structure</a></li>
35 <li><a href="#globalvars">Global Variables</a></li>
36 <li><a href="#functionstructure">Function Structure</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000037 </ol>
38 </li>
Chris Lattner00950542001-06-06 20:29:01 +000039 <li><a href="#instref">Instruction Reference</a>
40 <ol>
41 <li><a href="#terminators">Terminator Instructions</a>
42 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000043 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
44 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000045 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
46 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000047 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
48 </ol>
49 </li>
Chris Lattner00950542001-06-06 20:29:01 +000050 <li><a href="#binaryops">Binary Operations</a>
51 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000052 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
53 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
54 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
55 <li><a href="#i_div">'<tt>div</tt>' Instruction</a></li>
56 <li><a href="#i_rem">'<tt>rem</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000057 <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000058 </ol>
59 </li>
Chris Lattner00950542001-06-06 20:29:01 +000060 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
61 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000062 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000063 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000064 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
65 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
66 <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000067 </ol>
68 </li>
Chris Lattner00950542001-06-06 20:29:01 +000069 <li><a href="#memoryops">Memory Access Operations</a>
70 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000071 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
72 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
73 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
74 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
75 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
76 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
77 </ol>
78 </li>
Chris Lattner00950542001-06-06 20:29:01 +000079 <li><a href="#otherops">Other Operations</a>
80 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000081 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000082 <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li>
Chris Lattnercc37aae2004-03-12 05:50:16 +000083 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000084 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000085 <li><a href="#i_vanext">'<tt>vanext</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000086 <li><a href="#i_vaarg">'<tt>vaarg</tt>' Instruction</a></li>
Chris Lattner00950542001-06-06 20:29:01 +000087 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +000088 </li>
Chris Lattner00950542001-06-06 20:29:01 +000089 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +000090 </li>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +000091 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +000092 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000093 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
94 <ol>
95 <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
96 <li><a href="#i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
97 <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
98 </ol>
99 </li>
Chris Lattner10610642004-02-14 04:08:35 +0000100 <li><a href="#int_codegen">Code Generator Intrinsics</a>
101 <ol>
102 <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
103 <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
John Criswellcfd3bac2004-04-09 15:23:37 +0000104 <li><a href="#i_readport">'<tt>llvm.readport</tt>' Intrinsic</a></li>
105 <li><a href="#i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000106 </ol>
107 </li>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000108 <li><a href="#int_libc">Standard C Library Intrinsics</a>
109 <ol>
110 <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li>
Chris Lattner0eb51b42004-02-12 18:10:10 +0000111 <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000112 <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000113 </ol>
114 </li>
Chris Lattner8ff75902004-01-06 05:31:32 +0000115 <li><a href="#int_debugger">Debugger intrinsics</a>
Chris Lattner261efe92003-11-25 01:02:51 +0000116 </ol>
117 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000118</ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000119<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000120<p><b>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
121and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></b></p>
122<p> </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="abstract">Abstract </a></div>
126<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000127<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000128<p>This document is a reference manual for the LLVM assembly language.
129LLVM is an SSA based representation that provides type safety,
130low-level operations, flexibility, and the capability of representing
131'all' high-level languages cleanly. It is the common code
132representation used throughout all phases of the LLVM compilation
133strategy.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000134</div>
Chris Lattner00950542001-06-06 20:29:01 +0000135<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000136<div class="doc_section"> <a name="introduction">Introduction</a> </div>
137<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000138<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000139<p>The LLVM code representation is designed to be used in three
140different forms: as an in-memory compiler IR, as an on-disk bytecode
141representation (suitable for fast loading by a Just-In-Time compiler),
142and as a human readable assembly language representation. This allows
143LLVM to provide a powerful intermediate representation for efficient
144compiler transformations and analysis, while providing a natural means
145to debug and visualize the transformations. The three different forms
146of LLVM are all equivalent. This document describes the human readable
147representation and notation.</p>
148<p>The LLVM representation aims to be a light-weight and low-level
149while being expressive, typed, and extensible at the same time. It
150aims to be a "universal IR" of sorts, by being at a low enough level
151that high-level ideas may be cleanly mapped to it (similar to how
152microprocessors are "universal IR's", allowing many source languages to
153be mapped to them). By providing type information, LLVM can be used as
154the target of optimizations: for example, through pointer analysis, it
155can be proven that a C automatic variable is never accessed outside of
156the current function... allowing it to be promoted to a simple SSA
157value instead of a memory location.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000158</div>
Chris Lattner00950542001-06-06 20:29:01 +0000159<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000160<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000161<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000162<p>It is important to note that this document describes 'well formed'
163LLVM assembly language. There is a difference between what the parser
164accepts and what is considered 'well formed'. For example, the
165following instruction is syntactically okay, but not well formed:</p>
166<pre> %x = <a href="#i_add">add</a> int 1, %x<br></pre>
167<p>...because the definition of <tt>%x</tt> does not dominate all of
168its uses. The LLVM infrastructure provides a verification pass that may
169be used to verify that an LLVM module is well formed. This pass is
170automatically run by the parser after parsing input assembly, and by
171the optimizer before it outputs bytecode. The violations pointed out
172by the verifier pass indicate bugs in transformation passes or input to
173the parser.</p>
174<!-- Describe the typesetting conventions here. --> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000175<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000176<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000177<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000178<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000179<p>LLVM uses three different forms of identifiers, for different
180purposes:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000181<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000182 <li>Numeric constants are represented as you would expect: 12, -3
183123.421, etc. Floating point constants have an optional hexidecimal
184notation.</li>
185 <li>Named values are represented as a string of characters with a '%'
186prefix. For example, %foo, %DivisionByZero,
187%a.really.long.identifier. The actual regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
188Identifiers which require other characters in their names can be
189surrounded with quotes. In this way, anything except a <tt>"</tt>
190character can be used in a name.</li>
191 <li>Unnamed values are represented as an unsigned numeric value with
192a '%' prefix. For example, %12, %2, %44.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000193</ol>
John Criswell6794d922004-03-12 21:19:06 +0000194<p>LLVM requires that values start with a '%' sign for two reasons:
Chris Lattner261efe92003-11-25 01:02:51 +0000195Compilers don't need to worry about name clashes with reserved words,
196and the set of reserved words may be expanded in the future without
197penalty. Additionally, unnamed identifiers allow a compiler to quickly
198come up with a temporary variable without having to avoid symbol table
199conflicts.</p>
200<p>Reserved words in LLVM are very similar to reserved words in other
201languages. There are keywords for different opcodes ('<tt><a
202 href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
203 href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
204 href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>',
205etc...), and others. These reserved words cannot conflict with
206variable names, because none of them start with a '%' character.</p>
207<p>Here is an example of LLVM code to multiply the integer variable '<tt>%X</tt>'
208by 8:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000209<p>The easy way:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000210<pre> %result = <a href="#i_mul">mul</a> uint %X, 8<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000211<p>After strength reduction:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000212<pre> %result = <a href="#i_shl">shl</a> uint %X, ubyte 3<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000213<p>And the hard way:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000214<pre> <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
215 <a
216 href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
217 %result = <a
218 href="#i_add">add</a> uint %1, %1<br></pre>
219<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
220important lexical features of LLVM:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000221<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000222 <li>Comments are delimited with a '<tt>;</tt>' and go until the end
223of line.</li>
224 <li>Unnamed temporaries are created when the result of a computation
225is not assigned to a named value.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000226 <li>Unnamed temporaries are numbered sequentially</li>
227</ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000228<p>...and it also show a convention that we follow in this document.
229When demonstrating instructions, we will follow an instruction with a
230comment that defines the type and name of value produced. Comments are
231shown in italic text.</p>
232<p>The one non-intuitive notation for constants is the optional
233hexidecimal form of floating point constants. For example, the form '<tt>double
Chris Lattner2b7d3202002-05-06 03:03:22 +00002340x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
Chris Lattner261efe92003-11-25 01:02:51 +00002354.5e+15</tt>' which is also supported by the parser. The only time
236hexadecimal floating point constants are useful (and the only time that
237they are generated by the disassembler) is when an FP constant has to
238be emitted that is not representable as a decimal floating point number
239exactly. For example, NaN's, infinities, and other special cases are
240represented in their IEEE hexadecimal format so that assembly and
241disassembly do not cause any bits to change in the constants.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000242</div>
Chris Lattner00950542001-06-06 20:29:01 +0000243<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000244<div class="doc_section"> <a name="typesystem">Type System</a> </div>
245<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000246<div class="doc_text">
Misha Brukman9d0919f2003-11-08 01:05:38 +0000247<p>The LLVM type system is one of the most important features of the
Chris Lattner261efe92003-11-25 01:02:51 +0000248intermediate representation. Being typed enables a number of
249optimizations to be performed on the IR directly, without having to do
250extra analyses on the side before the transformation. A strong type
251system makes it easier to read the generated code and enables novel
252analyses and transformations that are not feasible to perform on normal
253three address code representations.</p>
Chris Lattner7bae3952002-06-25 18:03:17 +0000254<!-- The written form for the type system was heavily influenced by the
255syntactic problems with types in the C language<sup><a
Chris Lattner261efe92003-11-25 01:02:51 +0000256href="#rw_stroustrup">1</a></sup>.<p> --> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000257<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000258<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000259<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000260<p>The primitive types are the fundemental building blocks of the LLVM
261system. The current set of primitive types are as follows:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000262
263<table border="0" style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +0000264 <tbody>
265 <tr>
266 <td>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000267 <table border="1" cellspacing="0" cellpadding="4" style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +0000268 <tbody>
269 <tr>
270 <td><tt>void</tt></td>
271 <td>No value</td>
272 </tr>
273 <tr>
274 <td><tt>ubyte</tt></td>
275 <td>Unsigned 8 bit value</td>
276 </tr>
277 <tr>
278 <td><tt>ushort</tt></td>
279 <td>Unsigned 16 bit value</td>
280 </tr>
281 <tr>
282 <td><tt>uint</tt></td>
283 <td>Unsigned 32 bit value</td>
284 </tr>
285 <tr>
286 <td><tt>ulong</tt></td>
287 <td>Unsigned 64 bit value</td>
288 </tr>
289 <tr>
290 <td><tt>float</tt></td>
291 <td>32 bit floating point value</td>
292 </tr>
293 <tr>
294 <td><tt>label</tt></td>
295 <td>Branch destination</td>
296 </tr>
297 </tbody>
298 </table>
299 </td>
300 <td valign="top">
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000301 <table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +0000302 <tbody>
303 <tr>
304 <td><tt>bool</tt></td>
305 <td>True or False value</td>
306 </tr>
307 <tr>
308 <td><tt>sbyte</tt></td>
309 <td>Signed 8 bit value</td>
310 </tr>
311 <tr>
312 <td><tt>short</tt></td>
313 <td>Signed 16 bit value</td>
314 </tr>
315 <tr>
316 <td><tt>int</tt></td>
317 <td>Signed 32 bit value</td>
318 </tr>
319 <tr>
320 <td><tt>long</tt></td>
321 <td>Signed 64 bit value</td>
322 </tr>
323 <tr>
324 <td><tt>double</tt></td>
325 <td>64 bit floating point value</td>
326 </tr>
327 </tbody>
328 </table>
329 </td>
330 </tr>
331 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000332</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000333
Misha Brukman9d0919f2003-11-08 01:05:38 +0000334</div>
Chris Lattner00950542001-06-06 20:29:01 +0000335<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000336<div class="doc_subsubsection"> <a name="t_classifications">Type
337Classifications</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000338<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000339<p>These different primitive types fall into a few useful
340classifications:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000341
342<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +0000343 <tbody>
344 <tr>
345 <td><a name="t_signed">signed</a></td>
346 <td><tt>sbyte, short, int, long, float, double</tt></td>
347 </tr>
348 <tr>
349 <td><a name="t_unsigned">unsigned</a></td>
350 <td><tt>ubyte, ushort, uint, ulong</tt></td>
351 </tr>
352 <tr>
353 <td><a name="t_integer">integer</a></td>
354 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
355 </tr>
356 <tr>
357 <td><a name="t_integral">integral</a></td>
358 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
359 </tr>
360 <tr>
361 <td><a name="t_floating">floating point</a></td>
362 <td><tt>float, double</tt></td>
363 </tr>
364 <tr>
365 <td><a name="t_firstclass">first class</a></td>
366 <td><tt>bool, ubyte, sbyte, ushort, short,<br>
367uint, int, ulong, long, float, double, <a href="#t_pointer">pointer</a></tt></td>
368 </tr>
369 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000370</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000371
Chris Lattner261efe92003-11-25 01:02:51 +0000372<p>The <a href="#t_firstclass">first class</a> types are perhaps the
373most important. Values of these types are the only ones which can be
374produced by instructions, passed as arguments, or used as operands to
375instructions. This means that all structures and arrays must be
376manipulated either by pointer or by component.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000377</div>
Chris Lattner00950542001-06-06 20:29:01 +0000378<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000379<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000380<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000381<p>The real power in LLVM comes from the derived types in the system.
382This is what allows a programmer to represent arrays, functions,
383pointers, and other useful types. Note that these derived types may be
384recursive: For example, it is possible to have a two dimensional array.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000385</div>
Chris Lattner00950542001-06-06 20:29:01 +0000386<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000387<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000388<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000389<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000390<p>The array type is a very simple derived type that arranges elements
Chris Lattner261efe92003-11-25 01:02:51 +0000391sequentially in memory. The array type requires a size (number of
392elements) and an underlying data type.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000393<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000394<pre> [&lt;# elements&gt; x &lt;elementtype&gt;]<br></pre>
395<p>The number of elements is a constant integer value, elementtype may
396be any type with a size.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000397<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000398<p> <tt>[40 x int ]</tt>: Array of 40 integer values.<br>
399<tt>[41 x int ]</tt>: Array of 41 integer values.<br>
400<tt>[40 x uint]</tt>: Array of 40 unsigned integer values.</p>
401<p> </p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000402<p>Here are some examples of multidimensional arrays:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000403
Misha Brukman9d0919f2003-11-08 01:05:38 +0000404<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000405 <tbody>
406 <tr>
407 <td><tt>[3 x [4 x int]]</tt></td>
408 <td>: 3x4 array integer values.</td>
409 </tr>
410 <tr>
411 <td><tt>[12 x [10 x float]]</tt></td>
412 <td>: 12x10 array of single precision floating point values.</td>
413 </tr>
414 <tr>
415 <td><tt>[2 x [3 x [4 x uint]]]</tt></td>
416 <td>: 2x3x4 array of unsigned integer values.</td>
417 </tr>
418 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000419</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000420
Misha Brukman9d0919f2003-11-08 01:05:38 +0000421</div>
Chris Lattner00950542001-06-06 20:29:01 +0000422<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000423<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000424<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000425<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000426<p>The function type can be thought of as a function signature. It
427consists of a return type and a list of formal parameter types.
John Criswell009900b2003-11-25 21:45:46 +0000428Function types are usually used to build virtual function tables
Chris Lattner261efe92003-11-25 01:02:51 +0000429(which are structures of pointers to functions), for indirect function
430calls, and when defining a function.</p>
John Criswell009900b2003-11-25 21:45:46 +0000431<p>
432The return type of a function type cannot be an aggregate type.
433</p>
Chris Lattner00950542001-06-06 20:29:01 +0000434<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000435<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
436<p>Where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of
437type specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner27f71f22003-09-03 00:41:47 +0000438which indicates that the function takes a variable number of arguments.
439Variable argument functions can access their arguments with the <a
Chris Lattner261efe92003-11-25 01:02:51 +0000440 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000441<h5>Examples:</h5>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000442
Misha Brukman9d0919f2003-11-08 01:05:38 +0000443<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000444 <tbody>
445 <tr>
446 <td><tt>int (int)</tt></td>
447 <td>: function taking an <tt>int</tt>, returning an <tt>int</tt></td>
448 </tr>
449 <tr>
450 <td><tt>float (int, int *) *</tt></td>
451 <td>: <a href="#t_pointer">Pointer</a> to a function that takes
452an <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
453returning <tt>float</tt>.</td>
454 </tr>
455 <tr>
456 <td><tt>int (sbyte *, ...)</tt></td>
457 <td>: A vararg function that takes at least one <a
458 href="#t_pointer">pointer</a> to <tt>sbyte</tt> (signed char in C),
459which returns an integer. This is the signature for <tt>printf</tt>
460in LLVM.</td>
461 </tr>
462 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000463</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000464
Misha Brukman9d0919f2003-11-08 01:05:38 +0000465</div>
Chris Lattner00950542001-06-06 20:29:01 +0000466<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000467<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000468<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000469<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000470<p>The structure type is used to represent a collection of data members
471together in memory. The packing of the field types is defined to match
472the ABI of the underlying processor. The elements of a structure may
473be any type that has a size.</p>
474<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
475and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
476field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
477instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000478<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000479<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +0000480<h5>Examples:</h5>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000481
Misha Brukman9d0919f2003-11-08 01:05:38 +0000482<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000483 <tbody>
484 <tr>
485 <td><tt>{ int, int, int }</tt></td>
486 <td>: a triple of three <tt>int</tt> values</td>
487 </tr>
488 <tr>
489 <td><tt>{ float, int (int) * }</tt></td>
490 <td>: A pair, where the first element is a <tt>float</tt> and the
491second element is a <a href="#t_pointer">pointer</a> to a <a
492 href="t_function">function</a> that takes an <tt>int</tt>, returning
493an <tt>int</tt>.</td>
494 </tr>
495 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000496</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000497
Misha Brukman9d0919f2003-11-08 01:05:38 +0000498</div>
Chris Lattner00950542001-06-06 20:29:01 +0000499<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000500<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000501<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +0000502<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000503<p>As in many languages, the pointer type represents a pointer or
504reference to another object, which must live in memory.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000505<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000506<pre> &lt;type&gt; *<br></pre>
Chris Lattner7faa8832002-04-14 06:13:44 +0000507<h5>Examples:</h5>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000508
Misha Brukman9d0919f2003-11-08 01:05:38 +0000509<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000510 <tbody>
511 <tr>
512 <td><tt>[4x int]*</tt></td>
513 <td>: <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a>
514of four <tt>int</tt> values</td>
515 </tr>
516 <tr>
517 <td><tt>int (int *) *</tt></td>
518 <td>: A <a href="#t_pointer">pointer</a> to a <a
519 href="t_function">function</a> that takes an <tt>int</tt>, returning
520an <tt>int</tt>.</td>
521 </tr>
522 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000523</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000524
Misha Brukman9d0919f2003-11-08 01:05:38 +0000525</div>
Chris Lattner261efe92003-11-25 01:02:51 +0000526<!-- _______________________________________________________________________ --><!--
Misha Brukman9d0919f2003-11-08 01:05:38 +0000527<div class="doc_subsubsection">
528 <a name="t_packed">Packed Type</a>
529</div>
530
531<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000532
533Mention/decide that packed types work with saturation or not. Maybe have a packed+saturated type in addition to just a packed type.<p>
534
535Packed types should be 'nonsaturated' because standard data types are not saturated. Maybe have a saturated packed type?<p>
536
Misha Brukman9d0919f2003-11-08 01:05:38 +0000537</div>
538
Chris Lattner261efe92003-11-25 01:02:51 +0000539--><!-- *********************************************************************** -->
540<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
541<!-- *********************************************************************** --><!-- ======================================================================= -->
542<div class="doc_subsection"> <a name="modulestructure">Module Structure</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000543<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000544<p>LLVM programs are composed of "Module"s, each of which is a
545translation unit of the input programs. Each module consists of
546functions, global variables, and symbol table entries. Modules may be
547combined together with the LLVM linker, which merges function (and
548global variable) definitions, resolves forward declarations, and merges
549symbol table entries. Here is an example of the "hello world" module:</p>
550<pre><i>; Declare the string constant as a global constant...</i>
551<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
552 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 +0000553
Chris Lattner27f71f22003-09-03 00:41:47 +0000554<i>; External declaration of the puts function</i>
555<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000556
557<i>; Definition of main function</i>
Chris Lattner27f71f22003-09-03 00:41:47 +0000558int %main() { <i>; int()* </i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000559 <i>; Convert [13x sbyte]* to sbyte *...</i>
Chris Lattner261efe92003-11-25 01:02:51 +0000560 %cast210 = <a
561 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000562
563 <i>; Call puts function to write out the string to stdout...</i>
Chris Lattner261efe92003-11-25 01:02:51 +0000564 <a
565 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
566 <a
567 href="#i_ret">ret</a> int 0<br>}<br></pre>
568<p>This example is made up of a <a href="#globalvars">global variable</a>
569named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
570function, and a <a href="#functionstructure">function definition</a>
571for "<tt>main</tt>".</p>
572<a name="linkage"> In general, a module is made up of a list of global
573values, where both functions and global variables are global values.
574Global values are represented by a pointer to a memory location (in
575this case, a pointer to an array of char, and a pointer to a function),
576and have one of the following linkage types:</a>
577<p> </p>
Chris Lattner27f71f22003-09-03 00:41:47 +0000578<dl>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000579 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000580 <dd>Global values with internal linkage are only directly accessible
581by objects in the current module. In particular, linking code into a
582module with an internal global value may cause the internal to be
583renamed as necessary to avoid collisions. Because the symbol is
584internal to the module, all references can be updated. This
585corresponds to the notion of the '<tt>static</tt>' keyword in C, or the
586idea of "anonymous namespaces" in C++.
587 <p> </p>
588 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000589 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000590 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt>
591linkage, with the twist that linking together two modules defining the
592same <tt>linkonce</tt> globals will cause one of the globals to be
593discarded. This is typically used to implement inline functions.
594Unreferenced <tt>linkonce</tt> globals are allowed to be discarded.
595 <p> </p>
596 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000597 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000598 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt>
599linkage, except that unreferenced <tt>weak</tt> globals may not be
600discarded. This is used to implement constructs in C such as "<tt>int
601X;</tt>" at global scope.
602 <p> </p>
603 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000604 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000605 <dd>"<tt>appending</tt>" linkage may only be applied to global
606variables of pointer to array type. When two global variables with
607appending linkage are linked together, the two global arrays are
608appended together. This is the LLVM, typesafe, equivalent of having
609the system linker append together "sections" with identical names when
610.o files are linked.
611 <p> </p>
612 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000613 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000614 <dd>If none of the above identifiers are used, the global is
615externally visible, meaning that it participates in linkage and can be
616used to resolve external symbol references.
617 <p> </p>
618 </dd>
Chris Lattner261efe92003-11-25 01:02:51 +0000619</dl>
620<p> </p>
621<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
622variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
623variable and was linked with this one, one of the two would be renamed,
624preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
625external (i.e., lacking any linkage declarations), they are accessible
626outside of the current module. It is illegal for a function <i>declaration</i>
627to have any linkage type other than "externally visible".</a></p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000628</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000629
Chris Lattner00950542001-06-06 20:29:01 +0000630<!-- ======================================================================= -->
Chris Lattner9ee5d222004-03-08 16:49:10 +0000631<div class="doc_subsection">
632 <a name="globalvars">Global Variables</a>
633</div>
634
Misha Brukman9d0919f2003-11-08 01:05:38 +0000635<div class="doc_text">
Chris Lattner9ee5d222004-03-08 16:49:10 +0000636
Chris Lattner261efe92003-11-25 01:02:51 +0000637<p>Global variables define regions of memory allocated at compilation
638time instead of run-time. Global variables may optionally be
639initialized. A variable may be defined as a global "constant", which
640indicates that the contents of the variable will never be modified
Chris Lattner9ee5d222004-03-08 16:49:10 +0000641(opening options for optimization).</p>
642
Chris Lattner261efe92003-11-25 01:02:51 +0000643<p>As SSA values, global variables define pointer values that are in
644scope (i.e. they dominate) for all basic blocks in the program. Global
645variables always define a pointer to their "content" type because they
646describe a region of memory, and all memory objects in LLVM are
647accessed through pointers.</p>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000648
Misha Brukman9d0919f2003-11-08 01:05:38 +0000649</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000650
651
Chris Lattner2b7d3202002-05-06 03:03:22 +0000652<!-- ======================================================================= -->
Chris Lattner9ee5d222004-03-08 16:49:10 +0000653<div class="doc_subsection">
654 <a name="functionstructure">Functions</a>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000655</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000656
657<div class="doc_text">
658
659<p>LLVM function definitions are composed of a (possibly empty) argument list,
660an opening curly brace, a list of basic blocks, and a closing curly brace. LLVM
661function declarations are defined with the "<tt>declare</tt>" keyword, a
662function name, and a function signature.</p>
663
664<p>A function definition contains a list of basic blocks, forming the CFG for
665the function. Each basic block may optionally start with a label (giving the
666basic block a symbol table entry), contains a list of instructions, and ends
667with a <a href="#terminators">terminator</a> instruction (such as a branch or
668function return).</p>
669
670<p>The first basic block in program is special in two ways: it is immediately
671executed on entrance to the function, and it is not allowed to have predecessor
672basic blocks (i.e. there can not be any branches to the entry block of a
673function). Because the block can have no predecessors, it also cannot have any
674<a href="#i_phi">PHI nodes</a>.</p>
675
676<p>LLVM functions are identified by their name and type signature. Hence, two
677functions with the same name but different parameter lists or return values are
678considered different functions, and LLVM will resolves references to each
679appropriately.</p>
680
681</div>
682
683
Chris Lattner00950542001-06-06 20:29:01 +0000684<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000685<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
686<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000687<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000688<p>The LLVM instruction set consists of several different
689classifications of instructions: <a href="#terminators">terminator
690instructions</a>, <a href="#binaryops">binary instructions</a>, <a
691 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
692instructions</a>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000693</div>
Chris Lattner00950542001-06-06 20:29:01 +0000694<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000695<div class="doc_subsection"> <a name="terminators">Terminator
696Instructions</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000697<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000698<p>As mentioned <a href="#functionstructure">previously</a>, every
699basic block in a program ends with a "Terminator" instruction, which
700indicates which block should be executed after the current block is
701finished. These terminator instructions typically yield a '<tt>void</tt>'
702value: they produce control flow, not values (the one exception being
703the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000704<p>There are five different terminator instructions: the '<a
Chris Lattner261efe92003-11-25 01:02:51 +0000705 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
706instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
707the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, and the '<a
708 href="#i_unwind"><tt>unwind</tt></a>' instruction.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000709</div>
Chris Lattner00950542001-06-06 20:29:01 +0000710<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000711<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
712Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000713<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000714<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000715<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 +0000716 ret void <i>; Return from void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000717</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000718<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000719<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
720value) from a function, back to the caller.</p>
721<p>There are two forms of the '<tt>ret</tt>' instructruction: one that
722returns a value and then causes control flow, and one that just causes
723control flow to occur.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000724<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000725<p>The '<tt>ret</tt>' instruction may return any '<a
726 href="#t_firstclass">first class</a>' type. Notice that a function is
727not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
728instruction inside of the function that returns a value that does not
729match the return type of the function.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000730<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000731<p>When the '<tt>ret</tt>' instruction is executed, control flow
732returns back to the calling function's context. If the caller is a "<a
733 href="#i_call"><tt>call</tt></a> instruction, execution continues at
734the instruction after the call. If the caller was an "<a
735 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
736at the beginning "normal" of the destination block. If the instruction
737returns a value, that value shall set the call or invoke instruction's
738return value.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000739<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000740<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner7faa8832002-04-14 06:13:44 +0000741 ret void <i>; Return from a void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000742</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000743</div>
Chris Lattner00950542001-06-06 20:29:01 +0000744<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000745<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</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> 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 +0000749</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000750<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000751<p>The '<tt>br</tt>' instruction is used to cause control flow to
752transfer to a different basic block in the current function. There are
753two forms of this instruction, corresponding to a conditional branch
754and an unconditional branch.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000755<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000756<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
757single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
758unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
759value as a target.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000760<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000761<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
762argument is evaluated. If the value is <tt>true</tt>, control flows
763to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
764control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000765<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000766<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
767 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 +0000768</div>
Chris Lattner00950542001-06-06 20:29:01 +0000769<!-- _______________________________________________________________________ -->
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000770<div class="doc_subsubsection">
771 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
772</div>
773
Misha Brukman9d0919f2003-11-08 01:05:38 +0000774<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000775<h5>Syntax:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000776
777<pre>
778 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
779</pre>
780
Chris Lattner00950542001-06-06 20:29:01 +0000781<h5>Overview:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000782
783<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
784several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +0000785instruction, allowing a branch to occur to one of many possible
786destinations.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000787
788
Chris Lattner00950542001-06-06 20:29:01 +0000789<h5>Arguments:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000790
791<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
792comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
793an array of pairs of comparison value constants and '<tt>label</tt>'s. The
794table is not allowed to contain duplicate constant entries.</p>
795
Chris Lattner00950542001-06-06 20:29:01 +0000796<h5>Semantics:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000797
Chris Lattner261efe92003-11-25 01:02:51 +0000798<p>The <tt>switch</tt> instruction specifies a table of values and
799destinations. When the '<tt>switch</tt>' instruction is executed, this
800table is searched for the given value. If the value is found, the
801corresponding destination is branched to, otherwise the default value
802it transfered to.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000803
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000804<h5>Implementation:</h5>
805
806<p>Depending on properties of the target machine and the particular
807<tt>switch</tt> instruction, this instruction may be code generated in different
808ways, for example as a series of chained conditional branches, or with a lookup
809table.</p>
810
811<h5>Example:</h5>
812
813<pre>
814 <i>; Emulate a conditional br instruction</i>
815 %Val = <a href="#i_cast">cast</a> bool %value to int
816 switch int %Val, label %truedest [int 0, label %falsedest ]
817
818 <i>; Emulate an unconditional br instruction</i>
819 switch uint 0, label %dest [ ]
820
821 <i>; Implement a jump table:</i>
822 switch uint %val, label %otherwise [ uint 0, label %onzero
823 uint 1, label %onone
824 uint 2, label %ontwo ]
Chris Lattner00950542001-06-06 20:29:01 +0000825</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000826</div>
Chris Lattner00950542001-06-06 20:29:01 +0000827<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000828<div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>'
829Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000830<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000831<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000832<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 +0000833<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000834<p>The '<tt>invoke</tt>' instruction causes control to transfer to a
835specified function, with the possibility of control flow transfer to
836either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>.
837If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>"
838instruction, control flow will return to the "normal" label. If the
839callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
840instruction, control is interrupted, and continued at the dynamically
841nearest "except" label.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000842<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000843<p>This instruction requires several arguments:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000844<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000845 <li>'<tt>ptr to function ty</tt>': shall be the signature of the
846pointer to function value being invoked. In most cases, this is a
847direct function invocation, but indirect <tt>invoke</tt>s are just as
848possible, branching off an arbitrary pointer to function value. </li>
849 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer
850to a function to be invoked. </li>
851 <li>'<tt>function args</tt>': argument list whose types match the
852function signature argument types. If the function signature indicates
853the function accepts a variable number of arguments, the extra
854arguments can be specified. </li>
855 <li>'<tt>normal label</tt>': the label reached when the called
856function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
857 <li>'<tt>exception label</tt>': the label reached when a callee
858returns with the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
Chris Lattner00950542001-06-06 20:29:01 +0000859</ol>
Chris Lattner00950542001-06-06 20:29:01 +0000860<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000861<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner261efe92003-11-25 01:02:51 +0000862 href="#i_call">call</a></tt>' instruction in most regards. The
863primary difference is that it establishes an association with a label,
864which is used by the runtime library to unwind the stack.</p>
865<p>This instruction is used in languages with destructors to ensure
866that proper cleanup is performed in the case of either a <tt>longjmp</tt>
867or a thrown exception. Additionally, this is important for
868implementation of '<tt>catch</tt>' clauses in high-level languages that
869support them.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000870<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000871<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 +0000872</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000873</div>
Chris Lattner27f71f22003-09-03 00:41:47 +0000874<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000875<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
876Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000877<div class="doc_text">
Chris Lattner27f71f22003-09-03 00:41:47 +0000878<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000879<pre> unwind<br></pre>
Chris Lattner27f71f22003-09-03 00:41:47 +0000880<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000881<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing
882control flow at the first callee in the dynamic call stack which used
883an <a href="#i_invoke"><tt>invoke</tt></a> instruction to perform the
884call. This is primarily used to implement exception handling.</p>
Chris Lattner27f71f22003-09-03 00:41:47 +0000885<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000886<p>The '<tt>unwind</tt>' intrinsic causes execution of the current
887function to immediately halt. The dynamic call stack is then searched
888for the first <a href="#i_invoke"><tt>invoke</tt></a> instruction on
889the call stack. Once found, execution continues at the "exceptional"
890destination block specified by the <tt>invoke</tt> instruction. If
891there is no <tt>invoke</tt> instruction in the dynamic call chain,
892undefined behavior results.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000893</div>
Chris Lattner00950542001-06-06 20:29:01 +0000894<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000895<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000896<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000897<p>Binary operators are used to do most of the computation in a
898program. They require two operands, execute an operation on them, and
899produce a single value. The result value of a binary operator is not
900necessarily the same type as its operands.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000901<p>There are several different binary operators:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000902</div>
Chris Lattner00950542001-06-06 20:29:01 +0000903<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000904<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
905Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000906<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000907<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000908<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 +0000909</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000910<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000911<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000912<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000913<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +0000914 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
915values. Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000916<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000917<p>The value produced is the integer or floating point sum of the two
918operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000919<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000920<pre> &lt;result&gt; = add 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_sub">'<tt>sub</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; = sub &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +0000929</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000930<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000931<p>The '<tt>sub</tt>' instruction returns the difference of its two
932operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000933<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
934instruction present in most other intermediate representations.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000935<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000936<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +0000937 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
938values. Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000939<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000940<p>The value produced is the integer or floating point difference of
941the two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000942<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000943<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner00950542001-06-06 20:29:01 +0000944 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
945</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000946</div>
Chris Lattner00950542001-06-06 20:29:01 +0000947<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000948<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
949Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000950<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000951<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000952<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 +0000953</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000954<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000955<p>The '<tt>mul</tt>' instruction returns the product of its two
956operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000957<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000958<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +0000959 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
960values. Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000961<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000962<p>The value produced is the integer or floating point product of the
Misha Brukman9d0919f2003-11-08 01:05:38 +0000963two operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000964<p>There is no signed vs unsigned multiplication. The appropriate
965action is taken based on the type of the operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000966<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000967<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner00950542001-06-06 20:29:01 +0000968</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000969</div>
Chris Lattner00950542001-06-06 20:29:01 +0000970<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000971<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
972Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000973<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000974<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000975<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
976</pre>
977<h5>Overview:</h5>
978<p>The '<tt>div</tt>' instruction returns the quotient of its two
979operands.</p>
980<h5>Arguments:</h5>
981<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
982 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
983values. Both arguments must have identical types.</p>
984<h5>Semantics:</h5>
985<p>The value produced is the integer or floating point quotient of the
986two operands.</p>
987<h5>Example:</h5>
988<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
989</pre>
990</div>
991<!-- _______________________________________________________________________ -->
992<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
993Instruction</a> </div>
994<div class="doc_text">
995<h5>Syntax:</h5>
996<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
997</pre>
998<h5>Overview:</h5>
999<p>The '<tt>rem</tt>' instruction returns the remainder from the
1000division of its two operands.</p>
1001<h5>Arguments:</h5>
1002<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1003 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
1004values. Both arguments must have identical types.</p>
1005<h5>Semantics:</h5>
1006<p>This returns the <i>remainder</i> of a division (where the result
1007has the same sign as the divisor), not the <i>modulus</i> (where the
1008result has the same sign as the dividend) of a value. For more
1009information about the difference, see: <a
1010 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1011Math Forum</a>.</p>
1012<h5>Example:</h5>
1013<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1014</pre>
1015</div>
1016<!-- _______________________________________________________________________ -->
1017<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1018Instructions</a> </div>
1019<div class="doc_text">
1020<h5>Syntax:</h5>
1021<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 +00001022 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1023 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1024 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1025 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1026 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1027</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001028<h5>Overview:</h5>
1029<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1030value based on a comparison of their two operands.</p>
1031<h5>Arguments:</h5>
1032<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1033be of <a href="#t_firstclass">first class</a> type (it is not possible
1034to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1035or '<tt>void</tt>' values, etc...). Both arguments must have identical
1036types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001037<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001038<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1039value if both operands are equal.<br>
1040The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1041value if both operands are unequal.<br>
1042The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1043value if the first operand is less than the second operand.<br>
1044The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1045value if the first operand is greater than the second operand.<br>
1046The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1047value if the first operand is less than or equal to the second operand.<br>
1048The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1049value if the first operand is greater than or equal to the second
1050operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001051<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001052<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner00950542001-06-06 20:29:01 +00001053 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
1054 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1055 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1056 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1057 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1058</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001059</div>
Chris Lattner00950542001-06-06 20:29:01 +00001060<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001061<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1062Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001063<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001064<p>Bitwise binary operators are used to do various forms of
1065bit-twiddling in a program. They are generally very efficient
1066instructions, and can commonly be strength reduced from other
1067instructions. They require two operands, execute an operation on them,
1068and produce a single value. The resulting value of the bitwise binary
1069operators is always the same type as its first operand.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001070</div>
Chris Lattner00950542001-06-06 20:29:01 +00001071<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001072<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1073Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001074<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001075<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001076<pre> &lt;result&gt; = and &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001077</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001078<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001079<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1080its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001081<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001082<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001083 href="#t_integral">integral</a> values. Both arguments must have
1084identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001085<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001086<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001087<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001088<div style="align: center">
Misha Brukman9d0919f2003-11-08 01:05:38 +00001089<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +00001090 <tbody>
1091 <tr>
1092 <td>In0</td>
1093 <td>In1</td>
1094 <td>Out</td>
1095 </tr>
1096 <tr>
1097 <td>0</td>
1098 <td>0</td>
1099 <td>0</td>
1100 </tr>
1101 <tr>
1102 <td>0</td>
1103 <td>1</td>
1104 <td>0</td>
1105 </tr>
1106 <tr>
1107 <td>1</td>
1108 <td>0</td>
1109 <td>0</td>
1110 </tr>
1111 <tr>
1112 <td>1</td>
1113 <td>1</td>
1114 <td>1</td>
1115 </tr>
1116 </tbody>
1117</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001118</div>
Chris Lattner00950542001-06-06 20:29:01 +00001119<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001120<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001121 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1122 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1123</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001124</div>
Chris Lattner00950542001-06-06 20:29:01 +00001125<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001126<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001127<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001128<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001129<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 +00001130</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001131<h5>Overview:</h5>
1132<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1133or of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001134<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001135<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001136 href="#t_integral">integral</a> values. Both arguments must have
1137identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001138<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001139<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001140<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001141<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001142<table border="1" cellspacing="0" cellpadding="4">
1143 <tbody>
1144 <tr>
1145 <td>In0</td>
1146 <td>In1</td>
1147 <td>Out</td>
1148 </tr>
1149 <tr>
1150 <td>0</td>
1151 <td>0</td>
1152 <td>0</td>
1153 </tr>
1154 <tr>
1155 <td>0</td>
1156 <td>1</td>
1157 <td>1</td>
1158 </tr>
1159 <tr>
1160 <td>1</td>
1161 <td>0</td>
1162 <td>1</td>
1163 </tr>
1164 <tr>
1165 <td>1</td>
1166 <td>1</td>
1167 <td>1</td>
1168 </tr>
1169 </tbody>
1170</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001171</div>
Chris Lattner00950542001-06-06 20:29:01 +00001172<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001173<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001174 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1175 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1176</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001177</div>
Chris Lattner00950542001-06-06 20:29:01 +00001178<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001179<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1180Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001181<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001182<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001183<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 +00001184</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001185<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001186<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1187or of its two operands. The <tt>xor</tt> is used to implement the
1188"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001189<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001190<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001191 href="#t_integral">integral</a> values. Both arguments must have
1192identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001193<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001194<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001195<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001196<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001197<table border="1" cellspacing="0" cellpadding="4">
1198 <tbody>
1199 <tr>
1200 <td>In0</td>
1201 <td>In1</td>
1202 <td>Out</td>
1203 </tr>
1204 <tr>
1205 <td>0</td>
1206 <td>0</td>
1207 <td>0</td>
1208 </tr>
1209 <tr>
1210 <td>0</td>
1211 <td>1</td>
1212 <td>1</td>
1213 </tr>
1214 <tr>
1215 <td>1</td>
1216 <td>0</td>
1217 <td>1</td>
1218 </tr>
1219 <tr>
1220 <td>1</td>
1221 <td>1</td>
1222 <td>0</td>
1223 </tr>
1224 </tbody>
1225</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001226</div>
Chris Lattner261efe92003-11-25 01:02:51 +00001227<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001228<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001229<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001230 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1231 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner27f71f22003-09-03 00:41:47 +00001232 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner00950542001-06-06 20:29:01 +00001233</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001234</div>
Chris Lattner00950542001-06-06 20:29:01 +00001235<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001236<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1237Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001238<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001239<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001240<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 +00001241</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001242<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001243<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1244the left a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001245<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001246<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001247 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1248type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001249<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001250<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001251<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001252<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 +00001253 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1254 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1255</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001256</div>
Chris Lattner00950542001-06-06 20:29:01 +00001257<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001258<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1259Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001260<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001261<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001262<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 +00001263</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001264<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001265<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1266the right a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001267<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001268<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001269 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1270type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001271<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001272<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1273most significant bit is duplicated in the newly free'd bit positions.
1274If the first argument is unsigned, zero bits shall fill the empty
1275positions.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001276<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001277<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 +00001278 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001279 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner8c6bb902003-06-18 21:30:51 +00001280 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1281 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner00950542001-06-06 20:29:01 +00001282</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001283</div>
Chris Lattner00950542001-06-06 20:29:01 +00001284<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001285<div class="doc_subsection"> <a name="memoryops">Memory Access
1286Operations</a></div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001287<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001288<p>A key design point of an SSA-based representation is how it
1289represents memory. In LLVM, no memory locations are in SSA form, which
1290makes things very simple. This section describes how to read, write,
1291allocate and free memory in LLVM.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001292</div>
Chris Lattner00950542001-06-06 20:29:01 +00001293<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001294<div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>'
1295Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001296<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001297<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001298<pre> &lt;result&gt; = malloc &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001299 &lt;result&gt; = malloc &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001300</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001301<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001302<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1303heap and returns a pointer to it.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001304<h5>Arguments:</h5>
John Criswell6e4ca612004-02-24 16:13:56 +00001305<p>The '<tt>malloc</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1306bytes of memory from the operating system and returns a pointer of the
Chris Lattner261efe92003-11-25 01:02:51 +00001307appropriate type to the program. The second form of the instruction is
1308a shorter version of the first instruction that defaults to allocating
1309one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001310<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001311<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001312<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1313a pointer is returned.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001314<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001315<pre> %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001316
Chris Lattner261efe92003-11-25 01:02:51 +00001317 %size = <a
1318 href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001319 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1320 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001321</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001322</div>
Chris Lattner00950542001-06-06 20:29:01 +00001323<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001324<div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>'
1325Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001326<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001327<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001328<pre> free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner00950542001-06-06 20:29:01 +00001329</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001330<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001331<p>The '<tt>free</tt>' instruction returns memory back to the unused
1332memory heap, to be reallocated in the future.</p>
1333<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001334<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001335<p>'<tt>value</tt>' shall be a pointer value that points to a value
1336that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1337instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001338<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001339<p>Access to the memory pointed to by the pointer is not longer defined
1340after this instruction executes.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001341<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001342<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 +00001343 free [4 x ubyte]* %array
1344</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001345</div>
Chris Lattner00950542001-06-06 20:29:01 +00001346<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001347<div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>'
1348Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001349<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001350<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001351<pre> &lt;result&gt; = alloca &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001352 &lt;result&gt; = alloca &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001353</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001354<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001355<p>The '<tt>alloca</tt>' instruction allocates memory on the current
1356stack frame of the procedure that is live until the current function
1357returns to its caller.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001358<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001359<p>The the '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1360bytes of memory on the runtime stack, returning a pointer of the
1361appropriate type to the program. The second form of the instruction is
1362a shorter version of the first that defaults to allocating one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001363<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001364<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001365<p>Memory is allocated, a pointer is returned. '<tt>alloca</tt>'d
1366memory is automatically released when the function returns. The '<tt>alloca</tt>'
1367instruction is commonly used to represent automatic variables that must
1368have an address available. When the function returns (either with the <tt><a
1369 href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001370instructions), the memory is reclaimed.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001371<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001372<pre> %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001373 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner00950542001-06-06 20:29:01 +00001374</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001375</div>
Chris Lattner00950542001-06-06 20:29:01 +00001376<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001377<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1378Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001379<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00001380<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001381<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 +00001382<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001383<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001384<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001385<p>The argument to the '<tt>load</tt>' instruction specifies the memory
1386address to load from. The pointer must point to a <a
1387 href="t_firstclass">first class</a> type. If the <tt>load</tt> is
1388marked as <tt>volatile</tt> then the optimizer is not allowed to modify
1389the number or order of execution of this <tt>load</tt> with other
1390volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1391instructions. </p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001392<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001393<p>The location of memory pointed to is loaded.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001394<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001395<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1396 <a
1397 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001398 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1399</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001400</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001401<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001402<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1403Instruction</a> </div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001404<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001405<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 +00001406 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 +00001407</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001408<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001409<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001410<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001411<p>There are two arguments to the '<tt>store</tt>' instruction: a value
1412to store and an address to store it into. The type of the '<tt>&lt;pointer&gt;</tt>'
1413operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
1414operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the
1415optimizer is not allowed to modify the number or order of execution of
1416this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1417 href="#i_store">store</a></tt> instructions.</p>
1418<h5>Semantics:</h5>
1419<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
1420at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001421<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001422<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1423 <a
1424 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001425 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1426</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001427<!-- _______________________________________________________________________ -->
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001428<div class="doc_subsubsection">
1429 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
1430</div>
1431
Misha Brukman9d0919f2003-11-08 01:05:38 +00001432<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00001433<h5>Syntax:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001434<pre>
1435 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
1436</pre>
1437
Chris Lattner7faa8832002-04-14 06:13:44 +00001438<h5>Overview:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001439
1440<p>
1441The '<tt>getelementptr</tt>' instruction is used to get the address of a
1442subelement of an aggregate data structure.</p>
1443
Chris Lattner7faa8832002-04-14 06:13:44 +00001444<h5>Arguments:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001445
1446<p>This instruction takes a list of integer constants that indicate what
1447elements of the aggregate object to index to. The actual types of the arguments
1448provided depend on the type of the first pointer argument. The
1449'<tt>getelementptr</tt>' instruction is used to index down through the type
1450levels of a structure. When indexing into a structure, only <tt>uint</tt>
1451integer constants are allowed. When indexing into an array or pointer
1452<tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
1453
Chris Lattner261efe92003-11-25 01:02:51 +00001454<p>For example, let's consider a C code fragment and how it gets
1455compiled to LLVM:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001456
1457<pre>
1458 struct RT {
1459 char A;
1460 int B[10][20];
1461 char C;
1462 };
1463 struct ST {
1464 int X;
1465 double Y;
1466 struct RT Z;
1467 };
1468
1469 int *foo(struct ST *s) {
1470 return &amp;s[1].Z.B[5][13];
1471 }
1472</pre>
1473
Misha Brukman9d0919f2003-11-08 01:05:38 +00001474<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001475
1476<pre>
1477 %RT = type { sbyte, [10 x [20 x int]], sbyte }
1478 %ST = type { int, double, %RT }
1479
1480 int* "foo"(%ST* %s) {
1481 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13<br>
1482 ret int* %reg
1483 }
1484</pre>
1485
Chris Lattner7faa8832002-04-14 06:13:44 +00001486<h5>Semantics:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001487
1488<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
1489on the pointer type that is being index into. <a href="t_pointer">Pointer</a>
1490and <a href="t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
1491<tt>ulong</tt>, or <tt>long</tt> values, and <a href="t_struct">structure</a>
1492types require <tt>uint</tt> <b>constants</b>.</p>
1493
Misha Brukman9d0919f2003-11-08 01:05:38 +00001494<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001495type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
1496}</tt>' type, a structure. The second index indexes into the third element of
1497the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
1498sbyte }</tt>' type, another structure. The third index indexes into the second
1499element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
1500array. The two dimensions of the array are subscripted into, yielding an
1501'<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction return a pointer
1502to this element, thus computing a value of '<tt>int*</tt>' type.</p>
1503
Chris Lattner261efe92003-11-25 01:02:51 +00001504<p>Note that it is perfectly legal to index partially through a
1505structure, returning a pointer to an inner element. Because of this,
1506the LLVM code for the given testcase is equivalent to:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001507
1508<pre>
1509 int* "foo"(%ST* %s) {
1510 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
1511 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
1512 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
1513 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
1514 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
1515 ret int* %t5
1516 }
Chris Lattner6536cfe2002-05-06 22:08:29 +00001517</pre>
Chris Lattner7faa8832002-04-14 06:13:44 +00001518<h5>Example:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001519<pre>
1520 <i>; yields [12 x ubyte]*:aptr</i>
1521 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
1522</pre>
1523
1524</div>
Chris Lattner00950542001-06-06 20:29:01 +00001525<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001526<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001527<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001528<p>The instructions in this catagory are the "miscellaneous"
1529instructions, which defy better classification.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001530</div>
Chris Lattner00950542001-06-06 20:29:01 +00001531<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001532<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
1533Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001534<div class="doc_text">
Chris Lattner33ba0d92001-07-09 00:26:23 +00001535<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001536<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001537<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001538<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
1539the SSA graph representing the function.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001540<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001541<p>The type of the incoming values are specified with the first type
1542field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
1543as arguments, with one pair for each predecessor basic block of the
1544current block. Only values of <a href="#t_firstclass">first class</a>
1545type may be used as the value arguments to the PHI node. Only labels
1546may be used as the label arguments.</p>
1547<p>There must be no non-phi instructions between the start of a basic
1548block and the PHI instructions: i.e. PHI instructions must be first in
1549a basic block.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001550<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001551<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
1552value specified by the parameter, depending on which basic block we
1553came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001554<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001555<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 +00001556</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001557
Chris Lattner6536cfe2002-05-06 22:08:29 +00001558<!-- _______________________________________________________________________ -->
Chris Lattnercc37aae2004-03-12 05:50:16 +00001559<div class="doc_subsubsection">
1560 <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
1561</div>
1562
Misha Brukman9d0919f2003-11-08 01:05:38 +00001563<div class="doc_text">
Chris Lattnercc37aae2004-03-12 05:50:16 +00001564
Chris Lattner6536cfe2002-05-06 22:08:29 +00001565<h5>Syntax:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001566
1567<pre>
1568 &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 +00001569</pre>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001570
Chris Lattner6536cfe2002-05-06 22:08:29 +00001571<h5>Overview:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001572
1573<p>
1574The '<tt>cast</tt>' instruction is used as the primitive means to convert
1575integers to floating point, change data type sizes, and break type safety (by
1576casting pointers).
1577</p>
1578
1579
Chris Lattner6536cfe2002-05-06 22:08:29 +00001580<h5>Arguments:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001581
1582<p>
1583The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
1584class value, and a type to cast it to, which must also be a <a
1585href="#t_firstclass">first class</a> type.
1586</p>
1587
Chris Lattner6536cfe2002-05-06 22:08:29 +00001588<h5>Semantics:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001589
1590<p>
1591This instruction follows the C rules for explicit casts when determining how the
1592data being cast must change to fit in its new container.
1593</p>
1594
1595<p>
1596When casting to bool, any value that would be considered true in the context of
1597a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
1598all else are '<tt>false</tt>'.
1599</p>
1600
1601<p>
1602When extending an integral value from a type of one signness to another (for
1603example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
1604<b>source</b> value is signed, and zero-extended if the source value is
1605unsigned. <tt>bool</tt> values are always zero extended into either zero or
1606one.
1607</p>
1608
Chris Lattner33ba0d92001-07-09 00:26:23 +00001609<h5>Example:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001610
1611<pre>
1612 %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattner7bae3952002-06-25 18:03:17 +00001613 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001614</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001615</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001616
1617<!-- _______________________________________________________________________ -->
1618<div class="doc_subsubsection">
1619 <a name="i_select">'<tt>select</tt>' Instruction</a>
1620</div>
1621
1622<div class="doc_text">
1623
1624<h5>Syntax:</h5>
1625
1626<pre>
1627 &lt;result&gt; = select bool &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
1628</pre>
1629
1630<h5>Overview:</h5>
1631
1632<p>
1633The '<tt>select</tt>' instruction is used to choose one value based on a
1634condition, without branching.
1635</p>
1636
1637
1638<h5>Arguments:</h5>
1639
1640<p>
1641The '<tt>select</tt>' instruction requires a boolean value indicating the condition, and two values of the same <a href="#t_firstclass">first class</a> type.
1642</p>
1643
1644<h5>Semantics:</h5>
1645
1646<p>
1647If the boolean condition evaluates to true, the instruction returns the first
1648value argument, otherwise it returns the second value argument.
1649</p>
1650
1651<h5>Example:</h5>
1652
1653<pre>
1654 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
1655</pre>
1656</div>
1657
1658
1659
1660
1661
Chris Lattner33ba0d92001-07-09 00:26:23 +00001662<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001663<div class="doc_subsubsection"> <a name="i_call">'<tt>call</tt>'
1664Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001665<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001666<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001667<pre> &lt;result&gt; = call &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +00001668<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001669<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001670<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001671<p>This instruction requires several arguments:</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001672<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00001673 <li>
1674 <p>'<tt>ty</tt>': shall be the signature of the pointer to function
1675value being invoked. The argument types must match the types implied
1676by this signature.</p>
1677 </li>
1678 <li>
1679 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a
1680function to be invoked. In most cases, this is a direct function
1681invocation, but indirect <tt>call</tt>s are just as possible,
1682calling an arbitrary pointer to function values.</p>
1683 </li>
1684 <li>
1685 <p>'<tt>function args</tt>': argument list whose types match the
1686function signature argument types. If the function signature
1687indicates the function accepts a variable number of arguments, the
1688extra arguments can be specified.</p>
1689 </li>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001690</ol>
Chris Lattner00950542001-06-06 20:29:01 +00001691<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001692<p>The '<tt>call</tt>' instruction is used to cause control flow to
1693transfer to a specified function, with its incoming arguments bound to
1694the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
1695instruction in the called function, control flow continues with the
1696instruction after the function call, and the return value of the
1697function is bound to the result argument. This is a simpler case of
1698the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001699<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001700<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 +00001701</div>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001702<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001703<div class="doc_subsubsection"> <a name="i_vanext">'<tt>vanext</tt>'
1704Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001705<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001706<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001707<pre> &lt;resultarglist&gt; = vanext &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001708<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001709<p>The '<tt>vanext</tt>' instruction is used to access arguments passed
1710through the "variable argument" area of a function call. It is used to
1711implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001712<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001713<p>This instruction takes a <tt>valist</tt> value and the type of the
1714argument. It returns another <tt>valist</tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001715<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001716<p>The '<tt>vanext</tt>' instruction advances the specified <tt>valist</tt>
1717past an argument of the specified type. In conjunction with the <a
1718 href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement
1719the <tt>va_arg</tt> macro available in C. For more information, see
1720the variable argument handling <a href="#int_varargs">Intrinsic
1721Functions</a>.</p>
1722<p>It is legal for this instruction to be called in a function which
1723does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001724function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001725<p><tt>vanext</tt> is an LLVM instruction instead of an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001726 href="#intrinsics">intrinsic function</a> because it takes an type as
1727an argument.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001728<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001729<p>See the <a href="#int_varargs">variable argument processing</a>
1730section.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001731</div>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001732<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001733<div class="doc_subsubsection"> <a name="i_vaarg">'<tt>vaarg</tt>'
1734Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001735<div class="doc_text">
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001736<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001737<pre> &lt;resultval&gt; = vaarg &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;<br></pre>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001738<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001739<p>The '<tt>vaarg</tt>' instruction is used to access arguments passed
1740through the "variable argument" area of a function call. It is used to
1741implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001742<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001743<p>This instruction takes a <tt>valist</tt> value and the type of the
1744argument. It returns a value of the specified argument type.</p>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001745<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001746<p>The '<tt>vaarg</tt>' instruction loads an argument of the specified
1747type from the specified <tt>va_list</tt>. In conjunction with the <a
1748 href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to
1749implement the <tt>va_arg</tt> macro available in C. For more
1750information, see the variable argument handling <a href="#int_varargs">Intrinsic
1751Functions</a>.</p>
1752<p>It is legal for this instruction to be called in a function which
1753does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001754function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001755<p><tt>vaarg</tt> is an LLVM instruction instead of an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001756 href="#intrinsics">intrinsic function</a> because it takes an type as
1757an argument.</p>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001758<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001759<p>See the <a href="#int_varargs">variable argument processing</a>
1760section.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001761</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001762
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001763<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00001764<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
1765<!-- *********************************************************************** -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001766
Misha Brukman9d0919f2003-11-08 01:05:38 +00001767<div class="doc_text">
Chris Lattner33aec9e2004-02-12 17:01:32 +00001768
1769<p>LLVM supports the notion of an "intrinsic function". These functions have
1770well known names and semantics, and are required to follow certain
1771restrictions. Overall, these instructions represent an extension mechanism for
1772the LLVM language that does not require changing all of the transformations in
1773LLVM to add to the language (or the bytecode reader/writer, the parser,
1774etc...).</p>
1775
1776<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix, this
1777prefix is reserved in LLVM for intrinsic names, thus functions may not be named
1778this. Intrinsic functions must always be external functions: you cannot define
1779the body of intrinsic functions. Intrinsic functions may only be used in call
1780or invoke instructions: it is illegal to take the address of an intrinsic
1781function. Additionally, because intrinsic functions are part of the LLVM
1782language, it is required that they all be documented here if any are added.</p>
1783
1784
1785<p>
1786Adding an intrinsic to LLVM is straight-forward if it is possible to express the
1787concept in LLVM directly (ie, code generator support is not _required_). To do
1788this, extend the default implementation of the IntrinsicLowering class to handle
1789the intrinsic. Code generators use this class to lower intrinsics they do not
1790understand to raw LLVM instructions that they do.
1791</p>
1792
Misha Brukman9d0919f2003-11-08 01:05:38 +00001793</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001794
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001795<!-- ======================================================================= -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001796<div class="doc_subsection">
1797 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
1798</div>
1799
Misha Brukman9d0919f2003-11-08 01:05:38 +00001800<div class="doc_text">
Misha Brukman9d0919f2003-11-08 01:05:38 +00001801<p>Variable argument support is defined in LLVM with the <a
Chris Lattner261efe92003-11-25 01:02:51 +00001802 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
1803intrinsic functions. These functions are related to the similarly
1804named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
1805<p>All of these functions operate on arguments that use a
1806target-specific value type "<tt>va_list</tt>". The LLVM assembly
1807language reference manual does not define what this type is, so all
1808transformations should be prepared to handle intrinsics with any type
1809used.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001810<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner261efe92003-11-25 01:02:51 +00001811instruction and the variable argument handling intrinsic functions are
1812used.</p>
Chris Lattner33aec9e2004-02-12 17:01:32 +00001813<pre>
1814int %test(int %X, ...) {
1815 ; Initialize variable argument processing
1816 %ap = call sbyte* %<a href="#i_va_start">llvm.va_start</a>()
1817
1818 ; Read a single integer argument
1819 %tmp = vaarg sbyte* %ap, int
1820
1821 ; Advance to the next argument
1822 %ap2 = vanext sbyte* %ap, int
1823
1824 ; Demonstrate usage of llvm.va_copy and llvm.va_end
1825 %aq = call sbyte* %<a href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2)
1826 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %aq)
1827
1828 ; Stop processing of arguments.
1829 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %ap2)
1830 ret int %tmp
1831}
1832</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001833</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001834
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001835<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001836<div class="doc_subsubsection">
1837 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
1838</div>
1839
1840
Misha Brukman9d0919f2003-11-08 01:05:38 +00001841<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001842<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001843<pre> call va_list ()* %llvm.va_start()<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001844<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001845<p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt>&lt;arglist&gt;</tt>
1846for subsequent use by the variable argument intrinsics.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001847<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001848<p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001849macro available in C. In a target-dependent way, it initializes and
1850returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt>
1851will produce the first variable argument passed to the function. Unlike
1852the C <tt>va_start</tt> macro, this intrinsic does not need to know the
1853last argument of the function, the compiler can figure that out.</p>
1854<p>Note that this intrinsic function is only legal to be called from
1855within the body of a variable argument function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001856</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001857
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001858<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001859<div class="doc_subsubsection">
1860 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
1861</div>
1862
Misha Brukman9d0919f2003-11-08 01:05:38 +00001863<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001864<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001865<pre> call void (va_list)* %llvm.va_end(va_list &lt;arglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001866<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001867<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
1868which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
1869or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001870<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001871<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001872<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001873<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001874macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
1875Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
1876 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
1877with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001878</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001879
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001880<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001881<div class="doc_subsubsection">
1882 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
1883</div>
1884
Misha Brukman9d0919f2003-11-08 01:05:38 +00001885<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001886<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001887<pre> call va_list (va_list)* %llvm.va_copy(va_list &lt;destarglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001888<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001889<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument
1890position from the source argument list to the destination argument list.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001891<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001892<p>The argument is the <tt>va_list</tt> to copy.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001893<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001894<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001895macro available in C. In a target-dependent way, it copies the source <tt>va_list</tt>
1896element into the returned list. This intrinsic is necessary because the <tt><a
1897 href="i_va_start">llvm.va_start</a></tt> intrinsic may be arbitrarily
1898complex and require memory allocation, for example.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001899</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001900
Chris Lattner33aec9e2004-02-12 17:01:32 +00001901<!-- ======================================================================= -->
1902<div class="doc_subsection">
Chris Lattner10610642004-02-14 04:08:35 +00001903 <a name="int_codegen">Code Generator Intrinsics</a>
1904</div>
1905
1906<div class="doc_text">
1907<p>
1908These intrinsics are provided by LLVM to expose special features that may only
1909be implemented with code generator support.
1910</p>
1911
1912</div>
1913
1914<!-- _______________________________________________________________________ -->
1915<div class="doc_subsubsection">
1916 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
1917</div>
1918
1919<div class="doc_text">
1920
1921<h5>Syntax:</h5>
1922<pre>
1923 call void* ()* %llvm.returnaddress(uint &lt;level&gt;)
1924</pre>
1925
1926<h5>Overview:</h5>
1927
1928<p>
1929The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
1930indicating the return address of the current function or one of its callers.
1931</p>
1932
1933<h5>Arguments:</h5>
1934
1935<p>
1936The argument to this intrinsic indicates which function to return the address
1937for. Zero indicates the calling function, one indicates its caller, etc. The
1938argument is <b>required</b> to be a constant integer value.
1939</p>
1940
1941<h5>Semantics:</h5>
1942
1943<p>
1944The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
1945the return address of the specified call frame, or zero if it cannot be
1946identified. The value returned by this intrinsic is likely to be incorrect or 0
1947for arguments other than zero, so it should only be used for debugging purposes.
1948</p>
1949
1950<p>
1951Note that calling this intrinsic does not prevent function inlining or other
1952aggressive transformations, so the value returned may not that of the obvious
1953source-language caller.
1954</p>
1955</div>
1956
1957
1958<!-- _______________________________________________________________________ -->
1959<div class="doc_subsubsection">
1960 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
1961</div>
1962
1963<div class="doc_text">
1964
1965<h5>Syntax:</h5>
1966<pre>
1967 call void* ()* %llvm.frameaddress(uint &lt;level&gt;)
1968</pre>
1969
1970<h5>Overview:</h5>
1971
1972<p>
1973The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
1974pointer value for the specified stack frame.
1975</p>
1976
1977<h5>Arguments:</h5>
1978
1979<p>
1980The argument to this intrinsic indicates which function to return the frame
1981pointer for. Zero indicates the calling function, one indicates its caller,
1982etc. The argument is <b>required</b> to be a constant integer value.
1983</p>
1984
1985<h5>Semantics:</h5>
1986
1987<p>
1988The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
1989the frame address of the specified call frame, or zero if it cannot be
1990identified. The value returned by this intrinsic is likely to be incorrect or 0
1991for arguments other than zero, so it should only be used for debugging purposes.
1992</p>
1993
1994<p>
1995Note that calling this intrinsic does not prevent function inlining or other
1996aggressive transformations, so the value returned may not that of the obvious
1997source-language caller.
1998</p>
1999</div>
2000
John Criswellcfd3bac2004-04-09 15:23:37 +00002001<!-- _______________________________________________________________________ -->
2002<div class="doc_subsubsection">
2003 <a name="i_readport">'<tt>llvm.readport</tt>' Intrinsic</a>
2004</div>
2005
2006<div class="doc_text">
2007
2008<h5>Syntax:</h5>
2009<pre>
2010 call sbyte (ushort address)* %llvm.readport(ushort &lt;address&gt;)
2011 call ubyte (ushort address)* %llvm.readport(ushort &lt;address&gt;)
2012 call short (ushort address)* %llvm.readport(ushort &lt;address&gt;)
2013 call ushort (ushort address)* %llvm.readport(ushort &lt;address&gt;)
2014 call int (ushort address)* %llvm.readport(ushort &lt;address&gt;)
2015 call uint (ushort address)* %llvm.readport(ushort &lt;address&gt;)
2016</pre>
2017
2018<h5>Overview:</h5>
2019
2020<p>
2021The '<tt>llvm.readport</tt>' intrinsic reads data from the specified I/O port.
2022</p>
2023
2024<h5>Arguments:</h5>
2025
2026<p>
2027The argument to this intrinsic indicates the I/O address from which to read
2028the data. The address is in the I/O address namespace; it is not a memory
2029location.
2030</p>
2031
2032<h5>Semantics:</h5>
2033
2034<p>
2035The '<tt>llvm.readport</tt>' intrinsic reads data from the I/O port specified
2036by <i>address</i> and returns the value. The address and return value must
2037be integers, but the size is dependent upon the platform upon which the
2038program is code generated. For example, on x86, the address must be a
2039ushort, and the return value must be 8, 16, or 32 bits.
2040</p>
2041
2042</div>
2043
2044<!-- _______________________________________________________________________ -->
2045<div class="doc_subsubsection">
2046 <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a>
2047</div>
2048
2049<div class="doc_text">
2050
2051<h5>Syntax:</h5>
2052<pre>
2053 call void (ushort address, sbyte value)* %llvm.writeport(ushort &lt;address&gt;, sbyte &lt;value&gt;)
2054 call void (ushort address, ubyte value)* %llvm.writeport(ushort &lt;address&gt;, ubyte &lt;value&gt;)
2055 call void (ushort address, short value)* %llvm.writeport(ushort &lt;address&gt;, short &lt;value&gt;)
2056 call void (ushort address, ushort value)* %llvm.writeport(ushort &lt;address&gt;, ushort &lt;value&gt;)
2057 call void (ushort address, int value)* %llvm.writeport(ushort &lt;address&gt;, int &lt;value&gt;)
2058 call void (ushort address, uint value)* %llvm.writeport(ushort &lt;address&gt;, uint &lt;value&gt;)
2059</pre>
2060
2061<h5>Overview:</h5>
2062
2063<p>
2064The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified I/O port.
2065</p>
2066
2067<h5>Arguments:</h5>
2068
2069<p>
2070The first argument to this intrinsic indicates the I/O address to which data
2071should be written. The address is in the I/O address namespace; it is not a
2072memory location.
2073</p>
2074
2075<p>
2076The second argument is the value to write to the I/O port.
2077</p>
2078
2079<h5>Semantics:</h5>
2080
2081<p>
2082The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port
2083specified by <i>address</i>. The address and value must be integers, but the
2084size is dependent upon the platform upon which the program is code generated.
2085For example, on x86, the address must be a ushort, and the value written must
2086be 8, 16, or 32 bits in length.
2087</p>
2088
2089</div>
Chris Lattner10610642004-02-14 04:08:35 +00002090
2091<!-- ======================================================================= -->
2092<div class="doc_subsection">
Chris Lattner33aec9e2004-02-12 17:01:32 +00002093 <a name="int_libc">Standard C Library Intrinsics</a>
2094</div>
2095
2096<div class="doc_text">
2097<p>
Chris Lattner10610642004-02-14 04:08:35 +00002098LLVM provides intrinsics for a few important standard C library functions.
2099These intrinsics allow source-language front-ends to pass information about the
2100alignment of the pointer arguments to the code generator, providing opportunity
2101for more efficient code generation.
Chris Lattner33aec9e2004-02-12 17:01:32 +00002102</p>
2103
2104</div>
2105
2106<!-- _______________________________________________________________________ -->
2107<div class="doc_subsubsection">
2108 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
2109</div>
2110
2111<div class="doc_text">
2112
2113<h5>Syntax:</h5>
2114<pre>
2115 call void (sbyte*, sbyte*, uint, uint)* %llvm.memcpy(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2116 uint &lt;len&gt;, uint &lt;align&gt;)
2117</pre>
2118
2119<h5>Overview:</h5>
2120
2121<p>
2122The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2123location to the destination location.
2124</p>
2125
2126<p>
2127Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
2128does not return a value, and takes an extra alignment argument.
2129</p>
2130
2131<h5>Arguments:</h5>
2132
2133<p>
2134The first argument is a pointer to the destination, the second is a pointer to
2135the source. The third argument is an (arbitrarily sized) integer argument
2136specifying the number of bytes to copy, and the fourth argument is the alignment
2137of the source and destination locations.
2138</p>
2139
Chris Lattner3301ced2004-02-12 21:18:15 +00002140<p>
2141If the call to this intrinisic has an alignment value that is not 0 or 1, then
2142the caller guarantees that the size of the copy is a multiple of the alignment
2143and that both the source and destination pointers are aligned to that boundary.
2144</p>
2145
Chris Lattner33aec9e2004-02-12 17:01:32 +00002146<h5>Semantics:</h5>
2147
2148<p>
2149The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2150location to the destination location, which are not allowed to overlap. It
2151copies "len" bytes of memory over. If the argument is known to be aligned to
2152some boundary, this can be specified as the fourth argument, otherwise it should
2153be set to 0 or 1.
2154</p>
2155</div>
2156
2157
Chris Lattner0eb51b42004-02-12 18:10:10 +00002158<!-- _______________________________________________________________________ -->
2159<div class="doc_subsubsection">
2160 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
2161</div>
2162
2163<div class="doc_text">
2164
2165<h5>Syntax:</h5>
2166<pre>
2167 call void (sbyte*, sbyte*, uint, uint)* %llvm.memmove(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2168 uint &lt;len&gt;, uint &lt;align&gt;)
2169</pre>
2170
2171<h5>Overview:</h5>
2172
2173<p>
2174The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
2175location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>'
2176intrinsic but allows the two memory locations to overlap.
2177</p>
2178
2179<p>
2180Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
2181does not return a value, and takes an extra alignment argument.
2182</p>
2183
2184<h5>Arguments:</h5>
2185
2186<p>
2187The first argument is a pointer to the destination, the second is a pointer to
2188the source. The third argument is an (arbitrarily sized) integer argument
2189specifying the number of bytes to copy, and the fourth argument is the alignment
2190of the source and destination locations.
2191</p>
2192
Chris Lattner3301ced2004-02-12 21:18:15 +00002193<p>
2194If the call to this intrinisic has an alignment value that is not 0 or 1, then
2195the caller guarantees that the size of the copy is a multiple of the alignment
2196and that both the source and destination pointers are aligned to that boundary.
2197</p>
2198
Chris Lattner0eb51b42004-02-12 18:10:10 +00002199<h5>Semantics:</h5>
2200
2201<p>
2202The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
2203location to the destination location, which may overlap. It
2204copies "len" bytes of memory over. If the argument is known to be aligned to
2205some boundary, this can be specified as the fourth argument, otherwise it should
2206be set to 0 or 1.
2207</p>
2208</div>
2209
Chris Lattner8ff75902004-01-06 05:31:32 +00002210
Chris Lattner10610642004-02-14 04:08:35 +00002211<!-- _______________________________________________________________________ -->
2212<div class="doc_subsubsection">
2213 <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a>
2214</div>
2215
2216<div class="doc_text">
2217
2218<h5>Syntax:</h5>
2219<pre>
2220 call void (sbyte*, ubyte, uint, uint)* %llvm.memset(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
2221 uint &lt;len&gt;, uint &lt;align&gt;)
2222</pre>
2223
2224<h5>Overview:</h5>
2225
2226<p>
2227The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular
2228byte value.
2229</p>
2230
2231<p>
2232Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
2233does not return a value, and takes an extra alignment argument.
2234</p>
2235
2236<h5>Arguments:</h5>
2237
2238<p>
2239The first argument is a pointer to the destination to fill, the second is the
2240byte value to fill it with, the third argument is an (arbitrarily sized) integer
2241argument specifying the number of bytes to fill, and the fourth argument is the
2242known alignment of destination location.
2243</p>
2244
2245<p>
2246If the call to this intrinisic has an alignment value that is not 0 or 1, then
2247the caller guarantees that the size of the copy is a multiple of the alignment
2248and that the destination pointer is aligned to that boundary.
2249</p>
2250
2251<h5>Semantics:</h5>
2252
2253<p>
2254The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the
2255destination location. If the argument is known to be aligned to some boundary,
2256this can be specified as the fourth argument, otherwise it should be set to 0 or
22571.
2258</p>
2259</div>
2260
2261
Chris Lattner8ff75902004-01-06 05:31:32 +00002262<!-- ======================================================================= -->
2263<div class="doc_subsection">
2264 <a name="int_debugger">Debugger Intrinsics</a>
2265</div>
2266
2267<div class="doc_text">
2268<p>
2269The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
2270are described in the <a
2271href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
2272Debugging</a> document.
2273</p>
2274</div>
2275
2276
Chris Lattner00950542001-06-06 20:29:01 +00002277<!-- *********************************************************************** -->
Chris Lattner00950542001-06-06 20:29:01 +00002278<hr>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002279<address>
2280 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
2281 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
2282 <a href="http://validator.w3.org/check/referer"><img
2283 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
2284
2285 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
2286 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
2287 Last modified: $Date$
2288</address>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002289</body>
2290</html>