blob: 60dba677ba599a0ef1c87b743a2af52abbf7871d [file] [log] [blame]
Misha Brukmanc501f552004-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 Brukman76307852003-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 Lattner48b383b02003-11-25 01:02:51 +00009<div class="doc_title"> LLVM Language Reference Manual </div>
Chris Lattner2f7c9632001-06-06 20:29:01 +000010<ol>
Misha Brukman76307852003-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 Lattner2f7c9632001-06-06 20:29:01 +000014 <li><a href="#typesystem">Type System</a>
15 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000016 <li><a href="#t_primitive">Primitive Types</a>
17 <ol>
Misha Brukman76307852003-11-08 01:05:38 +000018 <li><a href="#t_classifications">Type Classifications</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000019 </ol>
20 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000021 <li><a href="#t_derived">Derived Types</a>
22 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000023 <li><a href="#t_array">Array Type</a></li>
Misha Brukman76307852003-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 Lattner48b383b02003-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 Lattner2f7c9632001-06-06 20:29:01 +000032 <li><a href="#highlevel">High Level Structure</a>
33 <ol>
Misha Brukman76307852003-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 Lattner48b383b02003-11-25 01:02:51 +000037 </ol>
38 </li>
Chris Lattner2f7c9632001-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 Lattner48b383b02003-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 Brukman76307852003-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 Lattner48b383b02003-11-25 01:02:51 +000047 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
48 </ol>
49 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000050 <li><a href="#binaryops">Binary Operations</a>
51 <ol>
Chris Lattner48b383b02003-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 Brukman76307852003-11-08 01:05:38 +000057 <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000058 </ol>
59 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000060 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
61 <ol>
Misha Brukman76307852003-11-08 01:05:38 +000062 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000063 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman76307852003-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 Lattner48b383b02003-11-25 01:02:51 +000067 </ol>
68 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000069 <li><a href="#memoryops">Memory Access Operations</a>
70 <ol>
Chris Lattner48b383b02003-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 Lattner2f7c9632001-06-06 20:29:01 +000079 <li><a href="#otherops">Other Operations</a>
80 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000081 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000082 <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li>
Chris Lattnerb53c28d2004-03-12 05:50:16 +000083 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000084 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000085 <li><a href="#i_vanext">'<tt>vanext</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000086 <li><a href="#i_vaarg">'<tt>vaarg</tt>' Instruction</a></li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000087 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000088 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000089 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000090 </li>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +000091 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +000092 <ol>
Chris Lattner48b383b02003-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 Lattner3649c3a2004-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>
104 </ol>
105 </li>
Chris Lattnerfee11462004-02-12 17:01:32 +0000106 <li><a href="#int_libc">Standard C Library Intrinsics</a>
107 <ol>
108 <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li>
Chris Lattnerf30152e2004-02-12 18:10:10 +0000109 <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li>
Chris Lattner3649c3a2004-02-14 04:08:35 +0000110 <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li>
Chris Lattnerfee11462004-02-12 17:01:32 +0000111 </ol>
112 </li>
Chris Lattner941515c2004-01-06 05:31:32 +0000113 <li><a href="#int_debugger">Debugger intrinsics</a>
Chris Lattner48b383b02003-11-25 01:02:51 +0000114 </ol>
115 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000116</ol>
Misha Brukman76307852003-11-08 01:05:38 +0000117<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000118<p><b>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
119and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></b></p>
120<p> </p>
Misha Brukman76307852003-11-08 01:05:38 +0000121</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000122<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000123<div class="doc_section"> <a name="abstract">Abstract </a></div>
124<!-- *********************************************************************** -->
Misha Brukman76307852003-11-08 01:05:38 +0000125<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000126<p>This document is a reference manual for the LLVM assembly language.
127LLVM is an SSA based representation that provides type safety,
128low-level operations, flexibility, and the capability of representing
129'all' high-level languages cleanly. It is the common code
130representation used throughout all phases of the LLVM compilation
131strategy.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000132</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000133<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000134<div class="doc_section"> <a name="introduction">Introduction</a> </div>
135<!-- *********************************************************************** -->
Misha Brukman76307852003-11-08 01:05:38 +0000136<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000137<p>The LLVM code representation is designed to be used in three
138different forms: as an in-memory compiler IR, as an on-disk bytecode
139representation (suitable for fast loading by a Just-In-Time compiler),
140and as a human readable assembly language representation. This allows
141LLVM to provide a powerful intermediate representation for efficient
142compiler transformations and analysis, while providing a natural means
143to debug and visualize the transformations. The three different forms
144of LLVM are all equivalent. This document describes the human readable
145representation and notation.</p>
146<p>The LLVM representation aims to be a light-weight and low-level
147while being expressive, typed, and extensible at the same time. It
148aims to be a "universal IR" of sorts, by being at a low enough level
149that high-level ideas may be cleanly mapped to it (similar to how
150microprocessors are "universal IR's", allowing many source languages to
151be mapped to them). By providing type information, LLVM can be used as
152the target of optimizations: for example, through pointer analysis, it
153can be proven that a C automatic variable is never accessed outside of
154the current function... allowing it to be promoted to a simple SSA
155value instead of a memory location.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000156</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000157<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000158<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000159<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000160<p>It is important to note that this document describes 'well formed'
161LLVM assembly language. There is a difference between what the parser
162accepts and what is considered 'well formed'. For example, the
163following instruction is syntactically okay, but not well formed:</p>
164<pre> %x = <a href="#i_add">add</a> int 1, %x<br></pre>
165<p>...because the definition of <tt>%x</tt> does not dominate all of
166its uses. The LLVM infrastructure provides a verification pass that may
167be used to verify that an LLVM module is well formed. This pass is
168automatically run by the parser after parsing input assembly, and by
169the optimizer before it outputs bytecode. The violations pointed out
170by the verifier pass indicate bugs in transformation passes or input to
171the parser.</p>
172<!-- Describe the typesetting conventions here. --> </div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000173<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000174<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000175<!-- *********************************************************************** -->
Misha Brukman76307852003-11-08 01:05:38 +0000176<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000177<p>LLVM uses three different forms of identifiers, for different
178purposes:</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000179<ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000180 <li>Numeric constants are represented as you would expect: 12, -3
181123.421, etc. Floating point constants have an optional hexidecimal
182notation.</li>
183 <li>Named values are represented as a string of characters with a '%'
184prefix. For example, %foo, %DivisionByZero,
185%a.really.long.identifier. The actual regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
186Identifiers which require other characters in their names can be
187surrounded with quotes. In this way, anything except a <tt>"</tt>
188character can be used in a name.</li>
189 <li>Unnamed values are represented as an unsigned numeric value with
190a '%' prefix. For example, %12, %2, %44.</li>
Misha Brukman76307852003-11-08 01:05:38 +0000191</ol>
John Criswelleb55b522004-03-12 21:19:06 +0000192<p>LLVM requires that values start with a '%' sign for two reasons:
Chris Lattner48b383b02003-11-25 01:02:51 +0000193Compilers don't need to worry about name clashes with reserved words,
194and the set of reserved words may be expanded in the future without
195penalty. Additionally, unnamed identifiers allow a compiler to quickly
196come up with a temporary variable without having to avoid symbol table
197conflicts.</p>
198<p>Reserved words in LLVM are very similar to reserved words in other
199languages. There are keywords for different opcodes ('<tt><a
200 href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
201 href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
202 href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>',
203etc...), and others. These reserved words cannot conflict with
204variable names, because none of them start with a '%' character.</p>
205<p>Here is an example of LLVM code to multiply the integer variable '<tt>%X</tt>'
206by 8:</p>
Misha Brukman76307852003-11-08 01:05:38 +0000207<p>The easy way:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +0000208<pre> %result = <a href="#i_mul">mul</a> uint %X, 8<br></pre>
Misha Brukman76307852003-11-08 01:05:38 +0000209<p>After strength reduction:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +0000210<pre> %result = <a href="#i_shl">shl</a> uint %X, ubyte 3<br></pre>
Misha Brukman76307852003-11-08 01:05:38 +0000211<p>And the hard way:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +0000212<pre> <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
213 <a
214 href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
215 %result = <a
216 href="#i_add">add</a> uint %1, %1<br></pre>
217<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
218important lexical features of LLVM:</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000219<ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000220 <li>Comments are delimited with a '<tt>;</tt>' and go until the end
221of line.</li>
222 <li>Unnamed temporaries are created when the result of a computation
223is not assigned to a named value.</li>
Misha Brukman76307852003-11-08 01:05:38 +0000224 <li>Unnamed temporaries are numbered sequentially</li>
225</ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000226<p>...and it also show a convention that we follow in this document.
227When demonstrating instructions, we will follow an instruction with a
228comment that defines the type and name of value produced. Comments are
229shown in italic text.</p>
230<p>The one non-intuitive notation for constants is the optional
231hexidecimal form of floating point constants. For example, the form '<tt>double
Chris Lattner095735d2002-05-06 03:03:22 +00002320x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
Chris Lattner48b383b02003-11-25 01:02:51 +00002334.5e+15</tt>' which is also supported by the parser. The only time
234hexadecimal floating point constants are useful (and the only time that
235they are generated by the disassembler) is when an FP constant has to
236be emitted that is not representable as a decimal floating point number
237exactly. For example, NaN's, infinities, and other special cases are
238represented in their IEEE hexadecimal format so that assembly and
239disassembly do not cause any bits to change in the constants.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000240</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000241<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000242<div class="doc_section"> <a name="typesystem">Type System</a> </div>
243<!-- *********************************************************************** -->
Misha Brukman76307852003-11-08 01:05:38 +0000244<div class="doc_text">
Misha Brukman76307852003-11-08 01:05:38 +0000245<p>The LLVM type system is one of the most important features of the
Chris Lattner48b383b02003-11-25 01:02:51 +0000246intermediate representation. Being typed enables a number of
247optimizations to be performed on the IR directly, without having to do
248extra analyses on the side before the transformation. A strong type
249system makes it easier to read the generated code and enables novel
250analyses and transformations that are not feasible to perform on normal
251three address code representations.</p>
Chris Lattnerd8f8ede2002-06-25 18:03:17 +0000252<!-- The written form for the type system was heavily influenced by the
253syntactic problems with types in the C language<sup><a
Chris Lattner48b383b02003-11-25 01:02:51 +0000254href="#rw_stroustrup">1</a></sup>.<p> --> </div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000255<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000256<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000257<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000258<p>The primitive types are the fundemental building blocks of the LLVM
259system. The current set of primitive types are as follows:</p>
Misha Brukmanc501f552004-03-01 17:47:27 +0000260
261<table border="0" style="align: center">
Chris Lattner48b383b02003-11-25 01:02:51 +0000262 <tbody>
263 <tr>
264 <td>
Misha Brukmanc501f552004-03-01 17:47:27 +0000265 <table border="1" cellspacing="0" cellpadding="4" style="align: center">
Chris Lattner48b383b02003-11-25 01:02:51 +0000266 <tbody>
267 <tr>
268 <td><tt>void</tt></td>
269 <td>No value</td>
270 </tr>
271 <tr>
272 <td><tt>ubyte</tt></td>
273 <td>Unsigned 8 bit value</td>
274 </tr>
275 <tr>
276 <td><tt>ushort</tt></td>
277 <td>Unsigned 16 bit value</td>
278 </tr>
279 <tr>
280 <td><tt>uint</tt></td>
281 <td>Unsigned 32 bit value</td>
282 </tr>
283 <tr>
284 <td><tt>ulong</tt></td>
285 <td>Unsigned 64 bit value</td>
286 </tr>
287 <tr>
288 <td><tt>float</tt></td>
289 <td>32 bit floating point value</td>
290 </tr>
291 <tr>
292 <td><tt>label</tt></td>
293 <td>Branch destination</td>
294 </tr>
295 </tbody>
296 </table>
297 </td>
298 <td valign="top">
Misha Brukmanc501f552004-03-01 17:47:27 +0000299 <table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +0000300 <tbody>
301 <tr>
302 <td><tt>bool</tt></td>
303 <td>True or False value</td>
304 </tr>
305 <tr>
306 <td><tt>sbyte</tt></td>
307 <td>Signed 8 bit value</td>
308 </tr>
309 <tr>
310 <td><tt>short</tt></td>
311 <td>Signed 16 bit value</td>
312 </tr>
313 <tr>
314 <td><tt>int</tt></td>
315 <td>Signed 32 bit value</td>
316 </tr>
317 <tr>
318 <td><tt>long</tt></td>
319 <td>Signed 64 bit value</td>
320 </tr>
321 <tr>
322 <td><tt>double</tt></td>
323 <td>64 bit floating point value</td>
324 </tr>
325 </tbody>
326 </table>
327 </td>
328 </tr>
329 </tbody>
Misha Brukman76307852003-11-08 01:05:38 +0000330</table>
Misha Brukmanc501f552004-03-01 17:47:27 +0000331
Misha Brukman76307852003-11-08 01:05:38 +0000332</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000333<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000334<div class="doc_subsubsection"> <a name="t_classifications">Type
335Classifications</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000336<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000337<p>These different primitive types fall into a few useful
338classifications:</p>
Misha Brukmanc501f552004-03-01 17:47:27 +0000339
340<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +0000341 <tbody>
342 <tr>
343 <td><a name="t_signed">signed</a></td>
344 <td><tt>sbyte, short, int, long, float, double</tt></td>
345 </tr>
346 <tr>
347 <td><a name="t_unsigned">unsigned</a></td>
348 <td><tt>ubyte, ushort, uint, ulong</tt></td>
349 </tr>
350 <tr>
351 <td><a name="t_integer">integer</a></td>
352 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
353 </tr>
354 <tr>
355 <td><a name="t_integral">integral</a></td>
356 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
357 </tr>
358 <tr>
359 <td><a name="t_floating">floating point</a></td>
360 <td><tt>float, double</tt></td>
361 </tr>
362 <tr>
363 <td><a name="t_firstclass">first class</a></td>
364 <td><tt>bool, ubyte, sbyte, ushort, short,<br>
365uint, int, ulong, long, float, double, <a href="#t_pointer">pointer</a></tt></td>
366 </tr>
367 </tbody>
Misha Brukman76307852003-11-08 01:05:38 +0000368</table>
Misha Brukmanc501f552004-03-01 17:47:27 +0000369
Chris Lattner48b383b02003-11-25 01:02:51 +0000370<p>The <a href="#t_firstclass">first class</a> types are perhaps the
371most important. Values of these types are the only ones which can be
372produced by instructions, passed as arguments, or used as operands to
373instructions. This means that all structures and arrays must be
374manipulated either by pointer or by component.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000375</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000376<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000377<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000378<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000379<p>The real power in LLVM comes from the derived types in the system.
380This is what allows a programmer to represent arrays, functions,
381pointers, and other useful types. Note that these derived types may be
382recursive: For example, it is possible to have a two dimensional array.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000383</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000384<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000385<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000386<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000387<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +0000388<p>The array type is a very simple derived type that arranges elements
Chris Lattner48b383b02003-11-25 01:02:51 +0000389sequentially in memory. The array type requires a size (number of
390elements) and an underlying data type.</p>
Chris Lattner590645f2002-04-14 06:13:44 +0000391<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000392<pre> [&lt;# elements&gt; x &lt;elementtype&gt;]<br></pre>
393<p>The number of elements is a constant integer value, elementtype may
394be any type with a size.</p>
Chris Lattner590645f2002-04-14 06:13:44 +0000395<h5>Examples:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000396<p> <tt>[40 x int ]</tt>: Array of 40 integer values.<br>
397<tt>[41 x int ]</tt>: Array of 41 integer values.<br>
398<tt>[40 x uint]</tt>: Array of 40 unsigned integer values.</p>
399<p> </p>
Misha Brukman76307852003-11-08 01:05:38 +0000400<p>Here are some examples of multidimensional arrays:</p>
Misha Brukmanc501f552004-03-01 17:47:27 +0000401
Misha Brukman76307852003-11-08 01:05:38 +0000402<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner48b383b02003-11-25 01:02:51 +0000403 <tbody>
404 <tr>
405 <td><tt>[3 x [4 x int]]</tt></td>
406 <td>: 3x4 array integer values.</td>
407 </tr>
408 <tr>
409 <td><tt>[12 x [10 x float]]</tt></td>
410 <td>: 12x10 array of single precision floating point values.</td>
411 </tr>
412 <tr>
413 <td><tt>[2 x [3 x [4 x uint]]]</tt></td>
414 <td>: 2x3x4 array of unsigned integer values.</td>
415 </tr>
416 </tbody>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000417</table>
Misha Brukmanc501f552004-03-01 17:47:27 +0000418
Misha Brukman76307852003-11-08 01:05:38 +0000419</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000420<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000421<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000422<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000423<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000424<p>The function type can be thought of as a function signature. It
425consists of a return type and a list of formal parameter types.
John Criswella0d50d22003-11-25 21:45:46 +0000426Function types are usually used to build virtual function tables
Chris Lattner48b383b02003-11-25 01:02:51 +0000427(which are structures of pointers to functions), for indirect function
428calls, and when defining a function.</p>
John Criswella0d50d22003-11-25 21:45:46 +0000429<p>
430The return type of a function type cannot be an aggregate type.
431</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000432<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000433<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
434<p>Where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of
435type specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner5ed60612003-09-03 00:41:47 +0000436which indicates that the function takes a variable number of arguments.
437Variable argument functions can access their arguments with the <a
Chris Lattner48b383b02003-11-25 01:02:51 +0000438 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000439<h5>Examples:</h5>
Misha Brukmanc501f552004-03-01 17:47:27 +0000440
Misha Brukman76307852003-11-08 01:05:38 +0000441<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner48b383b02003-11-25 01:02:51 +0000442 <tbody>
443 <tr>
444 <td><tt>int (int)</tt></td>
445 <td>: function taking an <tt>int</tt>, returning an <tt>int</tt></td>
446 </tr>
447 <tr>
448 <td><tt>float (int, int *) *</tt></td>
449 <td>: <a href="#t_pointer">Pointer</a> to a function that takes
450an <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
451returning <tt>float</tt>.</td>
452 </tr>
453 <tr>
454 <td><tt>int (sbyte *, ...)</tt></td>
455 <td>: A vararg function that takes at least one <a
456 href="#t_pointer">pointer</a> to <tt>sbyte</tt> (signed char in C),
457which returns an integer. This is the signature for <tt>printf</tt>
458in LLVM.</td>
459 </tr>
460 </tbody>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000461</table>
Misha Brukmanc501f552004-03-01 17:47:27 +0000462
Misha Brukman76307852003-11-08 01:05:38 +0000463</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000464<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000465<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000466<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000467<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000468<p>The structure type is used to represent a collection of data members
469together in memory. The packing of the field types is defined to match
470the ABI of the underlying processor. The elements of a structure may
471be any type that has a size.</p>
472<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
473and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
474field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
475instruction.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000476<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000477<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000478<h5>Examples:</h5>
Misha Brukmanc501f552004-03-01 17:47:27 +0000479
Misha Brukman76307852003-11-08 01:05:38 +0000480<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner48b383b02003-11-25 01:02:51 +0000481 <tbody>
482 <tr>
483 <td><tt>{ int, int, int }</tt></td>
484 <td>: a triple of three <tt>int</tt> values</td>
485 </tr>
486 <tr>
487 <td><tt>{ float, int (int) * }</tt></td>
488 <td>: A pair, where the first element is a <tt>float</tt> and the
489second element is a <a href="#t_pointer">pointer</a> to a <a
490 href="t_function">function</a> that takes an <tt>int</tt>, returning
491an <tt>int</tt>.</td>
492 </tr>
493 </tbody>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000494</table>
Misha Brukmanc501f552004-03-01 17:47:27 +0000495
Misha Brukman76307852003-11-08 01:05:38 +0000496</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000497<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000498<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000499<div class="doc_text">
Chris Lattner590645f2002-04-14 06:13:44 +0000500<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000501<p>As in many languages, the pointer type represents a pointer or
502reference to another object, which must live in memory.</p>
Chris Lattner590645f2002-04-14 06:13:44 +0000503<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000504<pre> &lt;type&gt; *<br></pre>
Chris Lattner590645f2002-04-14 06:13:44 +0000505<h5>Examples:</h5>
Misha Brukmanc501f552004-03-01 17:47:27 +0000506
Misha Brukman76307852003-11-08 01:05:38 +0000507<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner48b383b02003-11-25 01:02:51 +0000508 <tbody>
509 <tr>
510 <td><tt>[4x int]*</tt></td>
511 <td>: <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a>
512of four <tt>int</tt> values</td>
513 </tr>
514 <tr>
515 <td><tt>int (int *) *</tt></td>
516 <td>: A <a href="#t_pointer">pointer</a> to a <a
517 href="t_function">function</a> that takes an <tt>int</tt>, returning
518an <tt>int</tt>.</td>
519 </tr>
520 </tbody>
Misha Brukman76307852003-11-08 01:05:38 +0000521</table>
Misha Brukmanc501f552004-03-01 17:47:27 +0000522
Misha Brukman76307852003-11-08 01:05:38 +0000523</div>
Chris Lattner48b383b02003-11-25 01:02:51 +0000524<!-- _______________________________________________________________________ --><!--
Misha Brukman76307852003-11-08 01:05:38 +0000525<div class="doc_subsubsection">
526 <a name="t_packed">Packed Type</a>
527</div>
528
529<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000530
531Mention/decide that packed types work with saturation or not. Maybe have a packed+saturated type in addition to just a packed type.<p>
532
533Packed types should be 'nonsaturated' because standard data types are not saturated. Maybe have a saturated packed type?<p>
534
Misha Brukman76307852003-11-08 01:05:38 +0000535</div>
536
Chris Lattner48b383b02003-11-25 01:02:51 +0000537--><!-- *********************************************************************** -->
538<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
539<!-- *********************************************************************** --><!-- ======================================================================= -->
540<div class="doc_subsection"> <a name="modulestructure">Module Structure</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000541<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000542<p>LLVM programs are composed of "Module"s, each of which is a
543translation unit of the input programs. Each module consists of
544functions, global variables, and symbol table entries. Modules may be
545combined together with the LLVM linker, which merges function (and
546global variable) definitions, resolves forward declarations, and merges
547symbol table entries. Here is an example of the "hello world" module:</p>
548<pre><i>; Declare the string constant as a global constant...</i>
549<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
550 href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00" <i>; [13 x sbyte]*</i>
Chris Lattner095735d2002-05-06 03:03:22 +0000551
Chris Lattner5ed60612003-09-03 00:41:47 +0000552<i>; External declaration of the puts function</i>
553<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
Chris Lattner095735d2002-05-06 03:03:22 +0000554
555<i>; Definition of main function</i>
Chris Lattner5ed60612003-09-03 00:41:47 +0000556int %main() { <i>; int()* </i>
Chris Lattner095735d2002-05-06 03:03:22 +0000557 <i>; Convert [13x sbyte]* to sbyte *...</i>
Chris Lattner48b383b02003-11-25 01:02:51 +0000558 %cast210 = <a
559 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
Chris Lattner095735d2002-05-06 03:03:22 +0000560
561 <i>; Call puts function to write out the string to stdout...</i>
Chris Lattner48b383b02003-11-25 01:02:51 +0000562 <a
563 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
564 <a
565 href="#i_ret">ret</a> int 0<br>}<br></pre>
566<p>This example is made up of a <a href="#globalvars">global variable</a>
567named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
568function, and a <a href="#functionstructure">function definition</a>
569for "<tt>main</tt>".</p>
570<a name="linkage"> In general, a module is made up of a list of global
571values, where both functions and global variables are global values.
572Global values are represented by a pointer to a memory location (in
573this case, a pointer to an array of char, and a pointer to a function),
574and have one of the following linkage types:</a>
575<p> </p>
Chris Lattner5ed60612003-09-03 00:41:47 +0000576<dl>
Misha Brukmanc501f552004-03-01 17:47:27 +0000577 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattner48b383b02003-11-25 01:02:51 +0000578 <dd>Global values with internal linkage are only directly accessible
579by objects in the current module. In particular, linking code into a
580module with an internal global value may cause the internal to be
581renamed as necessary to avoid collisions. Because the symbol is
582internal to the module, all references can be updated. This
583corresponds to the notion of the '<tt>static</tt>' keyword in C, or the
584idea of "anonymous namespaces" in C++.
585 <p> </p>
586 </dd>
Misha Brukmanc501f552004-03-01 17:47:27 +0000587 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattner48b383b02003-11-25 01:02:51 +0000588 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt>
589linkage, with the twist that linking together two modules defining the
590same <tt>linkonce</tt> globals will cause one of the globals to be
591discarded. This is typically used to implement inline functions.
592Unreferenced <tt>linkonce</tt> globals are allowed to be discarded.
593 <p> </p>
594 </dd>
Misha Brukmanc501f552004-03-01 17:47:27 +0000595 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattner48b383b02003-11-25 01:02:51 +0000596 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt>
597linkage, except that unreferenced <tt>weak</tt> globals may not be
598discarded. This is used to implement constructs in C such as "<tt>int
599X;</tt>" at global scope.
600 <p> </p>
601 </dd>
Misha Brukmanc501f552004-03-01 17:47:27 +0000602 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattner48b383b02003-11-25 01:02:51 +0000603 <dd>"<tt>appending</tt>" linkage may only be applied to global
604variables of pointer to array type. When two global variables with
605appending linkage are linked together, the two global arrays are
606appended together. This is the LLVM, typesafe, equivalent of having
607the system linker append together "sections" with identical names when
608.o files are linked.
609 <p> </p>
610 </dd>
Misha Brukmanc501f552004-03-01 17:47:27 +0000611 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattner48b383b02003-11-25 01:02:51 +0000612 <dd>If none of the above identifiers are used, the global is
613externally visible, meaning that it participates in linkage and can be
614used to resolve external symbol references.
615 <p> </p>
616 </dd>
Chris Lattner48b383b02003-11-25 01:02:51 +0000617</dl>
618<p> </p>
619<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
620variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
621variable and was linked with this one, one of the two would be renamed,
622preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
623external (i.e., lacking any linkage declarations), they are accessible
624outside of the current module. It is illegal for a function <i>declaration</i>
625to have any linkage type other than "externally visible".</a></p>
Misha Brukman76307852003-11-08 01:05:38 +0000626</div>
Chris Lattnerb1652612004-03-08 16:49:10 +0000627
Chris Lattner2f7c9632001-06-06 20:29:01 +0000628<!-- ======================================================================= -->
Chris Lattnerb1652612004-03-08 16:49:10 +0000629<div class="doc_subsection">
630 <a name="globalvars">Global Variables</a>
631</div>
632
Misha Brukman76307852003-11-08 01:05:38 +0000633<div class="doc_text">
Chris Lattnerb1652612004-03-08 16:49:10 +0000634
Chris Lattner48b383b02003-11-25 01:02:51 +0000635<p>Global variables define regions of memory allocated at compilation
636time instead of run-time. Global variables may optionally be
637initialized. A variable may be defined as a global "constant", which
638indicates that the contents of the variable will never be modified
Chris Lattnerb1652612004-03-08 16:49:10 +0000639(opening options for optimization).</p>
640
Chris Lattner48b383b02003-11-25 01:02:51 +0000641<p>As SSA values, global variables define pointer values that are in
642scope (i.e. they dominate) for all basic blocks in the program. Global
643variables always define a pointer to their "content" type because they
644describe a region of memory, and all memory objects in LLVM are
645accessed through pointers.</p>
Chris Lattnerb1652612004-03-08 16:49:10 +0000646
Misha Brukman76307852003-11-08 01:05:38 +0000647</div>
Chris Lattnerb1652612004-03-08 16:49:10 +0000648
649
Chris Lattner095735d2002-05-06 03:03:22 +0000650<!-- ======================================================================= -->
Chris Lattnerb1652612004-03-08 16:49:10 +0000651<div class="doc_subsection">
652 <a name="functionstructure">Functions</a>
Misha Brukman76307852003-11-08 01:05:38 +0000653</div>
Chris Lattnerb1652612004-03-08 16:49:10 +0000654
655<div class="doc_text">
656
657<p>LLVM function definitions are composed of a (possibly empty) argument list,
658an opening curly brace, a list of basic blocks, and a closing curly brace. LLVM
659function declarations are defined with the "<tt>declare</tt>" keyword, a
660function name, and a function signature.</p>
661
662<p>A function definition contains a list of basic blocks, forming the CFG for
663the function. Each basic block may optionally start with a label (giving the
664basic block a symbol table entry), contains a list of instructions, and ends
665with a <a href="#terminators">terminator</a> instruction (such as a branch or
666function return).</p>
667
668<p>The first basic block in program is special in two ways: it is immediately
669executed on entrance to the function, and it is not allowed to have predecessor
670basic blocks (i.e. there can not be any branches to the entry block of a
671function). Because the block can have no predecessors, it also cannot have any
672<a href="#i_phi">PHI nodes</a>.</p>
673
674<p>LLVM functions are identified by their name and type signature. Hence, two
675functions with the same name but different parameter lists or return values are
676considered different functions, and LLVM will resolves references to each
677appropriately.</p>
678
679</div>
680
681
Chris Lattner2f7c9632001-06-06 20:29:01 +0000682<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000683<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
684<!-- *********************************************************************** -->
Misha Brukman76307852003-11-08 01:05:38 +0000685<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000686<p>The LLVM instruction set consists of several different
687classifications of instructions: <a href="#terminators">terminator
688instructions</a>, <a href="#binaryops">binary instructions</a>, <a
689 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
690instructions</a>.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000691</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000692<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000693<div class="doc_subsection"> <a name="terminators">Terminator
694Instructions</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000695<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000696<p>As mentioned <a href="#functionstructure">previously</a>, every
697basic block in a program ends with a "Terminator" instruction, which
698indicates which block should be executed after the current block is
699finished. These terminator instructions typically yield a '<tt>void</tt>'
700value: they produce control flow, not values (the one exception being
701the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
Misha Brukman76307852003-11-08 01:05:38 +0000702<p>There are five different terminator instructions: the '<a
Chris Lattner48b383b02003-11-25 01:02:51 +0000703 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
704instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
705the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, and the '<a
706 href="#i_unwind"><tt>unwind</tt></a>' instruction.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000707</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000708<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000709<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
710Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000711<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000712<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000713<pre> ret &lt;type&gt; &lt;value&gt; <i>; Return a value from a non-void function</i>
Chris Lattner590645f2002-04-14 06:13:44 +0000714 ret void <i>; Return from void function</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000715</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000716<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000717<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
718value) from a function, back to the caller.</p>
719<p>There are two forms of the '<tt>ret</tt>' instructruction: one that
720returns a value and then causes control flow, and one that just causes
721control flow to occur.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000722<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000723<p>The '<tt>ret</tt>' instruction may return any '<a
724 href="#t_firstclass">first class</a>' type. Notice that a function is
725not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
726instruction inside of the function that returns a value that does not
727match the return type of the function.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000728<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000729<p>When the '<tt>ret</tt>' instruction is executed, control flow
730returns back to the calling function's context. If the caller is a "<a
731 href="#i_call"><tt>call</tt></a> instruction, execution continues at
732the instruction after the call. If the caller was an "<a
733 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
734at the beginning "normal" of the destination block. If the instruction
735returns a value, that value shall set the call or invoke instruction's
736return value.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000737<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000738<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner590645f2002-04-14 06:13:44 +0000739 ret void <i>; Return from a void function</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000740</pre>
Misha Brukman76307852003-11-08 01:05:38 +0000741</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000742<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000743<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000744<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000745<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000746<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 Lattner2f7c9632001-06-06 20:29:01 +0000747</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000748<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000749<p>The '<tt>br</tt>' instruction is used to cause control flow to
750transfer to a different basic block in the current function. There are
751two forms of this instruction, corresponding to a conditional branch
752and an unconditional branch.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000753<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000754<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
755single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
756unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
757value as a target.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000758<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000759<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
760argument is evaluated. If the value is <tt>true</tt>, control flows
761to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
762control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000763<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000764<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
765 href="#i_ret">ret</a> int 1<br>IfUnequal:<br> <a href="#i_ret">ret</a> int 0<br></pre>
Misha Brukman76307852003-11-08 01:05:38 +0000766</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000767<!-- _______________________________________________________________________ -->
Chris Lattnercf96c6c2004-02-24 04:54:45 +0000768<div class="doc_subsubsection">
769 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
770</div>
771
Misha Brukman76307852003-11-08 01:05:38 +0000772<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000773<h5>Syntax:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +0000774
775<pre>
776 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
777</pre>
778
Chris Lattner2f7c9632001-06-06 20:29:01 +0000779<h5>Overview:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +0000780
781<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
782several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman76307852003-11-08 01:05:38 +0000783instruction, allowing a branch to occur to one of many possible
784destinations.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +0000785
786
Chris Lattner2f7c9632001-06-06 20:29:01 +0000787<h5>Arguments:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +0000788
789<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
790comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
791an array of pairs of comparison value constants and '<tt>label</tt>'s. The
792table is not allowed to contain duplicate constant entries.</p>
793
Chris Lattner2f7c9632001-06-06 20:29:01 +0000794<h5>Semantics:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +0000795
Chris Lattner48b383b02003-11-25 01:02:51 +0000796<p>The <tt>switch</tt> instruction specifies a table of values and
797destinations. When the '<tt>switch</tt>' instruction is executed, this
798table is searched for the given value. If the value is found, the
799corresponding destination is branched to, otherwise the default value
800it transfered to.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000801
Chris Lattnercf96c6c2004-02-24 04:54:45 +0000802<h5>Implementation:</h5>
803
804<p>Depending on properties of the target machine and the particular
805<tt>switch</tt> instruction, this instruction may be code generated in different
806ways, for example as a series of chained conditional branches, or with a lookup
807table.</p>
808
809<h5>Example:</h5>
810
811<pre>
812 <i>; Emulate a conditional br instruction</i>
813 %Val = <a href="#i_cast">cast</a> bool %value to int
814 switch int %Val, label %truedest [int 0, label %falsedest ]
815
816 <i>; Emulate an unconditional br instruction</i>
817 switch uint 0, label %dest [ ]
818
819 <i>; Implement a jump table:</i>
820 switch uint %val, label %otherwise [ uint 0, label %onzero
821 uint 1, label %onone
822 uint 2, label %ontwo ]
Chris Lattner2f7c9632001-06-06 20:29:01 +0000823</pre>
Misha Brukman76307852003-11-08 01:05:38 +0000824</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000825<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000826<div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>'
827Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000828<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000829<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000830<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 Lattnera8292f32002-05-06 22:08:29 +0000831<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000832<p>The '<tt>invoke</tt>' instruction causes control to transfer to a
833specified function, with the possibility of control flow transfer to
834either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>.
835If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>"
836instruction, control flow will return to the "normal" label. If the
837callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
838instruction, control is interrupted, and continued at the dynamically
839nearest "except" label.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000840<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +0000841<p>This instruction requires several arguments:</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000842<ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000843 <li>'<tt>ptr to function ty</tt>': shall be the signature of the
844pointer to function value being invoked. In most cases, this is a
845direct function invocation, but indirect <tt>invoke</tt>s are just as
846possible, branching off an arbitrary pointer to function value. </li>
847 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer
848to a function to be invoked. </li>
849 <li>'<tt>function args</tt>': argument list whose types match the
850function signature argument types. If the function signature indicates
851the function accepts a variable number of arguments, the extra
852arguments can be specified. </li>
853 <li>'<tt>normal label</tt>': the label reached when the called
854function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
855 <li>'<tt>exception label</tt>': the label reached when a callee
856returns with the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000857</ol>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000858<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +0000859<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner48b383b02003-11-25 01:02:51 +0000860 href="#i_call">call</a></tt>' instruction in most regards. The
861primary difference is that it establishes an association with a label,
862which is used by the runtime library to unwind the stack.</p>
863<p>This instruction is used in languages with destructors to ensure
864that proper cleanup is performed in the case of either a <tt>longjmp</tt>
865or a thrown exception. Additionally, this is important for
866implementation of '<tt>catch</tt>' clauses in high-level languages that
867support them.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000868<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000869<pre> %retval = invoke int %Test(int 15)<br> to label %Continue<br> except label %TestCleanup <i>; {int}:retval set</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000870</pre>
Misha Brukman76307852003-11-08 01:05:38 +0000871</div>
Chris Lattner5ed60612003-09-03 00:41:47 +0000872<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000873<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
874Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000875<div class="doc_text">
Chris Lattner5ed60612003-09-03 00:41:47 +0000876<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000877<pre> unwind<br></pre>
Chris Lattner5ed60612003-09-03 00:41:47 +0000878<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000879<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing
880control flow at the first callee in the dynamic call stack which used
881an <a href="#i_invoke"><tt>invoke</tt></a> instruction to perform the
882call. This is primarily used to implement exception handling.</p>
Chris Lattner5ed60612003-09-03 00:41:47 +0000883<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000884<p>The '<tt>unwind</tt>' intrinsic causes execution of the current
885function to immediately halt. The dynamic call stack is then searched
886for the first <a href="#i_invoke"><tt>invoke</tt></a> instruction on
887the call stack. Once found, execution continues at the "exceptional"
888destination block specified by the <tt>invoke</tt> instruction. If
889there is no <tt>invoke</tt> instruction in the dynamic call chain,
890undefined behavior results.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000891</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000892<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000893<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000894<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000895<p>Binary operators are used to do most of the computation in a
896program. They require two operands, execute an operation on them, and
897produce a single value. The result value of a binary operator is not
898necessarily the same type as its operands.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000899<p>There are several different binary operators:</p>
Misha Brukman76307852003-11-08 01:05:38 +0000900</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000901<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000902<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
903Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000904<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000905<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000906<pre> &lt;result&gt; = add &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000907</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000908<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +0000909<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000910<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +0000911<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattner48b383b02003-11-25 01:02:51 +0000912 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
913values. Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000914<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +0000915<p>The value produced is the integer or floating point sum of the two
916operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000917<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000918<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000919</pre>
Misha Brukman76307852003-11-08 01:05:38 +0000920</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000921<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000922<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
923Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000924<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000925<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000926<pre> &lt;result&gt; = sub &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000927</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000928<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +0000929<p>The '<tt>sub</tt>' instruction returns the difference of its two
930operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +0000931<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
932instruction present in most other intermediate representations.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000933<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +0000934<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner48b383b02003-11-25 01:02:51 +0000935 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
936values. Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000937<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000938<p>The value produced is the integer or floating point difference of
939the two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000940<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000941<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000942 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
943</pre>
Misha Brukman76307852003-11-08 01:05:38 +0000944</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000945<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000946<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
947Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000948<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000949<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000950<pre> &lt;result&gt; = mul &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000951</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000952<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000953<p>The '<tt>mul</tt>' instruction returns the product of its two
954operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000955<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +0000956<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner48b383b02003-11-25 01:02:51 +0000957 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
958values. Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000959<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000960<p>The value produced is the integer or floating point product of the
Misha Brukman76307852003-11-08 01:05:38 +0000961two operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +0000962<p>There is no signed vs unsigned multiplication. The appropriate
963action is taken based on the type of the operand.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000964<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000965<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000966</pre>
Misha Brukman76307852003-11-08 01:05:38 +0000967</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000968<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000969<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
970Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000971<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000972<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000973<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
974</pre>
975<h5>Overview:</h5>
976<p>The '<tt>div</tt>' instruction returns the quotient of its two
977operands.</p>
978<h5>Arguments:</h5>
979<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
980 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
981values. Both arguments must have identical types.</p>
982<h5>Semantics:</h5>
983<p>The value produced is the integer or floating point quotient of the
984two operands.</p>
985<h5>Example:</h5>
986<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
987</pre>
988</div>
989<!-- _______________________________________________________________________ -->
990<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
991Instruction</a> </div>
992<div class="doc_text">
993<h5>Syntax:</h5>
994<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
995</pre>
996<h5>Overview:</h5>
997<p>The '<tt>rem</tt>' instruction returns the remainder from the
998division of its two operands.</p>
999<h5>Arguments:</h5>
1000<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1001 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
1002values. Both arguments must have identical types.</p>
1003<h5>Semantics:</h5>
1004<p>This returns the <i>remainder</i> of a division (where the result
1005has the same sign as the divisor), not the <i>modulus</i> (where the
1006result has the same sign as the dividend) of a value. For more
1007information about the difference, see: <a
1008 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1009Math Forum</a>.</p>
1010<h5>Example:</h5>
1011<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1012</pre>
1013</div>
1014<!-- _______________________________________________________________________ -->
1015<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1016Instructions</a> </div>
1017<div class="doc_text">
1018<h5>Syntax:</h5>
1019<pre> &lt;result&gt; = seteq &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001020 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1021 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1022 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1023 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1024 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1025</pre>
Chris Lattner48b383b02003-11-25 01:02:51 +00001026<h5>Overview:</h5>
1027<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1028value based on a comparison of their two operands.</p>
1029<h5>Arguments:</h5>
1030<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1031be of <a href="#t_firstclass">first class</a> type (it is not possible
1032to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1033or '<tt>void</tt>' values, etc...). Both arguments must have identical
1034types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001035<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001036<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1037value if both operands are equal.<br>
1038The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1039value if both operands are unequal.<br>
1040The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1041value if the first operand is less than the second operand.<br>
1042The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1043value if the first operand is greater than the second operand.<br>
1044The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1045value if the first operand is less than or equal to the second operand.<br>
1046The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1047value if the first operand is greater than or equal to the second
1048operand.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001049<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001050<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001051 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
1052 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1053 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1054 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1055 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1056</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001057</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001058<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001059<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1060Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001061<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +00001062<p>Bitwise binary operators are used to do various forms of
1063bit-twiddling in a program. They are generally very efficient
1064instructions, and can commonly be strength reduced from other
1065instructions. They require two operands, execute an operation on them,
1066and produce a single value. The resulting value of the bitwise binary
1067operators is always the same type as its first operand.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001068</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001069<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001070<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1071Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001072<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001073<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001074<pre> &lt;result&gt; = and &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001075</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001076<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001077<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1078its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001079<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001080<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001081 href="#t_integral">integral</a> values. Both arguments must have
1082identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001083<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001084<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001085<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00001086<div style="align: center">
Misha Brukman76307852003-11-08 01:05:38 +00001087<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +00001088 <tbody>
1089 <tr>
1090 <td>In0</td>
1091 <td>In1</td>
1092 <td>Out</td>
1093 </tr>
1094 <tr>
1095 <td>0</td>
1096 <td>0</td>
1097 <td>0</td>
1098 </tr>
1099 <tr>
1100 <td>0</td>
1101 <td>1</td>
1102 <td>0</td>
1103 </tr>
1104 <tr>
1105 <td>1</td>
1106 <td>0</td>
1107 <td>0</td>
1108 </tr>
1109 <tr>
1110 <td>1</td>
1111 <td>1</td>
1112 <td>1</td>
1113 </tr>
1114 </tbody>
1115</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001116</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001117<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001118<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001119 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1120 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1121</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001122</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001123<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001124<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001125<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001126<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001127<pre> &lt;result&gt; = or &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001128</pre>
Chris Lattner48b383b02003-11-25 01:02:51 +00001129<h5>Overview:</h5>
1130<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1131or of its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001132<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001133<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001134 href="#t_integral">integral</a> values. Both arguments must have
1135identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001136<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001137<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001138<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00001139<div style="align: center">
Chris Lattner48b383b02003-11-25 01:02:51 +00001140<table border="1" cellspacing="0" cellpadding="4">
1141 <tbody>
1142 <tr>
1143 <td>In0</td>
1144 <td>In1</td>
1145 <td>Out</td>
1146 </tr>
1147 <tr>
1148 <td>0</td>
1149 <td>0</td>
1150 <td>0</td>
1151 </tr>
1152 <tr>
1153 <td>0</td>
1154 <td>1</td>
1155 <td>1</td>
1156 </tr>
1157 <tr>
1158 <td>1</td>
1159 <td>0</td>
1160 <td>1</td>
1161 </tr>
1162 <tr>
1163 <td>1</td>
1164 <td>1</td>
1165 <td>1</td>
1166 </tr>
1167 </tbody>
1168</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001169</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001170<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001171<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001172 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1173 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1174</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001175</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001176<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001177<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1178Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001179<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001180<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001181<pre> &lt;result&gt; = xor &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001182</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001183<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001184<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1185or of its two operands. The <tt>xor</tt> is used to implement the
1186"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001187<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001188<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001189 href="#t_integral">integral</a> values. Both arguments must have
1190identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001191<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001192<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001193<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00001194<div style="align: center">
Chris Lattner48b383b02003-11-25 01:02:51 +00001195<table border="1" cellspacing="0" cellpadding="4">
1196 <tbody>
1197 <tr>
1198 <td>In0</td>
1199 <td>In1</td>
1200 <td>Out</td>
1201 </tr>
1202 <tr>
1203 <td>0</td>
1204 <td>0</td>
1205 <td>0</td>
1206 </tr>
1207 <tr>
1208 <td>0</td>
1209 <td>1</td>
1210 <td>1</td>
1211 </tr>
1212 <tr>
1213 <td>1</td>
1214 <td>0</td>
1215 <td>1</td>
1216 </tr>
1217 <tr>
1218 <td>1</td>
1219 <td>1</td>
1220 <td>0</td>
1221 </tr>
1222 </tbody>
1223</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001224</div>
Chris Lattner48b383b02003-11-25 01:02:51 +00001225<p> </p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001226<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001227<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001228 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1229 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner5ed60612003-09-03 00:41:47 +00001230 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001231</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001232</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001233<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001234<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1235Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001236<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001237<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001238<pre> &lt;result&gt; = shl &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001239</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001240<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001241<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1242the left a specified number of bits.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001243<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001244<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001245 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1246type.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001247<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001248<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001249<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001250<pre> &lt;result&gt; = shl int 4, ubyte %var <i>; yields {int}:result = 4 &lt;&lt; %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001251 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1252 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1253</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001254</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001255<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001256<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1257Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001258<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001259<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001260<pre> &lt;result&gt; = shr &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001261</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001262<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001263<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1264the right a specified number of bits.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001265<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001266<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001267 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1268type.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001269<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001270<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1271most significant bit is duplicated in the newly free'd bit positions.
1272If the first argument is unsigned, zero bits shall fill the empty
1273positions.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001274<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001275<pre> &lt;result&gt; = shr int 4, ubyte %var <i>; yields {int}:result = 4 &gt;&gt; %var</i>
Chris Lattner33426d92003-06-18 21:30:51 +00001276 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001277 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner33426d92003-06-18 21:30:51 +00001278 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1279 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001280</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001281</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001282<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001283<div class="doc_subsection"> <a name="memoryops">Memory Access
1284Operations</a></div>
Misha Brukman76307852003-11-08 01:05:38 +00001285<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +00001286<p>A key design point of an SSA-based representation is how it
1287represents memory. In LLVM, no memory locations are in SSA form, which
1288makes things very simple. This section describes how to read, write,
1289allocate and free memory in LLVM.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001290</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001291<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001292<div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>'
1293Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001294<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001295<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001296<pre> &lt;result&gt; = malloc &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001297 &lt;result&gt; = malloc &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001298</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001299<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001300<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1301heap and returns a pointer to it.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001302<h5>Arguments:</h5>
John Criswella92e5862004-02-24 16:13:56 +00001303<p>The '<tt>malloc</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1304bytes of memory from the operating system and returns a pointer of the
Chris Lattner48b383b02003-11-25 01:02:51 +00001305appropriate type to the program. The second form of the instruction is
1306a shorter version of the first instruction that defaults to allocating
1307one element.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001308<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001309<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001310<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1311a pointer is returned.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001312<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001313<pre> %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
Misha Brukman76307852003-11-08 01:05:38 +00001314
Chris Lattner48b383b02003-11-25 01:02:51 +00001315 %size = <a
1316 href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001317 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1318 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001319</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001320</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001321<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001322<div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>'
1323Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001324<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001325<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001326<pre> free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001327</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001328<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001329<p>The '<tt>free</tt>' instruction returns memory back to the unused
1330memory heap, to be reallocated in the future.</p>
1331<p> </p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001332<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001333<p>'<tt>value</tt>' shall be a pointer value that points to a value
1334that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1335instruction.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001336<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001337<p>Access to the memory pointed to by the pointer is not longer defined
1338after this instruction executes.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001339<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001340<pre> %array = <a href="#i_malloc">malloc</a> [4 x ubyte] <i>; yields {[4 x ubyte]*}:array</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001341 free [4 x ubyte]* %array
1342</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001343</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001344<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001345<div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>'
1346Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001347<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001348<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001349<pre> &lt;result&gt; = alloca &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001350 &lt;result&gt; = alloca &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001351</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001352<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001353<p>The '<tt>alloca</tt>' instruction allocates memory on the current
1354stack frame of the procedure that is live until the current function
1355returns to its caller.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001356<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001357<p>The the '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1358bytes of memory on the runtime stack, returning a pointer of the
1359appropriate type to the program. The second form of the instruction is
1360a shorter version of the first that defaults to allocating one element.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001361<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001362<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001363<p>Memory is allocated, a pointer is returned. '<tt>alloca</tt>'d
1364memory is automatically released when the function returns. The '<tt>alloca</tt>'
1365instruction is commonly used to represent automatic variables that must
1366have an address available. When the function returns (either with the <tt><a
1367 href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt>
Misha Brukman76307852003-11-08 01:05:38 +00001368instructions), the memory is reclaimed.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001369<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001370<pre> %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001371 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001372</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001373</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001374<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001375<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1376Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001377<div class="doc_text">
Chris Lattner095735d2002-05-06 03:03:22 +00001378<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001379<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 Lattner095735d2002-05-06 03:03:22 +00001380<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001381<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00001382<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001383<p>The argument to the '<tt>load</tt>' instruction specifies the memory
1384address to load from. The pointer must point to a <a
1385 href="t_firstclass">first class</a> type. If the <tt>load</tt> is
1386marked as <tt>volatile</tt> then the optimizer is not allowed to modify
1387the number or order of execution of this <tt>load</tt> with other
1388volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1389instructions. </p>
Chris Lattner095735d2002-05-06 03:03:22 +00001390<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001391<p>The location of memory pointed to is loaded.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00001392<h5>Examples:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001393<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1394 <a
1395 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner095735d2002-05-06 03:03:22 +00001396 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1397</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001398</div>
Chris Lattner095735d2002-05-06 03:03:22 +00001399<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001400<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1401Instruction</a> </div>
Chris Lattner095735d2002-05-06 03:03:22 +00001402<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001403<pre> store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt; <i>; yields {void}</i>
Chris Lattner12d456c2003-09-08 18:27:49 +00001404 volatile store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt; <i>; yields {void}</i>
Chris Lattner095735d2002-05-06 03:03:22 +00001405</pre>
Chris Lattner095735d2002-05-06 03:03:22 +00001406<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001407<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00001408<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001409<p>There are two arguments to the '<tt>store</tt>' instruction: a value
1410to store and an address to store it into. The type of the '<tt>&lt;pointer&gt;</tt>'
1411operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
1412operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the
1413optimizer is not allowed to modify the number or order of execution of
1414this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1415 href="#i_store">store</a></tt> instructions.</p>
1416<h5>Semantics:</h5>
1417<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
1418at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00001419<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001420<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1421 <a
1422 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner095735d2002-05-06 03:03:22 +00001423 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1424</pre>
Chris Lattner095735d2002-05-06 03:03:22 +00001425<!-- _______________________________________________________________________ -->
Chris Lattner33fd7022004-04-05 01:30:49 +00001426<div class="doc_subsubsection">
1427 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
1428</div>
1429
Misha Brukman76307852003-11-08 01:05:38 +00001430<div class="doc_text">
Chris Lattner590645f2002-04-14 06:13:44 +00001431<h5>Syntax:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00001432<pre>
1433 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
1434</pre>
1435
Chris Lattner590645f2002-04-14 06:13:44 +00001436<h5>Overview:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00001437
1438<p>
1439The '<tt>getelementptr</tt>' instruction is used to get the address of a
1440subelement of an aggregate data structure.</p>
1441
Chris Lattner590645f2002-04-14 06:13:44 +00001442<h5>Arguments:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00001443
1444<p>This instruction takes a list of integer constants that indicate what
1445elements of the aggregate object to index to. The actual types of the arguments
1446provided depend on the type of the first pointer argument. The
1447'<tt>getelementptr</tt>' instruction is used to index down through the type
1448levels of a structure. When indexing into a structure, only <tt>uint</tt>
1449integer constants are allowed. When indexing into an array or pointer
1450<tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
1451
Chris Lattner48b383b02003-11-25 01:02:51 +00001452<p>For example, let's consider a C code fragment and how it gets
1453compiled to LLVM:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00001454
1455<pre>
1456 struct RT {
1457 char A;
1458 int B[10][20];
1459 char C;
1460 };
1461 struct ST {
1462 int X;
1463 double Y;
1464 struct RT Z;
1465 };
1466
1467 int *foo(struct ST *s) {
1468 return &amp;s[1].Z.B[5][13];
1469 }
1470</pre>
1471
Misha Brukman76307852003-11-08 01:05:38 +00001472<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00001473
1474<pre>
1475 %RT = type { sbyte, [10 x [20 x int]], sbyte }
1476 %ST = type { int, double, %RT }
1477
1478 int* "foo"(%ST* %s) {
1479 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13<br>
1480 ret int* %reg
1481 }
1482</pre>
1483
Chris Lattner590645f2002-04-14 06:13:44 +00001484<h5>Semantics:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00001485
1486<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
1487on the pointer type that is being index into. <a href="t_pointer">Pointer</a>
1488and <a href="t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
1489<tt>ulong</tt>, or <tt>long</tt> values, and <a href="t_struct">structure</a>
1490types require <tt>uint</tt> <b>constants</b>.</p>
1491
Misha Brukman76307852003-11-08 01:05:38 +00001492<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattner33fd7022004-04-05 01:30:49 +00001493type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
1494}</tt>' type, a structure. The second index indexes into the third element of
1495the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
1496sbyte }</tt>' type, another structure. The third index indexes into the second
1497element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
1498array. The two dimensions of the array are subscripted into, yielding an
1499'<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction return a pointer
1500to this element, thus computing a value of '<tt>int*</tt>' type.</p>
1501
Chris Lattner48b383b02003-11-25 01:02:51 +00001502<p>Note that it is perfectly legal to index partially through a
1503structure, returning a pointer to an inner element. Because of this,
1504the LLVM code for the given testcase is equivalent to:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00001505
1506<pre>
1507 int* "foo"(%ST* %s) {
1508 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
1509 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
1510 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
1511 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
1512 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
1513 ret int* %t5
1514 }
Chris Lattnera8292f32002-05-06 22:08:29 +00001515</pre>
Chris Lattner590645f2002-04-14 06:13:44 +00001516<h5>Example:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00001517<pre>
1518 <i>; yields [12 x ubyte]*:aptr</i>
1519 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
1520</pre>
1521
1522</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001523<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001524<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001525<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +00001526<p>The instructions in this catagory are the "miscellaneous"
1527instructions, which defy better classification.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001528</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001529<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001530<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
1531Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001532<div class="doc_text">
Chris Lattner70de6632001-07-09 00:26:23 +00001533<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001534<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner70de6632001-07-09 00:26:23 +00001535<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001536<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
1537the SSA graph representing the function.</p>
Chris Lattner70de6632001-07-09 00:26:23 +00001538<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001539<p>The type of the incoming values are specified with the first type
1540field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
1541as arguments, with one pair for each predecessor basic block of the
1542current block. Only values of <a href="#t_firstclass">first class</a>
1543type may be used as the value arguments to the PHI node. Only labels
1544may be used as the label arguments.</p>
1545<p>There must be no non-phi instructions between the start of a basic
1546block and the PHI instructions: i.e. PHI instructions must be first in
1547a basic block.</p>
Chris Lattner70de6632001-07-09 00:26:23 +00001548<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001549<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
1550value specified by the parameter, depending on which basic block we
1551came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattnera8292f32002-05-06 22:08:29 +00001552<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001553<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 Brukman76307852003-11-08 01:05:38 +00001554</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001555
Chris Lattnera8292f32002-05-06 22:08:29 +00001556<!-- _______________________________________________________________________ -->
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001557<div class="doc_subsubsection">
1558 <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
1559</div>
1560
Misha Brukman76307852003-11-08 01:05:38 +00001561<div class="doc_text">
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001562
Chris Lattnera8292f32002-05-06 22:08:29 +00001563<h5>Syntax:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001564
1565<pre>
1566 &lt;result&gt; = cast &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Chris Lattnera8292f32002-05-06 22:08:29 +00001567</pre>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001568
Chris Lattnera8292f32002-05-06 22:08:29 +00001569<h5>Overview:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001570
1571<p>
1572The '<tt>cast</tt>' instruction is used as the primitive means to convert
1573integers to floating point, change data type sizes, and break type safety (by
1574casting pointers).
1575</p>
1576
1577
Chris Lattnera8292f32002-05-06 22:08:29 +00001578<h5>Arguments:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001579
1580<p>
1581The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
1582class value, and a type to cast it to, which must also be a <a
1583href="#t_firstclass">first class</a> type.
1584</p>
1585
Chris Lattnera8292f32002-05-06 22:08:29 +00001586<h5>Semantics:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001587
1588<p>
1589This instruction follows the C rules for explicit casts when determining how the
1590data being cast must change to fit in its new container.
1591</p>
1592
1593<p>
1594When casting to bool, any value that would be considered true in the context of
1595a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
1596all else are '<tt>false</tt>'.
1597</p>
1598
1599<p>
1600When extending an integral value from a type of one signness to another (for
1601example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
1602<b>source</b> value is signed, and zero-extended if the source value is
1603unsigned. <tt>bool</tt> values are always zero extended into either zero or
1604one.
1605</p>
1606
Chris Lattner70de6632001-07-09 00:26:23 +00001607<h5>Example:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001608
1609<pre>
1610 %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattnerd8f8ede2002-06-25 18:03:17 +00001611 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner70de6632001-07-09 00:26:23 +00001612</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001613</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001614
1615<!-- _______________________________________________________________________ -->
1616<div class="doc_subsubsection">
1617 <a name="i_select">'<tt>select</tt>' Instruction</a>
1618</div>
1619
1620<div class="doc_text">
1621
1622<h5>Syntax:</h5>
1623
1624<pre>
1625 &lt;result&gt; = select bool &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
1626</pre>
1627
1628<h5>Overview:</h5>
1629
1630<p>
1631The '<tt>select</tt>' instruction is used to choose one value based on a
1632condition, without branching.
1633</p>
1634
1635
1636<h5>Arguments:</h5>
1637
1638<p>
1639The '<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.
1640</p>
1641
1642<h5>Semantics:</h5>
1643
1644<p>
1645If the boolean condition evaluates to true, the instruction returns the first
1646value argument, otherwise it returns the second value argument.
1647</p>
1648
1649<h5>Example:</h5>
1650
1651<pre>
1652 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
1653</pre>
1654</div>
1655
1656
1657
1658
1659
Chris Lattner70de6632001-07-09 00:26:23 +00001660<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001661<div class="doc_subsubsection"> <a name="i_call">'<tt>call</tt>'
1662Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001663<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001664<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001665<pre> &lt;result&gt; = call &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)<br></pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001666<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001667<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001668<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001669<p>This instruction requires several arguments:</p>
Chris Lattnera8292f32002-05-06 22:08:29 +00001670<ol>
Chris Lattner48b383b02003-11-25 01:02:51 +00001671 <li>
1672 <p>'<tt>ty</tt>': shall be the signature of the pointer to function
1673value being invoked. The argument types must match the types implied
1674by this signature.</p>
1675 </li>
1676 <li>
1677 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a
1678function to be invoked. In most cases, this is a direct function
1679invocation, but indirect <tt>call</tt>s are just as possible,
1680calling an arbitrary pointer to function values.</p>
1681 </li>
1682 <li>
1683 <p>'<tt>function args</tt>': argument list whose types match the
1684function signature argument types. If the function signature
1685indicates the function accepts a variable number of arguments, the
1686extra arguments can be specified.</p>
1687 </li>
Chris Lattnera8292f32002-05-06 22:08:29 +00001688</ol>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001689<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001690<p>The '<tt>call</tt>' instruction is used to cause control flow to
1691transfer to a specified function, with its incoming arguments bound to
1692the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
1693instruction in the called function, control flow continues with the
1694instruction after the function call, and the return value of the
1695function is bound to the result argument. This is a simpler case of
1696the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001697<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001698<pre> %retval = call int %test(int %argc)<br> call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42);<br></pre>
Misha Brukman76307852003-11-08 01:05:38 +00001699</div>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001700<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001701<div class="doc_subsubsection"> <a name="i_vanext">'<tt>vanext</tt>'
1702Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001703<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001704<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001705<pre> &lt;resultarglist&gt; = vanext &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001706<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001707<p>The '<tt>vanext</tt>' instruction is used to access arguments passed
1708through the "variable argument" area of a function call. It is used to
1709implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001710<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001711<p>This instruction takes a <tt>valist</tt> value and the type of the
1712argument. It returns another <tt>valist</tt>.</p>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001713<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001714<p>The '<tt>vanext</tt>' instruction advances the specified <tt>valist</tt>
1715past an argument of the specified type. In conjunction with the <a
1716 href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement
1717the <tt>va_arg</tt> macro available in C. For more information, see
1718the variable argument handling <a href="#int_varargs">Intrinsic
1719Functions</a>.</p>
1720<p>It is legal for this instruction to be called in a function which
1721does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman76307852003-11-08 01:05:38 +00001722function.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001723<p><tt>vanext</tt> is an LLVM instruction instead of an <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001724 href="#intrinsics">intrinsic function</a> because it takes an type as
1725an argument.</p>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001726<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001727<p>See the <a href="#int_varargs">variable argument processing</a>
1728section.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001729</div>
Chris Lattner26ca62e2003-10-18 05:51:36 +00001730<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001731<div class="doc_subsubsection"> <a name="i_vaarg">'<tt>vaarg</tt>'
1732Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001733<div class="doc_text">
Chris Lattner26ca62e2003-10-18 05:51:36 +00001734<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001735<pre> &lt;resultval&gt; = vaarg &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;<br></pre>
Chris Lattner26ca62e2003-10-18 05:51:36 +00001736<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001737<p>The '<tt>vaarg</tt>' instruction is used to access arguments passed
1738through the "variable argument" area of a function call. It is used to
1739implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattner26ca62e2003-10-18 05:51:36 +00001740<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001741<p>This instruction takes a <tt>valist</tt> value and the type of the
1742argument. It returns a value of the specified argument type.</p>
Chris Lattner26ca62e2003-10-18 05:51:36 +00001743<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001744<p>The '<tt>vaarg</tt>' instruction loads an argument of the specified
1745type from the specified <tt>va_list</tt>. In conjunction with the <a
1746 href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to
1747implement the <tt>va_arg</tt> macro available in C. For more
1748information, see the variable argument handling <a href="#int_varargs">Intrinsic
1749Functions</a>.</p>
1750<p>It is legal for this instruction to be called in a function which
1751does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman76307852003-11-08 01:05:38 +00001752function.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001753<p><tt>vaarg</tt> is an LLVM instruction instead of an <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001754 href="#intrinsics">intrinsic function</a> because it takes an type as
1755an argument.</p>
Chris Lattner26ca62e2003-10-18 05:51:36 +00001756<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001757<p>See the <a href="#int_varargs">variable argument processing</a>
1758section.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001759</div>
Chris Lattner941515c2004-01-06 05:31:32 +00001760
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001761<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001762<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
1763<!-- *********************************************************************** -->
Chris Lattner941515c2004-01-06 05:31:32 +00001764
Misha Brukman76307852003-11-08 01:05:38 +00001765<div class="doc_text">
Chris Lattnerfee11462004-02-12 17:01:32 +00001766
1767<p>LLVM supports the notion of an "intrinsic function". These functions have
1768well known names and semantics, and are required to follow certain
1769restrictions. Overall, these instructions represent an extension mechanism for
1770the LLVM language that does not require changing all of the transformations in
1771LLVM to add to the language (or the bytecode reader/writer, the parser,
1772etc...).</p>
1773
1774<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix, this
1775prefix is reserved in LLVM for intrinsic names, thus functions may not be named
1776this. Intrinsic functions must always be external functions: you cannot define
1777the body of intrinsic functions. Intrinsic functions may only be used in call
1778or invoke instructions: it is illegal to take the address of an intrinsic
1779function. Additionally, because intrinsic functions are part of the LLVM
1780language, it is required that they all be documented here if any are added.</p>
1781
1782
1783<p>
1784Adding an intrinsic to LLVM is straight-forward if it is possible to express the
1785concept in LLVM directly (ie, code generator support is not _required_). To do
1786this, extend the default implementation of the IntrinsicLowering class to handle
1787the intrinsic. Code generators use this class to lower intrinsics they do not
1788understand to raw LLVM instructions that they do.
1789</p>
1790
Misha Brukman76307852003-11-08 01:05:38 +00001791</div>
Chris Lattner941515c2004-01-06 05:31:32 +00001792
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001793<!-- ======================================================================= -->
Chris Lattner941515c2004-01-06 05:31:32 +00001794<div class="doc_subsection">
1795 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
1796</div>
1797
Misha Brukman76307852003-11-08 01:05:38 +00001798<div class="doc_text">
Misha Brukman76307852003-11-08 01:05:38 +00001799<p>Variable argument support is defined in LLVM with the <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001800 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
1801intrinsic functions. These functions are related to the similarly
1802named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
1803<p>All of these functions operate on arguments that use a
1804target-specific value type "<tt>va_list</tt>". The LLVM assembly
1805language reference manual does not define what this type is, so all
1806transformations should be prepared to handle intrinsics with any type
1807used.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001808<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner48b383b02003-11-25 01:02:51 +00001809instruction and the variable argument handling intrinsic functions are
1810used.</p>
Chris Lattnerfee11462004-02-12 17:01:32 +00001811<pre>
1812int %test(int %X, ...) {
1813 ; Initialize variable argument processing
1814 %ap = call sbyte* %<a href="#i_va_start">llvm.va_start</a>()
1815
1816 ; Read a single integer argument
1817 %tmp = vaarg sbyte* %ap, int
1818
1819 ; Advance to the next argument
1820 %ap2 = vanext sbyte* %ap, int
1821
1822 ; Demonstrate usage of llvm.va_copy and llvm.va_end
1823 %aq = call sbyte* %<a href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2)
1824 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %aq)
1825
1826 ; Stop processing of arguments.
1827 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %ap2)
1828 ret int %tmp
1829}
1830</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001831</div>
Chris Lattner941515c2004-01-06 05:31:32 +00001832
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001833<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00001834<div class="doc_subsubsection">
1835 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
1836</div>
1837
1838
Misha Brukman76307852003-11-08 01:05:38 +00001839<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001840<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001841<pre> call va_list ()* %llvm.va_start()<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001842<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001843<p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt>&lt;arglist&gt;</tt>
1844for subsequent use by the variable argument intrinsics.</p>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001845<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001846<p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00001847macro available in C. In a target-dependent way, it initializes and
1848returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt>
1849will produce the first variable argument passed to the function. Unlike
1850the C <tt>va_start</tt> macro, this intrinsic does not need to know the
1851last argument of the function, the compiler can figure that out.</p>
1852<p>Note that this intrinsic function is only legal to be called from
1853within the body of a variable argument function.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001854</div>
Chris Lattner941515c2004-01-06 05:31:32 +00001855
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001856<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00001857<div class="doc_subsubsection">
1858 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
1859</div>
1860
Misha Brukman76307852003-11-08 01:05:38 +00001861<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001862<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001863<pre> call void (va_list)* %llvm.va_end(va_list &lt;arglist&gt;)<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001864<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001865<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
1866which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
1867or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001868<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001869<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001870<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001871<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00001872macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
1873Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
1874 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
1875with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001876</div>
Chris Lattner941515c2004-01-06 05:31:32 +00001877
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001878<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00001879<div class="doc_subsubsection">
1880 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
1881</div>
1882
Misha Brukman76307852003-11-08 01:05:38 +00001883<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001884<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001885<pre> call va_list (va_list)* %llvm.va_copy(va_list &lt;destarglist&gt;)<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001886<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001887<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument
1888position from the source argument list to the destination argument list.</p>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001889<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001890<p>The argument is the <tt>va_list</tt> to copy.</p>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001891<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001892<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00001893macro available in C. In a target-dependent way, it copies the source <tt>va_list</tt>
1894element into the returned list. This intrinsic is necessary because the <tt><a
1895 href="i_va_start">llvm.va_start</a></tt> intrinsic may be arbitrarily
1896complex and require memory allocation, for example.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001897</div>
Chris Lattner941515c2004-01-06 05:31:32 +00001898
Chris Lattnerfee11462004-02-12 17:01:32 +00001899<!-- ======================================================================= -->
1900<div class="doc_subsection">
Chris Lattner3649c3a2004-02-14 04:08:35 +00001901 <a name="int_codegen">Code Generator Intrinsics</a>
1902</div>
1903
1904<div class="doc_text">
1905<p>
1906These intrinsics are provided by LLVM to expose special features that may only
1907be implemented with code generator support.
1908</p>
1909
1910</div>
1911
1912<!-- _______________________________________________________________________ -->
1913<div class="doc_subsubsection">
1914 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
1915</div>
1916
1917<div class="doc_text">
1918
1919<h5>Syntax:</h5>
1920<pre>
1921 call void* ()* %llvm.returnaddress(uint &lt;level&gt;)
1922</pre>
1923
1924<h5>Overview:</h5>
1925
1926<p>
1927The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
1928indicating the return address of the current function or one of its callers.
1929</p>
1930
1931<h5>Arguments:</h5>
1932
1933<p>
1934The argument to this intrinsic indicates which function to return the address
1935for. Zero indicates the calling function, one indicates its caller, etc. The
1936argument is <b>required</b> to be a constant integer value.
1937</p>
1938
1939<h5>Semantics:</h5>
1940
1941<p>
1942The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
1943the return address of the specified call frame, or zero if it cannot be
1944identified. The value returned by this intrinsic is likely to be incorrect or 0
1945for arguments other than zero, so it should only be used for debugging purposes.
1946</p>
1947
1948<p>
1949Note that calling this intrinsic does not prevent function inlining or other
1950aggressive transformations, so the value returned may not that of the obvious
1951source-language caller.
1952</p>
1953</div>
1954
1955
1956<!-- _______________________________________________________________________ -->
1957<div class="doc_subsubsection">
1958 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
1959</div>
1960
1961<div class="doc_text">
1962
1963<h5>Syntax:</h5>
1964<pre>
1965 call void* ()* %llvm.frameaddress(uint &lt;level&gt;)
1966</pre>
1967
1968<h5>Overview:</h5>
1969
1970<p>
1971The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
1972pointer value for the specified stack frame.
1973</p>
1974
1975<h5>Arguments:</h5>
1976
1977<p>
1978The argument to this intrinsic indicates which function to return the frame
1979pointer for. Zero indicates the calling function, one indicates its caller,
1980etc. The argument is <b>required</b> to be a constant integer value.
1981</p>
1982
1983<h5>Semantics:</h5>
1984
1985<p>
1986The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
1987the frame address of the specified call frame, or zero if it cannot be
1988identified. The value returned by this intrinsic is likely to be incorrect or 0
1989for arguments other than zero, so it should only be used for debugging purposes.
1990</p>
1991
1992<p>
1993Note that calling this intrinsic does not prevent function inlining or other
1994aggressive transformations, so the value returned may not that of the obvious
1995source-language caller.
1996</p>
1997</div>
1998
1999
2000<!-- ======================================================================= -->
2001<div class="doc_subsection">
Chris Lattnerfee11462004-02-12 17:01:32 +00002002 <a name="int_libc">Standard C Library Intrinsics</a>
2003</div>
2004
2005<div class="doc_text">
2006<p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00002007LLVM provides intrinsics for a few important standard C library functions.
2008These intrinsics allow source-language front-ends to pass information about the
2009alignment of the pointer arguments to the code generator, providing opportunity
2010for more efficient code generation.
Chris Lattnerfee11462004-02-12 17:01:32 +00002011</p>
2012
2013</div>
2014
2015<!-- _______________________________________________________________________ -->
2016<div class="doc_subsubsection">
2017 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
2018</div>
2019
2020<div class="doc_text">
2021
2022<h5>Syntax:</h5>
2023<pre>
2024 call void (sbyte*, sbyte*, uint, uint)* %llvm.memcpy(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2025 uint &lt;len&gt;, uint &lt;align&gt;)
2026</pre>
2027
2028<h5>Overview:</h5>
2029
2030<p>
2031The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2032location to the destination location.
2033</p>
2034
2035<p>
2036Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
2037does not return a value, and takes an extra alignment argument.
2038</p>
2039
2040<h5>Arguments:</h5>
2041
2042<p>
2043The first argument is a pointer to the destination, the second is a pointer to
2044the source. The third argument is an (arbitrarily sized) integer argument
2045specifying the number of bytes to copy, and the fourth argument is the alignment
2046of the source and destination locations.
2047</p>
2048
Chris Lattner4c67c482004-02-12 21:18:15 +00002049<p>
2050If the call to this intrinisic has an alignment value that is not 0 or 1, then
2051the caller guarantees that the size of the copy is a multiple of the alignment
2052and that both the source and destination pointers are aligned to that boundary.
2053</p>
2054
Chris Lattnerfee11462004-02-12 17:01:32 +00002055<h5>Semantics:</h5>
2056
2057<p>
2058The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2059location to the destination location, which are not allowed to overlap. It
2060copies "len" bytes of memory over. If the argument is known to be aligned to
2061some boundary, this can be specified as the fourth argument, otherwise it should
2062be set to 0 or 1.
2063</p>
2064</div>
2065
2066
Chris Lattnerf30152e2004-02-12 18:10:10 +00002067<!-- _______________________________________________________________________ -->
2068<div class="doc_subsubsection">
2069 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
2070</div>
2071
2072<div class="doc_text">
2073
2074<h5>Syntax:</h5>
2075<pre>
2076 call void (sbyte*, sbyte*, uint, uint)* %llvm.memmove(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2077 uint &lt;len&gt;, uint &lt;align&gt;)
2078</pre>
2079
2080<h5>Overview:</h5>
2081
2082<p>
2083The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
2084location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>'
2085intrinsic but allows the two memory locations to overlap.
2086</p>
2087
2088<p>
2089Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
2090does not return a value, and takes an extra alignment argument.
2091</p>
2092
2093<h5>Arguments:</h5>
2094
2095<p>
2096The first argument is a pointer to the destination, the second is a pointer to
2097the source. The third argument is an (arbitrarily sized) integer argument
2098specifying the number of bytes to copy, and the fourth argument is the alignment
2099of the source and destination locations.
2100</p>
2101
Chris Lattner4c67c482004-02-12 21:18:15 +00002102<p>
2103If the call to this intrinisic has an alignment value that is not 0 or 1, then
2104the caller guarantees that the size of the copy is a multiple of the alignment
2105and that both the source and destination pointers are aligned to that boundary.
2106</p>
2107
Chris Lattnerf30152e2004-02-12 18:10:10 +00002108<h5>Semantics:</h5>
2109
2110<p>
2111The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
2112location to the destination location, which may overlap. It
2113copies "len" bytes of memory over. If the argument is known to be aligned to
2114some boundary, this can be specified as the fourth argument, otherwise it should
2115be set to 0 or 1.
2116</p>
2117</div>
2118
Chris Lattner941515c2004-01-06 05:31:32 +00002119
Chris Lattner3649c3a2004-02-14 04:08:35 +00002120<!-- _______________________________________________________________________ -->
2121<div class="doc_subsubsection">
2122 <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a>
2123</div>
2124
2125<div class="doc_text">
2126
2127<h5>Syntax:</h5>
2128<pre>
2129 call void (sbyte*, ubyte, uint, uint)* %llvm.memset(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
2130 uint &lt;len&gt;, uint &lt;align&gt;)
2131</pre>
2132
2133<h5>Overview:</h5>
2134
2135<p>
2136The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular
2137byte value.
2138</p>
2139
2140<p>
2141Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
2142does not return a value, and takes an extra alignment argument.
2143</p>
2144
2145<h5>Arguments:</h5>
2146
2147<p>
2148The first argument is a pointer to the destination to fill, the second is the
2149byte value to fill it with, the third argument is an (arbitrarily sized) integer
2150argument specifying the number of bytes to fill, and the fourth argument is the
2151known alignment of destination location.
2152</p>
2153
2154<p>
2155If the call to this intrinisic has an alignment value that is not 0 or 1, then
2156the caller guarantees that the size of the copy is a multiple of the alignment
2157and that the destination pointer is aligned to that boundary.
2158</p>
2159
2160<h5>Semantics:</h5>
2161
2162<p>
2163The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the
2164destination location. If the argument is known to be aligned to some boundary,
2165this can be specified as the fourth argument, otherwise it should be set to 0 or
21661.
2167</p>
2168</div>
2169
2170
Chris Lattner941515c2004-01-06 05:31:32 +00002171<!-- ======================================================================= -->
2172<div class="doc_subsection">
2173 <a name="int_debugger">Debugger Intrinsics</a>
2174</div>
2175
2176<div class="doc_text">
2177<p>
2178The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
2179are described in the <a
2180href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
2181Debugging</a> document.
2182</p>
2183</div>
2184
2185
Chris Lattner2f7c9632001-06-06 20:29:01 +00002186<!-- *********************************************************************** -->
Chris Lattner2f7c9632001-06-06 20:29:01 +00002187<hr>
Misha Brukmanc501f552004-03-01 17:47:27 +00002188<address>
2189 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
2190 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
2191 <a href="http://validator.w3.org/check/referer"><img
2192 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
2193
2194 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
2195 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
2196 Last modified: $Date$
2197</address>
Misha Brukman76307852003-11-08 01:05:38 +00002198</body>
2199</html>