blob: 42767e63d50afbdd7fa7534df2797bc0ea1d0aca [file] [log] [blame]
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
Misha Brukman9d0919f2003-11-08 01:05:38 +00003<html>
4<head>
5 <title>LLVM Assembly Language Reference Manual</title>
Reid Spencer3921c742004-08-26 20:44:00 +00006 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7 <meta name="author" content="Chris Lattner">
8 <meta name="description"
9 content="LLVM Assembly Language Reference Manual.">
Misha Brukman9d0919f2003-11-08 01:05:38 +000010 <link rel="stylesheet" href="llvm.css" type="text/css">
11</head>
Chris Lattnerd7923912004-05-23 21:06:01 +000012
Misha Brukman9d0919f2003-11-08 01:05:38 +000013<body>
Chris Lattnerd7923912004-05-23 21:06:01 +000014
Chris Lattner261efe92003-11-25 01:02:51 +000015<div class="doc_title"> LLVM Language Reference Manual </div>
Chris Lattner00950542001-06-06 20:29:01 +000016<ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000017 <li><a href="#abstract">Abstract</a></li>
18 <li><a href="#introduction">Introduction</a></li>
19 <li><a href="#identifiers">Identifiers</a></li>
Chris Lattnerfa730212004-12-09 16:11:40 +000020 <li><a href="#highlevel">High Level Structure</a>
21 <ol>
22 <li><a href="#modulestructure">Module Structure</a></li>
Chris Lattnere5d947b2004-12-09 16:36:40 +000023 <li><a href="#linkage">Linkage Types</a></li>
Chris Lattnerfa730212004-12-09 16:11:40 +000024 <li><a href="#globalvars">Global Variables</a></li>
25 <li><a href="#functionstructure">Function Structure</a></li>
26 </ol>
27 </li>
Chris Lattner00950542001-06-06 20:29:01 +000028 <li><a href="#typesystem">Type System</a>
29 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000030 <li><a href="#t_primitive">Primitive Types</a>
31 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000032 <li><a href="#t_classifications">Type Classifications</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000033 </ol>
34 </li>
Chris Lattner00950542001-06-06 20:29:01 +000035 <li><a href="#t_derived">Derived Types</a>
36 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000037 <li><a href="#t_array">Array Type</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000038 <li><a href="#t_function">Function Type</a></li>
39 <li><a href="#t_pointer">Pointer Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000040 <li><a href="#t_struct">Structure Type</a></li>
Chris Lattnera58561b2004-08-12 19:12:28 +000041 <li><a href="#t_packed">Packed Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000042 </ol>
43 </li>
44 </ol>
45 </li>
Chris Lattnerfa730212004-12-09 16:11:40 +000046 <li><a href="#constants">Constants</a>
Chris Lattner261efe92003-11-25 01:02:51 +000047 </li>
Chris Lattner00950542001-06-06 20:29:01 +000048 <li><a href="#instref">Instruction Reference</a>
49 <ol>
50 <li><a href="#terminators">Terminator Instructions</a>
51 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000052 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
53 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000054 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
55 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000056 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
Chris Lattner35eca582004-10-16 18:04:13 +000057 <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000058 </ol>
59 </li>
Chris Lattner00950542001-06-06 20:29:01 +000060 <li><a href="#binaryops">Binary Operations</a>
61 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000062 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
63 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
64 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
65 <li><a href="#i_div">'<tt>div</tt>' Instruction</a></li>
66 <li><a href="#i_rem">'<tt>rem</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000067 <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000068 </ol>
69 </li>
Chris Lattner00950542001-06-06 20:29:01 +000070 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
71 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000072 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000073 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000074 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
75 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
76 <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000077 </ol>
78 </li>
Chris Lattner00950542001-06-06 20:29:01 +000079 <li><a href="#memoryops">Memory Access Operations</a>
80 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000081 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
82 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
83 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
84 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
85 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
86 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
87 </ol>
88 </li>
Chris Lattner00950542001-06-06 20:29:01 +000089 <li><a href="#otherops">Other Operations</a>
90 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000091 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000092 <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li>
Chris Lattnercc37aae2004-03-12 05:50:16 +000093 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000094 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000095 <li><a href="#i_vanext">'<tt>vanext</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000096 <li><a href="#i_vaarg">'<tt>vaarg</tt>' Instruction</a></li>
Chris Lattner00950542001-06-06 20:29:01 +000097 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +000098 </li>
Chris Lattner00950542001-06-06 20:29:01 +000099 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000100 </li>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +0000101 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +0000102 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000103 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
104 <ol>
105 <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
106 <li><a href="#i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
107 <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
108 </ol>
109 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000110 <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
111 <ol>
112 <li><a href="#i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li>
113 <li><a href="#i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li>
114 <li><a href="#i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li>
115 </ol>
116 </li>
Chris Lattner10610642004-02-14 04:08:35 +0000117 <li><a href="#int_codegen">Code Generator Intrinsics</a>
118 <ol>
119 <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
120 <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
John Criswell7123e272004-04-09 16:43:20 +0000121 </ol>
122 </li>
123 <li><a href="#int_os">Operating System Intrinsics</a>
124 <ol>
Chris Lattner32006282004-06-11 02:28:03 +0000125 <li><a href="#i_readport">'<tt>llvm.readport</tt>' Intrinsic</a></li>
126 <li><a href="#i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a></li>
John Criswell183402a2004-04-12 15:02:16 +0000127 <li><a href="#i_readio">'<tt>llvm.readio</tt>' Intrinsic</a></li>
128 <li><a href="#i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000129 </ol>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000130 <li><a href="#int_libc">Standard C Library Intrinsics</a>
131 <ol>
132 <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li>
Chris Lattner0eb51b42004-02-12 18:10:10 +0000133 <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000134 <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li>
Alkis Evlogimenos96853722004-06-12 19:19:14 +0000135 <li><a href="#i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a></li>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000136 </ol>
137 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000138 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000139 </ol>
140 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000141</ol>
Chris Lattnerd7923912004-05-23 21:06:01 +0000142
143<div class="doc_author">
144 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
145 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000146</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000147
Chris Lattner00950542001-06-06 20:29:01 +0000148<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000149<div class="doc_section"> <a name="abstract">Abstract </a></div>
150<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000151
Misha Brukman9d0919f2003-11-08 01:05:38 +0000152<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000153<p>This document is a reference manual for the LLVM assembly language.
154LLVM is an SSA based representation that provides type safety,
155low-level operations, flexibility, and the capability of representing
156'all' high-level languages cleanly. It is the common code
157representation used throughout all phases of the LLVM compilation
158strategy.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000159</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000160
Chris Lattner00950542001-06-06 20:29:01 +0000161<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000162<div class="doc_section"> <a name="introduction">Introduction</a> </div>
163<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000164
Misha Brukman9d0919f2003-11-08 01:05:38 +0000165<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000166
Chris Lattner261efe92003-11-25 01:02:51 +0000167<p>The LLVM code representation is designed to be used in three
168different forms: as an in-memory compiler IR, as an on-disk bytecode
169representation (suitable for fast loading by a Just-In-Time compiler),
170and as a human readable assembly language representation. This allows
171LLVM to provide a powerful intermediate representation for efficient
172compiler transformations and analysis, while providing a natural means
173to debug and visualize the transformations. The three different forms
174of LLVM are all equivalent. This document describes the human readable
175representation and notation.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000176
Chris Lattner261efe92003-11-25 01:02:51 +0000177<p>The LLVM representation aims to be a light-weight and low-level
178while being expressive, typed, and extensible at the same time. It
179aims to be a "universal IR" of sorts, by being at a low enough level
180that high-level ideas may be cleanly mapped to it (similar to how
181microprocessors are "universal IR's", allowing many source languages to
182be mapped to them). By providing type information, LLVM can be used as
183the target of optimizations: for example, through pointer analysis, it
184can be proven that a C automatic variable is never accessed outside of
185the current function... allowing it to be promoted to a simple SSA
186value instead of a memory location.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000187
Misha Brukman9d0919f2003-11-08 01:05:38 +0000188</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000189
Chris Lattner00950542001-06-06 20:29:01 +0000190<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000191<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000192
Misha Brukman9d0919f2003-11-08 01:05:38 +0000193<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000194
Chris Lattner261efe92003-11-25 01:02:51 +0000195<p>It is important to note that this document describes 'well formed'
196LLVM assembly language. There is a difference between what the parser
197accepts and what is considered 'well formed'. For example, the
198following instruction is syntactically okay, but not well formed:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000199
200<pre>
201 %x = <a href="#i_add">add</a> int 1, %x
202</pre>
203
Chris Lattner261efe92003-11-25 01:02:51 +0000204<p>...because the definition of <tt>%x</tt> does not dominate all of
205its uses. The LLVM infrastructure provides a verification pass that may
206be used to verify that an LLVM module is well formed. This pass is
207automatically run by the parser after parsing input assembly, and by
208the optimizer before it outputs bytecode. The violations pointed out
209by the verifier pass indicate bugs in transformation passes or input to
210the parser.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000211
Chris Lattner261efe92003-11-25 01:02:51 +0000212<!-- Describe the typesetting conventions here. --> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000213
Chris Lattner00950542001-06-06 20:29:01 +0000214<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000215<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000216<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000217
Misha Brukman9d0919f2003-11-08 01:05:38 +0000218<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000219
Chris Lattner261efe92003-11-25 01:02:51 +0000220<p>LLVM uses three different forms of identifiers, for different
221purposes:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000222
Chris Lattner00950542001-06-06 20:29:01 +0000223<ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000224 <li>Numeric constants are represented as you would expect: 12, -3 123.421,
225 etc. Floating point constants have an optional hexadecimal notation.</li>
226
227 <li>Named values are represented as a string of characters with a '%' prefix.
228 For example, %foo, %DivisionByZero, %a.really.long.identifier. The actual
229 regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
230 Identifiers which require other characters in their names can be surrounded
231 with quotes. In this way, anything except a <tt>"</tt> character can be used
232 in a name.</li>
233
234 <li>Unnamed values are represented as an unsigned numeric value with a '%'
235 prefix. For example, %12, %2, %44.</li>
236
Misha Brukman9d0919f2003-11-08 01:05:38 +0000237</ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000238
239<p>LLVM requires that values start with a '%' sign for two reasons: Compilers
240don't need to worry about name clashes with reserved words, and the set of
241reserved words may be expanded in the future without penalty. Additionally,
242unnamed identifiers allow a compiler to quickly come up with a temporary
243variable without having to avoid symbol table conflicts.</p>
244
Chris Lattner261efe92003-11-25 01:02:51 +0000245<p>Reserved words in LLVM are very similar to reserved words in other
246languages. There are keywords for different opcodes ('<tt><a
Chris Lattnere5d947b2004-12-09 16:36:40 +0000247href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
248href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
249href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>', etc...),
250and others. These reserved words cannot conflict with variable names, because
251none of them start with a '%' character.</p>
252
253<p>Here is an example of LLVM code to multiply the integer variable
254'<tt>%X</tt>' by 8:</p>
255
Misha Brukman9d0919f2003-11-08 01:05:38 +0000256<p>The easy way:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000257
258<pre>
259 %result = <a href="#i_mul">mul</a> uint %X, 8
260</pre>
261
Misha Brukman9d0919f2003-11-08 01:05:38 +0000262<p>After strength reduction:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000263
264<pre>
265 %result = <a href="#i_shl">shl</a> uint %X, ubyte 3
266</pre>
267
Misha Brukman9d0919f2003-11-08 01:05:38 +0000268<p>And the hard way:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000269
270<pre>
271 <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
272 <a href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
273 %result = <a href="#i_add">add</a> uint %1, %1
274</pre>
275
Chris Lattner261efe92003-11-25 01:02:51 +0000276<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
277important lexical features of LLVM:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000278
Chris Lattner00950542001-06-06 20:29:01 +0000279<ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000280
281 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
282 line.</li>
283
284 <li>Unnamed temporaries are created when the result of a computation is not
285 assigned to a named value.</li>
286
Misha Brukman9d0919f2003-11-08 01:05:38 +0000287 <li>Unnamed temporaries are numbered sequentially</li>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000288
Misha Brukman9d0919f2003-11-08 01:05:38 +0000289</ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000290
291<p>...and it also show a convention that we follow in this document. When
292demonstrating instructions, we will follow an instruction with a comment that
293defines the type and name of value produced. Comments are shown in italic
294text.</p>
295
296<p>The one non-intuitive notation for constants is the optional hexidecimal form
297of floating point constants. For example, the form '<tt>double
Chris Lattner2b7d3202002-05-06 03:03:22 +00002980x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
Chris Lattnere5d947b2004-12-09 16:36:40 +00002994.5e+15</tt>' which is also supported by the parser. The only time hexadecimal
300floating point constants are useful (and the only time that they are generated
301by the disassembler) is when an FP constant has to be emitted that is not
302representable as a decimal floating point number exactly. For example, NaN's,
303infinities, and other special cases are represented in their IEEE hexadecimal
304format so that assembly and disassembly do not cause any bits to change in the
305constants.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000306</div>
Chris Lattnerfa730212004-12-09 16:11:40 +0000307
308<!-- *********************************************************************** -->
309<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
310<!-- *********************************************************************** -->
311
312<!-- ======================================================================= -->
313<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
314</div>
315
316<div class="doc_text">
317
318<p>LLVM programs are composed of "Module"s, each of which is a
319translation unit of the input programs. Each module consists of
320functions, global variables, and symbol table entries. Modules may be
321combined together with the LLVM linker, which merges function (and
322global variable) definitions, resolves forward declarations, and merges
323symbol table entries. Here is an example of the "hello world" module:</p>
324
325<pre><i>; Declare the string constant as a global constant...</i>
326<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
327 href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00" <i>; [13 x sbyte]*</i>
328
329<i>; External declaration of the puts function</i>
330<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
331
332<i>; Definition of main function</i>
333int %main() { <i>; int()* </i>
334 <i>; Convert [13x sbyte]* to sbyte *...</i>
335 %cast210 = <a
336 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
337
338 <i>; Call puts function to write out the string to stdout...</i>
339 <a
340 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
341 <a
342 href="#i_ret">ret</a> int 0<br>}<br></pre>
343
344<p>This example is made up of a <a href="#globalvars">global variable</a>
345named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
346function, and a <a href="#functionstructure">function definition</a>
347for "<tt>main</tt>".</p>
348
Chris Lattnere5d947b2004-12-09 16:36:40 +0000349<p>In general, a module is made up of a list of global values,
350where both functions and global variables are global values. Global values are
351represented by a pointer to a memory location (in this case, a pointer to an
352array of char, and a pointer to a function), and have one of the following <a
353href="#linkage">linkage types</a>.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000354
Chris Lattnere5d947b2004-12-09 16:36:40 +0000355</div>
356
357<!-- ======================================================================= -->
358<div class="doc_subsection">
359 <a name="linkage">Linkage Types</a>
360</div>
361
362<div class="doc_text">
363
364<p>
365All Global Variables and Functions have one of the following types of linkage:
366</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000367
368<dl>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000369
Chris Lattnerfa730212004-12-09 16:11:40 +0000370 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000371
372 <dd>Global values with internal linkage are only directly accessible by
373 objects in the current module. In particular, linking code into a module with
374 an internal global value may cause the internal to be renamed as necessary to
375 avoid collisions. Because the symbol is internal to the module, all
376 references can be updated. This corresponds to the notion of the
377 '<tt>static</tt>' keyword in C, or the idea of "anonymous namespaces" in C++.
Chris Lattnerfa730212004-12-09 16:11:40 +0000378 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000379
Chris Lattnerfa730212004-12-09 16:11:40 +0000380 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000381
382 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt> linkage, with
383 the twist that linking together two modules defining the same
384 <tt>linkonce</tt> globals will cause one of the globals to be discarded. This
385 is typically used to implement inline functions. Unreferenced
386 <tt>linkonce</tt> globals are allowed to be discarded.
Chris Lattnerfa730212004-12-09 16:11:40 +0000387 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000388
Chris Lattnerfa730212004-12-09 16:11:40 +0000389 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000390
391 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage,
392 except that unreferenced <tt>weak</tt> globals may not be discarded. This is
393 used to implement constructs in C such as "<tt>int X;</tt>" at global scope.
Chris Lattnerfa730212004-12-09 16:11:40 +0000394 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000395
Chris Lattnerfa730212004-12-09 16:11:40 +0000396 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000397
398 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
399 pointer to array type. When two global variables with appending linkage are
400 linked together, the two global arrays are appended together. This is the
401 LLVM, typesafe, equivalent of having the system linker append together
402 "sections" with identical names when .o files are linked.
Chris Lattnerfa730212004-12-09 16:11:40 +0000403 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000404
Chris Lattnerfa730212004-12-09 16:11:40 +0000405 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000406
407 <dd>If none of the above identifiers are used, the global is externally
408 visible, meaning that it participates in linkage and can be used to resolve
409 external symbol references.
Chris Lattnerfa730212004-12-09 16:11:40 +0000410 </dd>
411</dl>
412
Chris Lattnerfa730212004-12-09 16:11:40 +0000413<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
414variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
415variable and was linked with this one, one of the two would be renamed,
416preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
417external (i.e., lacking any linkage declarations), they are accessible
418outside of the current module. It is illegal for a function <i>declaration</i>
419to have any linkage type other than "externally visible".</a></p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000420
Chris Lattnerfa730212004-12-09 16:11:40 +0000421</div>
422
423<!-- ======================================================================= -->
424<div class="doc_subsection">
425 <a name="globalvars">Global Variables</a>
426</div>
427
428<div class="doc_text">
429
430<p>Global variables define regions of memory allocated at compilation
431time instead of run-time. Global variables may optionally be
432initialized. A variable may be defined as a global "constant", which
433indicates that the contents of the variable will never be modified
434(enabling better optimization, allowing the global data to be placed in the
435read-only section of an executable, etc).</p>
436
437<p>As SSA values, global variables define pointer values that are in
438scope (i.e. they dominate) all basic blocks in the program. Global
439variables always define a pointer to their "content" type because they
440describe a region of memory, and all memory objects in LLVM are
441accessed through pointers.</p>
442
443</div>
444
445
446<!-- ======================================================================= -->
447<div class="doc_subsection">
448 <a name="functionstructure">Functions</a>
449</div>
450
451<div class="doc_text">
452
453<p>LLVM function definitions are composed of a (possibly empty) argument list,
454an opening curly brace, a list of basic blocks, and a closing curly brace. LLVM
455function declarations are defined with the "<tt>declare</tt>" keyword, a
456function name, and a function signature.</p>
457
458<p>A function definition contains a list of basic blocks, forming the CFG for
459the function. Each basic block may optionally start with a label (giving the
460basic block a symbol table entry), contains a list of instructions, and ends
461with a <a href="#terminators">terminator</a> instruction (such as a branch or
462function return).</p>
463
464<p>The first basic block in program is special in two ways: it is immediately
465executed on entrance to the function, and it is not allowed to have predecessor
466basic blocks (i.e. there can not be any branches to the entry block of a
467function). Because the block can have no predecessors, it also cannot have any
468<a href="#i_phi">PHI nodes</a>.</p>
469
470<p>LLVM functions are identified by their name and type signature. Hence, two
471functions with the same name but different parameter lists or return values are
472considered different functions, and LLVM will resolves references to each
473appropriately.</p>
474
475</div>
476
477
478
Chris Lattner00950542001-06-06 20:29:01 +0000479<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000480<div class="doc_section"> <a name="typesystem">Type System</a> </div>
481<!-- *********************************************************************** -->
Chris Lattnerfa730212004-12-09 16:11:40 +0000482
Misha Brukman9d0919f2003-11-08 01:05:38 +0000483<div class="doc_text">
Chris Lattnerfa730212004-12-09 16:11:40 +0000484
Misha Brukman9d0919f2003-11-08 01:05:38 +0000485<p>The LLVM type system is one of the most important features of the
Chris Lattner261efe92003-11-25 01:02:51 +0000486intermediate representation. Being typed enables a number of
487optimizations to be performed on the IR directly, without having to do
488extra analyses on the side before the transformation. A strong type
489system makes it easier to read the generated code and enables novel
490analyses and transformations that are not feasible to perform on normal
491three address code representations.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000492
493</div>
494
Chris Lattner00950542001-06-06 20:29:01 +0000495<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000496<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000497<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +0000498<p>The primitive types are the fundamental building blocks of the LLVM
Chris Lattner261efe92003-11-25 01:02:51 +0000499system. The current set of primitive types are as follows:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000500
Reid Spencerd3f876c2004-11-01 08:19:36 +0000501<table class="layout">
502 <tr class="layout">
503 <td class="left">
504 <table>
Chris Lattner261efe92003-11-25 01:02:51 +0000505 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000506 <tr><th>Type</th><th>Description</th></tr>
507 <tr><td><tt>void</tt></td><td>No value</td></tr>
508 <tr><td><tt>ubyte</tt></td><td>Unsigned 8 bit value</td></tr>
509 <tr><td><tt>ushort</tt></td><td>Unsigned 16 bit value</td></tr>
510 <tr><td><tt>uint</tt></td><td>Unsigned 32 bit value</td></tr>
511 <tr><td><tt>ulong</tt></td><td>Unsigned 64 bit value</td></tr>
512 <tr><td><tt>float</tt></td><td>32 bit floating point value</td></tr>
513 <tr><td><tt>label</tt></td><td>Branch destination</td></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000514 </tbody>
515 </table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000516 </td>
517 <td class="right">
518 <table>
Chris Lattner261efe92003-11-25 01:02:51 +0000519 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000520 <tr><th>Type</th><th>Description</th></tr>
521 <tr><td><tt>bool</tt></td><td>True or False value</td></tr>
522 <tr><td><tt>sbyte</tt></td><td>Signed 8 bit value</td></tr>
523 <tr><td><tt>short</tt></td><td>Signed 16 bit value</td></tr>
524 <tr><td><tt>int</tt></td><td>Signed 32 bit value</td></tr>
525 <tr><td><tt>long</tt></td><td>Signed 64 bit value</td></tr>
526 <tr><td><tt>double</tt></td><td>64 bit floating point value</td></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000527 </tbody>
528 </table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000529 </td>
530 </tr>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000531</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000532</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000533
Chris Lattner00950542001-06-06 20:29:01 +0000534<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000535<div class="doc_subsubsection"> <a name="t_classifications">Type
536Classifications</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000537<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000538<p>These different primitive types fall into a few useful
539classifications:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000540
541<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +0000542 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000543 <tr><th>Classification</th><th>Types</th></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000544 <tr>
545 <td><a name="t_signed">signed</a></td>
546 <td><tt>sbyte, short, int, long, float, double</tt></td>
547 </tr>
548 <tr>
549 <td><a name="t_unsigned">unsigned</a></td>
550 <td><tt>ubyte, ushort, uint, ulong</tt></td>
551 </tr>
552 <tr>
553 <td><a name="t_integer">integer</a></td>
554 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
555 </tr>
556 <tr>
557 <td><a name="t_integral">integral</a></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000558 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt>
559 </td>
Chris Lattner261efe92003-11-25 01:02:51 +0000560 </tr>
561 <tr>
562 <td><a name="t_floating">floating point</a></td>
563 <td><tt>float, double</tt></td>
564 </tr>
565 <tr>
566 <td><a name="t_firstclass">first class</a></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000567 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long,<br>
568 float, double, <a href="#t_pointer">pointer</a>,
569 <a href="#t_packed">packed</a></tt></td>
Chris Lattner261efe92003-11-25 01:02:51 +0000570 </tr>
571 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000572</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000573
Chris Lattner261efe92003-11-25 01:02:51 +0000574<p>The <a href="#t_firstclass">first class</a> types are perhaps the
575most important. Values of these types are the only ones which can be
576produced by instructions, passed as arguments, or used as operands to
577instructions. This means that all structures and arrays must be
578manipulated either by pointer or by component.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000579</div>
Chris Lattner00950542001-06-06 20:29:01 +0000580<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000581<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000582<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000583<p>The real power in LLVM comes from the derived types in the system.
584This is what allows a programmer to represent arrays, functions,
585pointers, and other useful types. Note that these derived types may be
586recursive: For example, it is possible to have a two dimensional array.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000587</div>
Chris Lattner00950542001-06-06 20:29:01 +0000588<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000589<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000590<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000591<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000592<p>The array type is a very simple derived type that arranges elements
Chris Lattner261efe92003-11-25 01:02:51 +0000593sequentially in memory. The array type requires a size (number of
594elements) and an underlying data type.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000595<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000596<pre> [&lt;# elements&gt; x &lt;elementtype&gt;]<br></pre>
597<p>The number of elements is a constant integer value, elementtype may
598be any type with a size.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000599<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000600<table class="layout">
601 <tr class="layout">
602 <td class="left">
603 <tt>[40 x int ]</tt><br/>
604 <tt>[41 x int ]</tt><br/>
605 <tt>[40 x uint]</tt><br/>
606 </td>
607 <td class="left">
608 Array of 40 integer values.<br/>
609 Array of 41 integer values.<br/>
610 Array of 40 unsigned integer values.<br/>
611 </td>
612 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000613</table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000614<p>Here are some examples of multidimensional arrays:</p>
615<table class="layout">
616 <tr class="layout">
617 <td class="left">
618 <tt>[3 x [4 x int]]</tt><br/>
619 <tt>[12 x [10 x float]]</tt><br/>
620 <tt>[2 x [3 x [4 x uint]]]</tt><br/>
621 </td>
622 <td class="left">
623 3x4 array integer values.<br/>
624 12x10 array of single precision floating point values.<br/>
625 2x3x4 array of unsigned integer values.<br/>
626 </td>
627 </tr>
628</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000629</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000630
Chris Lattner00950542001-06-06 20:29:01 +0000631<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000632<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000633<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000634<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000635<p>The function type can be thought of as a function signature. It
636consists of a return type and a list of formal parameter types.
John Criswell009900b2003-11-25 21:45:46 +0000637Function types are usually used to build virtual function tables
Chris Lattner261efe92003-11-25 01:02:51 +0000638(which are structures of pointers to functions), for indirect function
639calls, and when defining a function.</p>
John Criswell009900b2003-11-25 21:45:46 +0000640<p>
641The return type of a function type cannot be an aggregate type.
642</p>
Chris Lattner00950542001-06-06 20:29:01 +0000643<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000644<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000645<p>Where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
646specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner27f71f22003-09-03 00:41:47 +0000647which indicates that the function takes a variable number of arguments.
648Variable argument functions can access their arguments with the <a
Chris Lattner261efe92003-11-25 01:02:51 +0000649 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000650<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000651<table class="layout">
652 <tr class="layout">
653 <td class="left">
654 <tt>int (int)</tt> <br/>
655 <tt>float (int, int *) *</tt><br/>
656 <tt>int (sbyte *, ...)</tt><br/>
657 </td>
658 <td class="left">
659 function taking an <tt>int</tt>, returning an <tt>int</tt><br/>
660 <a href="#t_pointer">Pointer</a> to a function that takes an
Misha Brukmanc24b7582004-08-12 20:16:08 +0000661 <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
Reid Spencerd3f876c2004-11-01 08:19:36 +0000662 returning <tt>float</tt>.<br/>
663 A vararg function that takes at least one <a href="#t_pointer">pointer</a>
664 to <tt>sbyte</tt> (signed char in C), which returns an integer. This is
665 the signature for <tt>printf</tt> in LLVM.<br/>
666 </td>
667 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000668</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000669
Misha Brukman9d0919f2003-11-08 01:05:38 +0000670</div>
Chris Lattner00950542001-06-06 20:29:01 +0000671<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000672<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000673<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000674<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000675<p>The structure type is used to represent a collection of data members
676together in memory. The packing of the field types is defined to match
677the ABI of the underlying processor. The elements of a structure may
678be any type that has a size.</p>
679<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
680and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
681field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
682instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000683<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000684<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +0000685<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000686<table class="layout">
687 <tr class="layout">
688 <td class="left">
689 <tt>{ int, int, int }</tt><br/>
690 <tt>{ float, int (int) * }</tt><br/>
691 </td>
692 <td class="left">
693 a triple of three <tt>int</tt> values<br/>
694 A pair, where the first element is a <tt>float</tt> and the second element
695 is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a>
696 that takes an <tt>int</tt>, returning an <tt>int</tt>.<br/>
697 </td>
698 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000699</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000700</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000701
Chris Lattner00950542001-06-06 20:29:01 +0000702<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000703<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000704<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +0000705<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000706<p>As in many languages, the pointer type represents a pointer or
707reference to another object, which must live in memory.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000708<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000709<pre> &lt;type&gt; *<br></pre>
Chris Lattner7faa8832002-04-14 06:13:44 +0000710<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000711<table class="layout">
712 <tr class="layout">
713 <td class="left">
714 <tt>[4x int]*</tt><br/>
715 <tt>int (int *) *</tt><br/>
716 </td>
717 <td class="left">
718 A <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of
719 four <tt>int</tt> values<br/>
720 A <a href="#t_pointer">pointer</a> to a <a
Misha Brukmanc24b7582004-08-12 20:16:08 +0000721 href="#t_function">function</a> that takes an <tt>int</tt>, returning an
Reid Spencerd3f876c2004-11-01 08:19:36 +0000722 <tt>int</tt>.<br/>
723 </td>
724 </tr>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000725</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000726</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000727
Chris Lattnera58561b2004-08-12 19:12:28 +0000728<!-- _______________________________________________________________________ -->
729<div class="doc_subsubsection"> <a name="t_packed">Packed Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000730<div class="doc_text">
Chris Lattnera58561b2004-08-12 19:12:28 +0000731<h5>Overview:</h5>
732<p>A packed type is a simple derived type that represents a vector
733of elements. Packed types are used when multiple primitive data
734are operated in parallel using a single instruction (SIMD).
735A packed type requires a size (number of
736elements) and an underlying primitive data type. Packed types are
737considered <a href="#t_firstclass">first class</a>.</p>
738<h5>Syntax:</h5>
739<pre> &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;<br></pre>
740<p>The number of elements is a constant integer value, elementtype may
741be any integral or floating point type.</p>
742<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000743<table class="layout">
744 <tr class="layout">
745 <td class="left">
746 <tt>&lt;4 x int&gt;</tt><br/>
747 <tt>&lt;8 x float&gt;</tt><br/>
748 <tt>&lt;2 x uint&gt;</tt><br/>
749 </td>
750 <td class="left">
751 Packed vector of 4 integer values.<br/>
752 Packed vector of 8 floating-point values.<br/>
753 Packed vector of 2 unsigned integer values.<br/>
754 </td>
755 </tr>
756</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000757</div>
758
Chris Lattner9ee5d222004-03-08 16:49:10 +0000759
Chris Lattner00950542001-06-06 20:29:01 +0000760<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000761<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
762<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000763<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000764<p>The LLVM instruction set consists of several different
765classifications of instructions: <a href="#terminators">terminator
766instructions</a>, <a href="#binaryops">binary instructions</a>, <a
767 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
768instructions</a>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000769</div>
Chris Lattner00950542001-06-06 20:29:01 +0000770<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000771<div class="doc_subsection"> <a name="terminators">Terminator
772Instructions</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000773<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000774<p>As mentioned <a href="#functionstructure">previously</a>, every
775basic block in a program ends with a "Terminator" instruction, which
776indicates which block should be executed after the current block is
777finished. These terminator instructions typically yield a '<tt>void</tt>'
778value: they produce control flow, not values (the one exception being
779the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000780<p>There are five different terminator instructions: the '<a
Chris Lattner261efe92003-11-25 01:02:51 +0000781 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
782instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
Chris Lattner35eca582004-10-16 18:04:13 +0000783the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
784 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
785 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000786</div>
Chris Lattner00950542001-06-06 20:29:01 +0000787<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000788<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
789Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000790<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000791<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000792<pre> ret &lt;type&gt; &lt;value&gt; <i>; Return a value from a non-void function</i>
Chris Lattner7faa8832002-04-14 06:13:44 +0000793 ret void <i>; Return from void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000794</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000795<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000796<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
797value) from a function, back to the caller.</p>
John Criswell4457dc92004-04-09 16:48:45 +0000798<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner261efe92003-11-25 01:02:51 +0000799returns a value and then causes control flow, and one that just causes
800control flow to occur.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000801<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000802<p>The '<tt>ret</tt>' instruction may return any '<a
803 href="#t_firstclass">first class</a>' type. Notice that a function is
804not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
805instruction inside of the function that returns a value that does not
806match the return type of the function.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000807<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000808<p>When the '<tt>ret</tt>' instruction is executed, control flow
809returns back to the calling function's context. If the caller is a "<a
John Criswellfa081872004-06-25 15:16:57 +0000810 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner261efe92003-11-25 01:02:51 +0000811the instruction after the call. If the caller was an "<a
812 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
813at the beginning "normal" of the destination block. If the instruction
814returns a value, that value shall set the call or invoke instruction's
815return value.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000816<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000817<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner7faa8832002-04-14 06:13:44 +0000818 ret void <i>; Return from a void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000819</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000820</div>
Chris Lattner00950542001-06-06 20:29:01 +0000821<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000822<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000823<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000824<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000825<pre> br bool &lt;cond&gt;, label &lt;iftrue&gt;, label &lt;iffalse&gt;<br> br label &lt;dest&gt; <i>; Unconditional branch</i>
Chris Lattner00950542001-06-06 20:29:01 +0000826</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000827<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000828<p>The '<tt>br</tt>' instruction is used to cause control flow to
829transfer to a different basic block in the current function. There are
830two forms of this instruction, corresponding to a conditional branch
831and an unconditional branch.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000832<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000833<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
834single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
835unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
836value as a target.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000837<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000838<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
839argument is evaluated. If the value is <tt>true</tt>, control flows
840to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
841control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000842<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000843<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
844 href="#i_ret">ret</a> int 1<br>IfUnequal:<br> <a href="#i_ret">ret</a> int 0<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000845</div>
Chris Lattner00950542001-06-06 20:29:01 +0000846<!-- _______________________________________________________________________ -->
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000847<div class="doc_subsubsection">
848 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
849</div>
850
Misha Brukman9d0919f2003-11-08 01:05:38 +0000851<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000852<h5>Syntax:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000853
854<pre>
855 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
856</pre>
857
Chris Lattner00950542001-06-06 20:29:01 +0000858<h5>Overview:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000859
860<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
861several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +0000862instruction, allowing a branch to occur to one of many possible
863destinations.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000864
865
Chris Lattner00950542001-06-06 20:29:01 +0000866<h5>Arguments:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000867
868<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
869comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
870an array of pairs of comparison value constants and '<tt>label</tt>'s. The
871table is not allowed to contain duplicate constant entries.</p>
872
Chris Lattner00950542001-06-06 20:29:01 +0000873<h5>Semantics:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000874
Chris Lattner261efe92003-11-25 01:02:51 +0000875<p>The <tt>switch</tt> instruction specifies a table of values and
876destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswell84114752004-06-25 16:05:06 +0000877table is searched for the given value. If the value is found, control flow is
878transfered to the corresponding destination; otherwise, control flow is
879transfered to the default destination.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000880
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000881<h5>Implementation:</h5>
882
883<p>Depending on properties of the target machine and the particular
884<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswell84114752004-06-25 16:05:06 +0000885ways. For example, it could be generated as a series of chained conditional
886branches or with a lookup table.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000887
888<h5>Example:</h5>
889
890<pre>
891 <i>; Emulate a conditional br instruction</i>
892 %Val = <a href="#i_cast">cast</a> bool %value to int
893 switch int %Val, label %truedest [int 0, label %falsedest ]
894
895 <i>; Emulate an unconditional br instruction</i>
896 switch uint 0, label %dest [ ]
897
898 <i>; Implement a jump table:</i>
899 switch uint %val, label %otherwise [ uint 0, label %onzero
900 uint 1, label %onone
901 uint 2, label %ontwo ]
Chris Lattner00950542001-06-06 20:29:01 +0000902</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000903</div>
Chris Lattner00950542001-06-06 20:29:01 +0000904<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000905<div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>'
906Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000907<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000908<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000909<pre> &lt;result&gt; = invoke &lt;ptr to function ty&gt; %&lt;function ptr val&gt;(&lt;function args&gt;)<br> to label &lt;normal label&gt; except label &lt;exception label&gt;<br></pre>
Chris Lattner6536cfe2002-05-06 22:08:29 +0000910<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000911<p>The '<tt>invoke</tt>' instruction causes control to transfer to a
912specified function, with the possibility of control flow transfer to
913either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>.
914If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>"
915instruction, control flow will return to the "normal" label. If the
916callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
917instruction, control is interrupted, and continued at the dynamically
918nearest "except" label.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000919<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000920<p>This instruction requires several arguments:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000921<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000922 <li>'<tt>ptr to function ty</tt>': shall be the signature of the
923pointer to function value being invoked. In most cases, this is a
924direct function invocation, but indirect <tt>invoke</tt>s are just as
925possible, branching off an arbitrary pointer to function value. </li>
926 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer
927to a function to be invoked. </li>
928 <li>'<tt>function args</tt>': argument list whose types match the
929function signature argument types. If the function signature indicates
930the function accepts a variable number of arguments, the extra
931arguments can be specified. </li>
932 <li>'<tt>normal label</tt>': the label reached when the called
933function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
934 <li>'<tt>exception label</tt>': the label reached when a callee
935returns with the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
Chris Lattner00950542001-06-06 20:29:01 +0000936</ol>
Chris Lattner00950542001-06-06 20:29:01 +0000937<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000938<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner261efe92003-11-25 01:02:51 +0000939 href="#i_call">call</a></tt>' instruction in most regards. The
940primary difference is that it establishes an association with a label,
941which is used by the runtime library to unwind the stack.</p>
942<p>This instruction is used in languages with destructors to ensure
943that proper cleanup is performed in the case of either a <tt>longjmp</tt>
944or a thrown exception. Additionally, this is important for
945implementation of '<tt>catch</tt>' clauses in high-level languages that
946support them.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000947<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000948<pre> %retval = invoke int %Test(int 15)<br> to label %Continue<br> except label %TestCleanup <i>; {int}:retval set</i>
Chris Lattner00950542001-06-06 20:29:01 +0000949</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000950</div>
Chris Lattner35eca582004-10-16 18:04:13 +0000951
952
Chris Lattner27f71f22003-09-03 00:41:47 +0000953<!-- _______________________________________________________________________ -->
Chris Lattner35eca582004-10-16 18:04:13 +0000954
Chris Lattner261efe92003-11-25 01:02:51 +0000955<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
956Instruction</a> </div>
Chris Lattner35eca582004-10-16 18:04:13 +0000957
Misha Brukman9d0919f2003-11-08 01:05:38 +0000958<div class="doc_text">
Chris Lattner35eca582004-10-16 18:04:13 +0000959
Chris Lattner27f71f22003-09-03 00:41:47 +0000960<h5>Syntax:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +0000961<pre>
962 unwind
963</pre>
964
Chris Lattner27f71f22003-09-03 00:41:47 +0000965<h5>Overview:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +0000966
967<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
968at the first callee in the dynamic call stack which used an <a
969href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
970primarily used to implement exception handling.</p>
971
Chris Lattner27f71f22003-09-03 00:41:47 +0000972<h5>Semantics:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +0000973
974<p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to
975immediately halt. The dynamic call stack is then searched for the first <a
976href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
977execution continues at the "exceptional" destination block specified by the
978<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
979dynamic call chain, undefined behavior results.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000980</div>
Chris Lattner35eca582004-10-16 18:04:13 +0000981
982<!-- _______________________________________________________________________ -->
983
984<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
985Instruction</a> </div>
986
987<div class="doc_text">
988
989<h5>Syntax:</h5>
990<pre>
991 unreachable
992</pre>
993
994<h5>Overview:</h5>
995
996<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
997instruction is used to inform the optimizer that a particular portion of the
998code is not reachable. This can be used to indicate that the code after a
999no-return function cannot be reached, and other facts.</p>
1000
1001<h5>Semantics:</h5>
1002
1003<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
1004</div>
1005
1006
1007
Chris Lattner00950542001-06-06 20:29:01 +00001008<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001009<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001010<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001011<p>Binary operators are used to do most of the computation in a
1012program. They require two operands, execute an operation on them, and
Chris Lattnera58561b2004-08-12 19:12:28 +00001013produce a single value. Although, that single value might represent
1014multiple data, as is the case with the <a href="#t_packed">packed</a> data type.
1015The result value of a binary operator is not
Chris Lattner261efe92003-11-25 01:02:51 +00001016necessarily the same type as its operands.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001017<p>There are several different binary operators:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001018</div>
Chris Lattner00950542001-06-06 20:29:01 +00001019<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001020<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
1021Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001022<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001023<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001024<pre> &lt;result&gt; = add &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001025</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001026<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001027<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001028<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001029<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattnera58561b2004-08-12 19:12:28 +00001030 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
1031 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1032Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001033<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001034<p>The value produced is the integer or floating point sum of the two
1035operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001036<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001037<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001038</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001039</div>
Chris Lattner00950542001-06-06 20:29:01 +00001040<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001041<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
1042Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001043<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001044<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001045<pre> &lt;result&gt; = sub &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001046</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001047<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001048<p>The '<tt>sub</tt>' instruction returns the difference of its two
1049operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001050<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
1051instruction present in most other intermediate representations.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001052<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001053<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001054 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001055values.
1056This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1057Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001058<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001059<p>The value produced is the integer or floating point difference of
1060the two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001061<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001062<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001063 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
1064</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001065</div>
Chris Lattner00950542001-06-06 20:29:01 +00001066<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001067<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
1068Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001069<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001070<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001071<pre> &lt;result&gt; = mul &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001072</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001073<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001074<p>The '<tt>mul</tt>' instruction returns the product of its two
1075operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001076<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001077<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001078 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001079values.
1080This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1081Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001082<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001083<p>The value produced is the integer or floating point product of the
Misha Brukman9d0919f2003-11-08 01:05:38 +00001084two operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001085<p>There is no signed vs unsigned multiplication. The appropriate
1086action is taken based on the type of the operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001087<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001088<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001089</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001090</div>
Chris Lattner00950542001-06-06 20:29:01 +00001091<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001092<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
1093Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001094<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001095<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001096<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1097</pre>
1098<h5>Overview:</h5>
1099<p>The '<tt>div</tt>' instruction returns the quotient of its two
1100operands.</p>
1101<h5>Arguments:</h5>
1102<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
1103 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001104values.
1105This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1106Both arguments must have identical types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001107<h5>Semantics:</h5>
1108<p>The value produced is the integer or floating point quotient of the
1109two operands.</p>
1110<h5>Example:</h5>
1111<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
1112</pre>
1113</div>
1114<!-- _______________________________________________________________________ -->
1115<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
1116Instruction</a> </div>
1117<div class="doc_text">
1118<h5>Syntax:</h5>
1119<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1120</pre>
1121<h5>Overview:</h5>
1122<p>The '<tt>rem</tt>' instruction returns the remainder from the
1123division of its two operands.</p>
1124<h5>Arguments:</h5>
1125<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1126 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001127values.
1128This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1129Both arguments must have identical types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001130<h5>Semantics:</h5>
1131<p>This returns the <i>remainder</i> of a division (where the result
1132has the same sign as the divisor), not the <i>modulus</i> (where the
1133result has the same sign as the dividend) of a value. For more
1134information about the difference, see: <a
1135 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1136Math Forum</a>.</p>
1137<h5>Example:</h5>
1138<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1139</pre>
1140</div>
1141<!-- _______________________________________________________________________ -->
1142<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1143Instructions</a> </div>
1144<div class="doc_text">
1145<h5>Syntax:</h5>
1146<pre> &lt;result&gt; = seteq &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001147 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1148 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1149 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1150 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1151 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1152</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001153<h5>Overview:</h5>
1154<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1155value based on a comparison of their two operands.</p>
1156<h5>Arguments:</h5>
1157<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1158be of <a href="#t_firstclass">first class</a> type (it is not possible
1159to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1160or '<tt>void</tt>' values, etc...). Both arguments must have identical
1161types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001162<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001163<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1164value if both operands are equal.<br>
1165The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1166value if both operands are unequal.<br>
1167The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1168value if the first operand is less than the second operand.<br>
1169The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1170value if the first operand is greater than the second operand.<br>
1171The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1172value if the first operand is less than or equal to the second operand.<br>
1173The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1174value if the first operand is greater than or equal to the second
1175operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001176<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001177<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner00950542001-06-06 20:29:01 +00001178 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
1179 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1180 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1181 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1182 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1183</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001184</div>
Chris Lattner00950542001-06-06 20:29:01 +00001185<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001186<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1187Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001188<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001189<p>Bitwise binary operators are used to do various forms of
1190bit-twiddling in a program. They are generally very efficient
1191instructions, and can commonly be strength reduced from other
1192instructions. They require two operands, execute an operation on them,
1193and produce a single value. The resulting value of the bitwise binary
1194operators is always the same type as its first operand.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001195</div>
Chris Lattner00950542001-06-06 20:29:01 +00001196<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001197<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1198Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001199<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001200<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001201<pre> &lt;result&gt; = and &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001202</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001203<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001204<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1205its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001206<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001207<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001208 href="#t_integral">integral</a> values. Both arguments must have
1209identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001210<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001211<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001212<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001213<div style="align: center">
Misha Brukman9d0919f2003-11-08 01:05:38 +00001214<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +00001215 <tbody>
1216 <tr>
1217 <td>In0</td>
1218 <td>In1</td>
1219 <td>Out</td>
1220 </tr>
1221 <tr>
1222 <td>0</td>
1223 <td>0</td>
1224 <td>0</td>
1225 </tr>
1226 <tr>
1227 <td>0</td>
1228 <td>1</td>
1229 <td>0</td>
1230 </tr>
1231 <tr>
1232 <td>1</td>
1233 <td>0</td>
1234 <td>0</td>
1235 </tr>
1236 <tr>
1237 <td>1</td>
1238 <td>1</td>
1239 <td>1</td>
1240 </tr>
1241 </tbody>
1242</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001243</div>
Chris Lattner00950542001-06-06 20:29:01 +00001244<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001245<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001246 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1247 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1248</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001249</div>
Chris Lattner00950542001-06-06 20:29:01 +00001250<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001251<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001252<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001253<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001254<pre> &lt;result&gt; = or &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001255</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001256<h5>Overview:</h5>
1257<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1258or of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001259<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001260<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001261 href="#t_integral">integral</a> values. Both arguments must have
1262identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001263<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001264<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001265<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001266<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001267<table border="1" cellspacing="0" cellpadding="4">
1268 <tbody>
1269 <tr>
1270 <td>In0</td>
1271 <td>In1</td>
1272 <td>Out</td>
1273 </tr>
1274 <tr>
1275 <td>0</td>
1276 <td>0</td>
1277 <td>0</td>
1278 </tr>
1279 <tr>
1280 <td>0</td>
1281 <td>1</td>
1282 <td>1</td>
1283 </tr>
1284 <tr>
1285 <td>1</td>
1286 <td>0</td>
1287 <td>1</td>
1288 </tr>
1289 <tr>
1290 <td>1</td>
1291 <td>1</td>
1292 <td>1</td>
1293 </tr>
1294 </tbody>
1295</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001296</div>
Chris Lattner00950542001-06-06 20:29:01 +00001297<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001298<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001299 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1300 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1301</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001302</div>
Chris Lattner00950542001-06-06 20:29:01 +00001303<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001304<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1305Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001306<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001307<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001308<pre> &lt;result&gt; = xor &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001309</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001310<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001311<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1312or of its two operands. The <tt>xor</tt> is used to implement the
1313"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001314<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001315<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001316 href="#t_integral">integral</a> values. Both arguments must have
1317identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001318<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001319<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001320<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001321<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001322<table border="1" cellspacing="0" cellpadding="4">
1323 <tbody>
1324 <tr>
1325 <td>In0</td>
1326 <td>In1</td>
1327 <td>Out</td>
1328 </tr>
1329 <tr>
1330 <td>0</td>
1331 <td>0</td>
1332 <td>0</td>
1333 </tr>
1334 <tr>
1335 <td>0</td>
1336 <td>1</td>
1337 <td>1</td>
1338 </tr>
1339 <tr>
1340 <td>1</td>
1341 <td>0</td>
1342 <td>1</td>
1343 </tr>
1344 <tr>
1345 <td>1</td>
1346 <td>1</td>
1347 <td>0</td>
1348 </tr>
1349 </tbody>
1350</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001351</div>
Chris Lattner261efe92003-11-25 01:02:51 +00001352<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001353<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001354<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001355 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1356 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner27f71f22003-09-03 00:41:47 +00001357 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner00950542001-06-06 20:29:01 +00001358</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001359</div>
Chris Lattner00950542001-06-06 20:29:01 +00001360<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001361<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1362Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001363<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001364<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001365<pre> &lt;result&gt; = shl &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001366</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001367<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001368<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1369the left a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001370<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001371<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001372 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1373type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001374<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001375<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001376<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001377<pre> &lt;result&gt; = shl int 4, ubyte %var <i>; yields {int}:result = 4 &lt;&lt; %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001378 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1379 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1380</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001381</div>
Chris Lattner00950542001-06-06 20:29:01 +00001382<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001383<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1384Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001385<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001386<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001387<pre> &lt;result&gt; = shr &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001388</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001389<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001390<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1391the right a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001392<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001393<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001394 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1395type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001396<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001397<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1398most significant bit is duplicated in the newly free'd bit positions.
1399If the first argument is unsigned, zero bits shall fill the empty
1400positions.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001401<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001402<pre> &lt;result&gt; = shr int 4, ubyte %var <i>; yields {int}:result = 4 &gt;&gt; %var</i>
Chris Lattner8c6bb902003-06-18 21:30:51 +00001403 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001404 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner8c6bb902003-06-18 21:30:51 +00001405 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1406 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner00950542001-06-06 20:29:01 +00001407</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001408</div>
Chris Lattner00950542001-06-06 20:29:01 +00001409<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001410<div class="doc_subsection"> <a name="memoryops">Memory Access
1411Operations</a></div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001412<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001413<p>A key design point of an SSA-based representation is how it
1414represents memory. In LLVM, no memory locations are in SSA form, which
1415makes things very simple. This section describes how to read, write,
1416allocate and free memory in LLVM.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001417</div>
Chris Lattner00950542001-06-06 20:29:01 +00001418<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001419<div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>'
1420Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001421<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001422<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001423<pre> &lt;result&gt; = malloc &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001424 &lt;result&gt; = malloc &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001425</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001426<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001427<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1428heap and returns a pointer to it.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001429<h5>Arguments:</h5>
John Criswell6e4ca612004-02-24 16:13:56 +00001430<p>The '<tt>malloc</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1431bytes of memory from the operating system and returns a pointer of the
Chris Lattner261efe92003-11-25 01:02:51 +00001432appropriate type to the program. The second form of the instruction is
1433a shorter version of the first instruction that defaults to allocating
1434one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001435<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001436<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001437<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1438a pointer is returned.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001439<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001440<pre> %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001441
Chris Lattner261efe92003-11-25 01:02:51 +00001442 %size = <a
1443 href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001444 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1445 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001446</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001447</div>
Chris Lattner00950542001-06-06 20:29:01 +00001448<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001449<div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>'
1450Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001451<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001452<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001453<pre> free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner00950542001-06-06 20:29:01 +00001454</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001455<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001456<p>The '<tt>free</tt>' instruction returns memory back to the unused
1457memory heap, to be reallocated in the future.</p>
1458<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001459<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001460<p>'<tt>value</tt>' shall be a pointer value that points to a value
1461that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1462instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001463<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001464<p>Access to the memory pointed to by the pointer is not longer defined
1465after this instruction executes.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001466<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001467<pre> %array = <a href="#i_malloc">malloc</a> [4 x ubyte] <i>; yields {[4 x ubyte]*}:array</i>
Chris Lattner00950542001-06-06 20:29:01 +00001468 free [4 x ubyte]* %array
1469</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001470</div>
Chris Lattner00950542001-06-06 20:29:01 +00001471<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001472<div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>'
1473Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001474<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001475<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001476<pre> &lt;result&gt; = alloca &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001477 &lt;result&gt; = alloca &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001478</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001479<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001480<p>The '<tt>alloca</tt>' instruction allocates memory on the current
1481stack frame of the procedure that is live until the current function
1482returns to its caller.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001483<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001484<p>The the '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1485bytes of memory on the runtime stack, returning a pointer of the
1486appropriate type to the program. The second form of the instruction is
1487a shorter version of the first that defaults to allocating one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001488<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001489<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001490<p>Memory is allocated, a pointer is returned. '<tt>alloca</tt>'d
1491memory is automatically released when the function returns. The '<tt>alloca</tt>'
1492instruction is commonly used to represent automatic variables that must
1493have an address available. When the function returns (either with the <tt><a
1494 href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001495instructions), the memory is reclaimed.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001496<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001497<pre> %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001498 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner00950542001-06-06 20:29:01 +00001499</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001500</div>
Chris Lattner00950542001-06-06 20:29:01 +00001501<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001502<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1503Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001504<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00001505<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001506<pre> &lt;result&gt; = load &lt;ty&gt;* &lt;pointer&gt;<br> &lt;result&gt; = volatile load &lt;ty&gt;* &lt;pointer&gt;<br></pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001507<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001508<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001509<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001510<p>The argument to the '<tt>load</tt>' instruction specifies the memory
1511address to load from. The pointer must point to a <a
Chris Lattnere53e5082004-06-03 22:57:15 +00001512 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
Chris Lattner261efe92003-11-25 01:02:51 +00001513marked as <tt>volatile</tt> then the optimizer is not allowed to modify
1514the number or order of execution of this <tt>load</tt> with other
1515volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1516instructions. </p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001517<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001518<p>The location of memory pointed to is loaded.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001519<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001520<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1521 <a
1522 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001523 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1524</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001525</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001526<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001527<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1528Instruction</a> </div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001529<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001530<pre> store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt; <i>; yields {void}</i>
Chris Lattnerf0651072003-09-08 18:27:49 +00001531 volatile store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt; <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001532</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001533<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001534<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001535<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001536<p>There are two arguments to the '<tt>store</tt>' instruction: a value
1537to store and an address to store it into. The type of the '<tt>&lt;pointer&gt;</tt>'
1538operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
1539operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the
1540optimizer is not allowed to modify the number or order of execution of
1541this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1542 href="#i_store">store</a></tt> instructions.</p>
1543<h5>Semantics:</h5>
1544<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
1545at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001546<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001547<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1548 <a
1549 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001550 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1551</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001552<!-- _______________________________________________________________________ -->
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001553<div class="doc_subsubsection">
1554 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
1555</div>
1556
Misha Brukman9d0919f2003-11-08 01:05:38 +00001557<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00001558<h5>Syntax:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001559<pre>
1560 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
1561</pre>
1562
Chris Lattner7faa8832002-04-14 06:13:44 +00001563<h5>Overview:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001564
1565<p>
1566The '<tt>getelementptr</tt>' instruction is used to get the address of a
1567subelement of an aggregate data structure.</p>
1568
Chris Lattner7faa8832002-04-14 06:13:44 +00001569<h5>Arguments:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001570
1571<p>This instruction takes a list of integer constants that indicate what
1572elements of the aggregate object to index to. The actual types of the arguments
1573provided depend on the type of the first pointer argument. The
1574'<tt>getelementptr</tt>' instruction is used to index down through the type
1575levels of a structure. When indexing into a structure, only <tt>uint</tt>
1576integer constants are allowed. When indexing into an array or pointer
1577<tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
1578
Chris Lattner261efe92003-11-25 01:02:51 +00001579<p>For example, let's consider a C code fragment and how it gets
1580compiled to LLVM:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001581
1582<pre>
1583 struct RT {
1584 char A;
1585 int B[10][20];
1586 char C;
1587 };
1588 struct ST {
1589 int X;
1590 double Y;
1591 struct RT Z;
1592 };
1593
1594 int *foo(struct ST *s) {
1595 return &amp;s[1].Z.B[5][13];
1596 }
1597</pre>
1598
Misha Brukman9d0919f2003-11-08 01:05:38 +00001599<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001600
1601<pre>
1602 %RT = type { sbyte, [10 x [20 x int]], sbyte }
1603 %ST = type { int, double, %RT }
1604
Brian Gaeke7283e7c2004-07-02 21:08:14 +00001605 implementation
1606
1607 int* %foo(%ST* %s) {
1608 entry:
1609 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001610 ret int* %reg
1611 }
1612</pre>
1613
Chris Lattner7faa8832002-04-14 06:13:44 +00001614<h5>Semantics:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001615
1616<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
Chris Lattnere53e5082004-06-03 22:57:15 +00001617on the pointer type that is being index into. <a href="#t_pointer">Pointer</a>
1618and <a href="#t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
1619<tt>ulong</tt>, or <tt>long</tt> values, and <a href="#t_struct">structure</a>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001620types require <tt>uint</tt> <b>constants</b>.</p>
1621
Misha Brukman9d0919f2003-11-08 01:05:38 +00001622<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001623type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
1624}</tt>' type, a structure. The second index indexes into the third element of
1625the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
1626sbyte }</tt>' type, another structure. The third index indexes into the second
1627element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
1628array. The two dimensions of the array are subscripted into, yielding an
1629'<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction return a pointer
1630to this element, thus computing a value of '<tt>int*</tt>' type.</p>
1631
Chris Lattner261efe92003-11-25 01:02:51 +00001632<p>Note that it is perfectly legal to index partially through a
1633structure, returning a pointer to an inner element. Because of this,
1634the LLVM code for the given testcase is equivalent to:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001635
1636<pre>
1637 int* "foo"(%ST* %s) {
1638 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
1639 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
1640 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
1641 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
1642 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
1643 ret int* %t5
1644 }
Chris Lattner6536cfe2002-05-06 22:08:29 +00001645</pre>
Chris Lattner7faa8832002-04-14 06:13:44 +00001646<h5>Example:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001647<pre>
1648 <i>; yields [12 x ubyte]*:aptr</i>
1649 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
1650</pre>
1651
1652</div>
Chris Lattner00950542001-06-06 20:29:01 +00001653<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001654<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001655<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +00001656<p>The instructions in this category are the "miscellaneous"
Chris Lattner261efe92003-11-25 01:02:51 +00001657instructions, which defy better classification.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001658</div>
Chris Lattner00950542001-06-06 20:29:01 +00001659<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001660<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
1661Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001662<div class="doc_text">
Chris Lattner33ba0d92001-07-09 00:26:23 +00001663<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001664<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001665<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001666<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
1667the SSA graph representing the function.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001668<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001669<p>The type of the incoming values are specified with the first type
1670field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
1671as arguments, with one pair for each predecessor basic block of the
1672current block. Only values of <a href="#t_firstclass">first class</a>
1673type may be used as the value arguments to the PHI node. Only labels
1674may be used as the label arguments.</p>
1675<p>There must be no non-phi instructions between the start of a basic
1676block and the PHI instructions: i.e. PHI instructions must be first in
1677a basic block.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001678<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001679<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
1680value specified by the parameter, depending on which basic block we
1681came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001682<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001683<pre>Loop: ; Infinite loop that counts from 0 on up...<br> %indvar = phi uint [ 0, %LoopHeader ], [ %nextindvar, %Loop ]<br> %nextindvar = add uint %indvar, 1<br> br label %Loop<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001684</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001685
Chris Lattner6536cfe2002-05-06 22:08:29 +00001686<!-- _______________________________________________________________________ -->
Chris Lattnercc37aae2004-03-12 05:50:16 +00001687<div class="doc_subsubsection">
1688 <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
1689</div>
1690
Misha Brukman9d0919f2003-11-08 01:05:38 +00001691<div class="doc_text">
Chris Lattnercc37aae2004-03-12 05:50:16 +00001692
Chris Lattner6536cfe2002-05-06 22:08:29 +00001693<h5>Syntax:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001694
1695<pre>
1696 &lt;result&gt; = cast &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001697</pre>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001698
Chris Lattner6536cfe2002-05-06 22:08:29 +00001699<h5>Overview:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001700
1701<p>
1702The '<tt>cast</tt>' instruction is used as the primitive means to convert
1703integers to floating point, change data type sizes, and break type safety (by
1704casting pointers).
1705</p>
1706
1707
Chris Lattner6536cfe2002-05-06 22:08:29 +00001708<h5>Arguments:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001709
1710<p>
1711The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
1712class value, and a type to cast it to, which must also be a <a
1713href="#t_firstclass">first class</a> type.
1714</p>
1715
Chris Lattner6536cfe2002-05-06 22:08:29 +00001716<h5>Semantics:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001717
1718<p>
1719This instruction follows the C rules for explicit casts when determining how the
1720data being cast must change to fit in its new container.
1721</p>
1722
1723<p>
1724When casting to bool, any value that would be considered true in the context of
1725a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
1726all else are '<tt>false</tt>'.
1727</p>
1728
1729<p>
1730When extending an integral value from a type of one signness to another (for
1731example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
1732<b>source</b> value is signed, and zero-extended if the source value is
1733unsigned. <tt>bool</tt> values are always zero extended into either zero or
1734one.
1735</p>
1736
Chris Lattner33ba0d92001-07-09 00:26:23 +00001737<h5>Example:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001738
1739<pre>
1740 %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattner7bae3952002-06-25 18:03:17 +00001741 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001742</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001743</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001744
1745<!-- _______________________________________________________________________ -->
1746<div class="doc_subsubsection">
1747 <a name="i_select">'<tt>select</tt>' Instruction</a>
1748</div>
1749
1750<div class="doc_text">
1751
1752<h5>Syntax:</h5>
1753
1754<pre>
1755 &lt;result&gt; = select bool &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
1756</pre>
1757
1758<h5>Overview:</h5>
1759
1760<p>
1761The '<tt>select</tt>' instruction is used to choose one value based on a
1762condition, without branching.
1763</p>
1764
1765
1766<h5>Arguments:</h5>
1767
1768<p>
1769The '<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.
1770</p>
1771
1772<h5>Semantics:</h5>
1773
1774<p>
1775If the boolean condition evaluates to true, the instruction returns the first
1776value argument, otherwise it returns the second value argument.
1777</p>
1778
1779<h5>Example:</h5>
1780
1781<pre>
1782 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
1783</pre>
1784</div>
1785
1786
1787
1788
1789
Chris Lattner33ba0d92001-07-09 00:26:23 +00001790<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001791<div class="doc_subsubsection"> <a name="i_call">'<tt>call</tt>'
1792Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001793<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001794<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001795<pre> &lt;result&gt; = call &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +00001796<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001797<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001798<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001799<p>This instruction requires several arguments:</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001800<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00001801 <li>
1802 <p>'<tt>ty</tt>': shall be the signature of the pointer to function
1803value being invoked. The argument types must match the types implied
1804by this signature.</p>
1805 </li>
1806 <li>
1807 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a
1808function to be invoked. In most cases, this is a direct function
1809invocation, but indirect <tt>call</tt>s are just as possible,
1810calling an arbitrary pointer to function values.</p>
1811 </li>
1812 <li>
1813 <p>'<tt>function args</tt>': argument list whose types match the
1814function signature argument types. If the function signature
1815indicates the function accepts a variable number of arguments, the
1816extra arguments can be specified.</p>
1817 </li>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001818</ol>
Chris Lattner00950542001-06-06 20:29:01 +00001819<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001820<p>The '<tt>call</tt>' instruction is used to cause control flow to
1821transfer to a specified function, with its incoming arguments bound to
1822the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
1823instruction in the called function, control flow continues with the
1824instruction after the function call, and the return value of the
1825function is bound to the result argument. This is a simpler case of
1826the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001827<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001828<pre> %retval = call int %test(int %argc)<br> call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42);<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001829</div>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001830
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001831<!-- _______________________________________________________________________ -->
Chris Lattnere19d7a72004-09-27 21:51:25 +00001832<div class="doc_subsubsection">
1833 <a name="i_vanext">'<tt>vanext</tt>' Instruction</a>
1834</div>
1835
Misha Brukman9d0919f2003-11-08 01:05:38 +00001836<div class="doc_text">
Chris Lattnere19d7a72004-09-27 21:51:25 +00001837
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001838<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001839
1840<pre>
1841 &lt;resultarglist&gt; = vanext &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;
1842</pre>
1843
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001844<h5>Overview:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001845
Chris Lattner261efe92003-11-25 01:02:51 +00001846<p>The '<tt>vanext</tt>' instruction is used to access arguments passed
1847through the "variable argument" area of a function call. It is used to
1848implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001849
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001850<h5>Arguments:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001851
1852<p>This instruction takes a <tt>va_list</tt> value and the type of the
1853argument. It returns another <tt>va_list</tt>. The actual type of
1854<tt>va_list</tt> may be defined differently for different targets. Most targets
1855use a <tt>va_list</tt> type of <tt>sbyte*</tt> or some other pointer type.</p>
1856
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001857<h5>Semantics:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001858
1859<p>The '<tt>vanext</tt>' instruction advances the specified <tt>va_list</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001860past an argument of the specified type. In conjunction with the <a
1861 href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement
1862the <tt>va_arg</tt> macro available in C. For more information, see
1863the variable argument handling <a href="#int_varargs">Intrinsic
1864Functions</a>.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001865
Chris Lattner261efe92003-11-25 01:02:51 +00001866<p>It is legal for this instruction to be called in a function which
1867does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001868function.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001869
Misha Brukman9d0919f2003-11-08 01:05:38 +00001870<p><tt>vanext</tt> is an LLVM instruction instead of an <a
Chris Lattnere19d7a72004-09-27 21:51:25 +00001871href="#intrinsics">intrinsic function</a> because it takes a type as an
1872argument. The type refers to the current argument in the <tt>va_list</tt>, it
1873tells the compiler how far on the stack it needs to advance to find the next
1874argument</p>
1875
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001876<h5>Example:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001877
Chris Lattner261efe92003-11-25 01:02:51 +00001878<p>See the <a href="#int_varargs">variable argument processing</a>
1879section.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001880
Misha Brukman9d0919f2003-11-08 01:05:38 +00001881</div>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001882
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001883<!-- _______________________________________________________________________ -->
Chris Lattnere19d7a72004-09-27 21:51:25 +00001884<div class="doc_subsubsection">
1885 <a name="i_vaarg">'<tt>vaarg</tt>' Instruction</a>
1886</div>
1887
Misha Brukman9d0919f2003-11-08 01:05:38 +00001888<div class="doc_text">
Chris Lattnere19d7a72004-09-27 21:51:25 +00001889
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001890<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001891
1892<pre>
1893 &lt;resultval&gt; = vaarg &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;
1894</pre>
1895
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001896<h5>Overview:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001897
1898<p>The '<tt>vaarg</tt>' instruction is used to access arguments passed through
1899the "variable argument" area of a function call. It is used to implement the
1900<tt>va_arg</tt> macro in C.</p>
1901
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001902<h5>Arguments:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001903
1904<p>This instruction takes a <tt>va_list</tt> value and the type of the
1905argument. It returns a value of the specified argument type. Again, the actual
1906type of <tt>va_list</tt> is target specific.</p>
1907
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001908<h5>Semantics:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001909
1910<p>The '<tt>vaarg</tt>' instruction loads an argument of the specified type from
1911the specified <tt>va_list</tt>. In conjunction with the <a
1912href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to implement the
1913<tt>va_arg</tt> macro available in C. For more information, see the variable
1914argument handling <a href="#int_varargs">Intrinsic Functions</a>.</p>
1915
1916<p>It is legal for this instruction to be called in a function which does not
1917take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001918function.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001919
Misha Brukman9d0919f2003-11-08 01:05:38 +00001920<p><tt>vaarg</tt> is an LLVM instruction instead of an <a
Chris Lattnere19d7a72004-09-27 21:51:25 +00001921href="#intrinsics">intrinsic function</a> because it takes an type as an
1922argument.</p>
1923
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001924<h5>Example:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001925
1926<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
1927
Misha Brukman9d0919f2003-11-08 01:05:38 +00001928</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001929
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001930<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00001931<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
1932<!-- *********************************************************************** -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001933
Misha Brukman9d0919f2003-11-08 01:05:38 +00001934<div class="doc_text">
Chris Lattner33aec9e2004-02-12 17:01:32 +00001935
1936<p>LLVM supports the notion of an "intrinsic function". These functions have
1937well known names and semantics, and are required to follow certain
1938restrictions. Overall, these instructions represent an extension mechanism for
1939the LLVM language that does not require changing all of the transformations in
1940LLVM to add to the language (or the bytecode reader/writer, the parser,
1941etc...).</p>
1942
1943<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix, this
1944prefix is reserved in LLVM for intrinsic names, thus functions may not be named
1945this. Intrinsic functions must always be external functions: you cannot define
1946the body of intrinsic functions. Intrinsic functions may only be used in call
1947or invoke instructions: it is illegal to take the address of an intrinsic
1948function. Additionally, because intrinsic functions are part of the LLVM
1949language, it is required that they all be documented here if any are added.</p>
1950
1951
1952<p>
1953Adding an intrinsic to LLVM is straight-forward if it is possible to express the
1954concept in LLVM directly (ie, code generator support is not _required_). To do
1955this, extend the default implementation of the IntrinsicLowering class to handle
1956the intrinsic. Code generators use this class to lower intrinsics they do not
1957understand to raw LLVM instructions that they do.
1958</p>
1959
Misha Brukman9d0919f2003-11-08 01:05:38 +00001960</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001961
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001962<!-- ======================================================================= -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001963<div class="doc_subsection">
1964 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
1965</div>
1966
Misha Brukman9d0919f2003-11-08 01:05:38 +00001967<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00001968
Misha Brukman9d0919f2003-11-08 01:05:38 +00001969<p>Variable argument support is defined in LLVM with the <a
Chris Lattner261efe92003-11-25 01:02:51 +00001970 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
1971intrinsic functions. These functions are related to the similarly
1972named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00001973
Chris Lattner261efe92003-11-25 01:02:51 +00001974<p>All of these functions operate on arguments that use a
1975target-specific value type "<tt>va_list</tt>". The LLVM assembly
1976language reference manual does not define what this type is, so all
1977transformations should be prepared to handle intrinsics with any type
1978used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00001979
Misha Brukman9d0919f2003-11-08 01:05:38 +00001980<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner261efe92003-11-25 01:02:51 +00001981instruction and the variable argument handling intrinsic functions are
1982used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00001983
Chris Lattner33aec9e2004-02-12 17:01:32 +00001984<pre>
1985int %test(int %X, ...) {
1986 ; Initialize variable argument processing
1987 %ap = call sbyte* %<a href="#i_va_start">llvm.va_start</a>()
1988
1989 ; Read a single integer argument
1990 %tmp = vaarg sbyte* %ap, int
1991
1992 ; Advance to the next argument
1993 %ap2 = vanext sbyte* %ap, int
1994
1995 ; Demonstrate usage of llvm.va_copy and llvm.va_end
1996 %aq = call sbyte* %<a href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2)
1997 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %aq)
1998
1999 ; Stop processing of arguments.
2000 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %ap2)
2001 ret int %tmp
2002}
2003</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002004</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002005
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002006<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002007<div class="doc_subsubsection">
2008 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
2009</div>
2010
2011
Misha Brukman9d0919f2003-11-08 01:05:38 +00002012<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002013<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002014<pre> call &lt;va_list&gt; ()* %llvm.va_start()<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002015<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002016<p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt>&lt;arglist&gt;</tt>
2017for subsequent use by the variable argument intrinsics.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002018<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002019<p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002020macro available in C. In a target-dependent way, it initializes and
2021returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt>
2022will produce the first variable argument passed to the function. Unlike
2023the C <tt>va_start</tt> macro, this intrinsic does not need to know the
2024last argument of the function, the compiler can figure that out.</p>
2025<p>Note that this intrinsic function is only legal to be called from
2026within the body of a variable argument function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002027</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002028
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002029<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002030<div class="doc_subsubsection">
2031 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
2032</div>
2033
Misha Brukman9d0919f2003-11-08 01:05:38 +00002034<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002035<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002036<pre> call void (&lt;va_list&gt;)* %llvm.va_end(&lt;va_list&gt; &lt;arglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002037<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002038<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
2039which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
2040or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002041<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002042<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002043<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002044<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002045macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
2046Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
2047 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
2048with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002049</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002050
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002051<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002052<div class="doc_subsubsection">
2053 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
2054</div>
2055
Misha Brukman9d0919f2003-11-08 01:05:38 +00002056<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00002057
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002058<h5>Syntax:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002059
2060<pre>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002061 call &lt;va_list&gt; (&lt;va_list&gt;)* %llvm.va_copy(&lt;va_list&gt; &lt;destarglist&gt;)
Chris Lattnerd7923912004-05-23 21:06:01 +00002062</pre>
2063
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002064<h5>Overview:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002065
2066<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position
2067from the source argument list to the destination argument list.</p>
2068
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002069<h5>Arguments:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002070
Misha Brukman9d0919f2003-11-08 01:05:38 +00002071<p>The argument is the <tt>va_list</tt> to copy.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002072
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002073<h5>Semantics:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002074
Misha Brukman9d0919f2003-11-08 01:05:38 +00002075<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
Chris Lattnerd7923912004-05-23 21:06:01 +00002076macro available in C. In a target-dependent way, it copies the source
2077<tt>va_list</tt> element into the returned list. This intrinsic is necessary
Chris Lattnerfcd37252004-06-21 22:52:48 +00002078because the <tt><a href="#i_va_start">llvm.va_start</a></tt> intrinsic may be
Chris Lattnerd7923912004-05-23 21:06:01 +00002079arbitrarily complex and require memory allocation, for example.</p>
2080
Misha Brukman9d0919f2003-11-08 01:05:38 +00002081</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002082
Chris Lattner33aec9e2004-02-12 17:01:32 +00002083<!-- ======================================================================= -->
2084<div class="doc_subsection">
Chris Lattnerd7923912004-05-23 21:06:01 +00002085 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
2086</div>
2087
2088<div class="doc_text">
2089
2090<p>
2091LLVM support for <a href="GarbageCollection.html">Accurate Garbage
2092Collection</a> requires the implementation and generation of these intrinsics.
2093These intrinsics allow identification of <a href="#i_gcroot">GC roots on the
2094stack</a>, as well as garbage collector implementations that require <a
2095href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers.
2096Front-ends for type-safe garbage collected languages should generate these
2097intrinsics to make use of the LLVM garbage collectors. For more details, see <a
2098href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
2099</p>
2100</div>
2101
2102<!-- _______________________________________________________________________ -->
2103<div class="doc_subsubsection">
2104 <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
2105</div>
2106
2107<div class="doc_text">
2108
2109<h5>Syntax:</h5>
2110
2111<pre>
2112 call void (&lt;ty&gt;**, &lt;ty2&gt;*)* %llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
2113</pre>
2114
2115<h5>Overview:</h5>
2116
2117<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existance of a GC root to
2118the code generator, and allows some metadata to be associated with it.</p>
2119
2120<h5>Arguments:</h5>
2121
2122<p>The first argument specifies the address of a stack object that contains the
2123root pointer. The second pointer (which must be either a constant or a global
2124value address) contains the meta-data to be associated with the root.</p>
2125
2126<h5>Semantics:</h5>
2127
2128<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
2129location. At compile-time, the code generator generates information to allow
2130the runtime to find the pointer at GC safe points.
2131</p>
2132
2133</div>
2134
2135
2136<!-- _______________________________________________________________________ -->
2137<div class="doc_subsubsection">
2138 <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
2139</div>
2140
2141<div class="doc_text">
2142
2143<h5>Syntax:</h5>
2144
2145<pre>
2146 call sbyte* (sbyte**)* %llvm.gcread(sbyte** %Ptr)
2147</pre>
2148
2149<h5>Overview:</h5>
2150
2151<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
2152locations, allowing garbage collector implementations that require read
2153barriers.</p>
2154
2155<h5>Arguments:</h5>
2156
2157<p>The argument is the address to read from, which should be an address
2158allocated from the garbage collector.</p>
2159
2160<h5>Semantics:</h5>
2161
2162<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
2163instruction, but may be replaced with substantially more complex code by the
2164garbage collector runtime, as needed.</p>
2165
2166</div>
2167
2168
2169<!-- _______________________________________________________________________ -->
2170<div class="doc_subsubsection">
2171 <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
2172</div>
2173
2174<div class="doc_text">
2175
2176<h5>Syntax:</h5>
2177
2178<pre>
2179 call void (sbyte*, sbyte**)* %llvm.gcwrite(sbyte* %P1, sbyte** %P2)
2180</pre>
2181
2182<h5>Overview:</h5>
2183
2184<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
2185locations, allowing garbage collector implementations that require write
2186barriers (such as generational or reference counting collectors).</p>
2187
2188<h5>Arguments:</h5>
2189
2190<p>The first argument is the reference to store, and the second is the heap
2191location to store to.</p>
2192
2193<h5>Semantics:</h5>
2194
2195<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
2196instruction, but may be replaced with substantially more complex code by the
2197garbage collector runtime, as needed.</p>
2198
2199</div>
2200
2201
2202
2203<!-- ======================================================================= -->
2204<div class="doc_subsection">
Chris Lattner10610642004-02-14 04:08:35 +00002205 <a name="int_codegen">Code Generator Intrinsics</a>
2206</div>
2207
2208<div class="doc_text">
2209<p>
2210These intrinsics are provided by LLVM to expose special features that may only
2211be implemented with code generator support.
2212</p>
2213
2214</div>
2215
2216<!-- _______________________________________________________________________ -->
2217<div class="doc_subsubsection">
2218 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
2219</div>
2220
2221<div class="doc_text">
2222
2223<h5>Syntax:</h5>
2224<pre>
2225 call void* ()* %llvm.returnaddress(uint &lt;level&gt;)
2226</pre>
2227
2228<h5>Overview:</h5>
2229
2230<p>
2231The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
2232indicating the return address of the current function or one of its callers.
2233</p>
2234
2235<h5>Arguments:</h5>
2236
2237<p>
2238The argument to this intrinsic indicates which function to return the address
2239for. Zero indicates the calling function, one indicates its caller, etc. The
2240argument is <b>required</b> to be a constant integer value.
2241</p>
2242
2243<h5>Semantics:</h5>
2244
2245<p>
2246The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
2247the return address of the specified call frame, or zero if it cannot be
2248identified. The value returned by this intrinsic is likely to be incorrect or 0
2249for arguments other than zero, so it should only be used for debugging purposes.
2250</p>
2251
2252<p>
2253Note that calling this intrinsic does not prevent function inlining or other
2254aggressive transformations, so the value returned may not that of the obvious
2255source-language caller.
2256</p>
2257</div>
2258
2259
2260<!-- _______________________________________________________________________ -->
2261<div class="doc_subsubsection">
2262 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
2263</div>
2264
2265<div class="doc_text">
2266
2267<h5>Syntax:</h5>
2268<pre>
2269 call void* ()* %llvm.frameaddress(uint &lt;level&gt;)
2270</pre>
2271
2272<h5>Overview:</h5>
2273
2274<p>
2275The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
2276pointer value for the specified stack frame.
2277</p>
2278
2279<h5>Arguments:</h5>
2280
2281<p>
2282The argument to this intrinsic indicates which function to return the frame
2283pointer for. Zero indicates the calling function, one indicates its caller,
2284etc. The argument is <b>required</b> to be a constant integer value.
2285</p>
2286
2287<h5>Semantics:</h5>
2288
2289<p>
2290The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
2291the frame address of the specified call frame, or zero if it cannot be
2292identified. The value returned by this intrinsic is likely to be incorrect or 0
2293for arguments other than zero, so it should only be used for debugging purposes.
2294</p>
2295
2296<p>
2297Note that calling this intrinsic does not prevent function inlining or other
2298aggressive transformations, so the value returned may not that of the obvious
2299source-language caller.
2300</p>
2301</div>
2302
John Criswell7123e272004-04-09 16:43:20 +00002303<!-- ======================================================================= -->
2304<div class="doc_subsection">
2305 <a name="int_os">Operating System Intrinsics</a>
2306</div>
2307
2308<div class="doc_text">
2309<p>
2310These intrinsics are provided by LLVM to support the implementation of
2311operating system level code.
2312</p>
2313
2314</div>
John Criswell183402a2004-04-12 15:02:16 +00002315
John Criswellcfd3bac2004-04-09 15:23:37 +00002316<!-- _______________________________________________________________________ -->
2317<div class="doc_subsubsection">
2318 <a name="i_readport">'<tt>llvm.readport</tt>' Intrinsic</a>
2319</div>
2320
2321<div class="doc_text">
2322
2323<h5>Syntax:</h5>
2324<pre>
John Criswell7123e272004-04-09 16:43:20 +00002325 call &lt;integer type&gt; (&lt;integer type&gt;)* %llvm.readport (&lt;integer type&gt; &lt;address&gt;)
John Criswellcfd3bac2004-04-09 15:23:37 +00002326</pre>
2327
2328<h5>Overview:</h5>
2329
2330<p>
John Criswell7123e272004-04-09 16:43:20 +00002331The '<tt>llvm.readport</tt>' intrinsic reads data from the specified hardware
2332I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002333</p>
2334
2335<h5>Arguments:</h5>
2336
2337<p>
John Criswell7123e272004-04-09 16:43:20 +00002338The argument to this intrinsic indicates the hardware I/O address from which
2339to read the data. The address is in the hardware I/O address namespace (as
2340opposed to being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002341</p>
2342
2343<h5>Semantics:</h5>
2344
2345<p>
John Criswell7123e272004-04-09 16:43:20 +00002346The '<tt>llvm.readport</tt>' intrinsic reads data from the hardware I/O port
2347specified by <i>address</i> and returns the value. The address and return
2348value must be integers, but the size is dependent upon the platform upon which
2349the program is code generated. For example, on x86, the address must be an
2350unsigned 16 bit value, and the return value must be 8, 16, or 32 bits.
John Criswellcfd3bac2004-04-09 15:23:37 +00002351</p>
2352
2353</div>
2354
2355<!-- _______________________________________________________________________ -->
2356<div class="doc_subsubsection">
2357 <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a>
2358</div>
2359
2360<div class="doc_text">
2361
2362<h5>Syntax:</h5>
2363<pre>
John Criswell7123e272004-04-09 16:43:20 +00002364 call void (&lt;integer type&gt;, &lt;integer type&gt;)* %llvm.writeport (&lt;integer type&gt; &lt;value&gt;, &lt;integer type&gt; &lt;address&gt;)
John Criswellcfd3bac2004-04-09 15:23:37 +00002365</pre>
2366
2367<h5>Overview:</h5>
2368
2369<p>
John Criswell7123e272004-04-09 16:43:20 +00002370The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified hardware
2371I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002372</p>
2373
2374<h5>Arguments:</h5>
2375
2376<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002377The first argument is the value to write to the I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002378</p>
2379
2380<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002381The second argument indicates the hardware I/O address to which data should be
2382written. The address is in the hardware I/O address namespace (as opposed to
2383being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002384</p>
2385
2386<h5>Semantics:</h5>
2387
2388<p>
2389The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port
2390specified by <i>address</i>. The address and value must be integers, but the
2391size is dependent upon the platform upon which the program is code generated.
John Criswell7123e272004-04-09 16:43:20 +00002392For example, on x86, the address must be an unsigned 16 bit value, and the
2393value written must be 8, 16, or 32 bits in length.
John Criswellcfd3bac2004-04-09 15:23:37 +00002394</p>
2395
2396</div>
Chris Lattner10610642004-02-14 04:08:35 +00002397
John Criswell183402a2004-04-12 15:02:16 +00002398<!-- _______________________________________________________________________ -->
2399<div class="doc_subsubsection">
2400 <a name="i_readio">'<tt>llvm.readio</tt>' Intrinsic</a>
2401</div>
2402
2403<div class="doc_text">
2404
2405<h5>Syntax:</h5>
2406<pre>
John Criswell96db6fc2004-04-12 16:33:19 +00002407 call &lt;result&gt; (&lt;ty&gt;*)* %llvm.readio (&lt;ty&gt; * &lt;pointer&gt;)
John Criswell183402a2004-04-12 15:02:16 +00002408</pre>
2409
2410<h5>Overview:</h5>
2411
2412<p>
2413The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
2414address.
2415</p>
2416
2417<h5>Arguments:</h5>
2418
2419<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002420The argument to this intrinsic is a pointer indicating the memory address from
2421which to read the data. The data must be a
2422<a href="#t_firstclass">first class</a> type.
John Criswell183402a2004-04-12 15:02:16 +00002423</p>
2424
2425<h5>Semantics:</h5>
2426
2427<p>
2428The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
John Criswell96db6fc2004-04-12 16:33:19 +00002429location specified by <i>pointer</i> and returns the value. The argument must
2430be a pointer, and the return value must be a
2431<a href="#t_firstclass">first class</a> type. However, certain architectures
2432may not support I/O on all first class types. For example, 32 bit processors
2433may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00002434</p>
2435
2436<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002437This intrinsic enforces an in-order memory model for llvm.readio and
2438llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2439scheduled processors may execute loads and stores out of order, re-ordering at
2440run time accesses to memory mapped I/O registers. Using these intrinsics
2441ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00002442</p>
2443
2444</div>
2445
2446<!-- _______________________________________________________________________ -->
2447<div class="doc_subsubsection">
2448 <a name="i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a>
2449</div>
2450
2451<div class="doc_text">
2452
2453<h5>Syntax:</h5>
2454<pre>
John Criswell96db6fc2004-04-12 16:33:19 +00002455 call void (&lt;ty1&gt;, &lt;ty2&gt;*)* %llvm.writeio (&lt;ty1&gt; &lt;value&gt;, &lt;ty2&gt; * &lt;pointer&gt;)
John Criswell183402a2004-04-12 15:02:16 +00002456</pre>
2457
2458<h5>Overview:</h5>
2459
2460<p>
2461The '<tt>llvm.writeio</tt>' intrinsic writes data to the specified memory
2462mapped I/O address.
2463</p>
2464
2465<h5>Arguments:</h5>
2466
2467<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002468The first argument is the value to write to the memory mapped I/O location.
2469The second argument is a pointer indicating the memory address to which the
2470data should be written.
John Criswell183402a2004-04-12 15:02:16 +00002471</p>
2472
2473<h5>Semantics:</h5>
2474
2475<p>
2476The '<tt>llvm.writeio</tt>' intrinsic writes <i>value</i> to the memory mapped
John Criswell96db6fc2004-04-12 16:33:19 +00002477I/O address specified by <i>pointer</i>. The value must be a
2478<a href="#t_firstclass">first class</a> type. However, certain architectures
2479may not support I/O on all first class types. For example, 32 bit processors
2480may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00002481</p>
2482
2483<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002484This intrinsic enforces an in-order memory model for llvm.readio and
2485llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2486scheduled processors may execute loads and stores out of order, re-ordering at
2487run time accesses to memory mapped I/O registers. Using these intrinsics
2488ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00002489</p>
2490
2491</div>
2492
Chris Lattner10610642004-02-14 04:08:35 +00002493<!-- ======================================================================= -->
2494<div class="doc_subsection">
Chris Lattner33aec9e2004-02-12 17:01:32 +00002495 <a name="int_libc">Standard C Library Intrinsics</a>
2496</div>
2497
2498<div class="doc_text">
2499<p>
Chris Lattner10610642004-02-14 04:08:35 +00002500LLVM provides intrinsics for a few important standard C library functions.
2501These intrinsics allow source-language front-ends to pass information about the
2502alignment of the pointer arguments to the code generator, providing opportunity
2503for more efficient code generation.
Chris Lattner33aec9e2004-02-12 17:01:32 +00002504</p>
2505
2506</div>
2507
2508<!-- _______________________________________________________________________ -->
2509<div class="doc_subsubsection">
2510 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
2511</div>
2512
2513<div class="doc_text">
2514
2515<h5>Syntax:</h5>
2516<pre>
2517 call void (sbyte*, sbyte*, uint, uint)* %llvm.memcpy(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2518 uint &lt;len&gt;, uint &lt;align&gt;)
2519</pre>
2520
2521<h5>Overview:</h5>
2522
2523<p>
2524The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2525location to the destination location.
2526</p>
2527
2528<p>
2529Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
2530does not return a value, and takes an extra alignment argument.
2531</p>
2532
2533<h5>Arguments:</h5>
2534
2535<p>
2536The first argument is a pointer to the destination, the second is a pointer to
2537the source. The third argument is an (arbitrarily sized) integer argument
2538specifying the number of bytes to copy, and the fourth argument is the alignment
2539of the source and destination locations.
2540</p>
2541
Chris Lattner3301ced2004-02-12 21:18:15 +00002542<p>
2543If the call to this intrinisic has an alignment value that is not 0 or 1, then
2544the caller guarantees that the size of the copy is a multiple of the alignment
2545and that both the source and destination pointers are aligned to that boundary.
2546</p>
2547
Chris Lattner33aec9e2004-02-12 17:01:32 +00002548<h5>Semantics:</h5>
2549
2550<p>
2551The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2552location to the destination location, which are not allowed to overlap. It
2553copies "len" bytes of memory over. If the argument is known to be aligned to
2554some boundary, this can be specified as the fourth argument, otherwise it should
2555be set to 0 or 1.
2556</p>
2557</div>
2558
2559
Chris Lattner0eb51b42004-02-12 18:10:10 +00002560<!-- _______________________________________________________________________ -->
2561<div class="doc_subsubsection">
2562 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
2563</div>
2564
2565<div class="doc_text">
2566
2567<h5>Syntax:</h5>
2568<pre>
2569 call void (sbyte*, sbyte*, uint, uint)* %llvm.memmove(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2570 uint &lt;len&gt;, uint &lt;align&gt;)
2571</pre>
2572
2573<h5>Overview:</h5>
2574
2575<p>
2576The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
2577location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>'
2578intrinsic but allows the two memory locations to overlap.
2579</p>
2580
2581<p>
2582Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
2583does not return a value, and takes an extra alignment argument.
2584</p>
2585
2586<h5>Arguments:</h5>
2587
2588<p>
2589The first argument is a pointer to the destination, the second is a pointer to
2590the source. The third argument is an (arbitrarily sized) integer argument
2591specifying the number of bytes to copy, and the fourth argument is the alignment
2592of the source and destination locations.
2593</p>
2594
Chris Lattner3301ced2004-02-12 21:18:15 +00002595<p>
2596If the call to this intrinisic has an alignment value that is not 0 or 1, then
2597the caller guarantees that the size of the copy is a multiple of the alignment
2598and that both the source and destination pointers are aligned to that boundary.
2599</p>
2600
Chris Lattner0eb51b42004-02-12 18:10:10 +00002601<h5>Semantics:</h5>
2602
2603<p>
2604The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
2605location to the destination location, which may overlap. It
2606copies "len" bytes of memory over. If the argument is known to be aligned to
2607some boundary, this can be specified as the fourth argument, otherwise it should
2608be set to 0 or 1.
2609</p>
2610</div>
2611
Chris Lattner8ff75902004-01-06 05:31:32 +00002612
Chris Lattner10610642004-02-14 04:08:35 +00002613<!-- _______________________________________________________________________ -->
2614<div class="doc_subsubsection">
2615 <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a>
2616</div>
2617
2618<div class="doc_text">
2619
2620<h5>Syntax:</h5>
2621<pre>
2622 call void (sbyte*, ubyte, uint, uint)* %llvm.memset(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
2623 uint &lt;len&gt;, uint &lt;align&gt;)
2624</pre>
2625
2626<h5>Overview:</h5>
2627
2628<p>
2629The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular
2630byte value.
2631</p>
2632
2633<p>
2634Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
2635does not return a value, and takes an extra alignment argument.
2636</p>
2637
2638<h5>Arguments:</h5>
2639
2640<p>
2641The first argument is a pointer to the destination to fill, the second is the
2642byte value to fill it with, the third argument is an (arbitrarily sized) integer
2643argument specifying the number of bytes to fill, and the fourth argument is the
2644known alignment of destination location.
2645</p>
2646
2647<p>
2648If the call to this intrinisic has an alignment value that is not 0 or 1, then
2649the caller guarantees that the size of the copy is a multiple of the alignment
2650and that the destination pointer is aligned to that boundary.
2651</p>
2652
2653<h5>Semantics:</h5>
2654
2655<p>
2656The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the
2657destination location. If the argument is known to be aligned to some boundary,
2658this can be specified as the fourth argument, otherwise it should be set to 0 or
26591.
2660</p>
2661</div>
2662
2663
Chris Lattner32006282004-06-11 02:28:03 +00002664<!-- _______________________________________________________________________ -->
2665<div class="doc_subsubsection">
Alkis Evlogimenos26bbe932004-06-13 01:16:15 +00002666 <a name="i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a>
2667</div>
2668
2669<div class="doc_text">
2670
2671<h5>Syntax:</h5>
2672<pre>
2673 call bool (&lt;float or double&gt;, &lt;float or double&gt;)* %llvm.isunordered(&lt;float or double&gt; Val1,
2674 &lt;float or double&gt; Val2)
2675</pre>
2676
2677<h5>Overview:</h5>
2678
2679<p>
2680The '<tt>llvm.isunordered</tt>' intrinsic returns true if either or both of the
2681specified floating point values is a NAN.
2682</p>
2683
2684<h5>Arguments:</h5>
2685
2686<p>
2687The arguments are floating point numbers of the same type.
2688</p>
2689
2690<h5>Semantics:</h5>
2691
2692<p>
2693If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise
2694false.
2695</p>
2696</div>
2697
2698
Chris Lattner32006282004-06-11 02:28:03 +00002699
2700
Chris Lattner8ff75902004-01-06 05:31:32 +00002701<!-- ======================================================================= -->
2702<div class="doc_subsection">
2703 <a name="int_debugger">Debugger Intrinsics</a>
2704</div>
2705
2706<div class="doc_text">
2707<p>
2708The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
2709are described in the <a
2710href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
2711Debugging</a> document.
2712</p>
2713</div>
2714
2715
Chris Lattner00950542001-06-06 20:29:01 +00002716<!-- *********************************************************************** -->
Chris Lattner00950542001-06-06 20:29:01 +00002717<hr>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002718<address>
2719 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
2720 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
2721 <a href="http://validator.w3.org/check/referer"><img
2722 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
2723
2724 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
2725 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
2726 Last modified: $Date$
2727</address>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002728</body>
2729</html>