blob: 0c5346ae5917f12301bb0038b3fb050ac61ef57d [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 Lattner69c11bb2005-04-25 17:34:15 +000042 <li><a href="#t_opaque">Opaque Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000043 </ol>
44 </li>
45 </ol>
46 </li>
Chris Lattnerfa730212004-12-09 16:11:40 +000047 <li><a href="#constants">Constants</a>
Chris Lattnerc3f59762004-12-09 17:30:23 +000048 <ol>
49 <li><a href="#simpleconstants">Simple Constants</a>
50 <li><a href="#aggregateconstants">Aggregate Constants</a>
51 <li><a href="#globalconstants">Global Variable and Function Addresses</a>
52 <li><a href="#undefvalues">Undefined Values</a>
53 <li><a href="#constantexprs">Constant Expressions</a>
54 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +000055 </li>
Chris Lattner00950542001-06-06 20:29:01 +000056 <li><a href="#instref">Instruction Reference</a>
57 <ol>
58 <li><a href="#terminators">Terminator Instructions</a>
59 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000060 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
61 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000062 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
63 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000064 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
Chris Lattner35eca582004-10-16 18:04:13 +000065 <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000066 </ol>
67 </li>
Chris Lattner00950542001-06-06 20:29:01 +000068 <li><a href="#binaryops">Binary Operations</a>
69 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000070 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
71 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
72 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
73 <li><a href="#i_div">'<tt>div</tt>' Instruction</a></li>
74 <li><a href="#i_rem">'<tt>rem</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000075 <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000076 </ol>
77 </li>
Chris Lattner00950542001-06-06 20:29:01 +000078 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
79 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000080 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000081 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000082 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
83 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
84 <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000085 </ol>
86 </li>
Chris Lattner00950542001-06-06 20:29:01 +000087 <li><a href="#memoryops">Memory Access Operations</a>
88 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000089 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
90 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
91 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
92 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
93 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
94 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
95 </ol>
96 </li>
Chris Lattner00950542001-06-06 20:29:01 +000097 <li><a href="#otherops">Other Operations</a>
98 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000099 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000100 <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li>
Chris Lattnercc37aae2004-03-12 05:50:16 +0000101 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000102 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000103 <li><a href="#i_vanext">'<tt>vanext</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000104 <li><a href="#i_vaarg">'<tt>vaarg</tt>' Instruction</a></li>
Chris Lattner00950542001-06-06 20:29:01 +0000105 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000106 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000107 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000108 </li>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +0000109 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +0000110 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000111 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
112 <ol>
113 <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
114 <li><a href="#i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
115 <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
116 </ol>
117 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000118 <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
119 <ol>
120 <li><a href="#i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li>
121 <li><a href="#i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li>
122 <li><a href="#i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li>
123 </ol>
124 </li>
Chris Lattner10610642004-02-14 04:08:35 +0000125 <li><a href="#int_codegen">Code Generator Intrinsics</a>
126 <ol>
127 <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
128 <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
Chris Lattner9a9d7ac2005-02-28 19:24:19 +0000129 <li><a href="#i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a></li>
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +0000130 <li><a href="#i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a></li>
John Criswell7123e272004-04-09 16:43:20 +0000131 </ol>
132 </li>
133 <li><a href="#int_os">Operating System Intrinsics</a>
134 <ol>
Chris Lattner32006282004-06-11 02:28:03 +0000135 <li><a href="#i_readport">'<tt>llvm.readport</tt>' Intrinsic</a></li>
136 <li><a href="#i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a></li>
John Criswell183402a2004-04-12 15:02:16 +0000137 <li><a href="#i_readio">'<tt>llvm.readio</tt>' Intrinsic</a></li>
138 <li><a href="#i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000139 </ol>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000140 <li><a href="#int_libc">Standard C Library Intrinsics</a>
141 <ol>
142 <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li>
Chris Lattner0eb51b42004-02-12 18:10:10 +0000143 <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000144 <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li>
Alkis Evlogimenos96853722004-06-12 19:19:14 +0000145 <li><a href="#i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a></li>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000146 </ol>
147 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000148 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000149 </ol>
150 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000151</ol>
Chris Lattnerd7923912004-05-23 21:06:01 +0000152
153<div class="doc_author">
154 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
155 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000156</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000157
Chris Lattner00950542001-06-06 20:29:01 +0000158<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000159<div class="doc_section"> <a name="abstract">Abstract </a></div>
160<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000161
Misha Brukman9d0919f2003-11-08 01:05:38 +0000162<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000163<p>This document is a reference manual for the LLVM assembly language.
164LLVM is an SSA based representation that provides type safety,
165low-level operations, flexibility, and the capability of representing
166'all' high-level languages cleanly. It is the common code
167representation used throughout all phases of the LLVM compilation
168strategy.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000169</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000170
Chris Lattner00950542001-06-06 20:29:01 +0000171<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000172<div class="doc_section"> <a name="introduction">Introduction</a> </div>
173<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000174
Misha Brukman9d0919f2003-11-08 01:05:38 +0000175<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000176
Chris Lattner261efe92003-11-25 01:02:51 +0000177<p>The LLVM code representation is designed to be used in three
178different forms: as an in-memory compiler IR, as an on-disk bytecode
179representation (suitable for fast loading by a Just-In-Time compiler),
180and as a human readable assembly language representation. This allows
181LLVM to provide a powerful intermediate representation for efficient
182compiler transformations and analysis, while providing a natural means
183to debug and visualize the transformations. The three different forms
184of LLVM are all equivalent. This document describes the human readable
185representation and notation.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000186
Chris Lattner261efe92003-11-25 01:02:51 +0000187<p>The LLVM representation aims to be a light-weight and low-level
188while being expressive, typed, and extensible at the same time. It
189aims to be a "universal IR" of sorts, by being at a low enough level
190that high-level ideas may be cleanly mapped to it (similar to how
191microprocessors are "universal IR's", allowing many source languages to
192be mapped to them). By providing type information, LLVM can be used as
193the target of optimizations: for example, through pointer analysis, it
194can be proven that a C automatic variable is never accessed outside of
195the current function... allowing it to be promoted to a simple SSA
196value instead of a memory location.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000197
Misha Brukman9d0919f2003-11-08 01:05:38 +0000198</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000199
Chris Lattner00950542001-06-06 20:29:01 +0000200<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000201<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000202
Misha Brukman9d0919f2003-11-08 01:05:38 +0000203<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000204
Chris Lattner261efe92003-11-25 01:02:51 +0000205<p>It is important to note that this document describes 'well formed'
206LLVM assembly language. There is a difference between what the parser
207accepts and what is considered 'well formed'. For example, the
208following instruction is syntactically okay, but not well formed:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000209
210<pre>
211 %x = <a href="#i_add">add</a> int 1, %x
212</pre>
213
Chris Lattner261efe92003-11-25 01:02:51 +0000214<p>...because the definition of <tt>%x</tt> does not dominate all of
215its uses. The LLVM infrastructure provides a verification pass that may
216be used to verify that an LLVM module is well formed. This pass is
217automatically run by the parser after parsing input assembly, and by
218the optimizer before it outputs bytecode. The violations pointed out
219by the verifier pass indicate bugs in transformation passes or input to
220the parser.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000221
Chris Lattner261efe92003-11-25 01:02:51 +0000222<!-- Describe the typesetting conventions here. --> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000223
Chris Lattner00950542001-06-06 20:29:01 +0000224<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000225<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000226<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000227
Misha Brukman9d0919f2003-11-08 01:05:38 +0000228<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000229
Chris Lattner261efe92003-11-25 01:02:51 +0000230<p>LLVM uses three different forms of identifiers, for different
231purposes:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000232
Chris Lattner00950542001-06-06 20:29:01 +0000233<ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000234 <li>Named values are represented as a string of characters with a '%' prefix.
235 For example, %foo, %DivisionByZero, %a.really.long.identifier. The actual
236 regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
237 Identifiers which require other characters in their names can be surrounded
238 with quotes. In this way, anything except a <tt>"</tt> character can be used
239 in a name.</li>
240
241 <li>Unnamed values are represented as an unsigned numeric value with a '%'
242 prefix. For example, %12, %2, %44.</li>
243
Reid Spencercc16dc32004-12-09 18:02:53 +0000244 <li>Constants, which are described in a <a href="#constants">section about
245 constants</a>, below.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000246</ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000247
248<p>LLVM requires that values start with a '%' sign for two reasons: Compilers
249don't need to worry about name clashes with reserved words, and the set of
250reserved words may be expanded in the future without penalty. Additionally,
251unnamed identifiers allow a compiler to quickly come up with a temporary
252variable without having to avoid symbol table conflicts.</p>
253
Chris Lattner261efe92003-11-25 01:02:51 +0000254<p>Reserved words in LLVM are very similar to reserved words in other
255languages. There are keywords for different opcodes ('<tt><a
Chris Lattnere5d947b2004-12-09 16:36:40 +0000256href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
257href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
258href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>', etc...),
259and others. These reserved words cannot conflict with variable names, because
260none of them start with a '%' character.</p>
261
262<p>Here is an example of LLVM code to multiply the integer variable
263'<tt>%X</tt>' by 8:</p>
264
Misha Brukman9d0919f2003-11-08 01:05:38 +0000265<p>The easy way:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000266
267<pre>
268 %result = <a href="#i_mul">mul</a> uint %X, 8
269</pre>
270
Misha Brukman9d0919f2003-11-08 01:05:38 +0000271<p>After strength reduction:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000272
273<pre>
274 %result = <a href="#i_shl">shl</a> uint %X, ubyte 3
275</pre>
276
Misha Brukman9d0919f2003-11-08 01:05:38 +0000277<p>And the hard way:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000278
279<pre>
280 <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
281 <a href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
282 %result = <a href="#i_add">add</a> uint %1, %1
283</pre>
284
Chris Lattner261efe92003-11-25 01:02:51 +0000285<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
286important lexical features of LLVM:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000287
Chris Lattner00950542001-06-06 20:29:01 +0000288<ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000289
290 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
291 line.</li>
292
293 <li>Unnamed temporaries are created when the result of a computation is not
294 assigned to a named value.</li>
295
Misha Brukman9d0919f2003-11-08 01:05:38 +0000296 <li>Unnamed temporaries are numbered sequentially</li>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000297
Misha Brukman9d0919f2003-11-08 01:05:38 +0000298</ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000299
300<p>...and it also show a convention that we follow in this document. When
301demonstrating instructions, we will follow an instruction with a comment that
302defines the type and name of value produced. Comments are shown in italic
303text.</p>
304
Misha Brukman9d0919f2003-11-08 01:05:38 +0000305</div>
Chris Lattnerfa730212004-12-09 16:11:40 +0000306
307<!-- *********************************************************************** -->
308<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
309<!-- *********************************************************************** -->
310
311<!-- ======================================================================= -->
312<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
313</div>
314
315<div class="doc_text">
316
317<p>LLVM programs are composed of "Module"s, each of which is a
318translation unit of the input programs. Each module consists of
319functions, global variables, and symbol table entries. Modules may be
320combined together with the LLVM linker, which merges function (and
321global variable) definitions, resolves forward declarations, and merges
322symbol table entries. Here is an example of the "hello world" module:</p>
323
324<pre><i>; Declare the string constant as a global constant...</i>
325<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
326 href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00" <i>; [13 x sbyte]*</i>
327
328<i>; External declaration of the puts function</i>
329<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
330
331<i>; Definition of main function</i>
332int %main() { <i>; int()* </i>
333 <i>; Convert [13x sbyte]* to sbyte *...</i>
334 %cast210 = <a
335 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
336
337 <i>; Call puts function to write out the string to stdout...</i>
338 <a
339 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
340 <a
341 href="#i_ret">ret</a> int 0<br>}<br></pre>
342
343<p>This example is made up of a <a href="#globalvars">global variable</a>
344named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
345function, and a <a href="#functionstructure">function definition</a>
346for "<tt>main</tt>".</p>
347
Chris Lattnere5d947b2004-12-09 16:36:40 +0000348<p>In general, a module is made up of a list of global values,
349where both functions and global variables are global values. Global values are
350represented by a pointer to a memory location (in this case, a pointer to an
351array of char, and a pointer to a function), and have one of the following <a
352href="#linkage">linkage types</a>.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000353
Chris Lattnere5d947b2004-12-09 16:36:40 +0000354</div>
355
356<!-- ======================================================================= -->
357<div class="doc_subsection">
358 <a name="linkage">Linkage Types</a>
359</div>
360
361<div class="doc_text">
362
363<p>
364All Global Variables and Functions have one of the following types of linkage:
365</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000366
367<dl>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000368
Chris Lattnerfa730212004-12-09 16:11:40 +0000369 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000370
371 <dd>Global values with internal linkage are only directly accessible by
372 objects in the current module. In particular, linking code into a module with
373 an internal global value may cause the internal to be renamed as necessary to
374 avoid collisions. Because the symbol is internal to the module, all
375 references can be updated. This corresponds to the notion of the
376 '<tt>static</tt>' keyword in C, or the idea of "anonymous namespaces" in C++.
Chris Lattnerfa730212004-12-09 16:11:40 +0000377 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000378
Chris Lattnerfa730212004-12-09 16:11:40 +0000379 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000380
381 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt> linkage, with
382 the twist that linking together two modules defining the same
383 <tt>linkonce</tt> globals will cause one of the globals to be discarded. This
384 is typically used to implement inline functions. Unreferenced
385 <tt>linkonce</tt> globals are allowed to be discarded.
Chris Lattnerfa730212004-12-09 16:11:40 +0000386 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000387
Chris Lattnerfa730212004-12-09 16:11:40 +0000388 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000389
390 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage,
391 except that unreferenced <tt>weak</tt> globals may not be discarded. This is
392 used to implement constructs in C such as "<tt>int X;</tt>" at global scope.
Chris Lattnerfa730212004-12-09 16:11:40 +0000393 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000394
Chris Lattnerfa730212004-12-09 16:11:40 +0000395 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000396
397 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
398 pointer to array type. When two global variables with appending linkage are
399 linked together, the two global arrays are appended together. This is the
400 LLVM, typesafe, equivalent of having the system linker append together
401 "sections" with identical names when .o files are linked.
Chris Lattnerfa730212004-12-09 16:11:40 +0000402 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000403
Chris Lattnerfa730212004-12-09 16:11:40 +0000404 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000405
406 <dd>If none of the above identifiers are used, the global is externally
407 visible, meaning that it participates in linkage and can be used to resolve
408 external symbol references.
Chris Lattnerfa730212004-12-09 16:11:40 +0000409 </dd>
410</dl>
411
Chris Lattnerfa730212004-12-09 16:11:40 +0000412<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
413variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
414variable and was linked with this one, one of the two would be renamed,
415preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
416external (i.e., lacking any linkage declarations), they are accessible
417outside of the current module. It is illegal for a function <i>declaration</i>
418to have any linkage type other than "externally visible".</a></p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000419
Chris Lattnerfa730212004-12-09 16:11:40 +0000420</div>
421
422<!-- ======================================================================= -->
423<div class="doc_subsection">
424 <a name="globalvars">Global Variables</a>
425</div>
426
427<div class="doc_text">
428
Chris Lattner3689a342005-02-12 19:30:21 +0000429<p>Global variables define regions of memory allocated at compilation time
430instead of run-time. Global variables may optionally be initialized. A
431variable may be defined as a global "constant", which indicates that the
432contents of the variable will <b>never</b> be modified (enabling better
433optimization, allowing the global data to be placed in the read-only section of
434an executable, etc). Note that variables that need runtime initialization
435cannot be marked "constant", as there is a store to the variable.</p>
436
437<p>
438LLVM explicitly allows <em>declarations</em> of global variables to be marked
439constant, even if the final definition of the global is not. This capability
440can be used to enable slightly better optimization of the program, but requires
441the language definition to guarantee that optimizations based on the
442'constantness' are valid for the translation units that do not include the
443definition.
444</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000445
446<p>As SSA values, global variables define pointer values that are in
447scope (i.e. they dominate) all basic blocks in the program. Global
448variables always define a pointer to their "content" type because they
449describe a region of memory, and all memory objects in LLVM are
450accessed through pointers.</p>
451
452</div>
453
454
455<!-- ======================================================================= -->
456<div class="doc_subsection">
457 <a name="functionstructure">Functions</a>
458</div>
459
460<div class="doc_text">
461
462<p>LLVM function definitions are composed of a (possibly empty) argument list,
463an opening curly brace, a list of basic blocks, and a closing curly brace. LLVM
464function declarations are defined with the "<tt>declare</tt>" keyword, a
465function name, and a function signature.</p>
466
467<p>A function definition contains a list of basic blocks, forming the CFG for
468the function. Each basic block may optionally start with a label (giving the
469basic block a symbol table entry), contains a list of instructions, and ends
470with a <a href="#terminators">terminator</a> instruction (such as a branch or
471function return).</p>
472
473<p>The first basic block in program is special in two ways: it is immediately
474executed on entrance to the function, and it is not allowed to have predecessor
475basic blocks (i.e. there can not be any branches to the entry block of a
476function). Because the block can have no predecessors, it also cannot have any
477<a href="#i_phi">PHI nodes</a>.</p>
478
479<p>LLVM functions are identified by their name and type signature. Hence, two
480functions with the same name but different parameter lists or return values are
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000481considered different functions, and LLVM will resolve references to each
Chris Lattnerfa730212004-12-09 16:11:40 +0000482appropriately.</p>
483
484</div>
485
486
487
Chris Lattner00950542001-06-06 20:29:01 +0000488<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000489<div class="doc_section"> <a name="typesystem">Type System</a> </div>
490<!-- *********************************************************************** -->
Chris Lattnerfa730212004-12-09 16:11:40 +0000491
Misha Brukman9d0919f2003-11-08 01:05:38 +0000492<div class="doc_text">
Chris Lattnerfa730212004-12-09 16:11:40 +0000493
Misha Brukman9d0919f2003-11-08 01:05:38 +0000494<p>The LLVM type system is one of the most important features of the
Chris Lattner261efe92003-11-25 01:02:51 +0000495intermediate representation. Being typed enables a number of
496optimizations to be performed on the IR directly, without having to do
497extra analyses on the side before the transformation. A strong type
498system makes it easier to read the generated code and enables novel
499analyses and transformations that are not feasible to perform on normal
500three address code representations.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000501
502</div>
503
Chris Lattner00950542001-06-06 20:29:01 +0000504<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000505<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000506<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +0000507<p>The primitive types are the fundamental building blocks of the LLVM
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000508system. The current set of primitive types is as follows:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000509
Reid Spencerd3f876c2004-11-01 08:19:36 +0000510<table class="layout">
511 <tr class="layout">
512 <td class="left">
513 <table>
Chris Lattner261efe92003-11-25 01:02:51 +0000514 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000515 <tr><th>Type</th><th>Description</th></tr>
516 <tr><td><tt>void</tt></td><td>No value</td></tr>
Misha Brukmancfa87bc2005-04-22 18:02:52 +0000517 <tr><td><tt>ubyte</tt></td><td>Unsigned 8-bit value</td></tr>
518 <tr><td><tt>ushort</tt></td><td>Unsigned 16-bit value</td></tr>
519 <tr><td><tt>uint</tt></td><td>Unsigned 32-bit value</td></tr>
520 <tr><td><tt>ulong</tt></td><td>Unsigned 64-bit value</td></tr>
521 <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000522 <tr><td><tt>label</tt></td><td>Branch destination</td></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000523 </tbody>
524 </table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000525 </td>
526 <td class="right">
527 <table>
Chris Lattner261efe92003-11-25 01:02:51 +0000528 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000529 <tr><th>Type</th><th>Description</th></tr>
530 <tr><td><tt>bool</tt></td><td>True or False value</td></tr>
Misha Brukmancfa87bc2005-04-22 18:02:52 +0000531 <tr><td><tt>sbyte</tt></td><td>Signed 8-bit value</td></tr>
532 <tr><td><tt>short</tt></td><td>Signed 16-bit value</td></tr>
533 <tr><td><tt>int</tt></td><td>Signed 32-bit value</td></tr>
534 <tr><td><tt>long</tt></td><td>Signed 64-bit value</td></tr>
535 <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000536 </tbody>
537 </table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000538 </td>
539 </tr>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000540</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000541</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000542
Chris Lattner00950542001-06-06 20:29:01 +0000543<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000544<div class="doc_subsubsection"> <a name="t_classifications">Type
545Classifications</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000546<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000547<p>These different primitive types fall into a few useful
548classifications:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000549
550<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +0000551 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000552 <tr><th>Classification</th><th>Types</th></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000553 <tr>
554 <td><a name="t_signed">signed</a></td>
555 <td><tt>sbyte, short, int, long, float, double</tt></td>
556 </tr>
557 <tr>
558 <td><a name="t_unsigned">unsigned</a></td>
559 <td><tt>ubyte, ushort, uint, ulong</tt></td>
560 </tr>
561 <tr>
562 <td><a name="t_integer">integer</a></td>
563 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
564 </tr>
565 <tr>
566 <td><a name="t_integral">integral</a></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000567 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt>
568 </td>
Chris Lattner261efe92003-11-25 01:02:51 +0000569 </tr>
570 <tr>
571 <td><a name="t_floating">floating point</a></td>
572 <td><tt>float, double</tt></td>
573 </tr>
574 <tr>
575 <td><a name="t_firstclass">first class</a></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000576 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long,<br>
577 float, double, <a href="#t_pointer">pointer</a>,
578 <a href="#t_packed">packed</a></tt></td>
Chris Lattner261efe92003-11-25 01:02:51 +0000579 </tr>
580 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000581</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000582
Chris Lattner261efe92003-11-25 01:02:51 +0000583<p>The <a href="#t_firstclass">first class</a> types are perhaps the
584most important. Values of these types are the only ones which can be
585produced by instructions, passed as arguments, or used as operands to
586instructions. This means that all structures and arrays must be
587manipulated either by pointer or by component.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000588</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000589
Chris Lattner00950542001-06-06 20:29:01 +0000590<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000591<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000592
Misha Brukman9d0919f2003-11-08 01:05:38 +0000593<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +0000594
Chris Lattner261efe92003-11-25 01:02:51 +0000595<p>The real power in LLVM comes from the derived types in the system.
596This is what allows a programmer to represent arrays, functions,
597pointers, and other useful types. Note that these derived types may be
598recursive: For example, it is possible to have a two dimensional array.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000599
Misha Brukman9d0919f2003-11-08 01:05:38 +0000600</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000601
Chris Lattner00950542001-06-06 20:29:01 +0000602<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000603<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000604
Misha Brukman9d0919f2003-11-08 01:05:38 +0000605<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +0000606
Chris Lattner00950542001-06-06 20:29:01 +0000607<h5>Overview:</h5>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000608
Misha Brukman9d0919f2003-11-08 01:05:38 +0000609<p>The array type is a very simple derived type that arranges elements
Chris Lattner261efe92003-11-25 01:02:51 +0000610sequentially in memory. The array type requires a size (number of
611elements) and an underlying data type.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000612
Chris Lattner7faa8832002-04-14 06:13:44 +0000613<h5>Syntax:</h5>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000614
615<pre>
616 [&lt;# elements&gt; x &lt;elementtype&gt;]
617</pre>
618
Chris Lattner261efe92003-11-25 01:02:51 +0000619<p>The number of elements is a constant integer value, elementtype may
620be any type with a size.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000621
Chris Lattner7faa8832002-04-14 06:13:44 +0000622<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000623<table class="layout">
624 <tr class="layout">
625 <td class="left">
626 <tt>[40 x int ]</tt><br/>
627 <tt>[41 x int ]</tt><br/>
628 <tt>[40 x uint]</tt><br/>
629 </td>
630 <td class="left">
631 Array of 40 integer values.<br/>
632 Array of 41 integer values.<br/>
633 Array of 40 unsigned integer values.<br/>
634 </td>
635 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000636</table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000637<p>Here are some examples of multidimensional arrays:</p>
638<table class="layout">
639 <tr class="layout">
640 <td class="left">
641 <tt>[3 x [4 x int]]</tt><br/>
642 <tt>[12 x [10 x float]]</tt><br/>
643 <tt>[2 x [3 x [4 x uint]]]</tt><br/>
644 </td>
645 <td class="left">
646 3x4 array integer values.<br/>
647 12x10 array of single precision floating point values.<br/>
648 2x3x4 array of unsigned integer values.<br/>
649 </td>
650 </tr>
651</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000652</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000653
Chris Lattner00950542001-06-06 20:29:01 +0000654<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000655<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000656<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000657<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000658<p>The function type can be thought of as a function signature. It
659consists of a return type and a list of formal parameter types.
John Criswell009900b2003-11-25 21:45:46 +0000660Function types are usually used to build virtual function tables
Chris Lattner261efe92003-11-25 01:02:51 +0000661(which are structures of pointers to functions), for indirect function
662calls, and when defining a function.</p>
John Criswell009900b2003-11-25 21:45:46 +0000663<p>
664The return type of a function type cannot be an aggregate type.
665</p>
Chris Lattner00950542001-06-06 20:29:01 +0000666<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000667<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000668<p>Where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
669specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner27f71f22003-09-03 00:41:47 +0000670which indicates that the function takes a variable number of arguments.
671Variable argument functions can access their arguments with the <a
Chris Lattner261efe92003-11-25 01:02:51 +0000672 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000673<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000674<table class="layout">
675 <tr class="layout">
676 <td class="left">
677 <tt>int (int)</tt> <br/>
678 <tt>float (int, int *) *</tt><br/>
679 <tt>int (sbyte *, ...)</tt><br/>
680 </td>
681 <td class="left">
682 function taking an <tt>int</tt>, returning an <tt>int</tt><br/>
683 <a href="#t_pointer">Pointer</a> to a function that takes an
Misha Brukmanc24b7582004-08-12 20:16:08 +0000684 <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
Reid Spencerd3f876c2004-11-01 08:19:36 +0000685 returning <tt>float</tt>.<br/>
686 A vararg function that takes at least one <a href="#t_pointer">pointer</a>
687 to <tt>sbyte</tt> (signed char in C), which returns an integer. This is
688 the signature for <tt>printf</tt> in LLVM.<br/>
689 </td>
690 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000691</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000692
Misha Brukman9d0919f2003-11-08 01:05:38 +0000693</div>
Chris Lattner00950542001-06-06 20:29:01 +0000694<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000695<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000696<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000697<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000698<p>The structure type is used to represent a collection of data members
699together in memory. The packing of the field types is defined to match
700the ABI of the underlying processor. The elements of a structure may
701be any type that has a size.</p>
702<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
703and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
704field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
705instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000706<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000707<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +0000708<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000709<table class="layout">
710 <tr class="layout">
711 <td class="left">
712 <tt>{ int, int, int }</tt><br/>
713 <tt>{ float, int (int) * }</tt><br/>
714 </td>
715 <td class="left">
716 a triple of three <tt>int</tt> values<br/>
717 A pair, where the first element is a <tt>float</tt> and the second element
718 is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a>
719 that takes an <tt>int</tt>, returning an <tt>int</tt>.<br/>
720 </td>
721 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000722</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000723</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000724
Chris Lattner00950542001-06-06 20:29:01 +0000725<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000726<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000727<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +0000728<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000729<p>As in many languages, the pointer type represents a pointer or
730reference to another object, which must live in memory.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000731<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000732<pre> &lt;type&gt; *<br></pre>
Chris Lattner7faa8832002-04-14 06:13:44 +0000733<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000734<table class="layout">
735 <tr class="layout">
736 <td class="left">
737 <tt>[4x int]*</tt><br/>
738 <tt>int (int *) *</tt><br/>
739 </td>
740 <td class="left">
741 A <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of
742 four <tt>int</tt> values<br/>
743 A <a href="#t_pointer">pointer</a> to a <a
Chris Lattnera977c482005-02-19 02:22:14 +0000744 href="#t_function">function</a> that takes an <tt>int*</tt>, returning an
Reid Spencerd3f876c2004-11-01 08:19:36 +0000745 <tt>int</tt>.<br/>
746 </td>
747 </tr>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000748</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000749</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000750
Chris Lattnera58561b2004-08-12 19:12:28 +0000751<!-- _______________________________________________________________________ -->
752<div class="doc_subsubsection"> <a name="t_packed">Packed Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000753<div class="doc_text">
Chris Lattner69c11bb2005-04-25 17:34:15 +0000754
Chris Lattnera58561b2004-08-12 19:12:28 +0000755<h5>Overview:</h5>
Chris Lattner69c11bb2005-04-25 17:34:15 +0000756
Chris Lattnera58561b2004-08-12 19:12:28 +0000757<p>A packed type is a simple derived type that represents a vector
758of elements. Packed types are used when multiple primitive data
759are operated in parallel using a single instruction (SIMD).
760A packed type requires a size (number of
761elements) and an underlying primitive data type. Packed types are
762considered <a href="#t_firstclass">first class</a>.</p>
Chris Lattner69c11bb2005-04-25 17:34:15 +0000763
Chris Lattnera58561b2004-08-12 19:12:28 +0000764<h5>Syntax:</h5>
Chris Lattner69c11bb2005-04-25 17:34:15 +0000765
766<pre>
767 &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;
768</pre>
769
Chris Lattnera58561b2004-08-12 19:12:28 +0000770<p>The number of elements is a constant integer value, elementtype may
771be any integral or floating point type.</p>
Chris Lattner69c11bb2005-04-25 17:34:15 +0000772
Chris Lattnera58561b2004-08-12 19:12:28 +0000773<h5>Examples:</h5>
Chris Lattner69c11bb2005-04-25 17:34:15 +0000774
Reid Spencerd3f876c2004-11-01 08:19:36 +0000775<table class="layout">
776 <tr class="layout">
777 <td class="left">
778 <tt>&lt;4 x int&gt;</tt><br/>
779 <tt>&lt;8 x float&gt;</tt><br/>
780 <tt>&lt;2 x uint&gt;</tt><br/>
781 </td>
782 <td class="left">
783 Packed vector of 4 integer values.<br/>
784 Packed vector of 8 floating-point values.<br/>
785 Packed vector of 2 unsigned integer values.<br/>
786 </td>
787 </tr>
788</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000789</div>
790
Chris Lattner69c11bb2005-04-25 17:34:15 +0000791<!-- _______________________________________________________________________ -->
792<div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div>
793<div class="doc_text">
794
795<h5>Overview:</h5>
796
797<p>Opaque types are used to represent unknown types in the system. This
798corresponds (for example) to the C notion of a foward declared structure type.
799In LLVM, opaque types can eventually be resolved to any type (not just a
800structure type).</p>
801
802<h5>Syntax:</h5>
803
804<pre>
805 opaque
806</pre>
807
808<h5>Examples:</h5>
809
810<table class="layout">
811 <tr class="layout">
812 <td class="left">
813 <tt>opaque</tt>
814 </td>
815 <td class="left">
816 An opaque type.<br/>
817 </td>
818 </tr>
819</table>
820</div>
821
822
Chris Lattnerc3f59762004-12-09 17:30:23 +0000823<!-- *********************************************************************** -->
824<div class="doc_section"> <a name="constants">Constants</a> </div>
825<!-- *********************************************************************** -->
826
827<div class="doc_text">
828
829<p>LLVM has several different basic types of constants. This section describes
830them all and their syntax.</p>
831
832</div>
833
834<!-- ======================================================================= -->
Reid Spencercc16dc32004-12-09 18:02:53 +0000835<div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000836
837<div class="doc_text">
838
839<dl>
840 <dt><b>Boolean constants</b></dt>
841
842 <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
843 constants of the <tt><a href="#t_primitive">bool</a></tt> type.
844 </dd>
845
846 <dt><b>Integer constants</b></dt>
847
Reid Spencercc16dc32004-12-09 18:02:53 +0000848 <dd>Standard integers (such as '4') are constants of the <a
Chris Lattnerc3f59762004-12-09 17:30:23 +0000849 href="#t_integer">integer</a> type. Negative numbers may be used with signed
850 integer types.
851 </dd>
852
853 <dt><b>Floating point constants</b></dt>
854
855 <dd>Floating point constants use standard decimal notation (e.g. 123.421),
856 exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
Reid Spencercc16dc32004-12-09 18:02:53 +0000857 notation. Floating point constants have an optional hexadecimal
Chris Lattnerc3f59762004-12-09 17:30:23 +0000858 notation (see below). Floating point constants must have a <a
859 href="#t_floating">floating point</a> type. </dd>
860
861 <dt><b>Null pointer constants</b></dt>
862
John Criswell9e2485c2004-12-10 15:51:16 +0000863 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
Chris Lattnerc3f59762004-12-09 17:30:23 +0000864 and must be of <a href="#t_pointer">pointer type</a>.</dd>
865
866</dl>
867
John Criswell9e2485c2004-12-10 15:51:16 +0000868<p>The one non-intuitive notation for constants is the optional hexadecimal form
Chris Lattnerc3f59762004-12-09 17:30:23 +0000869of floating point constants. For example, the form '<tt>double
8700x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
8714.5e+15</tt>'. The only time hexadecimal floating point constants are required
Reid Spencercc16dc32004-12-09 18:02:53 +0000872(and the only time that they are generated by the disassembler) is when a
873floating point constant must be emitted but it cannot be represented as a
874decimal floating point number. For example, NaN's, infinities, and other
875special values are represented in their IEEE hexadecimal format so that
876assembly and disassembly do not cause any bits to change in the constants.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000877
878</div>
879
880<!-- ======================================================================= -->
881<div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a>
882</div>
883
884<div class="doc_text">
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000885<p>Aggregate constants arise from aggregation of simple constants
886and smaller aggregate constants.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000887
888<dl>
889 <dt><b>Structure constants</b></dt>
890
891 <dd>Structure constants are represented with notation similar to structure
892 type definitions (a comma separated list of elements, surrounded by braces
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000893 (<tt>{}</tt>)). For example: "<tt>{ int 4, float 17.0, int* %G }</tt>",
894 where "<tt>%G</tt>" is declared as "<tt>%G = external global int</tt>". Structure constants
895 must have <a href="#t_struct">structure type</a>, and the number and
Chris Lattnerc3f59762004-12-09 17:30:23 +0000896 types of elements must match those specified by the type.
897 </dd>
898
899 <dt><b>Array constants</b></dt>
900
901 <dd>Array constants are represented with notation similar to array type
902 definitions (a comma separated list of elements, surrounded by square brackets
John Criswell9e2485c2004-12-10 15:51:16 +0000903 (<tt>[]</tt>)). For example: "<tt>[ int 42, int 11, int 74 ]</tt>". Array
Chris Lattnerc3f59762004-12-09 17:30:23 +0000904 constants must have <a href="#t_array">array type</a>, and the number and
905 types of elements must match those specified by the type.
906 </dd>
907
908 <dt><b>Packed constants</b></dt>
909
910 <dd>Packed constants are represented with notation similar to packed type
911 definitions (a comma separated list of elements, surrounded by
John Criswell9e2485c2004-12-10 15:51:16 +0000912 less-than/greater-than's (<tt>&lt;&gt;</tt>)). For example: "<tt>&lt; int 42,
Chris Lattnerc3f59762004-12-09 17:30:23 +0000913 int 11, int 74, int 100 &gt;</tt>". Packed constants must have <a
914 href="#t_packed">packed type</a>, and the number and types of elements must
915 match those specified by the type.
916 </dd>
917
918 <dt><b>Zero initialization</b></dt>
919
920 <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
921 value to zero of <em>any</em> type, including scalar and aggregate types.
922 This is often used to avoid having to print large zero initializers (e.g. for
923 large arrays), and is always exactly equivalent to using explicit zero
924 initializers.
925 </dd>
926</dl>
927
928</div>
929
930<!-- ======================================================================= -->
931<div class="doc_subsection">
932 <a name="globalconstants">Global Variable and Function Addresses</a>
933</div>
934
935<div class="doc_text">
936
937<p>The addresses of <a href="#globalvars">global variables</a> and <a
938href="#functionstructure">functions</a> are always implicitly valid (link-time)
John Criswell9e2485c2004-12-10 15:51:16 +0000939constants. These constants are explicitly referenced when the <a
940href="#identifiers">identifier for the global</a> is used and always have <a
Chris Lattnerc3f59762004-12-09 17:30:23 +0000941href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
942file:</p>
943
944<pre>
945 %X = global int 17
946 %Y = global int 42
947 %Z = global [2 x int*] [ int* %X, int* %Y ]
948</pre>
949
950</div>
951
952<!-- ======================================================================= -->
Reid Spencer2dc45b82004-12-09 18:13:12 +0000953<div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000954<div class="doc_text">
Reid Spencer2dc45b82004-12-09 18:13:12 +0000955 <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has
956 no specific value. Undefined values may be of any type, and be used anywhere
957 a constant is permitted.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000958
Reid Spencer2dc45b82004-12-09 18:13:12 +0000959 <p>Undefined values indicate to the compiler that the program is well defined
960 no matter what value is used, giving the compiler more freedom to optimize.
961 </p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000962</div>
963
964<!-- ======================================================================= -->
965<div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
966</div>
967
968<div class="doc_text">
969
970<p>Constant expressions are used to allow expressions involving other constants
971to be used as constants. Constant expressions may be of any <a
972href="#t_firstclass">first class</a> type, and may involve any LLVM operation
973that does not have side effects (e.g. load and call are not supported). The
974following is the syntax for constant expressions:</p>
975
976<dl>
977 <dt><b><tt>cast ( CST to TYPE )</tt></b></dt>
978
979 <dd>Cast a constant to another type.</dd>
980
981 <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
982
983 <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
984 constants. As with the <a href="#i_getelementptr">getelementptr</a>
985 instruction, the index list may have zero or more indexes, which are required
986 to make sense for the type of "CSTPTR".</dd>
987
988 <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
989
Reid Spencer2dc45b82004-12-09 18:13:12 +0000990 <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
991 be any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise
Chris Lattnerc3f59762004-12-09 17:30:23 +0000992 binary</a> operations. The constraints on operands are the same as those for
993 the corresponding instruction (e.g. no bitwise operations on floating point
994 are allowed).</dd>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000995</dl>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000996</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000997
Chris Lattner00950542001-06-06 20:29:01 +0000998<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000999<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
1000<!-- *********************************************************************** -->
Chris Lattnerc3f59762004-12-09 17:30:23 +00001001
Misha Brukman9d0919f2003-11-08 01:05:38 +00001002<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +00001003
Chris Lattner261efe92003-11-25 01:02:51 +00001004<p>The LLVM instruction set consists of several different
1005classifications of instructions: <a href="#terminators">terminator
1006instructions</a>, <a href="#binaryops">binary instructions</a>, <a
1007 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
1008instructions</a>.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001009
Misha Brukman9d0919f2003-11-08 01:05:38 +00001010</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001011
Chris Lattner00950542001-06-06 20:29:01 +00001012<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001013<div class="doc_subsection"> <a name="terminators">Terminator
1014Instructions</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001015
Misha Brukman9d0919f2003-11-08 01:05:38 +00001016<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +00001017
Chris Lattner261efe92003-11-25 01:02:51 +00001018<p>As mentioned <a href="#functionstructure">previously</a>, every
1019basic block in a program ends with a "Terminator" instruction, which
1020indicates which block should be executed after the current block is
1021finished. These terminator instructions typically yield a '<tt>void</tt>'
1022value: they produce control flow, not values (the one exception being
1023the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
John Criswell9e2485c2004-12-10 15:51:16 +00001024<p>There are six different terminator instructions: the '<a
Chris Lattner261efe92003-11-25 01:02:51 +00001025 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
1026instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
Chris Lattner35eca582004-10-16 18:04:13 +00001027the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
1028 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
1029 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001030
Misha Brukman9d0919f2003-11-08 01:05:38 +00001031</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001032
Chris Lattner00950542001-06-06 20:29:01 +00001033<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001034<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
1035Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001036<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001037<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001038<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 +00001039 ret void <i>; Return from void function</i>
Chris Lattner00950542001-06-06 20:29:01 +00001040</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001041<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001042<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
1043value) from a function, back to the caller.</p>
John Criswell4457dc92004-04-09 16:48:45 +00001044<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner261efe92003-11-25 01:02:51 +00001045returns a value and then causes control flow, and one that just causes
1046control flow to occur.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001047<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001048<p>The '<tt>ret</tt>' instruction may return any '<a
1049 href="#t_firstclass">first class</a>' type. Notice that a function is
1050not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
1051instruction inside of the function that returns a value that does not
1052match the return type of the function.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001053<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001054<p>When the '<tt>ret</tt>' instruction is executed, control flow
1055returns back to the calling function's context. If the caller is a "<a
John Criswellfa081872004-06-25 15:16:57 +00001056 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner261efe92003-11-25 01:02:51 +00001057the instruction after the call. If the caller was an "<a
1058 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
1059at the beginning "normal" of the destination block. If the instruction
1060returns a value, that value shall set the call or invoke instruction's
1061return value.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001062<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001063<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001064 ret void <i>; Return from a void function</i>
Chris Lattner00950542001-06-06 20:29:01 +00001065</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001066</div>
Chris Lattner00950542001-06-06 20:29:01 +00001067<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001068<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</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> 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 +00001072</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001073<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001074<p>The '<tt>br</tt>' instruction is used to cause control flow to
1075transfer to a different basic block in the current function. There are
1076two forms of this instruction, corresponding to a conditional branch
1077and an unconditional branch.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001078<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001079<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
1080single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
1081unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
1082value as a target.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001083<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001084<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
1085argument is evaluated. If the value is <tt>true</tt>, control flows
1086to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
1087control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001088<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001089<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
1090 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 +00001091</div>
Chris Lattner00950542001-06-06 20:29:01 +00001092<!-- _______________________________________________________________________ -->
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001093<div class="doc_subsubsection">
1094 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
1095</div>
1096
Misha Brukman9d0919f2003-11-08 01:05:38 +00001097<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001098<h5>Syntax:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001099
1100<pre>
1101 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
1102</pre>
1103
Chris Lattner00950542001-06-06 20:29:01 +00001104<h5>Overview:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001105
1106<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
1107several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +00001108instruction, allowing a branch to occur to one of many possible
1109destinations.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001110
1111
Chris Lattner00950542001-06-06 20:29:01 +00001112<h5>Arguments:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001113
1114<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
1115comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
1116an array of pairs of comparison value constants and '<tt>label</tt>'s. The
1117table is not allowed to contain duplicate constant entries.</p>
1118
Chris Lattner00950542001-06-06 20:29:01 +00001119<h5>Semantics:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001120
Chris Lattner261efe92003-11-25 01:02:51 +00001121<p>The <tt>switch</tt> instruction specifies a table of values and
1122destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswell84114752004-06-25 16:05:06 +00001123table is searched for the given value. If the value is found, control flow is
1124transfered to the corresponding destination; otherwise, control flow is
1125transfered to the default destination.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001126
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001127<h5>Implementation:</h5>
1128
1129<p>Depending on properties of the target machine and the particular
1130<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswell84114752004-06-25 16:05:06 +00001131ways. For example, it could be generated as a series of chained conditional
1132branches or with a lookup table.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001133
1134<h5>Example:</h5>
1135
1136<pre>
1137 <i>; Emulate a conditional br instruction</i>
1138 %Val = <a href="#i_cast">cast</a> bool %value to int
1139 switch int %Val, label %truedest [int 0, label %falsedest ]
1140
1141 <i>; Emulate an unconditional br instruction</i>
1142 switch uint 0, label %dest [ ]
1143
1144 <i>; Implement a jump table:</i>
1145 switch uint %val, label %otherwise [ uint 0, label %onzero
1146 uint 1, label %onone
1147 uint 2, label %ontwo ]
Chris Lattner00950542001-06-06 20:29:01 +00001148</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001149</div>
Chris Lattner00950542001-06-06 20:29:01 +00001150<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001151<div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>'
1152Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001153<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001154<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001155<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 +00001156<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001157<p>The '<tt>invoke</tt>' instruction causes control to transfer to a
1158specified function, with the possibility of control flow transfer to
1159either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>.
1160If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>"
1161instruction, control flow will return to the "normal" label. If the
1162callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
1163instruction, control is interrupted, and continued at the dynamically
1164nearest "except" label.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001165<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001166<p>This instruction requires several arguments:</p>
Chris Lattner00950542001-06-06 20:29:01 +00001167<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00001168 <li>'<tt>ptr to function ty</tt>': shall be the signature of the
1169pointer to function value being invoked. In most cases, this is a
1170direct function invocation, but indirect <tt>invoke</tt>s are just as
1171possible, branching off an arbitrary pointer to function value. </li>
1172 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer
1173to a function to be invoked. </li>
1174 <li>'<tt>function args</tt>': argument list whose types match the
1175function signature argument types. If the function signature indicates
1176the function accepts a variable number of arguments, the extra
1177arguments can be specified. </li>
1178 <li>'<tt>normal label</tt>': the label reached when the called
1179function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
1180 <li>'<tt>exception label</tt>': the label reached when a callee
1181returns with the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
Chris Lattner00950542001-06-06 20:29:01 +00001182</ol>
Chris Lattner00950542001-06-06 20:29:01 +00001183<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001184<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner261efe92003-11-25 01:02:51 +00001185 href="#i_call">call</a></tt>' instruction in most regards. The
1186primary difference is that it establishes an association with a label,
1187which is used by the runtime library to unwind the stack.</p>
1188<p>This instruction is used in languages with destructors to ensure
1189that proper cleanup is performed in the case of either a <tt>longjmp</tt>
1190or a thrown exception. Additionally, this is important for
1191implementation of '<tt>catch</tt>' clauses in high-level languages that
1192support them.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001193<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001194<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 +00001195</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001196</div>
Chris Lattner35eca582004-10-16 18:04:13 +00001197
1198
Chris Lattner27f71f22003-09-03 00:41:47 +00001199<!-- _______________________________________________________________________ -->
Chris Lattner35eca582004-10-16 18:04:13 +00001200
Chris Lattner261efe92003-11-25 01:02:51 +00001201<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
1202Instruction</a> </div>
Chris Lattner35eca582004-10-16 18:04:13 +00001203
Misha Brukman9d0919f2003-11-08 01:05:38 +00001204<div class="doc_text">
Chris Lattner35eca582004-10-16 18:04:13 +00001205
Chris Lattner27f71f22003-09-03 00:41:47 +00001206<h5>Syntax:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001207<pre>
1208 unwind
1209</pre>
1210
Chris Lattner27f71f22003-09-03 00:41:47 +00001211<h5>Overview:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001212
1213<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
1214at the first callee in the dynamic call stack which used an <a
1215href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
1216primarily used to implement exception handling.</p>
1217
Chris Lattner27f71f22003-09-03 00:41:47 +00001218<h5>Semantics:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001219
1220<p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to
1221immediately halt. The dynamic call stack is then searched for the first <a
1222href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
1223execution continues at the "exceptional" destination block specified by the
1224<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
1225dynamic call chain, undefined behavior results.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001226</div>
Chris Lattner35eca582004-10-16 18:04:13 +00001227
1228<!-- _______________________________________________________________________ -->
1229
1230<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
1231Instruction</a> </div>
1232
1233<div class="doc_text">
1234
1235<h5>Syntax:</h5>
1236<pre>
1237 unreachable
1238</pre>
1239
1240<h5>Overview:</h5>
1241
1242<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
1243instruction is used to inform the optimizer that a particular portion of the
1244code is not reachable. This can be used to indicate that the code after a
1245no-return function cannot be reached, and other facts.</p>
1246
1247<h5>Semantics:</h5>
1248
1249<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
1250</div>
1251
1252
1253
Chris Lattner00950542001-06-06 20:29:01 +00001254<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001255<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001256<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001257<p>Binary operators are used to do most of the computation in a
1258program. They require two operands, execute an operation on them, and
John Criswell9e2485c2004-12-10 15:51:16 +00001259produce a single value. The operands might represent
Chris Lattnera58561b2004-08-12 19:12:28 +00001260multiple data, as is the case with the <a href="#t_packed">packed</a> data type.
1261The result value of a binary operator is not
Chris Lattner261efe92003-11-25 01:02:51 +00001262necessarily the same type as its operands.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001263<p>There are several different binary operators:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001264</div>
Chris Lattner00950542001-06-06 20:29:01 +00001265<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001266<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
1267Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001268<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001269<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001270<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 +00001271</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001272<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001273<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001274<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001275<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattnera58561b2004-08-12 19:12:28 +00001276 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
1277 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1278Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001279<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001280<p>The value produced is the integer or floating point sum of the two
1281operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001282<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001283<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001284</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001285</div>
Chris Lattner00950542001-06-06 20:29:01 +00001286<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001287<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
1288Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001289<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001290<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001291<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 +00001292</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001293<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001294<p>The '<tt>sub</tt>' instruction returns the difference of its two
1295operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001296<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
1297instruction present in most other intermediate representations.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001298<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001299<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001300 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001301values.
1302This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1303Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001304<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001305<p>The value produced is the integer or floating point difference of
1306the two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001307<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001308<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001309 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
1310</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001311</div>
Chris Lattner00950542001-06-06 20:29:01 +00001312<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001313<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
1314Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001315<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001316<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001317<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 +00001318</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001319<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001320<p>The '<tt>mul</tt>' instruction returns the product of its two
1321operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001322<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001323<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001324 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001325values.
1326This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1327Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001328<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001329<p>The value produced is the integer or floating point product of the
Misha Brukman9d0919f2003-11-08 01:05:38 +00001330two operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001331<p>There is no signed vs unsigned multiplication. The appropriate
1332action is taken based on the type of the operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001333<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001334<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001335</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001336</div>
Chris Lattner00950542001-06-06 20:29:01 +00001337<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001338<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
1339Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001340<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001341<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001342<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1343</pre>
1344<h5>Overview:</h5>
1345<p>The '<tt>div</tt>' instruction returns the quotient of its two
1346operands.</p>
1347<h5>Arguments:</h5>
1348<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
1349 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001350values.
1351This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1352Both arguments must have identical types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001353<h5>Semantics:</h5>
1354<p>The value produced is the integer or floating point quotient of the
1355two operands.</p>
1356<h5>Example:</h5>
1357<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
1358</pre>
1359</div>
1360<!-- _______________________________________________________________________ -->
1361<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
1362Instruction</a> </div>
1363<div class="doc_text">
1364<h5>Syntax:</h5>
1365<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1366</pre>
1367<h5>Overview:</h5>
1368<p>The '<tt>rem</tt>' instruction returns the remainder from the
1369division of its two operands.</p>
1370<h5>Arguments:</h5>
1371<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1372 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001373values.
1374This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1375Both arguments must have identical types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001376<h5>Semantics:</h5>
1377<p>This returns the <i>remainder</i> of a division (where the result
1378has the same sign as the divisor), not the <i>modulus</i> (where the
1379result has the same sign as the dividend) of a value. For more
1380information about the difference, see: <a
1381 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1382Math Forum</a>.</p>
1383<h5>Example:</h5>
1384<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1385</pre>
1386</div>
1387<!-- _______________________________________________________________________ -->
1388<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1389Instructions</a> </div>
1390<div class="doc_text">
1391<h5>Syntax:</h5>
1392<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 +00001393 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1394 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1395 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1396 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1397 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1398</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001399<h5>Overview:</h5>
1400<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1401value based on a comparison of their two operands.</p>
1402<h5>Arguments:</h5>
1403<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1404be of <a href="#t_firstclass">first class</a> type (it is not possible
1405to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1406or '<tt>void</tt>' values, etc...). Both arguments must have identical
1407types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001408<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001409<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1410value if both operands are equal.<br>
1411The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1412value if both operands are unequal.<br>
1413The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1414value if the first operand is less than the second operand.<br>
1415The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1416value if the first operand is greater than the second operand.<br>
1417The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1418value if the first operand is less than or equal to the second operand.<br>
1419The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1420value if the first operand is greater than or equal to the second
1421operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001422<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001423<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner00950542001-06-06 20:29:01 +00001424 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
1425 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1426 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1427 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1428 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1429</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001430</div>
Chris Lattner00950542001-06-06 20:29:01 +00001431<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001432<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1433Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001434<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001435<p>Bitwise binary operators are used to do various forms of
1436bit-twiddling in a program. They are generally very efficient
John Criswell9e2485c2004-12-10 15:51:16 +00001437instructions and can commonly be strength reduced from other
Chris Lattner261efe92003-11-25 01:02:51 +00001438instructions. They require two operands, execute an operation on them,
1439and produce a single value. The resulting value of the bitwise binary
1440operators is always the same type as its first operand.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001441</div>
Chris Lattner00950542001-06-06 20:29:01 +00001442<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001443<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1444Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001445<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001446<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001447<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 +00001448</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001449<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001450<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1451its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001452<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001453<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001454 href="#t_integral">integral</a> values. Both arguments must have
1455identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001456<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001457<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001458<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001459<div style="align: center">
Misha Brukman9d0919f2003-11-08 01:05:38 +00001460<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +00001461 <tbody>
1462 <tr>
1463 <td>In0</td>
1464 <td>In1</td>
1465 <td>Out</td>
1466 </tr>
1467 <tr>
1468 <td>0</td>
1469 <td>0</td>
1470 <td>0</td>
1471 </tr>
1472 <tr>
1473 <td>0</td>
1474 <td>1</td>
1475 <td>0</td>
1476 </tr>
1477 <tr>
1478 <td>1</td>
1479 <td>0</td>
1480 <td>0</td>
1481 </tr>
1482 <tr>
1483 <td>1</td>
1484 <td>1</td>
1485 <td>1</td>
1486 </tr>
1487 </tbody>
1488</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001489</div>
Chris Lattner00950542001-06-06 20:29:01 +00001490<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001491<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001492 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1493 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1494</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001495</div>
Chris Lattner00950542001-06-06 20:29:01 +00001496<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001497<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001498<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001499<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001500<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 +00001501</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001502<h5>Overview:</h5>
1503<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1504or of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001505<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001506<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001507 href="#t_integral">integral</a> values. Both arguments must have
1508identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001509<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001510<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001511<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001512<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001513<table border="1" cellspacing="0" cellpadding="4">
1514 <tbody>
1515 <tr>
1516 <td>In0</td>
1517 <td>In1</td>
1518 <td>Out</td>
1519 </tr>
1520 <tr>
1521 <td>0</td>
1522 <td>0</td>
1523 <td>0</td>
1524 </tr>
1525 <tr>
1526 <td>0</td>
1527 <td>1</td>
1528 <td>1</td>
1529 </tr>
1530 <tr>
1531 <td>1</td>
1532 <td>0</td>
1533 <td>1</td>
1534 </tr>
1535 <tr>
1536 <td>1</td>
1537 <td>1</td>
1538 <td>1</td>
1539 </tr>
1540 </tbody>
1541</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001542</div>
Chris Lattner00950542001-06-06 20:29:01 +00001543<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001544<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001545 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1546 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1547</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001548</div>
Chris Lattner00950542001-06-06 20:29:01 +00001549<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001550<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1551Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001552<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001553<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001554<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 +00001555</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001556<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001557<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1558or of its two operands. The <tt>xor</tt> is used to implement the
1559"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001560<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001561<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001562 href="#t_integral">integral</a> values. Both arguments must have
1563identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001564<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001565<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001566<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001567<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001568<table border="1" cellspacing="0" cellpadding="4">
1569 <tbody>
1570 <tr>
1571 <td>In0</td>
1572 <td>In1</td>
1573 <td>Out</td>
1574 </tr>
1575 <tr>
1576 <td>0</td>
1577 <td>0</td>
1578 <td>0</td>
1579 </tr>
1580 <tr>
1581 <td>0</td>
1582 <td>1</td>
1583 <td>1</td>
1584 </tr>
1585 <tr>
1586 <td>1</td>
1587 <td>0</td>
1588 <td>1</td>
1589 </tr>
1590 <tr>
1591 <td>1</td>
1592 <td>1</td>
1593 <td>0</td>
1594 </tr>
1595 </tbody>
1596</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001597</div>
Chris Lattner261efe92003-11-25 01:02:51 +00001598<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001599<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001600<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001601 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1602 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner27f71f22003-09-03 00:41:47 +00001603 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner00950542001-06-06 20:29:01 +00001604</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001605</div>
Chris Lattner00950542001-06-06 20:29:01 +00001606<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001607<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1608Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001609<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001610<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001611<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 +00001612</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001613<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001614<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1615the left a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001616<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001617<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001618 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1619type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001620<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001621<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001622<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001623<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 +00001624 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1625 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1626</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001627</div>
Chris Lattner00950542001-06-06 20:29:01 +00001628<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001629<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1630Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001631<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001632<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001633<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 +00001634</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001635<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001636<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1637the right a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001638<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001639<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001640 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1641type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001642<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001643<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1644most significant bit is duplicated in the newly free'd bit positions.
1645If the first argument is unsigned, zero bits shall fill the empty
1646positions.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001647<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001648<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 +00001649 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001650 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner8c6bb902003-06-18 21:30:51 +00001651 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1652 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner00950542001-06-06 20:29:01 +00001653</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001654</div>
Chris Lattner00950542001-06-06 20:29:01 +00001655<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001656<div class="doc_subsection"> <a name="memoryops">Memory Access
1657Operations</a></div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001658<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001659<p>A key design point of an SSA-based representation is how it
1660represents memory. In LLVM, no memory locations are in SSA form, which
1661makes things very simple. This section describes how to read, write,
John Criswell9e2485c2004-12-10 15:51:16 +00001662allocate, and free memory in LLVM.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001663</div>
Chris Lattner00950542001-06-06 20:29:01 +00001664<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001665<div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>'
1666Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001667<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001668<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001669<pre> &lt;result&gt; = malloc &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001670 &lt;result&gt; = malloc &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001671</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001672<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001673<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1674heap and returns a pointer to it.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001675<h5>Arguments:</h5>
John Criswell6e4ca612004-02-24 16:13:56 +00001676<p>The '<tt>malloc</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1677bytes of memory from the operating system and returns a pointer of the
Chris Lattner261efe92003-11-25 01:02:51 +00001678appropriate type to the program. The second form of the instruction is
1679a shorter version of the first instruction that defaults to allocating
1680one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001681<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001682<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001683<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1684a pointer is returned.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001685<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001686<pre> %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001687
Chris Lattner261efe92003-11-25 01:02:51 +00001688 %size = <a
1689 href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001690 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1691 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001692</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001693</div>
Chris Lattner00950542001-06-06 20:29:01 +00001694<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001695<div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>'
1696Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001697<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001698<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001699<pre> free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner00950542001-06-06 20:29:01 +00001700</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001701<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001702<p>The '<tt>free</tt>' instruction returns memory back to the unused
1703memory heap, to be reallocated in the future.</p>
1704<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001705<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001706<p>'<tt>value</tt>' shall be a pointer value that points to a value
1707that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1708instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001709<h5>Semantics:</h5>
John Criswell9e2485c2004-12-10 15:51:16 +00001710<p>Access to the memory pointed to by the pointer is no longer defined
Chris Lattner261efe92003-11-25 01:02:51 +00001711after this instruction executes.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001712<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001713<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 +00001714 free [4 x ubyte]* %array
1715</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001716</div>
Chris Lattner00950542001-06-06 20:29:01 +00001717<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001718<div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>'
1719Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001720<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001721<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001722<pre> &lt;result&gt; = alloca &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001723 &lt;result&gt; = alloca &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001724</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001725<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001726<p>The '<tt>alloca</tt>' instruction allocates memory on the current
1727stack frame of the procedure that is live until the current function
1728returns to its caller.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001729<h5>Arguments:</h5>
John Criswell9e2485c2004-12-10 15:51:16 +00001730<p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001731bytes of memory on the runtime stack, returning a pointer of the
1732appropriate type to the program. The second form of the instruction is
1733a shorter version of the first that defaults to allocating one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001734<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001735<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001736<p>Memory is allocated, a pointer is returned. '<tt>alloca</tt>'d
1737memory is automatically released when the function returns. The '<tt>alloca</tt>'
1738instruction is commonly used to represent automatic variables that must
1739have an address available. When the function returns (either with the <tt><a
1740 href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001741instructions), the memory is reclaimed.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001742<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001743<pre> %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001744 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner00950542001-06-06 20:29:01 +00001745</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001746</div>
Chris Lattner00950542001-06-06 20:29:01 +00001747<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001748<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1749Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001750<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00001751<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001752<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 +00001753<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001754<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001755<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001756<p>The argument to the '<tt>load</tt>' instruction specifies the memory
1757address to load from. The pointer must point to a <a
Chris Lattnere53e5082004-06-03 22:57:15 +00001758 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
Chris Lattner261efe92003-11-25 01:02:51 +00001759marked as <tt>volatile</tt> then the optimizer is not allowed to modify
1760the number or order of execution of this <tt>load</tt> with other
1761volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1762instructions. </p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001763<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001764<p>The location of memory pointed to is loaded.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001765<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001766<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1767 <a
1768 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001769 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1770</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001771</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001772<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001773<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1774Instruction</a> </div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001775<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001776<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 +00001777 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 +00001778</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001779<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001780<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001781<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001782<p>There are two arguments to the '<tt>store</tt>' instruction: a value
1783to store and an address to store it into. The type of the '<tt>&lt;pointer&gt;</tt>'
1784operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
1785operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the
1786optimizer is not allowed to modify the number or order of execution of
1787this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1788 href="#i_store">store</a></tt> instructions.</p>
1789<h5>Semantics:</h5>
1790<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
1791at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001792<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001793<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1794 <a
1795 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001796 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1797</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001798<!-- _______________________________________________________________________ -->
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001799<div class="doc_subsubsection">
1800 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
1801</div>
1802
Misha Brukman9d0919f2003-11-08 01:05:38 +00001803<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00001804<h5>Syntax:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001805<pre>
1806 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
1807</pre>
1808
Chris Lattner7faa8832002-04-14 06:13:44 +00001809<h5>Overview:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001810
1811<p>
1812The '<tt>getelementptr</tt>' instruction is used to get the address of a
1813subelement of an aggregate data structure.</p>
1814
Chris Lattner7faa8832002-04-14 06:13:44 +00001815<h5>Arguments:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001816
1817<p>This instruction takes a list of integer constants that indicate what
1818elements of the aggregate object to index to. The actual types of the arguments
1819provided depend on the type of the first pointer argument. The
1820'<tt>getelementptr</tt>' instruction is used to index down through the type
1821levels of a structure. When indexing into a structure, only <tt>uint</tt>
1822integer constants are allowed. When indexing into an array or pointer
1823<tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
1824
Chris Lattner261efe92003-11-25 01:02:51 +00001825<p>For example, let's consider a C code fragment and how it gets
1826compiled to LLVM:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001827
1828<pre>
1829 struct RT {
1830 char A;
1831 int B[10][20];
1832 char C;
1833 };
1834 struct ST {
1835 int X;
1836 double Y;
1837 struct RT Z;
1838 };
1839
1840 int *foo(struct ST *s) {
1841 return &amp;s[1].Z.B[5][13];
1842 }
1843</pre>
1844
Misha Brukman9d0919f2003-11-08 01:05:38 +00001845<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001846
1847<pre>
1848 %RT = type { sbyte, [10 x [20 x int]], sbyte }
1849 %ST = type { int, double, %RT }
1850
Brian Gaeke7283e7c2004-07-02 21:08:14 +00001851 implementation
1852
1853 int* %foo(%ST* %s) {
1854 entry:
1855 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001856 ret int* %reg
1857 }
1858</pre>
1859
Chris Lattner7faa8832002-04-14 06:13:44 +00001860<h5>Semantics:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001861
1862<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
Chris Lattnere53e5082004-06-03 22:57:15 +00001863on the pointer type that is being index into. <a href="#t_pointer">Pointer</a>
1864and <a href="#t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
1865<tt>ulong</tt>, or <tt>long</tt> values, and <a href="#t_struct">structure</a>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001866types require <tt>uint</tt> <b>constants</b>.</p>
1867
Misha Brukman9d0919f2003-11-08 01:05:38 +00001868<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001869type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
1870}</tt>' type, a structure. The second index indexes into the third element of
1871the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
1872sbyte }</tt>' type, another structure. The third index indexes into the second
1873element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
1874array. The two dimensions of the array are subscripted into, yielding an
1875'<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction return a pointer
1876to this element, thus computing a value of '<tt>int*</tt>' type.</p>
1877
Chris Lattner261efe92003-11-25 01:02:51 +00001878<p>Note that it is perfectly legal to index partially through a
1879structure, returning a pointer to an inner element. Because of this,
1880the LLVM code for the given testcase is equivalent to:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001881
1882<pre>
Chris Lattnerd4f6b172005-03-07 22:13:59 +00001883 int* %foo(%ST* %s) {
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001884 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
1885 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
1886 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
1887 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
1888 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
1889 ret int* %t5
1890 }
Chris Lattner6536cfe2002-05-06 22:08:29 +00001891</pre>
Chris Lattner7faa8832002-04-14 06:13:44 +00001892<h5>Example:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001893<pre>
1894 <i>; yields [12 x ubyte]*:aptr</i>
1895 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
1896</pre>
1897
1898</div>
Chris Lattner00950542001-06-06 20:29:01 +00001899<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001900<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001901<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +00001902<p>The instructions in this category are the "miscellaneous"
Chris Lattner261efe92003-11-25 01:02:51 +00001903instructions, which defy better classification.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001904</div>
Chris Lattner00950542001-06-06 20:29:01 +00001905<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001906<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
1907Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001908<div class="doc_text">
Chris Lattner33ba0d92001-07-09 00:26:23 +00001909<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001910<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001911<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001912<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
1913the SSA graph representing the function.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001914<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001915<p>The type of the incoming values are specified with the first type
1916field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
1917as arguments, with one pair for each predecessor basic block of the
1918current block. Only values of <a href="#t_firstclass">first class</a>
1919type may be used as the value arguments to the PHI node. Only labels
1920may be used as the label arguments.</p>
1921<p>There must be no non-phi instructions between the start of a basic
1922block and the PHI instructions: i.e. PHI instructions must be first in
1923a basic block.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001924<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001925<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
1926value specified by the parameter, depending on which basic block we
1927came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001928<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001929<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 +00001930</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001931
Chris Lattner6536cfe2002-05-06 22:08:29 +00001932<!-- _______________________________________________________________________ -->
Chris Lattnercc37aae2004-03-12 05:50:16 +00001933<div class="doc_subsubsection">
1934 <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
1935</div>
1936
Misha Brukman9d0919f2003-11-08 01:05:38 +00001937<div class="doc_text">
Chris Lattnercc37aae2004-03-12 05:50:16 +00001938
Chris Lattner6536cfe2002-05-06 22:08:29 +00001939<h5>Syntax:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001940
1941<pre>
1942 &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 +00001943</pre>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001944
Chris Lattner6536cfe2002-05-06 22:08:29 +00001945<h5>Overview:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001946
1947<p>
1948The '<tt>cast</tt>' instruction is used as the primitive means to convert
1949integers to floating point, change data type sizes, and break type safety (by
1950casting pointers).
1951</p>
1952
1953
Chris Lattner6536cfe2002-05-06 22:08:29 +00001954<h5>Arguments:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001955
1956<p>
1957The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
1958class value, and a type to cast it to, which must also be a <a
1959href="#t_firstclass">first class</a> type.
1960</p>
1961
Chris Lattner6536cfe2002-05-06 22:08:29 +00001962<h5>Semantics:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001963
1964<p>
1965This instruction follows the C rules for explicit casts when determining how the
1966data being cast must change to fit in its new container.
1967</p>
1968
1969<p>
1970When casting to bool, any value that would be considered true in the context of
1971a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
1972all else are '<tt>false</tt>'.
1973</p>
1974
1975<p>
1976When extending an integral value from a type of one signness to another (for
1977example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
1978<b>source</b> value is signed, and zero-extended if the source value is
1979unsigned. <tt>bool</tt> values are always zero extended into either zero or
1980one.
1981</p>
1982
Chris Lattner33ba0d92001-07-09 00:26:23 +00001983<h5>Example:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001984
1985<pre>
1986 %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattner7bae3952002-06-25 18:03:17 +00001987 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001988</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001989</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001990
1991<!-- _______________________________________________________________________ -->
1992<div class="doc_subsubsection">
1993 <a name="i_select">'<tt>select</tt>' Instruction</a>
1994</div>
1995
1996<div class="doc_text">
1997
1998<h5>Syntax:</h5>
1999
2000<pre>
2001 &lt;result&gt; = select bool &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
2002</pre>
2003
2004<h5>Overview:</h5>
2005
2006<p>
2007The '<tt>select</tt>' instruction is used to choose one value based on a
2008condition, without branching.
2009</p>
2010
2011
2012<h5>Arguments:</h5>
2013
2014<p>
2015The '<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.
2016</p>
2017
2018<h5>Semantics:</h5>
2019
2020<p>
2021If the boolean condition evaluates to true, the instruction returns the first
2022value argument, otherwise it returns the second value argument.
2023</p>
2024
2025<h5>Example:</h5>
2026
2027<pre>
2028 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
2029</pre>
2030</div>
2031
2032
2033
2034
2035
Chris Lattner33ba0d92001-07-09 00:26:23 +00002036<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00002037<div class="doc_subsubsection"> <a name="i_call">'<tt>call</tt>'
2038Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002039<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00002040<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002041<pre> &lt;result&gt; = call &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +00002042<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002043<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002044<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002045<p>This instruction requires several arguments:</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00002046<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00002047 <li>
2048 <p>'<tt>ty</tt>': shall be the signature of the pointer to function
2049value being invoked. The argument types must match the types implied
2050by this signature.</p>
2051 </li>
2052 <li>
2053 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a
2054function to be invoked. In most cases, this is a direct function
2055invocation, but indirect <tt>call</tt>s are just as possible,
2056calling an arbitrary pointer to function values.</p>
2057 </li>
2058 <li>
2059 <p>'<tt>function args</tt>': argument list whose types match the
2060function signature argument types. If the function signature
2061indicates the function accepts a variable number of arguments, the
2062extra arguments can be specified.</p>
2063 </li>
Chris Lattner6536cfe2002-05-06 22:08:29 +00002064</ol>
Chris Lattner00950542001-06-06 20:29:01 +00002065<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002066<p>The '<tt>call</tt>' instruction is used to cause control flow to
2067transfer to a specified function, with its incoming arguments bound to
2068the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
2069instruction in the called function, control flow continues with the
2070instruction after the function call, and the return value of the
2071function is bound to the result argument. This is a simpler case of
2072the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002073<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002074<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 +00002075</div>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002076
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002077<!-- _______________________________________________________________________ -->
Chris Lattnere19d7a72004-09-27 21:51:25 +00002078<div class="doc_subsubsection">
2079 <a name="i_vanext">'<tt>vanext</tt>' Instruction</a>
2080</div>
2081
Misha Brukman9d0919f2003-11-08 01:05:38 +00002082<div class="doc_text">
Chris Lattnere19d7a72004-09-27 21:51:25 +00002083
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002084<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002085
2086<pre>
2087 &lt;resultarglist&gt; = vanext &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;
2088</pre>
2089
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002090<h5>Overview:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002091
Chris Lattner261efe92003-11-25 01:02:51 +00002092<p>The '<tt>vanext</tt>' instruction is used to access arguments passed
2093through the "variable argument" area of a function call. It is used to
2094implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002095
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002096<h5>Arguments:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002097
2098<p>This instruction takes a <tt>va_list</tt> value and the type of the
2099argument. It returns another <tt>va_list</tt>. The actual type of
2100<tt>va_list</tt> may be defined differently for different targets. Most targets
2101use a <tt>va_list</tt> type of <tt>sbyte*</tt> or some other pointer type.</p>
2102
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002103<h5>Semantics:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002104
2105<p>The '<tt>vanext</tt>' instruction advances the specified <tt>va_list</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002106past an argument of the specified type. In conjunction with the <a
2107 href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement
2108the <tt>va_arg</tt> macro available in C. For more information, see
2109the variable argument handling <a href="#int_varargs">Intrinsic
2110Functions</a>.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002111
Chris Lattner261efe92003-11-25 01:02:51 +00002112<p>It is legal for this instruction to be called in a function which
2113does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002114function.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002115
Misha Brukman9d0919f2003-11-08 01:05:38 +00002116<p><tt>vanext</tt> is an LLVM instruction instead of an <a
Chris Lattnere19d7a72004-09-27 21:51:25 +00002117href="#intrinsics">intrinsic function</a> because it takes a type as an
2118argument. The type refers to the current argument in the <tt>va_list</tt>, it
2119tells the compiler how far on the stack it needs to advance to find the next
2120argument</p>
2121
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002122<h5>Example:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002123
Chris Lattner261efe92003-11-25 01:02:51 +00002124<p>See the <a href="#int_varargs">variable argument processing</a>
2125section.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002126
Misha Brukman9d0919f2003-11-08 01:05:38 +00002127</div>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002128
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002129<!-- _______________________________________________________________________ -->
Chris Lattnere19d7a72004-09-27 21:51:25 +00002130<div class="doc_subsubsection">
2131 <a name="i_vaarg">'<tt>vaarg</tt>' Instruction</a>
2132</div>
2133
Misha Brukman9d0919f2003-11-08 01:05:38 +00002134<div class="doc_text">
Chris Lattnere19d7a72004-09-27 21:51:25 +00002135
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002136<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002137
2138<pre>
2139 &lt;resultval&gt; = vaarg &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;
2140</pre>
2141
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002142<h5>Overview:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002143
2144<p>The '<tt>vaarg</tt>' instruction is used to access arguments passed through
2145the "variable argument" area of a function call. It is used to implement the
2146<tt>va_arg</tt> macro in C.</p>
2147
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002148<h5>Arguments:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002149
2150<p>This instruction takes a <tt>va_list</tt> value and the type of the
2151argument. It returns a value of the specified argument type. Again, the actual
2152type of <tt>va_list</tt> is target specific.</p>
2153
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002154<h5>Semantics:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002155
2156<p>The '<tt>vaarg</tt>' instruction loads an argument of the specified type from
2157the specified <tt>va_list</tt>. In conjunction with the <a
2158href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to implement the
2159<tt>va_arg</tt> macro available in C. For more information, see the variable
2160argument handling <a href="#int_varargs">Intrinsic Functions</a>.</p>
2161
2162<p>It is legal for this instruction to be called in a function which does not
2163take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002164function.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002165
Misha Brukman9d0919f2003-11-08 01:05:38 +00002166<p><tt>vaarg</tt> is an LLVM instruction instead of an <a
Chris Lattnere19d7a72004-09-27 21:51:25 +00002167href="#intrinsics">intrinsic function</a> because it takes an type as an
2168argument.</p>
2169
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002170<h5>Example:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002171
2172<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
2173
Misha Brukman9d0919f2003-11-08 01:05:38 +00002174</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002175
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002176<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00002177<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
2178<!-- *********************************************************************** -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002179
Misha Brukman9d0919f2003-11-08 01:05:38 +00002180<div class="doc_text">
Chris Lattner33aec9e2004-02-12 17:01:32 +00002181
2182<p>LLVM supports the notion of an "intrinsic function". These functions have
2183well known names and semantics, and are required to follow certain
2184restrictions. Overall, these instructions represent an extension mechanism for
2185the LLVM language that does not require changing all of the transformations in
2186LLVM to add to the language (or the bytecode reader/writer, the parser,
2187etc...).</p>
2188
2189<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix, this
2190prefix is reserved in LLVM for intrinsic names, thus functions may not be named
2191this. Intrinsic functions must always be external functions: you cannot define
2192the body of intrinsic functions. Intrinsic functions may only be used in call
2193or invoke instructions: it is illegal to take the address of an intrinsic
2194function. Additionally, because intrinsic functions are part of the LLVM
2195language, it is required that they all be documented here if any are added.</p>
2196
2197
2198<p>
2199Adding an intrinsic to LLVM is straight-forward if it is possible to express the
2200concept in LLVM directly (ie, code generator support is not _required_). To do
2201this, extend the default implementation of the IntrinsicLowering class to handle
2202the intrinsic. Code generators use this class to lower intrinsics they do not
2203understand to raw LLVM instructions that they do.
2204</p>
2205
Misha Brukman9d0919f2003-11-08 01:05:38 +00002206</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002207
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002208<!-- ======================================================================= -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002209<div class="doc_subsection">
2210 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
2211</div>
2212
Misha Brukman9d0919f2003-11-08 01:05:38 +00002213<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00002214
Misha Brukman9d0919f2003-11-08 01:05:38 +00002215<p>Variable argument support is defined in LLVM with the <a
Chris Lattner261efe92003-11-25 01:02:51 +00002216 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
2217intrinsic functions. These functions are related to the similarly
2218named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002219
Chris Lattner261efe92003-11-25 01:02:51 +00002220<p>All of these functions operate on arguments that use a
2221target-specific value type "<tt>va_list</tt>". The LLVM assembly
2222language reference manual does not define what this type is, so all
2223transformations should be prepared to handle intrinsics with any type
2224used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002225
Misha Brukman9d0919f2003-11-08 01:05:38 +00002226<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner261efe92003-11-25 01:02:51 +00002227instruction and the variable argument handling intrinsic functions are
2228used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002229
Chris Lattner33aec9e2004-02-12 17:01:32 +00002230<pre>
2231int %test(int %X, ...) {
2232 ; Initialize variable argument processing
2233 %ap = call sbyte* %<a href="#i_va_start">llvm.va_start</a>()
2234
2235 ; Read a single integer argument
2236 %tmp = vaarg sbyte* %ap, int
2237
2238 ; Advance to the next argument
2239 %ap2 = vanext sbyte* %ap, int
2240
2241 ; Demonstrate usage of llvm.va_copy and llvm.va_end
2242 %aq = call sbyte* %<a href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2)
2243 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %aq)
2244
2245 ; Stop processing of arguments.
2246 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %ap2)
2247 ret int %tmp
2248}
2249</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002250</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002251
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002252<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002253<div class="doc_subsubsection">
2254 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
2255</div>
2256
2257
Misha Brukman9d0919f2003-11-08 01:05:38 +00002258<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002259<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002260<pre> call &lt;va_list&gt; ()* %llvm.va_start()<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002261<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002262<p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt>&lt;arglist&gt;</tt>
2263for subsequent use by the variable argument intrinsics.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002264<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002265<p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002266macro available in C. In a target-dependent way, it initializes and
2267returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt>
2268will produce the first variable argument passed to the function. Unlike
2269the C <tt>va_start</tt> macro, this intrinsic does not need to know the
2270last argument of the function, the compiler can figure that out.</p>
2271<p>Note that this intrinsic function is only legal to be called from
2272within the body of a variable argument function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002273</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002274
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002275<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002276<div class="doc_subsubsection">
2277 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
2278</div>
2279
Misha Brukman9d0919f2003-11-08 01:05:38 +00002280<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002281<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002282<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 +00002283<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002284<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
2285which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
2286or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002287<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002288<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002289<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002290<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002291macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
2292Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
2293 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
2294with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002295</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002296
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002297<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002298<div class="doc_subsubsection">
2299 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
2300</div>
2301
Misha Brukman9d0919f2003-11-08 01:05:38 +00002302<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00002303
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002304<h5>Syntax:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002305
2306<pre>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002307 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 +00002308</pre>
2309
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002310<h5>Overview:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002311
2312<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position
2313from the source argument list to the destination argument list.</p>
2314
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002315<h5>Arguments:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002316
Misha Brukman9d0919f2003-11-08 01:05:38 +00002317<p>The argument is the <tt>va_list</tt> to copy.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002318
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002319<h5>Semantics:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002320
Misha Brukman9d0919f2003-11-08 01:05:38 +00002321<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
Chris Lattnerd7923912004-05-23 21:06:01 +00002322macro available in C. In a target-dependent way, it copies the source
2323<tt>va_list</tt> element into the returned list. This intrinsic is necessary
Chris Lattnerfcd37252004-06-21 22:52:48 +00002324because the <tt><a href="#i_va_start">llvm.va_start</a></tt> intrinsic may be
Chris Lattnerd7923912004-05-23 21:06:01 +00002325arbitrarily complex and require memory allocation, for example.</p>
2326
Misha Brukman9d0919f2003-11-08 01:05:38 +00002327</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002328
Chris Lattner33aec9e2004-02-12 17:01:32 +00002329<!-- ======================================================================= -->
2330<div class="doc_subsection">
Chris Lattnerd7923912004-05-23 21:06:01 +00002331 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
2332</div>
2333
2334<div class="doc_text">
2335
2336<p>
2337LLVM support for <a href="GarbageCollection.html">Accurate Garbage
2338Collection</a> requires the implementation and generation of these intrinsics.
2339These intrinsics allow identification of <a href="#i_gcroot">GC roots on the
2340stack</a>, as well as garbage collector implementations that require <a
2341href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers.
2342Front-ends for type-safe garbage collected languages should generate these
2343intrinsics to make use of the LLVM garbage collectors. For more details, see <a
2344href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
2345</p>
2346</div>
2347
2348<!-- _______________________________________________________________________ -->
2349<div class="doc_subsubsection">
2350 <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
2351</div>
2352
2353<div class="doc_text">
2354
2355<h5>Syntax:</h5>
2356
2357<pre>
2358 call void (&lt;ty&gt;**, &lt;ty2&gt;*)* %llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
2359</pre>
2360
2361<h5>Overview:</h5>
2362
John Criswell9e2485c2004-12-10 15:51:16 +00002363<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
Chris Lattnerd7923912004-05-23 21:06:01 +00002364the code generator, and allows some metadata to be associated with it.</p>
2365
2366<h5>Arguments:</h5>
2367
2368<p>The first argument specifies the address of a stack object that contains the
2369root pointer. The second pointer (which must be either a constant or a global
2370value address) contains the meta-data to be associated with the root.</p>
2371
2372<h5>Semantics:</h5>
2373
2374<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
2375location. At compile-time, the code generator generates information to allow
2376the runtime to find the pointer at GC safe points.
2377</p>
2378
2379</div>
2380
2381
2382<!-- _______________________________________________________________________ -->
2383<div class="doc_subsubsection">
2384 <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
2385</div>
2386
2387<div class="doc_text">
2388
2389<h5>Syntax:</h5>
2390
2391<pre>
2392 call sbyte* (sbyte**)* %llvm.gcread(sbyte** %Ptr)
2393</pre>
2394
2395<h5>Overview:</h5>
2396
2397<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
2398locations, allowing garbage collector implementations that require read
2399barriers.</p>
2400
2401<h5>Arguments:</h5>
2402
2403<p>The argument is the address to read from, which should be an address
2404allocated from the garbage collector.</p>
2405
2406<h5>Semantics:</h5>
2407
2408<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
2409instruction, but may be replaced with substantially more complex code by the
2410garbage collector runtime, as needed.</p>
2411
2412</div>
2413
2414
2415<!-- _______________________________________________________________________ -->
2416<div class="doc_subsubsection">
2417 <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
2418</div>
2419
2420<div class="doc_text">
2421
2422<h5>Syntax:</h5>
2423
2424<pre>
2425 call void (sbyte*, sbyte**)* %llvm.gcwrite(sbyte* %P1, sbyte** %P2)
2426</pre>
2427
2428<h5>Overview:</h5>
2429
2430<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
2431locations, allowing garbage collector implementations that require write
2432barriers (such as generational or reference counting collectors).</p>
2433
2434<h5>Arguments:</h5>
2435
2436<p>The first argument is the reference to store, and the second is the heap
2437location to store to.</p>
2438
2439<h5>Semantics:</h5>
2440
2441<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
2442instruction, but may be replaced with substantially more complex code by the
2443garbage collector runtime, as needed.</p>
2444
2445</div>
2446
2447
2448
2449<!-- ======================================================================= -->
2450<div class="doc_subsection">
Chris Lattner10610642004-02-14 04:08:35 +00002451 <a name="int_codegen">Code Generator Intrinsics</a>
2452</div>
2453
2454<div class="doc_text">
2455<p>
2456These intrinsics are provided by LLVM to expose special features that may only
2457be implemented with code generator support.
2458</p>
2459
2460</div>
2461
2462<!-- _______________________________________________________________________ -->
2463<div class="doc_subsubsection">
2464 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
2465</div>
2466
2467<div class="doc_text">
2468
2469<h5>Syntax:</h5>
2470<pre>
2471 call void* ()* %llvm.returnaddress(uint &lt;level&gt;)
2472</pre>
2473
2474<h5>Overview:</h5>
2475
2476<p>
2477The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
2478indicating the return address of the current function or one of its callers.
2479</p>
2480
2481<h5>Arguments:</h5>
2482
2483<p>
2484The argument to this intrinsic indicates which function to return the address
2485for. Zero indicates the calling function, one indicates its caller, etc. The
2486argument is <b>required</b> to be a constant integer value.
2487</p>
2488
2489<h5>Semantics:</h5>
2490
2491<p>
2492The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
2493the return address of the specified call frame, or zero if it cannot be
2494identified. The value returned by this intrinsic is likely to be incorrect or 0
2495for arguments other than zero, so it should only be used for debugging purposes.
2496</p>
2497
2498<p>
2499Note that calling this intrinsic does not prevent function inlining or other
Chris Lattnerb40bb382005-03-07 20:30:51 +00002500aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner10610642004-02-14 04:08:35 +00002501source-language caller.
2502</p>
2503</div>
2504
2505
2506<!-- _______________________________________________________________________ -->
2507<div class="doc_subsubsection">
2508 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
2509</div>
2510
2511<div class="doc_text">
2512
2513<h5>Syntax:</h5>
2514<pre>
2515 call void* ()* %llvm.frameaddress(uint &lt;level&gt;)
2516</pre>
2517
2518<h5>Overview:</h5>
2519
2520<p>
2521The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
2522pointer value for the specified stack frame.
2523</p>
2524
2525<h5>Arguments:</h5>
2526
2527<p>
2528The argument to this intrinsic indicates which function to return the frame
2529pointer for. Zero indicates the calling function, one indicates its caller,
2530etc. The argument is <b>required</b> to be a constant integer value.
2531</p>
2532
2533<h5>Semantics:</h5>
2534
2535<p>
2536The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
2537the frame address of the specified call frame, or zero if it cannot be
2538identified. The value returned by this intrinsic is likely to be incorrect or 0
2539for arguments other than zero, so it should only be used for debugging purposes.
2540</p>
2541
2542<p>
2543Note that calling this intrinsic does not prevent function inlining or other
Chris Lattnerb40bb382005-03-07 20:30:51 +00002544aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner10610642004-02-14 04:08:35 +00002545source-language caller.
2546</p>
2547</div>
2548
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00002549<!-- _______________________________________________________________________ -->
2550<div class="doc_subsubsection">
2551 <a name="i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a>
2552</div>
2553
2554<div class="doc_text">
2555
2556<h5>Syntax:</h5>
2557<pre>
2558 call void (sbyte *, uint, uint)* %llvm.prefetch(sbyte * &lt;address&gt;,
2559 uint &lt;rw&gt;,
2560 uint &lt;locality&gt;)
2561</pre>
2562
2563<h5>Overview:</h5>
2564
2565
2566<p>
2567The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to insert
2568a prefetch instruction if supported, otherwise it is a noop. Prefetches have no
Chris Lattner2a615362005-02-28 19:47:14 +00002569effect on the behavior of the program, but can change its performance
2570characteristics.
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00002571</p>
2572
2573<h5>Arguments:</h5>
2574
2575<p>
2576<tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier
2577determining if the fetch should be for a read (0) or write (1), and
2578<tt>locality</tt> is a temporal locality specifier ranging from (0) - no
Chris Lattneraeffb4a2005-03-07 20:31:38 +00002579locality, to (3) - extremely local keep in cache. The <tt>rw</tt> and
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00002580<tt>locality</tt> arguments must be constant integers.
2581</p>
2582
2583<h5>Semantics:</h5>
2584
2585<p>
2586This intrinsic does not modify the behavior of the program. In particular,
2587prefetches cannot trap and do not produce a value. On targets that support this
2588intrinsic, the prefetch can provide hints to the processor cache for better
2589performance.
2590</p>
2591
2592</div>
2593
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00002594<!-- _______________________________________________________________________ -->
2595<div class="doc_subsubsection">
2596 <a name="i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a>
2597</div>
2598
2599<div class="doc_text">
2600
2601<h5>Syntax:</h5>
2602<pre>
2603 call void (uint)* %llvm.pcmarker( uint &lt;id&gt; )
2604</pre>
2605
2606<h5>Overview:</h5>
2607
2608
2609<p>
2610The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a PC in a region of
2611code to simulators and other tools. The method is target specific, but it is
2612expected that the marker will use exported symbols to transmit the PC of the marker.
2613The marker makes no guaranties that it will remain with any specific instruction
2614after optimizations. It is possible that the presense of a marker will inhibit
2615optimizations. The intended use is to be inserted after optmizations to allow
2616corrolations of simulation runs.
2617</p>
2618
2619<h5>Arguments:</h5>
2620
2621<p>
2622<tt>id</tt> is a numerical id identifying the marker.
2623</p>
2624
2625<h5>Semantics:</h5>
2626
2627<p>
2628This intrinsic does not modify the behavior of the program. Backends that do not
2629support this intrinisic may ignore it.
2630</p>
2631
2632</div>
2633
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00002634
John Criswell7123e272004-04-09 16:43:20 +00002635<!-- ======================================================================= -->
2636<div class="doc_subsection">
2637 <a name="int_os">Operating System Intrinsics</a>
2638</div>
2639
2640<div class="doc_text">
2641<p>
2642These intrinsics are provided by LLVM to support the implementation of
2643operating system level code.
2644</p>
2645
2646</div>
John Criswell183402a2004-04-12 15:02:16 +00002647
John Criswellcfd3bac2004-04-09 15:23:37 +00002648<!-- _______________________________________________________________________ -->
2649<div class="doc_subsubsection">
2650 <a name="i_readport">'<tt>llvm.readport</tt>' Intrinsic</a>
2651</div>
2652
2653<div class="doc_text">
2654
2655<h5>Syntax:</h5>
2656<pre>
John Criswell7123e272004-04-09 16:43:20 +00002657 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 +00002658</pre>
2659
2660<h5>Overview:</h5>
2661
2662<p>
John Criswell7123e272004-04-09 16:43:20 +00002663The '<tt>llvm.readport</tt>' intrinsic reads data from the specified hardware
2664I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002665</p>
2666
2667<h5>Arguments:</h5>
2668
2669<p>
John Criswell7123e272004-04-09 16:43:20 +00002670The argument to this intrinsic indicates the hardware I/O address from which
2671to read the data. The address is in the hardware I/O address namespace (as
2672opposed to being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002673</p>
2674
2675<h5>Semantics:</h5>
2676
2677<p>
John Criswell7123e272004-04-09 16:43:20 +00002678The '<tt>llvm.readport</tt>' intrinsic reads data from the hardware I/O port
2679specified by <i>address</i> and returns the value. The address and return
2680value must be integers, but the size is dependent upon the platform upon which
2681the program is code generated. For example, on x86, the address must be an
Misha Brukmancfa87bc2005-04-22 18:02:52 +00002682unsigned 16-bit value, and the return value must be 8, 16, or 32 bits.
John Criswellcfd3bac2004-04-09 15:23:37 +00002683</p>
2684
2685</div>
2686
2687<!-- _______________________________________________________________________ -->
2688<div class="doc_subsubsection">
2689 <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a>
2690</div>
2691
2692<div class="doc_text">
2693
2694<h5>Syntax:</h5>
2695<pre>
Chris Lattnerc3f59762004-12-09 17:30:23 +00002696 call void (&lt;integer type&gt;, &lt;integer type&gt;)*
2697 %llvm.writeport (&lt;integer type&gt; &lt;value&gt;,
2698 &lt;integer type&gt; &lt;address&gt;)
John Criswellcfd3bac2004-04-09 15:23:37 +00002699</pre>
2700
2701<h5>Overview:</h5>
2702
2703<p>
John Criswell7123e272004-04-09 16:43:20 +00002704The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified hardware
2705I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002706</p>
2707
2708<h5>Arguments:</h5>
2709
2710<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002711The first argument is the value to write to the I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002712</p>
2713
2714<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002715The second argument indicates the hardware I/O address to which data should be
2716written. The address is in the hardware I/O address namespace (as opposed to
2717being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002718</p>
2719
2720<h5>Semantics:</h5>
2721
2722<p>
2723The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port
2724specified by <i>address</i>. The address and value must be integers, but the
2725size is dependent upon the platform upon which the program is code generated.
Misha Brukmancfa87bc2005-04-22 18:02:52 +00002726For example, on x86, the address must be an unsigned 16-bit value, and the
John Criswell7123e272004-04-09 16:43:20 +00002727value written must be 8, 16, or 32 bits in length.
John Criswellcfd3bac2004-04-09 15:23:37 +00002728</p>
2729
2730</div>
Chris Lattner10610642004-02-14 04:08:35 +00002731
John Criswell183402a2004-04-12 15:02:16 +00002732<!-- _______________________________________________________________________ -->
2733<div class="doc_subsubsection">
2734 <a name="i_readio">'<tt>llvm.readio</tt>' Intrinsic</a>
2735</div>
2736
2737<div class="doc_text">
2738
2739<h5>Syntax:</h5>
2740<pre>
John Criswell96db6fc2004-04-12 16:33:19 +00002741 call &lt;result&gt; (&lt;ty&gt;*)* %llvm.readio (&lt;ty&gt; * &lt;pointer&gt;)
John Criswell183402a2004-04-12 15:02:16 +00002742</pre>
2743
2744<h5>Overview:</h5>
2745
2746<p>
2747The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
2748address.
2749</p>
2750
2751<h5>Arguments:</h5>
2752
2753<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002754The argument to this intrinsic is a pointer indicating the memory address from
2755which to read the data. The data must be a
2756<a href="#t_firstclass">first class</a> type.
John Criswell183402a2004-04-12 15:02:16 +00002757</p>
2758
2759<h5>Semantics:</h5>
2760
2761<p>
2762The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
John Criswell96db6fc2004-04-12 16:33:19 +00002763location specified by <i>pointer</i> and returns the value. The argument must
2764be a pointer, and the return value must be a
2765<a href="#t_firstclass">first class</a> type. However, certain architectures
Misha Brukmancfa87bc2005-04-22 18:02:52 +00002766may not support I/O on all first class types. For example, 32-bit processors
John Criswell96db6fc2004-04-12 16:33:19 +00002767may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00002768</p>
2769
2770<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002771This intrinsic enforces an in-order memory model for llvm.readio and
2772llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2773scheduled processors may execute loads and stores out of order, re-ordering at
2774run time accesses to memory mapped I/O registers. Using these intrinsics
2775ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00002776</p>
2777
2778</div>
2779
2780<!-- _______________________________________________________________________ -->
2781<div class="doc_subsubsection">
2782 <a name="i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a>
2783</div>
2784
2785<div class="doc_text">
2786
2787<h5>Syntax:</h5>
2788<pre>
John Criswell96db6fc2004-04-12 16:33:19 +00002789 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 +00002790</pre>
2791
2792<h5>Overview:</h5>
2793
2794<p>
2795The '<tt>llvm.writeio</tt>' intrinsic writes data to the specified memory
2796mapped I/O address.
2797</p>
2798
2799<h5>Arguments:</h5>
2800
2801<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002802The first argument is the value to write to the memory mapped I/O location.
2803The second argument is a pointer indicating the memory address to which the
2804data should be written.
John Criswell183402a2004-04-12 15:02:16 +00002805</p>
2806
2807<h5>Semantics:</h5>
2808
2809<p>
2810The '<tt>llvm.writeio</tt>' intrinsic writes <i>value</i> to the memory mapped
John Criswell96db6fc2004-04-12 16:33:19 +00002811I/O address specified by <i>pointer</i>. The value must be a
2812<a href="#t_firstclass">first class</a> type. However, certain architectures
Misha Brukmancfa87bc2005-04-22 18:02:52 +00002813may not support I/O on all first class types. For example, 32-bit processors
John Criswell96db6fc2004-04-12 16:33:19 +00002814may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00002815</p>
2816
2817<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002818This intrinsic enforces an in-order memory model for llvm.readio and
2819llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2820scheduled processors may execute loads and stores out of order, re-ordering at
2821run time accesses to memory mapped I/O registers. Using these intrinsics
2822ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00002823</p>
2824
2825</div>
2826
Chris Lattner10610642004-02-14 04:08:35 +00002827<!-- ======================================================================= -->
2828<div class="doc_subsection">
Chris Lattner33aec9e2004-02-12 17:01:32 +00002829 <a name="int_libc">Standard C Library Intrinsics</a>
2830</div>
2831
2832<div class="doc_text">
2833<p>
Chris Lattner10610642004-02-14 04:08:35 +00002834LLVM provides intrinsics for a few important standard C library functions.
2835These intrinsics allow source-language front-ends to pass information about the
2836alignment of the pointer arguments to the code generator, providing opportunity
2837for more efficient code generation.
Chris Lattner33aec9e2004-02-12 17:01:32 +00002838</p>
2839
2840</div>
2841
2842<!-- _______________________________________________________________________ -->
2843<div class="doc_subsubsection">
2844 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
2845</div>
2846
2847<div class="doc_text">
2848
2849<h5>Syntax:</h5>
2850<pre>
2851 call void (sbyte*, sbyte*, uint, uint)* %llvm.memcpy(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2852 uint &lt;len&gt;, uint &lt;align&gt;)
2853</pre>
2854
2855<h5>Overview:</h5>
2856
2857<p>
2858The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2859location to the destination location.
2860</p>
2861
2862<p>
2863Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
2864does not return a value, and takes an extra alignment argument.
2865</p>
2866
2867<h5>Arguments:</h5>
2868
2869<p>
2870The first argument is a pointer to the destination, the second is a pointer to
2871the source. The third argument is an (arbitrarily sized) integer argument
2872specifying the number of bytes to copy, and the fourth argument is the alignment
2873of the source and destination locations.
2874</p>
2875
Chris Lattner3301ced2004-02-12 21:18:15 +00002876<p>
2877If the call to this intrinisic has an alignment value that is not 0 or 1, then
2878the caller guarantees that the size of the copy is a multiple of the alignment
2879and that both the source and destination pointers are aligned to that boundary.
2880</p>
2881
Chris Lattner33aec9e2004-02-12 17:01:32 +00002882<h5>Semantics:</h5>
2883
2884<p>
2885The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2886location to the destination location, which are not allowed to overlap. It
2887copies "len" bytes of memory over. If the argument is known to be aligned to
2888some boundary, this can be specified as the fourth argument, otherwise it should
2889be set to 0 or 1.
2890</p>
2891</div>
2892
2893
Chris Lattner0eb51b42004-02-12 18:10:10 +00002894<!-- _______________________________________________________________________ -->
2895<div class="doc_subsubsection">
2896 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
2897</div>
2898
2899<div class="doc_text">
2900
2901<h5>Syntax:</h5>
2902<pre>
2903 call void (sbyte*, sbyte*, uint, uint)* %llvm.memmove(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2904 uint &lt;len&gt;, uint &lt;align&gt;)
2905</pre>
2906
2907<h5>Overview:</h5>
2908
2909<p>
2910The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
2911location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>'
2912intrinsic but allows the two memory locations to overlap.
2913</p>
2914
2915<p>
2916Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
2917does not return a value, and takes an extra alignment argument.
2918</p>
2919
2920<h5>Arguments:</h5>
2921
2922<p>
2923The first argument is a pointer to the destination, the second is a pointer to
2924the source. The third argument is an (arbitrarily sized) integer argument
2925specifying the number of bytes to copy, and the fourth argument is the alignment
2926of the source and destination locations.
2927</p>
2928
Chris Lattner3301ced2004-02-12 21:18:15 +00002929<p>
2930If the call to this intrinisic has an alignment value that is not 0 or 1, then
2931the caller guarantees that the size of the copy is a multiple of the alignment
2932and that both the source and destination pointers are aligned to that boundary.
2933</p>
2934
Chris Lattner0eb51b42004-02-12 18:10:10 +00002935<h5>Semantics:</h5>
2936
2937<p>
2938The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
2939location to the destination location, which may overlap. It
2940copies "len" bytes of memory over. If the argument is known to be aligned to
2941some boundary, this can be specified as the fourth argument, otherwise it should
2942be set to 0 or 1.
2943</p>
2944</div>
2945
Chris Lattner8ff75902004-01-06 05:31:32 +00002946
Chris Lattner10610642004-02-14 04:08:35 +00002947<!-- _______________________________________________________________________ -->
2948<div class="doc_subsubsection">
2949 <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a>
2950</div>
2951
2952<div class="doc_text">
2953
2954<h5>Syntax:</h5>
2955<pre>
2956 call void (sbyte*, ubyte, uint, uint)* %llvm.memset(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
2957 uint &lt;len&gt;, uint &lt;align&gt;)
2958</pre>
2959
2960<h5>Overview:</h5>
2961
2962<p>
2963The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular
2964byte value.
2965</p>
2966
2967<p>
2968Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
2969does not return a value, and takes an extra alignment argument.
2970</p>
2971
2972<h5>Arguments:</h5>
2973
2974<p>
2975The first argument is a pointer to the destination to fill, the second is the
2976byte value to fill it with, the third argument is an (arbitrarily sized) integer
2977argument specifying the number of bytes to fill, and the fourth argument is the
2978known alignment of destination location.
2979</p>
2980
2981<p>
2982If the call to this intrinisic has an alignment value that is not 0 or 1, then
2983the caller guarantees that the size of the copy is a multiple of the alignment
2984and that the destination pointer is aligned to that boundary.
2985</p>
2986
2987<h5>Semantics:</h5>
2988
2989<p>
2990The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the
2991destination location. If the argument is known to be aligned to some boundary,
2992this can be specified as the fourth argument, otherwise it should be set to 0 or
29931.
2994</p>
2995</div>
2996
2997
Chris Lattner32006282004-06-11 02:28:03 +00002998<!-- _______________________________________________________________________ -->
2999<div class="doc_subsubsection">
Alkis Evlogimenos26bbe932004-06-13 01:16:15 +00003000 <a name="i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a>
3001</div>
3002
3003<div class="doc_text">
3004
3005<h5>Syntax:</h5>
3006<pre>
3007 call bool (&lt;float or double&gt;, &lt;float or double&gt;)* %llvm.isunordered(&lt;float or double&gt; Val1,
3008 &lt;float or double&gt; Val2)
3009</pre>
3010
3011<h5>Overview:</h5>
3012
3013<p>
3014The '<tt>llvm.isunordered</tt>' intrinsic returns true if either or both of the
3015specified floating point values is a NAN.
3016</p>
3017
3018<h5>Arguments:</h5>
3019
3020<p>
3021The arguments are floating point numbers of the same type.
3022</p>
3023
3024<h5>Semantics:</h5>
3025
3026<p>
3027If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise
3028false.
3029</p>
3030</div>
3031
3032
Chris Lattner32006282004-06-11 02:28:03 +00003033
3034
Chris Lattner8ff75902004-01-06 05:31:32 +00003035<!-- ======================================================================= -->
3036<div class="doc_subsection">
3037 <a name="int_debugger">Debugger Intrinsics</a>
3038</div>
3039
3040<div class="doc_text">
3041<p>
3042The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
3043are described in the <a
3044href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
3045Debugging</a> document.
3046</p>
3047</div>
3048
3049
Chris Lattner00950542001-06-06 20:29:01 +00003050<!-- *********************************************************************** -->
Chris Lattner00950542001-06-06 20:29:01 +00003051<hr>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00003052<address>
3053 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
3054 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
3055 <a href="http://validator.w3.org/check/referer"><img
3056 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
3057
3058 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
3059 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
3060 Last modified: $Date$
3061</address>
Misha Brukman9d0919f2003-11-08 01:05:38 +00003062</body>
3063</html>