blob: d3695bb3a0d3306e6fff69a49292412fd1f65e09 [file] [log] [blame]
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
Misha Brukman9d0919f2003-11-08 01:05:38 +00003<html>
4<head>
5 <title>LLVM Assembly Language Reference Manual</title>
Reid Spencer3921c742004-08-26 20:44:00 +00006 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7 <meta name="author" content="Chris Lattner">
8 <meta name="description"
9 content="LLVM Assembly Language Reference Manual.">
Misha Brukman9d0919f2003-11-08 01:05:38 +000010 <link rel="stylesheet" href="llvm.css" type="text/css">
11</head>
Chris Lattnerd7923912004-05-23 21:06:01 +000012
Misha Brukman9d0919f2003-11-08 01:05:38 +000013<body>
Chris Lattnerd7923912004-05-23 21:06:01 +000014
Chris Lattner261efe92003-11-25 01:02:51 +000015<div class="doc_title"> LLVM Language Reference Manual </div>
Chris Lattner00950542001-06-06 20:29:01 +000016<ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000017 <li><a href="#abstract">Abstract</a></li>
18 <li><a href="#introduction">Introduction</a></li>
19 <li><a href="#identifiers">Identifiers</a></li>
Chris Lattnerfa730212004-12-09 16:11:40 +000020 <li><a href="#highlevel">High Level Structure</a>
21 <ol>
22 <li><a href="#modulestructure">Module Structure</a></li>
Chris Lattnere5d947b2004-12-09 16:36:40 +000023 <li><a href="#linkage">Linkage Types</a></li>
Chris Lattnerfa730212004-12-09 16:11:40 +000024 <li><a href="#globalvars">Global Variables</a></li>
25 <li><a href="#functionstructure">Function Structure</a></li>
26 </ol>
27 </li>
Chris Lattner00950542001-06-06 20:29:01 +000028 <li><a href="#typesystem">Type System</a>
29 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000030 <li><a href="#t_primitive">Primitive Types</a>
31 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000032 <li><a href="#t_classifications">Type Classifications</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000033 </ol>
34 </li>
Chris Lattner00950542001-06-06 20:29:01 +000035 <li><a href="#t_derived">Derived Types</a>
36 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000037 <li><a href="#t_array">Array Type</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000038 <li><a href="#t_function">Function Type</a></li>
39 <li><a href="#t_pointer">Pointer Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000040 <li><a href="#t_struct">Structure Type</a></li>
Chris Lattnera58561b2004-08-12 19:12:28 +000041 <li><a href="#t_packed">Packed Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000042 </ol>
43 </li>
44 </ol>
45 </li>
Chris Lattnerfa730212004-12-09 16:11:40 +000046 <li><a href="#constants">Constants</a>
Chris Lattnerc3f59762004-12-09 17:30:23 +000047 <ol>
48 <li><a href="#simpleconstants">Simple Constants</a>
49 <li><a href="#aggregateconstants">Aggregate Constants</a>
50 <li><a href="#globalconstants">Global Variable and Function Addresses</a>
51 <li><a href="#undefvalues">Undefined Values</a>
52 <li><a href="#constantexprs">Constant Expressions</a>
53 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +000054 </li>
Chris Lattner00950542001-06-06 20:29:01 +000055 <li><a href="#instref">Instruction Reference</a>
56 <ol>
57 <li><a href="#terminators">Terminator Instructions</a>
58 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000059 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
60 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000061 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
62 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000063 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
Chris Lattner35eca582004-10-16 18:04:13 +000064 <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000065 </ol>
66 </li>
Chris Lattner00950542001-06-06 20:29:01 +000067 <li><a href="#binaryops">Binary Operations</a>
68 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000069 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
70 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
71 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
72 <li><a href="#i_div">'<tt>div</tt>' Instruction</a></li>
73 <li><a href="#i_rem">'<tt>rem</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000074 <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000075 </ol>
76 </li>
Chris Lattner00950542001-06-06 20:29:01 +000077 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
78 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000079 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000080 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000081 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
82 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
83 <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000084 </ol>
85 </li>
Chris Lattner00950542001-06-06 20:29:01 +000086 <li><a href="#memoryops">Memory Access Operations</a>
87 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000088 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
89 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
90 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
91 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
92 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
93 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
94 </ol>
95 </li>
Chris Lattner00950542001-06-06 20:29:01 +000096 <li><a href="#otherops">Other Operations</a>
97 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000098 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000099 <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li>
Chris Lattnercc37aae2004-03-12 05:50:16 +0000100 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000101 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000102 <li><a href="#i_vanext">'<tt>vanext</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000103 <li><a href="#i_vaarg">'<tt>vaarg</tt>' Instruction</a></li>
Chris Lattner00950542001-06-06 20:29:01 +0000104 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000105 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000106 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000107 </li>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +0000108 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +0000109 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000110 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
111 <ol>
112 <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
113 <li><a href="#i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
114 <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
115 </ol>
116 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000117 <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
118 <ol>
119 <li><a href="#i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li>
120 <li><a href="#i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li>
121 <li><a href="#i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li>
122 </ol>
123 </li>
Chris Lattner10610642004-02-14 04:08:35 +0000124 <li><a href="#int_codegen">Code Generator Intrinsics</a>
125 <ol>
126 <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
127 <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
John Criswell7123e272004-04-09 16:43:20 +0000128 </ol>
129 </li>
130 <li><a href="#int_os">Operating System Intrinsics</a>
131 <ol>
Chris Lattner32006282004-06-11 02:28:03 +0000132 <li><a href="#i_readport">'<tt>llvm.readport</tt>' Intrinsic</a></li>
133 <li><a href="#i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a></li>
John Criswell183402a2004-04-12 15:02:16 +0000134 <li><a href="#i_readio">'<tt>llvm.readio</tt>' Intrinsic</a></li>
135 <li><a href="#i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000136 </ol>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000137 <li><a href="#int_libc">Standard C Library Intrinsics</a>
138 <ol>
139 <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li>
Chris Lattner0eb51b42004-02-12 18:10:10 +0000140 <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000141 <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li>
Alkis Evlogimenos96853722004-06-12 19:19:14 +0000142 <li><a href="#i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a></li>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000143 </ol>
144 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000145 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000146 </ol>
147 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000148</ol>
Chris Lattnerd7923912004-05-23 21:06:01 +0000149
150<div class="doc_author">
151 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
152 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000153</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000154
Chris Lattner00950542001-06-06 20:29:01 +0000155<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000156<div class="doc_section"> <a name="abstract">Abstract </a></div>
157<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000158
Misha Brukman9d0919f2003-11-08 01:05:38 +0000159<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000160<p>This document is a reference manual for the LLVM assembly language.
161LLVM is an SSA based representation that provides type safety,
162low-level operations, flexibility, and the capability of representing
163'all' high-level languages cleanly. It is the common code
164representation used throughout all phases of the LLVM compilation
165strategy.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000166</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000167
Chris Lattner00950542001-06-06 20:29:01 +0000168<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000169<div class="doc_section"> <a name="introduction">Introduction</a> </div>
170<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000171
Misha Brukman9d0919f2003-11-08 01:05:38 +0000172<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000173
Chris Lattner261efe92003-11-25 01:02:51 +0000174<p>The LLVM code representation is designed to be used in three
175different forms: as an in-memory compiler IR, as an on-disk bytecode
176representation (suitable for fast loading by a Just-In-Time compiler),
177and as a human readable assembly language representation. This allows
178LLVM to provide a powerful intermediate representation for efficient
179compiler transformations and analysis, while providing a natural means
180to debug and visualize the transformations. The three different forms
181of LLVM are all equivalent. This document describes the human readable
182representation and notation.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000183
Chris Lattner261efe92003-11-25 01:02:51 +0000184<p>The LLVM representation aims to be a light-weight and low-level
185while being expressive, typed, and extensible at the same time. It
186aims to be a "universal IR" of sorts, by being at a low enough level
187that high-level ideas may be cleanly mapped to it (similar to how
188microprocessors are "universal IR's", allowing many source languages to
189be mapped to them). By providing type information, LLVM can be used as
190the target of optimizations: for example, through pointer analysis, it
191can be proven that a C automatic variable is never accessed outside of
192the current function... allowing it to be promoted to a simple SSA
193value instead of a memory location.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000194
Misha Brukman9d0919f2003-11-08 01:05:38 +0000195</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000196
Chris Lattner00950542001-06-06 20:29:01 +0000197<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000198<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000199
Misha Brukman9d0919f2003-11-08 01:05:38 +0000200<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000201
Chris Lattner261efe92003-11-25 01:02:51 +0000202<p>It is important to note that this document describes 'well formed'
203LLVM assembly language. There is a difference between what the parser
204accepts and what is considered 'well formed'. For example, the
205following instruction is syntactically okay, but not well formed:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000206
207<pre>
208 %x = <a href="#i_add">add</a> int 1, %x
209</pre>
210
Chris Lattner261efe92003-11-25 01:02:51 +0000211<p>...because the definition of <tt>%x</tt> does not dominate all of
212its uses. The LLVM infrastructure provides a verification pass that may
213be used to verify that an LLVM module is well formed. This pass is
214automatically run by the parser after parsing input assembly, and by
215the optimizer before it outputs bytecode. The violations pointed out
216by the verifier pass indicate bugs in transformation passes or input to
217the parser.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000218
Chris Lattner261efe92003-11-25 01:02:51 +0000219<!-- Describe the typesetting conventions here. --> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000220
Chris Lattner00950542001-06-06 20:29:01 +0000221<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000222<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000223<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000224
Misha Brukman9d0919f2003-11-08 01:05:38 +0000225<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000226
Chris Lattner261efe92003-11-25 01:02:51 +0000227<p>LLVM uses three different forms of identifiers, for different
228purposes:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000229
Chris Lattner00950542001-06-06 20:29:01 +0000230<ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000231 <li>Named values are represented as a string of characters with a '%' prefix.
232 For example, %foo, %DivisionByZero, %a.really.long.identifier. The actual
233 regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
234 Identifiers which require other characters in their names can be surrounded
235 with quotes. In this way, anything except a <tt>"</tt> character can be used
236 in a name.</li>
237
238 <li>Unnamed values are represented as an unsigned numeric value with a '%'
239 prefix. For example, %12, %2, %44.</li>
240
Reid Spencercc16dc32004-12-09 18:02:53 +0000241 <li>Constants, which are described in a <a href="#constants">section about
242 constants</a>, below.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000243</ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000244
245<p>LLVM requires that values start with a '%' sign for two reasons: Compilers
246don't need to worry about name clashes with reserved words, and the set of
247reserved words may be expanded in the future without penalty. Additionally,
248unnamed identifiers allow a compiler to quickly come up with a temporary
249variable without having to avoid symbol table conflicts.</p>
250
Chris Lattner261efe92003-11-25 01:02:51 +0000251<p>Reserved words in LLVM are very similar to reserved words in other
252languages. There are keywords for different opcodes ('<tt><a
Chris Lattnere5d947b2004-12-09 16:36:40 +0000253href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
254href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
255href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>', etc...),
256and others. These reserved words cannot conflict with variable names, because
257none of them start with a '%' character.</p>
258
259<p>Here is an example of LLVM code to multiply the integer variable
260'<tt>%X</tt>' by 8:</p>
261
Misha Brukman9d0919f2003-11-08 01:05:38 +0000262<p>The easy way:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000263
264<pre>
265 %result = <a href="#i_mul">mul</a> uint %X, 8
266</pre>
267
Misha Brukman9d0919f2003-11-08 01:05:38 +0000268<p>After strength reduction:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000269
270<pre>
271 %result = <a href="#i_shl">shl</a> uint %X, ubyte 3
272</pre>
273
Misha Brukman9d0919f2003-11-08 01:05:38 +0000274<p>And the hard way:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000275
276<pre>
277 <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
278 <a href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
279 %result = <a href="#i_add">add</a> uint %1, %1
280</pre>
281
Chris Lattner261efe92003-11-25 01:02:51 +0000282<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
283important lexical features of LLVM:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000284
Chris Lattner00950542001-06-06 20:29:01 +0000285<ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000286
287 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
288 line.</li>
289
290 <li>Unnamed temporaries are created when the result of a computation is not
291 assigned to a named value.</li>
292
Misha Brukman9d0919f2003-11-08 01:05:38 +0000293 <li>Unnamed temporaries are numbered sequentially</li>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000294
Misha Brukman9d0919f2003-11-08 01:05:38 +0000295</ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000296
297<p>...and it also show a convention that we follow in this document. When
298demonstrating instructions, we will follow an instruction with a comment that
299defines the type and name of value produced. Comments are shown in italic
300text.</p>
301
Misha Brukman9d0919f2003-11-08 01:05:38 +0000302</div>
Chris Lattnerfa730212004-12-09 16:11:40 +0000303
304<!-- *********************************************************************** -->
305<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
306<!-- *********************************************************************** -->
307
308<!-- ======================================================================= -->
309<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
310</div>
311
312<div class="doc_text">
313
314<p>LLVM programs are composed of "Module"s, each of which is a
315translation unit of the input programs. Each module consists of
316functions, global variables, and symbol table entries. Modules may be
317combined together with the LLVM linker, which merges function (and
318global variable) definitions, resolves forward declarations, and merges
319symbol table entries. Here is an example of the "hello world" module:</p>
320
321<pre><i>; Declare the string constant as a global constant...</i>
322<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
323 href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00" <i>; [13 x sbyte]*</i>
324
325<i>; External declaration of the puts function</i>
326<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
327
328<i>; Definition of main function</i>
329int %main() { <i>; int()* </i>
330 <i>; Convert [13x sbyte]* to sbyte *...</i>
331 %cast210 = <a
332 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
333
334 <i>; Call puts function to write out the string to stdout...</i>
335 <a
336 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
337 <a
338 href="#i_ret">ret</a> int 0<br>}<br></pre>
339
340<p>This example is made up of a <a href="#globalvars">global variable</a>
341named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
342function, and a <a href="#functionstructure">function definition</a>
343for "<tt>main</tt>".</p>
344
Chris Lattnere5d947b2004-12-09 16:36:40 +0000345<p>In general, a module is made up of a list of global values,
346where both functions and global variables are global values. Global values are
347represented by a pointer to a memory location (in this case, a pointer to an
348array of char, and a pointer to a function), and have one of the following <a
349href="#linkage">linkage types</a>.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000350
Chris Lattnere5d947b2004-12-09 16:36:40 +0000351</div>
352
353<!-- ======================================================================= -->
354<div class="doc_subsection">
355 <a name="linkage">Linkage Types</a>
356</div>
357
358<div class="doc_text">
359
360<p>
361All Global Variables and Functions have one of the following types of linkage:
362</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000363
364<dl>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000365
Chris Lattnerfa730212004-12-09 16:11:40 +0000366 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000367
368 <dd>Global values with internal linkage are only directly accessible by
369 objects in the current module. In particular, linking code into a module with
370 an internal global value may cause the internal to be renamed as necessary to
371 avoid collisions. Because the symbol is internal to the module, all
372 references can be updated. This corresponds to the notion of the
373 '<tt>static</tt>' keyword in C, or the idea of "anonymous namespaces" in C++.
Chris Lattnerfa730212004-12-09 16:11:40 +0000374 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000375
Chris Lattnerfa730212004-12-09 16:11:40 +0000376 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000377
378 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt> linkage, with
379 the twist that linking together two modules defining the same
380 <tt>linkonce</tt> globals will cause one of the globals to be discarded. This
381 is typically used to implement inline functions. Unreferenced
382 <tt>linkonce</tt> globals are allowed to be discarded.
Chris Lattnerfa730212004-12-09 16:11:40 +0000383 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000384
Chris Lattnerfa730212004-12-09 16:11:40 +0000385 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000386
387 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage,
388 except that unreferenced <tt>weak</tt> globals may not be discarded. This is
389 used to implement constructs in C such as "<tt>int X;</tt>" at global scope.
Chris Lattnerfa730212004-12-09 16:11:40 +0000390 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000391
Chris Lattnerfa730212004-12-09 16:11:40 +0000392 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000393
394 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
395 pointer to array type. When two global variables with appending linkage are
396 linked together, the two global arrays are appended together. This is the
397 LLVM, typesafe, equivalent of having the system linker append together
398 "sections" with identical names when .o files are linked.
Chris Lattnerfa730212004-12-09 16:11:40 +0000399 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000400
Chris Lattnerfa730212004-12-09 16:11:40 +0000401 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000402
403 <dd>If none of the above identifiers are used, the global is externally
404 visible, meaning that it participates in linkage and can be used to resolve
405 external symbol references.
Chris Lattnerfa730212004-12-09 16:11:40 +0000406 </dd>
407</dl>
408
Chris Lattnerfa730212004-12-09 16:11:40 +0000409<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
410variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
411variable and was linked with this one, one of the two would be renamed,
412preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
413external (i.e., lacking any linkage declarations), they are accessible
414outside of the current module. It is illegal for a function <i>declaration</i>
415to have any linkage type other than "externally visible".</a></p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000416
Chris Lattnerfa730212004-12-09 16:11:40 +0000417</div>
418
419<!-- ======================================================================= -->
420<div class="doc_subsection">
421 <a name="globalvars">Global Variables</a>
422</div>
423
424<div class="doc_text">
425
426<p>Global variables define regions of memory allocated at compilation
427time instead of run-time. Global variables may optionally be
428initialized. A variable may be defined as a global "constant", which
429indicates that the contents of the variable will never be modified
430(enabling better optimization, allowing the global data to be placed in the
431read-only section of an executable, etc).</p>
432
433<p>As SSA values, global variables define pointer values that are in
434scope (i.e. they dominate) all basic blocks in the program. Global
435variables always define a pointer to their "content" type because they
436describe a region of memory, and all memory objects in LLVM are
437accessed through pointers.</p>
438
439</div>
440
441
442<!-- ======================================================================= -->
443<div class="doc_subsection">
444 <a name="functionstructure">Functions</a>
445</div>
446
447<div class="doc_text">
448
449<p>LLVM function definitions are composed of a (possibly empty) argument list,
450an opening curly brace, a list of basic blocks, and a closing curly brace. LLVM
451function declarations are defined with the "<tt>declare</tt>" keyword, a
452function name, and a function signature.</p>
453
454<p>A function definition contains a list of basic blocks, forming the CFG for
455the function. Each basic block may optionally start with a label (giving the
456basic block a symbol table entry), contains a list of instructions, and ends
457with a <a href="#terminators">terminator</a> instruction (such as a branch or
458function return).</p>
459
460<p>The first basic block in program is special in two ways: it is immediately
461executed on entrance to the function, and it is not allowed to have predecessor
462basic blocks (i.e. there can not be any branches to the entry block of a
463function). Because the block can have no predecessors, it also cannot have any
464<a href="#i_phi">PHI nodes</a>.</p>
465
466<p>LLVM functions are identified by their name and type signature. Hence, two
467functions with the same name but different parameter lists or return values are
468considered different functions, and LLVM will resolves references to each
469appropriately.</p>
470
471</div>
472
473
474
Chris Lattner00950542001-06-06 20:29:01 +0000475<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000476<div class="doc_section"> <a name="typesystem">Type System</a> </div>
477<!-- *********************************************************************** -->
Chris Lattnerfa730212004-12-09 16:11:40 +0000478
Misha Brukman9d0919f2003-11-08 01:05:38 +0000479<div class="doc_text">
Chris Lattnerfa730212004-12-09 16:11:40 +0000480
Misha Brukman9d0919f2003-11-08 01:05:38 +0000481<p>The LLVM type system is one of the most important features of the
Chris Lattner261efe92003-11-25 01:02:51 +0000482intermediate representation. Being typed enables a number of
483optimizations to be performed on the IR directly, without having to do
484extra analyses on the side before the transformation. A strong type
485system makes it easier to read the generated code and enables novel
486analyses and transformations that are not feasible to perform on normal
487three address code representations.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000488
489</div>
490
Chris Lattner00950542001-06-06 20:29:01 +0000491<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000492<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000493<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +0000494<p>The primitive types are the fundamental building blocks of the LLVM
Chris Lattner261efe92003-11-25 01:02:51 +0000495system. The current set of primitive types are as follows:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000496
Reid Spencerd3f876c2004-11-01 08:19:36 +0000497<table class="layout">
498 <tr class="layout">
499 <td class="left">
500 <table>
Chris Lattner261efe92003-11-25 01:02:51 +0000501 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000502 <tr><th>Type</th><th>Description</th></tr>
503 <tr><td><tt>void</tt></td><td>No value</td></tr>
504 <tr><td><tt>ubyte</tt></td><td>Unsigned 8 bit value</td></tr>
505 <tr><td><tt>ushort</tt></td><td>Unsigned 16 bit value</td></tr>
506 <tr><td><tt>uint</tt></td><td>Unsigned 32 bit value</td></tr>
507 <tr><td><tt>ulong</tt></td><td>Unsigned 64 bit value</td></tr>
508 <tr><td><tt>float</tt></td><td>32 bit floating point value</td></tr>
509 <tr><td><tt>label</tt></td><td>Branch destination</td></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000510 </tbody>
511 </table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000512 </td>
513 <td class="right">
514 <table>
Chris Lattner261efe92003-11-25 01:02:51 +0000515 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000516 <tr><th>Type</th><th>Description</th></tr>
517 <tr><td><tt>bool</tt></td><td>True or False value</td></tr>
518 <tr><td><tt>sbyte</tt></td><td>Signed 8 bit value</td></tr>
519 <tr><td><tt>short</tt></td><td>Signed 16 bit value</td></tr>
520 <tr><td><tt>int</tt></td><td>Signed 32 bit value</td></tr>
521 <tr><td><tt>long</tt></td><td>Signed 64 bit value</td></tr>
522 <tr><td><tt>double</tt></td><td>64 bit floating point value</td></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000523 </tbody>
524 </table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000525 </td>
526 </tr>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000527</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000528</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000529
Chris Lattner00950542001-06-06 20:29:01 +0000530<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000531<div class="doc_subsubsection"> <a name="t_classifications">Type
532Classifications</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000533<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000534<p>These different primitive types fall into a few useful
535classifications:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000536
537<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +0000538 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000539 <tr><th>Classification</th><th>Types</th></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000540 <tr>
541 <td><a name="t_signed">signed</a></td>
542 <td><tt>sbyte, short, int, long, float, double</tt></td>
543 </tr>
544 <tr>
545 <td><a name="t_unsigned">unsigned</a></td>
546 <td><tt>ubyte, ushort, uint, ulong</tt></td>
547 </tr>
548 <tr>
549 <td><a name="t_integer">integer</a></td>
550 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
551 </tr>
552 <tr>
553 <td><a name="t_integral">integral</a></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000554 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt>
555 </td>
Chris Lattner261efe92003-11-25 01:02:51 +0000556 </tr>
557 <tr>
558 <td><a name="t_floating">floating point</a></td>
559 <td><tt>float, double</tt></td>
560 </tr>
561 <tr>
562 <td><a name="t_firstclass">first class</a></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000563 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long,<br>
564 float, double, <a href="#t_pointer">pointer</a>,
565 <a href="#t_packed">packed</a></tt></td>
Chris Lattner261efe92003-11-25 01:02:51 +0000566 </tr>
567 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000568</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000569
Chris Lattner261efe92003-11-25 01:02:51 +0000570<p>The <a href="#t_firstclass">first class</a> types are perhaps the
571most important. Values of these types are the only ones which can be
572produced by instructions, passed as arguments, or used as operands to
573instructions. This means that all structures and arrays must be
574manipulated either by pointer or by component.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000575</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000576
Chris Lattner00950542001-06-06 20:29:01 +0000577<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000578<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000579
Misha Brukman9d0919f2003-11-08 01:05:38 +0000580<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +0000581
Chris Lattner261efe92003-11-25 01:02:51 +0000582<p>The real power in LLVM comes from the derived types in the system.
583This is what allows a programmer to represent arrays, functions,
584pointers, and other useful types. Note that these derived types may be
585recursive: For example, it is possible to have a two dimensional array.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000586
Misha Brukman9d0919f2003-11-08 01:05:38 +0000587</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000588
Chris Lattner00950542001-06-06 20:29:01 +0000589<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000590<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000591
Misha Brukman9d0919f2003-11-08 01:05:38 +0000592<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +0000593
Chris Lattner00950542001-06-06 20:29:01 +0000594<h5>Overview:</h5>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000595
Misha Brukman9d0919f2003-11-08 01:05:38 +0000596<p>The array type is a very simple derived type that arranges elements
Chris Lattner261efe92003-11-25 01:02:51 +0000597sequentially in memory. The array type requires a size (number of
598elements) and an underlying data type.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000599
Chris Lattner7faa8832002-04-14 06:13:44 +0000600<h5>Syntax:</h5>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000601
602<pre>
603 [&lt;# elements&gt; x &lt;elementtype&gt;]
604</pre>
605
Chris Lattner261efe92003-11-25 01:02:51 +0000606<p>The number of elements is a constant integer value, elementtype may
607be any type with a size.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000608
Chris Lattner7faa8832002-04-14 06:13:44 +0000609<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000610<table class="layout">
611 <tr class="layout">
612 <td class="left">
613 <tt>[40 x int ]</tt><br/>
614 <tt>[41 x int ]</tt><br/>
615 <tt>[40 x uint]</tt><br/>
616 </td>
617 <td class="left">
618 Array of 40 integer values.<br/>
619 Array of 41 integer values.<br/>
620 Array of 40 unsigned integer values.<br/>
621 </td>
622 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000623</table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000624<p>Here are some examples of multidimensional arrays:</p>
625<table class="layout">
626 <tr class="layout">
627 <td class="left">
628 <tt>[3 x [4 x int]]</tt><br/>
629 <tt>[12 x [10 x float]]</tt><br/>
630 <tt>[2 x [3 x [4 x uint]]]</tt><br/>
631 </td>
632 <td class="left">
633 3x4 array integer values.<br/>
634 12x10 array of single precision floating point values.<br/>
635 2x3x4 array of unsigned integer values.<br/>
636 </td>
637 </tr>
638</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000639</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000640
Chris Lattner00950542001-06-06 20:29:01 +0000641<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000642<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000643<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000644<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000645<p>The function type can be thought of as a function signature. It
646consists of a return type and a list of formal parameter types.
John Criswell009900b2003-11-25 21:45:46 +0000647Function types are usually used to build virtual function tables
Chris Lattner261efe92003-11-25 01:02:51 +0000648(which are structures of pointers to functions), for indirect function
649calls, and when defining a function.</p>
John Criswell009900b2003-11-25 21:45:46 +0000650<p>
651The return type of a function type cannot be an aggregate type.
652</p>
Chris Lattner00950542001-06-06 20:29:01 +0000653<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000654<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000655<p>Where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
656specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner27f71f22003-09-03 00:41:47 +0000657which indicates that the function takes a variable number of arguments.
658Variable argument functions can access their arguments with the <a
Chris Lattner261efe92003-11-25 01:02:51 +0000659 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000660<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000661<table class="layout">
662 <tr class="layout">
663 <td class="left">
664 <tt>int (int)</tt> <br/>
665 <tt>float (int, int *) *</tt><br/>
666 <tt>int (sbyte *, ...)</tt><br/>
667 </td>
668 <td class="left">
669 function taking an <tt>int</tt>, returning an <tt>int</tt><br/>
670 <a href="#t_pointer">Pointer</a> to a function that takes an
Misha Brukmanc24b7582004-08-12 20:16:08 +0000671 <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
Reid Spencerd3f876c2004-11-01 08:19:36 +0000672 returning <tt>float</tt>.<br/>
673 A vararg function that takes at least one <a href="#t_pointer">pointer</a>
674 to <tt>sbyte</tt> (signed char in C), which returns an integer. This is
675 the signature for <tt>printf</tt> in LLVM.<br/>
676 </td>
677 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000678</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000679
Misha Brukman9d0919f2003-11-08 01:05:38 +0000680</div>
Chris Lattner00950542001-06-06 20:29:01 +0000681<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000682<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000683<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000684<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000685<p>The structure type is used to represent a collection of data members
686together in memory. The packing of the field types is defined to match
687the ABI of the underlying processor. The elements of a structure may
688be any type that has a size.</p>
689<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
690and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
691field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
692instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000693<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000694<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +0000695<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000696<table class="layout">
697 <tr class="layout">
698 <td class="left">
699 <tt>{ int, int, int }</tt><br/>
700 <tt>{ float, int (int) * }</tt><br/>
701 </td>
702 <td class="left">
703 a triple of three <tt>int</tt> values<br/>
704 A pair, where the first element is a <tt>float</tt> and the second element
705 is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a>
706 that takes an <tt>int</tt>, returning an <tt>int</tt>.<br/>
707 </td>
708 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000709</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000710</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000711
Chris Lattner00950542001-06-06 20:29:01 +0000712<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000713<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000714<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +0000715<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000716<p>As in many languages, the pointer type represents a pointer or
717reference to another object, which must live in memory.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000718<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000719<pre> &lt;type&gt; *<br></pre>
Chris Lattner7faa8832002-04-14 06:13:44 +0000720<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000721<table class="layout">
722 <tr class="layout">
723 <td class="left">
724 <tt>[4x int]*</tt><br/>
725 <tt>int (int *) *</tt><br/>
726 </td>
727 <td class="left">
728 A <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of
729 four <tt>int</tt> values<br/>
730 A <a href="#t_pointer">pointer</a> to a <a
Misha Brukmanc24b7582004-08-12 20:16:08 +0000731 href="#t_function">function</a> that takes an <tt>int</tt>, returning an
Reid Spencerd3f876c2004-11-01 08:19:36 +0000732 <tt>int</tt>.<br/>
733 </td>
734 </tr>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000735</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000736</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000737
Chris Lattnera58561b2004-08-12 19:12:28 +0000738<!-- _______________________________________________________________________ -->
739<div class="doc_subsubsection"> <a name="t_packed">Packed Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000740<div class="doc_text">
Chris Lattnera58561b2004-08-12 19:12:28 +0000741<h5>Overview:</h5>
742<p>A packed type is a simple derived type that represents a vector
743of elements. Packed types are used when multiple primitive data
744are operated in parallel using a single instruction (SIMD).
745A packed type requires a size (number of
746elements) and an underlying primitive data type. Packed types are
747considered <a href="#t_firstclass">first class</a>.</p>
748<h5>Syntax:</h5>
749<pre> &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;<br></pre>
750<p>The number of elements is a constant integer value, elementtype may
751be any integral or floating point type.</p>
752<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000753<table class="layout">
754 <tr class="layout">
755 <td class="left">
756 <tt>&lt;4 x int&gt;</tt><br/>
757 <tt>&lt;8 x float&gt;</tt><br/>
758 <tt>&lt;2 x uint&gt;</tt><br/>
759 </td>
760 <td class="left">
761 Packed vector of 4 integer values.<br/>
762 Packed vector of 8 floating-point values.<br/>
763 Packed vector of 2 unsigned integer values.<br/>
764 </td>
765 </tr>
766</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000767</div>
768
Chris Lattnerc3f59762004-12-09 17:30:23 +0000769<!-- *********************************************************************** -->
770<div class="doc_section"> <a name="constants">Constants</a> </div>
771<!-- *********************************************************************** -->
772
773<div class="doc_text">
774
775<p>LLVM has several different basic types of constants. This section describes
776them all and their syntax.</p>
777
778</div>
779
780<!-- ======================================================================= -->
Reid Spencercc16dc32004-12-09 18:02:53 +0000781<div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000782
783<div class="doc_text">
784
785<dl>
786 <dt><b>Boolean constants</b></dt>
787
788 <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
789 constants of the <tt><a href="#t_primitive">bool</a></tt> type.
790 </dd>
791
792 <dt><b>Integer constants</b></dt>
793
Reid Spencercc16dc32004-12-09 18:02:53 +0000794 <dd>Standard integers (such as '4') are constants of the <a
Chris Lattnerc3f59762004-12-09 17:30:23 +0000795 href="#t_integer">integer</a> type. Negative numbers may be used with signed
796 integer types.
797 </dd>
798
799 <dt><b>Floating point constants</b></dt>
800
801 <dd>Floating point constants use standard decimal notation (e.g. 123.421),
802 exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
Reid Spencercc16dc32004-12-09 18:02:53 +0000803 notation. Floating point constants have an optional hexadecimal
Chris Lattnerc3f59762004-12-09 17:30:23 +0000804 notation (see below). Floating point constants must have a <a
805 href="#t_floating">floating point</a> type. </dd>
806
807 <dt><b>Null pointer constants</b></dt>
808
809 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant,
810 and must be of <a href="#t_pointer">pointer type</a>.</dd>
811
812</dl>
813
814<p>The one non-intuitive notation for constants is the optional hexidecimal form
815of floating point constants. For example, the form '<tt>double
8160x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
8174.5e+15</tt>'. The only time hexadecimal floating point constants are required
Reid Spencercc16dc32004-12-09 18:02:53 +0000818(and the only time that they are generated by the disassembler) is when a
819floating point constant must be emitted but it cannot be represented as a
820decimal floating point number. For example, NaN's, infinities, and other
821special values are represented in their IEEE hexadecimal format so that
822assembly and disassembly do not cause any bits to change in the constants.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000823
824</div>
825
826<!-- ======================================================================= -->
827<div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a>
828</div>
829
830<div class="doc_text">
831
832<dl>
833 <dt><b>Structure constants</b></dt>
834
835 <dd>Structure constants are represented with notation similar to structure
836 type definitions (a comma separated list of elements, surrounded by braces
837 (<tt>{}</tt>). For example: "<tt>{ int 4, float 17.0 }</tt>". Structure
838 constants must have <a href="#t_struct">structure type</a>, and the number and
839 types of elements must match those specified by the type.
840 </dd>
841
842 <dt><b>Array constants</b></dt>
843
844 <dd>Array constants are represented with notation similar to array type
845 definitions (a comma separated list of elements, surrounded by square brackets
846 (<tt>[]</tt>). For example: "<tt>[ int 42, int 11, int 74 ]</tt>". Array
847 constants must have <a href="#t_array">array type</a>, and the number and
848 types of elements must match those specified by the type.
849 </dd>
850
851 <dt><b>Packed constants</b></dt>
852
853 <dd>Packed constants are represented with notation similar to packed type
854 definitions (a comma separated list of elements, surrounded by
855 less-than/greater-than's (<tt>&lt;&gt;</tt>). For example: "<tt>&lt; int 42,
856 int 11, int 74, int 100 &gt;</tt>". Packed constants must have <a
857 href="#t_packed">packed type</a>, and the number and types of elements must
858 match those specified by the type.
859 </dd>
860
861 <dt><b>Zero initialization</b></dt>
862
863 <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
864 value to zero of <em>any</em> type, including scalar and aggregate types.
865 This is often used to avoid having to print large zero initializers (e.g. for
866 large arrays), and is always exactly equivalent to using explicit zero
867 initializers.
868 </dd>
869</dl>
870
871</div>
872
873<!-- ======================================================================= -->
874<div class="doc_subsection">
875 <a name="globalconstants">Global Variable and Function Addresses</a>
876</div>
877
878<div class="doc_text">
879
880<p>The addresses of <a href="#globalvars">global variables</a> and <a
881href="#functionstructure">functions</a> are always implicitly valid (link-time)
882constants. These constants explicitly referenced when the <a
883href="#identifiers">identifier for the global</a> is used, and always have <a
884href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
885file:</p>
886
887<pre>
888 %X = global int 17
889 %Y = global int 42
890 %Z = global [2 x int*] [ int* %X, int* %Y ]
891</pre>
892
893</div>
894
895<!-- ======================================================================= -->
Reid Spencer2dc45b82004-12-09 18:13:12 +0000896<div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000897<div class="doc_text">
Reid Spencer2dc45b82004-12-09 18:13:12 +0000898 <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has
899 no specific value. Undefined values may be of any type, and be used anywhere
900 a constant is permitted.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000901
Reid Spencer2dc45b82004-12-09 18:13:12 +0000902 <p>Undefined values indicate to the compiler that the program is well defined
903 no matter what value is used, giving the compiler more freedom to optimize.
904 </p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000905</div>
906
907<!-- ======================================================================= -->
908<div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
909</div>
910
911<div class="doc_text">
912
913<p>Constant expressions are used to allow expressions involving other constants
914to be used as constants. Constant expressions may be of any <a
915href="#t_firstclass">first class</a> type, and may involve any LLVM operation
916that does not have side effects (e.g. load and call are not supported). The
917following is the syntax for constant expressions:</p>
918
919<dl>
920 <dt><b><tt>cast ( CST to TYPE )</tt></b></dt>
921
922 <dd>Cast a constant to another type.</dd>
923
924 <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
925
926 <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
927 constants. As with the <a href="#i_getelementptr">getelementptr</a>
928 instruction, the index list may have zero or more indexes, which are required
929 to make sense for the type of "CSTPTR".</dd>
930
931 <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
932
Reid Spencer2dc45b82004-12-09 18:13:12 +0000933 <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
934 be any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise
Chris Lattnerc3f59762004-12-09 17:30:23 +0000935 binary</a> operations. The constraints on operands are the same as those for
936 the corresponding instruction (e.g. no bitwise operations on floating point
937 are allowed).</dd>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000938</dl>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000939</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000940
Chris Lattner00950542001-06-06 20:29:01 +0000941<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000942<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
943<!-- *********************************************************************** -->
Chris Lattnerc3f59762004-12-09 17:30:23 +0000944
Misha Brukman9d0919f2003-11-08 01:05:38 +0000945<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +0000946
Chris Lattner261efe92003-11-25 01:02:51 +0000947<p>The LLVM instruction set consists of several different
948classifications of instructions: <a href="#terminators">terminator
949instructions</a>, <a href="#binaryops">binary instructions</a>, <a
950 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
951instructions</a>.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000952
Misha Brukman9d0919f2003-11-08 01:05:38 +0000953</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000954
Chris Lattner00950542001-06-06 20:29:01 +0000955<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000956<div class="doc_subsection"> <a name="terminators">Terminator
957Instructions</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000958
Misha Brukman9d0919f2003-11-08 01:05:38 +0000959<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +0000960
Chris Lattner261efe92003-11-25 01:02:51 +0000961<p>As mentioned <a href="#functionstructure">previously</a>, every
962basic block in a program ends with a "Terminator" instruction, which
963indicates which block should be executed after the current block is
964finished. These terminator instructions typically yield a '<tt>void</tt>'
965value: they produce control flow, not values (the one exception being
966the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000967
Misha Brukman9d0919f2003-11-08 01:05:38 +0000968<p>There are five different terminator instructions: the '<a
Chris Lattner261efe92003-11-25 01:02:51 +0000969 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
970instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
Chris Lattner35eca582004-10-16 18:04:13 +0000971the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
972 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
973 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000974
Misha Brukman9d0919f2003-11-08 01:05:38 +0000975</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000976
Chris Lattner00950542001-06-06 20:29:01 +0000977<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000978<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
979Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000980<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000981<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000982<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 +0000983 ret void <i>; Return from void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000984</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000985<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000986<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
987value) from a function, back to the caller.</p>
John Criswell4457dc92004-04-09 16:48:45 +0000988<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner261efe92003-11-25 01:02:51 +0000989returns a value and then causes control flow, and one that just causes
990control flow to occur.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000991<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000992<p>The '<tt>ret</tt>' instruction may return any '<a
993 href="#t_firstclass">first class</a>' type. Notice that a function is
994not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
995instruction inside of the function that returns a value that does not
996match the return type of the function.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000997<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000998<p>When the '<tt>ret</tt>' instruction is executed, control flow
999returns back to the calling function's context. If the caller is a "<a
John Criswellfa081872004-06-25 15:16:57 +00001000 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner261efe92003-11-25 01:02:51 +00001001the instruction after the call. If the caller was an "<a
1002 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
1003at the beginning "normal" of the destination block. If the instruction
1004returns a value, that value shall set the call or invoke instruction's
1005return value.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001006<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001007<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001008 ret void <i>; Return from a void function</i>
Chris Lattner00950542001-06-06 20:29:01 +00001009</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001010</div>
Chris Lattner00950542001-06-06 20:29:01 +00001011<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001012<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001013<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001014<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001015<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 +00001016</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001017<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001018<p>The '<tt>br</tt>' instruction is used to cause control flow to
1019transfer to a different basic block in the current function. There are
1020two forms of this instruction, corresponding to a conditional branch
1021and an unconditional branch.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001022<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001023<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
1024single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
1025unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
1026value as a target.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001027<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001028<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
1029argument is evaluated. If the value is <tt>true</tt>, control flows
1030to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
1031control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001032<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001033<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
1034 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 +00001035</div>
Chris Lattner00950542001-06-06 20:29:01 +00001036<!-- _______________________________________________________________________ -->
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001037<div class="doc_subsubsection">
1038 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
1039</div>
1040
Misha Brukman9d0919f2003-11-08 01:05:38 +00001041<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001042<h5>Syntax:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001043
1044<pre>
1045 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
1046</pre>
1047
Chris Lattner00950542001-06-06 20:29:01 +00001048<h5>Overview:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001049
1050<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
1051several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +00001052instruction, allowing a branch to occur to one of many possible
1053destinations.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001054
1055
Chris Lattner00950542001-06-06 20:29:01 +00001056<h5>Arguments:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001057
1058<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
1059comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
1060an array of pairs of comparison value constants and '<tt>label</tt>'s. The
1061table is not allowed to contain duplicate constant entries.</p>
1062
Chris Lattner00950542001-06-06 20:29:01 +00001063<h5>Semantics:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001064
Chris Lattner261efe92003-11-25 01:02:51 +00001065<p>The <tt>switch</tt> instruction specifies a table of values and
1066destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswell84114752004-06-25 16:05:06 +00001067table is searched for the given value. If the value is found, control flow is
1068transfered to the corresponding destination; otherwise, control flow is
1069transfered to the default destination.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001070
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001071<h5>Implementation:</h5>
1072
1073<p>Depending on properties of the target machine and the particular
1074<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswell84114752004-06-25 16:05:06 +00001075ways. For example, it could be generated as a series of chained conditional
1076branches or with a lookup table.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001077
1078<h5>Example:</h5>
1079
1080<pre>
1081 <i>; Emulate a conditional br instruction</i>
1082 %Val = <a href="#i_cast">cast</a> bool %value to int
1083 switch int %Val, label %truedest [int 0, label %falsedest ]
1084
1085 <i>; Emulate an unconditional br instruction</i>
1086 switch uint 0, label %dest [ ]
1087
1088 <i>; Implement a jump table:</i>
1089 switch uint %val, label %otherwise [ uint 0, label %onzero
1090 uint 1, label %onone
1091 uint 2, label %ontwo ]
Chris Lattner00950542001-06-06 20:29:01 +00001092</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001093</div>
Chris Lattner00950542001-06-06 20:29:01 +00001094<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001095<div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>'
1096Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001097<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001098<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001099<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 +00001100<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001101<p>The '<tt>invoke</tt>' instruction causes control to transfer to a
1102specified function, with the possibility of control flow transfer to
1103either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>.
1104If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>"
1105instruction, control flow will return to the "normal" label. If the
1106callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
1107instruction, control is interrupted, and continued at the dynamically
1108nearest "except" label.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001109<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001110<p>This instruction requires several arguments:</p>
Chris Lattner00950542001-06-06 20:29:01 +00001111<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00001112 <li>'<tt>ptr to function ty</tt>': shall be the signature of the
1113pointer to function value being invoked. In most cases, this is a
1114direct function invocation, but indirect <tt>invoke</tt>s are just as
1115possible, branching off an arbitrary pointer to function value. </li>
1116 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer
1117to a function to be invoked. </li>
1118 <li>'<tt>function args</tt>': argument list whose types match the
1119function signature argument types. If the function signature indicates
1120the function accepts a variable number of arguments, the extra
1121arguments can be specified. </li>
1122 <li>'<tt>normal label</tt>': the label reached when the called
1123function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
1124 <li>'<tt>exception label</tt>': the label reached when a callee
1125returns with the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
Chris Lattner00950542001-06-06 20:29:01 +00001126</ol>
Chris Lattner00950542001-06-06 20:29:01 +00001127<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001128<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner261efe92003-11-25 01:02:51 +00001129 href="#i_call">call</a></tt>' instruction in most regards. The
1130primary difference is that it establishes an association with a label,
1131which is used by the runtime library to unwind the stack.</p>
1132<p>This instruction is used in languages with destructors to ensure
1133that proper cleanup is performed in the case of either a <tt>longjmp</tt>
1134or a thrown exception. Additionally, this is important for
1135implementation of '<tt>catch</tt>' clauses in high-level languages that
1136support them.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001137<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001138<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 +00001139</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001140</div>
Chris Lattner35eca582004-10-16 18:04:13 +00001141
1142
Chris Lattner27f71f22003-09-03 00:41:47 +00001143<!-- _______________________________________________________________________ -->
Chris Lattner35eca582004-10-16 18:04:13 +00001144
Chris Lattner261efe92003-11-25 01:02:51 +00001145<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
1146Instruction</a> </div>
Chris Lattner35eca582004-10-16 18:04:13 +00001147
Misha Brukman9d0919f2003-11-08 01:05:38 +00001148<div class="doc_text">
Chris Lattner35eca582004-10-16 18:04:13 +00001149
Chris Lattner27f71f22003-09-03 00:41:47 +00001150<h5>Syntax:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001151<pre>
1152 unwind
1153</pre>
1154
Chris Lattner27f71f22003-09-03 00:41:47 +00001155<h5>Overview:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001156
1157<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
1158at the first callee in the dynamic call stack which used an <a
1159href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
1160primarily used to implement exception handling.</p>
1161
Chris Lattner27f71f22003-09-03 00:41:47 +00001162<h5>Semantics:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001163
1164<p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to
1165immediately halt. The dynamic call stack is then searched for the first <a
1166href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
1167execution continues at the "exceptional" destination block specified by the
1168<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
1169dynamic call chain, undefined behavior results.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001170</div>
Chris Lattner35eca582004-10-16 18:04:13 +00001171
1172<!-- _______________________________________________________________________ -->
1173
1174<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
1175Instruction</a> </div>
1176
1177<div class="doc_text">
1178
1179<h5>Syntax:</h5>
1180<pre>
1181 unreachable
1182</pre>
1183
1184<h5>Overview:</h5>
1185
1186<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
1187instruction is used to inform the optimizer that a particular portion of the
1188code is not reachable. This can be used to indicate that the code after a
1189no-return function cannot be reached, and other facts.</p>
1190
1191<h5>Semantics:</h5>
1192
1193<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
1194</div>
1195
1196
1197
Chris Lattner00950542001-06-06 20:29:01 +00001198<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001199<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001200<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001201<p>Binary operators are used to do most of the computation in a
1202program. They require two operands, execute an operation on them, and
Chris Lattnera58561b2004-08-12 19:12:28 +00001203produce a single value. Although, that single value might represent
1204multiple data, as is the case with the <a href="#t_packed">packed</a> data type.
1205The result value of a binary operator is not
Chris Lattner261efe92003-11-25 01:02:51 +00001206necessarily the same type as its operands.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001207<p>There are several different binary operators:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001208</div>
Chris Lattner00950542001-06-06 20:29:01 +00001209<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001210<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
1211Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001212<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001213<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001214<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 +00001215</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001216<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001217<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001218<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001219<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattnera58561b2004-08-12 19:12:28 +00001220 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
1221 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1222Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001223<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001224<p>The value produced is the integer or floating point sum of the two
1225operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001226<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001227<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001228</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001229</div>
Chris Lattner00950542001-06-06 20:29:01 +00001230<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001231<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
1232Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001233<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001234<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001235<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 +00001236</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001237<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001238<p>The '<tt>sub</tt>' instruction returns the difference of its two
1239operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001240<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
1241instruction present in most other intermediate representations.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001242<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001243<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001244 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001245values.
1246This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1247Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001248<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001249<p>The value produced is the integer or floating point difference of
1250the two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001251<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001252<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001253 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
1254</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001255</div>
Chris Lattner00950542001-06-06 20:29:01 +00001256<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001257<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
1258Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001259<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001260<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001261<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 +00001262</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001263<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001264<p>The '<tt>mul</tt>' instruction returns the product of its two
1265operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001266<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001267<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001268 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001269values.
1270This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1271Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001272<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001273<p>The value produced is the integer or floating point product of the
Misha Brukman9d0919f2003-11-08 01:05:38 +00001274two operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001275<p>There is no signed vs unsigned multiplication. The appropriate
1276action is taken based on the type of the operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001277<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001278<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001279</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001280</div>
Chris Lattner00950542001-06-06 20:29:01 +00001281<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001282<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
1283Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001284<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001285<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001286<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1287</pre>
1288<h5>Overview:</h5>
1289<p>The '<tt>div</tt>' instruction returns the quotient of its two
1290operands.</p>
1291<h5>Arguments:</h5>
1292<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
1293 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001294values.
1295This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1296Both arguments must have identical types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001297<h5>Semantics:</h5>
1298<p>The value produced is the integer or floating point quotient of the
1299two operands.</p>
1300<h5>Example:</h5>
1301<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
1302</pre>
1303</div>
1304<!-- _______________________________________________________________________ -->
1305<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
1306Instruction</a> </div>
1307<div class="doc_text">
1308<h5>Syntax:</h5>
1309<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1310</pre>
1311<h5>Overview:</h5>
1312<p>The '<tt>rem</tt>' instruction returns the remainder from the
1313division of its two operands.</p>
1314<h5>Arguments:</h5>
1315<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1316 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001317values.
1318This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1319Both arguments must have identical types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001320<h5>Semantics:</h5>
1321<p>This returns the <i>remainder</i> of a division (where the result
1322has the same sign as the divisor), not the <i>modulus</i> (where the
1323result has the same sign as the dividend) of a value. For more
1324information about the difference, see: <a
1325 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1326Math Forum</a>.</p>
1327<h5>Example:</h5>
1328<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1329</pre>
1330</div>
1331<!-- _______________________________________________________________________ -->
1332<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1333Instructions</a> </div>
1334<div class="doc_text">
1335<h5>Syntax:</h5>
1336<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 +00001337 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1338 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1339 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1340 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1341 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1342</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001343<h5>Overview:</h5>
1344<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1345value based on a comparison of their two operands.</p>
1346<h5>Arguments:</h5>
1347<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1348be of <a href="#t_firstclass">first class</a> type (it is not possible
1349to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1350or '<tt>void</tt>' values, etc...). Both arguments must have identical
1351types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001352<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001353<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1354value if both operands are equal.<br>
1355The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1356value if both operands are unequal.<br>
1357The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1358value if the first operand is less than the second operand.<br>
1359The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1360value if the first operand is greater than the second operand.<br>
1361The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1362value if the first operand is less than or equal to the second operand.<br>
1363The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1364value if the first operand is greater than or equal to the second
1365operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001366<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001367<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner00950542001-06-06 20:29:01 +00001368 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
1369 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1370 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1371 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1372 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1373</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001374</div>
Chris Lattner00950542001-06-06 20:29:01 +00001375<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001376<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1377Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001378<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001379<p>Bitwise binary operators are used to do various forms of
1380bit-twiddling in a program. They are generally very efficient
1381instructions, and can commonly be strength reduced from other
1382instructions. They require two operands, execute an operation on them,
1383and produce a single value. The resulting value of the bitwise binary
1384operators is always the same type as its first operand.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001385</div>
Chris Lattner00950542001-06-06 20:29:01 +00001386<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001387<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1388Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001389<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001390<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001391<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 +00001392</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001393<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001394<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1395its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001396<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001397<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001398 href="#t_integral">integral</a> values. Both arguments must have
1399identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001400<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001401<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001402<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001403<div style="align: center">
Misha Brukman9d0919f2003-11-08 01:05:38 +00001404<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +00001405 <tbody>
1406 <tr>
1407 <td>In0</td>
1408 <td>In1</td>
1409 <td>Out</td>
1410 </tr>
1411 <tr>
1412 <td>0</td>
1413 <td>0</td>
1414 <td>0</td>
1415 </tr>
1416 <tr>
1417 <td>0</td>
1418 <td>1</td>
1419 <td>0</td>
1420 </tr>
1421 <tr>
1422 <td>1</td>
1423 <td>0</td>
1424 <td>0</td>
1425 </tr>
1426 <tr>
1427 <td>1</td>
1428 <td>1</td>
1429 <td>1</td>
1430 </tr>
1431 </tbody>
1432</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001433</div>
Chris Lattner00950542001-06-06 20:29:01 +00001434<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001435<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001436 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1437 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1438</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001439</div>
Chris Lattner00950542001-06-06 20:29:01 +00001440<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001441<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001442<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001443<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001444<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 +00001445</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001446<h5>Overview:</h5>
1447<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1448or of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001449<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001450<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001451 href="#t_integral">integral</a> values. Both arguments must have
1452identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001453<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001454<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001455<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001456<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001457<table border="1" cellspacing="0" cellpadding="4">
1458 <tbody>
1459 <tr>
1460 <td>In0</td>
1461 <td>In1</td>
1462 <td>Out</td>
1463 </tr>
1464 <tr>
1465 <td>0</td>
1466 <td>0</td>
1467 <td>0</td>
1468 </tr>
1469 <tr>
1470 <td>0</td>
1471 <td>1</td>
1472 <td>1</td>
1473 </tr>
1474 <tr>
1475 <td>1</td>
1476 <td>0</td>
1477 <td>1</td>
1478 </tr>
1479 <tr>
1480 <td>1</td>
1481 <td>1</td>
1482 <td>1</td>
1483 </tr>
1484 </tbody>
1485</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001486</div>
Chris Lattner00950542001-06-06 20:29:01 +00001487<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001488<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001489 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1490 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1491</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001492</div>
Chris Lattner00950542001-06-06 20:29:01 +00001493<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001494<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1495Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001496<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001497<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001498<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 +00001499</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001500<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001501<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1502or of its two operands. The <tt>xor</tt> is used to implement the
1503"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001504<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001505<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001506 href="#t_integral">integral</a> values. Both arguments must have
1507identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001508<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001509<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001510<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001511<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001512<table border="1" cellspacing="0" cellpadding="4">
1513 <tbody>
1514 <tr>
1515 <td>In0</td>
1516 <td>In1</td>
1517 <td>Out</td>
1518 </tr>
1519 <tr>
1520 <td>0</td>
1521 <td>0</td>
1522 <td>0</td>
1523 </tr>
1524 <tr>
1525 <td>0</td>
1526 <td>1</td>
1527 <td>1</td>
1528 </tr>
1529 <tr>
1530 <td>1</td>
1531 <td>0</td>
1532 <td>1</td>
1533 </tr>
1534 <tr>
1535 <td>1</td>
1536 <td>1</td>
1537 <td>0</td>
1538 </tr>
1539 </tbody>
1540</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001541</div>
Chris Lattner261efe92003-11-25 01:02:51 +00001542<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001543<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001544<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001545 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1546 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner27f71f22003-09-03 00:41:47 +00001547 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner00950542001-06-06 20:29:01 +00001548</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001549</div>
Chris Lattner00950542001-06-06 20:29:01 +00001550<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001551<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1552Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001553<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001554<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001555<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 +00001556</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001557<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001558<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1559the left a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001560<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001561<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001562 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1563type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001564<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001565<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001566<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001567<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 +00001568 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1569 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1570</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001571</div>
Chris Lattner00950542001-06-06 20:29:01 +00001572<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001573<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1574Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001575<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001576<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001577<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 +00001578</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001579<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001580<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1581the right a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001582<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001583<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001584 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1585type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001586<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001587<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1588most significant bit is duplicated in the newly free'd bit positions.
1589If the first argument is unsigned, zero bits shall fill the empty
1590positions.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001591<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001592<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 +00001593 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001594 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner8c6bb902003-06-18 21:30:51 +00001595 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1596 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner00950542001-06-06 20:29:01 +00001597</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001598</div>
Chris Lattner00950542001-06-06 20:29:01 +00001599<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001600<div class="doc_subsection"> <a name="memoryops">Memory Access
1601Operations</a></div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001602<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001603<p>A key design point of an SSA-based representation is how it
1604represents memory. In LLVM, no memory locations are in SSA form, which
1605makes things very simple. This section describes how to read, write,
1606allocate and free memory in LLVM.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001607</div>
Chris Lattner00950542001-06-06 20:29:01 +00001608<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001609<div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>'
1610Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001611<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001612<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001613<pre> &lt;result&gt; = malloc &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001614 &lt;result&gt; = malloc &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001615</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001616<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001617<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1618heap and returns a pointer to it.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001619<h5>Arguments:</h5>
John Criswell6e4ca612004-02-24 16:13:56 +00001620<p>The '<tt>malloc</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1621bytes of memory from the operating system and returns a pointer of the
Chris Lattner261efe92003-11-25 01:02:51 +00001622appropriate type to the program. The second form of the instruction is
1623a shorter version of the first instruction that defaults to allocating
1624one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001625<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001626<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001627<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1628a pointer is returned.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001629<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001630<pre> %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001631
Chris Lattner261efe92003-11-25 01:02:51 +00001632 %size = <a
1633 href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001634 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1635 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001636</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001637</div>
Chris Lattner00950542001-06-06 20:29:01 +00001638<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001639<div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>'
1640Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001641<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001642<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001643<pre> free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner00950542001-06-06 20:29:01 +00001644</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001645<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001646<p>The '<tt>free</tt>' instruction returns memory back to the unused
1647memory heap, to be reallocated in the future.</p>
1648<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001649<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001650<p>'<tt>value</tt>' shall be a pointer value that points to a value
1651that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1652instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001653<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001654<p>Access to the memory pointed to by the pointer is not longer defined
1655after this instruction executes.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001656<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001657<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 +00001658 free [4 x ubyte]* %array
1659</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001660</div>
Chris Lattner00950542001-06-06 20:29:01 +00001661<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001662<div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>'
1663Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001664<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001665<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001666<pre> &lt;result&gt; = alloca &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001667 &lt;result&gt; = alloca &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001668</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001669<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001670<p>The '<tt>alloca</tt>' instruction allocates memory on the current
1671stack frame of the procedure that is live until the current function
1672returns to its caller.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001673<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001674<p>The the '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1675bytes of memory on the runtime stack, returning a pointer of the
1676appropriate type to the program. The second form of the instruction is
1677a shorter version of the first that defaults to allocating one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001678<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001679<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001680<p>Memory is allocated, a pointer is returned. '<tt>alloca</tt>'d
1681memory is automatically released when the function returns. The '<tt>alloca</tt>'
1682instruction is commonly used to represent automatic variables that must
1683have an address available. When the function returns (either with the <tt><a
1684 href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001685instructions), the memory is reclaimed.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001686<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001687<pre> %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001688 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner00950542001-06-06 20:29:01 +00001689</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001690</div>
Chris Lattner00950542001-06-06 20:29:01 +00001691<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001692<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1693Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001694<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00001695<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001696<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 +00001697<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001698<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001699<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001700<p>The argument to the '<tt>load</tt>' instruction specifies the memory
1701address to load from. The pointer must point to a <a
Chris Lattnere53e5082004-06-03 22:57:15 +00001702 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
Chris Lattner261efe92003-11-25 01:02:51 +00001703marked as <tt>volatile</tt> then the optimizer is not allowed to modify
1704the number or order of execution of this <tt>load</tt> with other
1705volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1706instructions. </p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001707<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001708<p>The location of memory pointed to is loaded.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001709<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001710<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1711 <a
1712 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001713 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1714</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001715</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001716<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001717<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1718Instruction</a> </div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001719<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001720<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 +00001721 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 +00001722</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001723<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001724<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001725<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001726<p>There are two arguments to the '<tt>store</tt>' instruction: a value
1727to store and an address to store it into. The type of the '<tt>&lt;pointer&gt;</tt>'
1728operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
1729operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the
1730optimizer is not allowed to modify the number or order of execution of
1731this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1732 href="#i_store">store</a></tt> instructions.</p>
1733<h5>Semantics:</h5>
1734<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
1735at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001736<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001737<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1738 <a
1739 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001740 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1741</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001742<!-- _______________________________________________________________________ -->
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001743<div class="doc_subsubsection">
1744 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
1745</div>
1746
Misha Brukman9d0919f2003-11-08 01:05:38 +00001747<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00001748<h5>Syntax:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001749<pre>
1750 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
1751</pre>
1752
Chris Lattner7faa8832002-04-14 06:13:44 +00001753<h5>Overview:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001754
1755<p>
1756The '<tt>getelementptr</tt>' instruction is used to get the address of a
1757subelement of an aggregate data structure.</p>
1758
Chris Lattner7faa8832002-04-14 06:13:44 +00001759<h5>Arguments:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001760
1761<p>This instruction takes a list of integer constants that indicate what
1762elements of the aggregate object to index to. The actual types of the arguments
1763provided depend on the type of the first pointer argument. The
1764'<tt>getelementptr</tt>' instruction is used to index down through the type
1765levels of a structure. When indexing into a structure, only <tt>uint</tt>
1766integer constants are allowed. When indexing into an array or pointer
1767<tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
1768
Chris Lattner261efe92003-11-25 01:02:51 +00001769<p>For example, let's consider a C code fragment and how it gets
1770compiled to LLVM:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001771
1772<pre>
1773 struct RT {
1774 char A;
1775 int B[10][20];
1776 char C;
1777 };
1778 struct ST {
1779 int X;
1780 double Y;
1781 struct RT Z;
1782 };
1783
1784 int *foo(struct ST *s) {
1785 return &amp;s[1].Z.B[5][13];
1786 }
1787</pre>
1788
Misha Brukman9d0919f2003-11-08 01:05:38 +00001789<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001790
1791<pre>
1792 %RT = type { sbyte, [10 x [20 x int]], sbyte }
1793 %ST = type { int, double, %RT }
1794
Brian Gaeke7283e7c2004-07-02 21:08:14 +00001795 implementation
1796
1797 int* %foo(%ST* %s) {
1798 entry:
1799 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001800 ret int* %reg
1801 }
1802</pre>
1803
Chris Lattner7faa8832002-04-14 06:13:44 +00001804<h5>Semantics:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001805
1806<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
Chris Lattnere53e5082004-06-03 22:57:15 +00001807on the pointer type that is being index into. <a href="#t_pointer">Pointer</a>
1808and <a href="#t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
1809<tt>ulong</tt>, or <tt>long</tt> values, and <a href="#t_struct">structure</a>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001810types require <tt>uint</tt> <b>constants</b>.</p>
1811
Misha Brukman9d0919f2003-11-08 01:05:38 +00001812<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001813type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
1814}</tt>' type, a structure. The second index indexes into the third element of
1815the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
1816sbyte }</tt>' type, another structure. The third index indexes into the second
1817element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
1818array. The two dimensions of the array are subscripted into, yielding an
1819'<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction return a pointer
1820to this element, thus computing a value of '<tt>int*</tt>' type.</p>
1821
Chris Lattner261efe92003-11-25 01:02:51 +00001822<p>Note that it is perfectly legal to index partially through a
1823structure, returning a pointer to an inner element. Because of this,
1824the LLVM code for the given testcase is equivalent to:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001825
1826<pre>
1827 int* "foo"(%ST* %s) {
1828 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
1829 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
1830 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
1831 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
1832 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
1833 ret int* %t5
1834 }
Chris Lattner6536cfe2002-05-06 22:08:29 +00001835</pre>
Chris Lattner7faa8832002-04-14 06:13:44 +00001836<h5>Example:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001837<pre>
1838 <i>; yields [12 x ubyte]*:aptr</i>
1839 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
1840</pre>
1841
1842</div>
Chris Lattner00950542001-06-06 20:29:01 +00001843<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001844<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001845<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +00001846<p>The instructions in this category are the "miscellaneous"
Chris Lattner261efe92003-11-25 01:02:51 +00001847instructions, which defy better classification.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001848</div>
Chris Lattner00950542001-06-06 20:29:01 +00001849<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001850<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
1851Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001852<div class="doc_text">
Chris Lattner33ba0d92001-07-09 00:26:23 +00001853<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001854<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001855<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001856<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
1857the SSA graph representing the function.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001858<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001859<p>The type of the incoming values are specified with the first type
1860field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
1861as arguments, with one pair for each predecessor basic block of the
1862current block. Only values of <a href="#t_firstclass">first class</a>
1863type may be used as the value arguments to the PHI node. Only labels
1864may be used as the label arguments.</p>
1865<p>There must be no non-phi instructions between the start of a basic
1866block and the PHI instructions: i.e. PHI instructions must be first in
1867a basic block.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001868<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001869<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
1870value specified by the parameter, depending on which basic block we
1871came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001872<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001873<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 +00001874</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001875
Chris Lattner6536cfe2002-05-06 22:08:29 +00001876<!-- _______________________________________________________________________ -->
Chris Lattnercc37aae2004-03-12 05:50:16 +00001877<div class="doc_subsubsection">
1878 <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
1879</div>
1880
Misha Brukman9d0919f2003-11-08 01:05:38 +00001881<div class="doc_text">
Chris Lattnercc37aae2004-03-12 05:50:16 +00001882
Chris Lattner6536cfe2002-05-06 22:08:29 +00001883<h5>Syntax:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001884
1885<pre>
1886 &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 +00001887</pre>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001888
Chris Lattner6536cfe2002-05-06 22:08:29 +00001889<h5>Overview:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001890
1891<p>
1892The '<tt>cast</tt>' instruction is used as the primitive means to convert
1893integers to floating point, change data type sizes, and break type safety (by
1894casting pointers).
1895</p>
1896
1897
Chris Lattner6536cfe2002-05-06 22:08:29 +00001898<h5>Arguments:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001899
1900<p>
1901The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
1902class value, and a type to cast it to, which must also be a <a
1903href="#t_firstclass">first class</a> type.
1904</p>
1905
Chris Lattner6536cfe2002-05-06 22:08:29 +00001906<h5>Semantics:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001907
1908<p>
1909This instruction follows the C rules for explicit casts when determining how the
1910data being cast must change to fit in its new container.
1911</p>
1912
1913<p>
1914When casting to bool, any value that would be considered true in the context of
1915a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
1916all else are '<tt>false</tt>'.
1917</p>
1918
1919<p>
1920When extending an integral value from a type of one signness to another (for
1921example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
1922<b>source</b> value is signed, and zero-extended if the source value is
1923unsigned. <tt>bool</tt> values are always zero extended into either zero or
1924one.
1925</p>
1926
Chris Lattner33ba0d92001-07-09 00:26:23 +00001927<h5>Example:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001928
1929<pre>
1930 %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattner7bae3952002-06-25 18:03:17 +00001931 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001932</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001933</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001934
1935<!-- _______________________________________________________________________ -->
1936<div class="doc_subsubsection">
1937 <a name="i_select">'<tt>select</tt>' Instruction</a>
1938</div>
1939
1940<div class="doc_text">
1941
1942<h5>Syntax:</h5>
1943
1944<pre>
1945 &lt;result&gt; = select bool &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
1946</pre>
1947
1948<h5>Overview:</h5>
1949
1950<p>
1951The '<tt>select</tt>' instruction is used to choose one value based on a
1952condition, without branching.
1953</p>
1954
1955
1956<h5>Arguments:</h5>
1957
1958<p>
1959The '<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.
1960</p>
1961
1962<h5>Semantics:</h5>
1963
1964<p>
1965If the boolean condition evaluates to true, the instruction returns the first
1966value argument, otherwise it returns the second value argument.
1967</p>
1968
1969<h5>Example:</h5>
1970
1971<pre>
1972 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
1973</pre>
1974</div>
1975
1976
1977
1978
1979
Chris Lattner33ba0d92001-07-09 00:26:23 +00001980<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001981<div class="doc_subsubsection"> <a name="i_call">'<tt>call</tt>'
1982Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001983<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001984<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001985<pre> &lt;result&gt; = call &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +00001986<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001987<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001988<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001989<p>This instruction requires several arguments:</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001990<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00001991 <li>
1992 <p>'<tt>ty</tt>': shall be the signature of the pointer to function
1993value being invoked. The argument types must match the types implied
1994by this signature.</p>
1995 </li>
1996 <li>
1997 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a
1998function to be invoked. In most cases, this is a direct function
1999invocation, but indirect <tt>call</tt>s are just as possible,
2000calling an arbitrary pointer to function values.</p>
2001 </li>
2002 <li>
2003 <p>'<tt>function args</tt>': argument list whose types match the
2004function signature argument types. If the function signature
2005indicates the function accepts a variable number of arguments, the
2006extra arguments can be specified.</p>
2007 </li>
Chris Lattner6536cfe2002-05-06 22:08:29 +00002008</ol>
Chris Lattner00950542001-06-06 20:29:01 +00002009<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002010<p>The '<tt>call</tt>' instruction is used to cause control flow to
2011transfer to a specified function, with its incoming arguments bound to
2012the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
2013instruction in the called function, control flow continues with the
2014instruction after the function call, and the return value of the
2015function is bound to the result argument. This is a simpler case of
2016the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002017<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002018<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 +00002019</div>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002020
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002021<!-- _______________________________________________________________________ -->
Chris Lattnere19d7a72004-09-27 21:51:25 +00002022<div class="doc_subsubsection">
2023 <a name="i_vanext">'<tt>vanext</tt>' Instruction</a>
2024</div>
2025
Misha Brukman9d0919f2003-11-08 01:05:38 +00002026<div class="doc_text">
Chris Lattnere19d7a72004-09-27 21:51:25 +00002027
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002028<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002029
2030<pre>
2031 &lt;resultarglist&gt; = vanext &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;
2032</pre>
2033
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002034<h5>Overview:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002035
Chris Lattner261efe92003-11-25 01:02:51 +00002036<p>The '<tt>vanext</tt>' instruction is used to access arguments passed
2037through the "variable argument" area of a function call. It is used to
2038implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002039
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002040<h5>Arguments:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002041
2042<p>This instruction takes a <tt>va_list</tt> value and the type of the
2043argument. It returns another <tt>va_list</tt>. The actual type of
2044<tt>va_list</tt> may be defined differently for different targets. Most targets
2045use a <tt>va_list</tt> type of <tt>sbyte*</tt> or some other pointer type.</p>
2046
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002047<h5>Semantics:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002048
2049<p>The '<tt>vanext</tt>' instruction advances the specified <tt>va_list</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002050past an argument of the specified type. In conjunction with the <a
2051 href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement
2052the <tt>va_arg</tt> macro available in C. For more information, see
2053the variable argument handling <a href="#int_varargs">Intrinsic
2054Functions</a>.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002055
Chris Lattner261efe92003-11-25 01:02:51 +00002056<p>It is legal for this instruction to be called in a function which
2057does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002058function.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002059
Misha Brukman9d0919f2003-11-08 01:05:38 +00002060<p><tt>vanext</tt> is an LLVM instruction instead of an <a
Chris Lattnere19d7a72004-09-27 21:51:25 +00002061href="#intrinsics">intrinsic function</a> because it takes a type as an
2062argument. The type refers to the current argument in the <tt>va_list</tt>, it
2063tells the compiler how far on the stack it needs to advance to find the next
2064argument</p>
2065
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002066<h5>Example:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002067
Chris Lattner261efe92003-11-25 01:02:51 +00002068<p>See the <a href="#int_varargs">variable argument processing</a>
2069section.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002070
Misha Brukman9d0919f2003-11-08 01:05:38 +00002071</div>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002072
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002073<!-- _______________________________________________________________________ -->
Chris Lattnere19d7a72004-09-27 21:51:25 +00002074<div class="doc_subsubsection">
2075 <a name="i_vaarg">'<tt>vaarg</tt>' Instruction</a>
2076</div>
2077
Misha Brukman9d0919f2003-11-08 01:05:38 +00002078<div class="doc_text">
Chris Lattnere19d7a72004-09-27 21:51:25 +00002079
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002080<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002081
2082<pre>
2083 &lt;resultval&gt; = vaarg &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;
2084</pre>
2085
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002086<h5>Overview:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002087
2088<p>The '<tt>vaarg</tt>' instruction is used to access arguments passed through
2089the "variable argument" area of a function call. It is used to implement the
2090<tt>va_arg</tt> macro in C.</p>
2091
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002092<h5>Arguments:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002093
2094<p>This instruction takes a <tt>va_list</tt> value and the type of the
2095argument. It returns a value of the specified argument type. Again, the actual
2096type of <tt>va_list</tt> is target specific.</p>
2097
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002098<h5>Semantics:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002099
2100<p>The '<tt>vaarg</tt>' instruction loads an argument of the specified type from
2101the specified <tt>va_list</tt>. In conjunction with the <a
2102href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to implement the
2103<tt>va_arg</tt> macro available in C. For more information, see the variable
2104argument handling <a href="#int_varargs">Intrinsic Functions</a>.</p>
2105
2106<p>It is legal for this instruction to be called in a function which does not
2107take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002108function.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002109
Misha Brukman9d0919f2003-11-08 01:05:38 +00002110<p><tt>vaarg</tt> is an LLVM instruction instead of an <a
Chris Lattnere19d7a72004-09-27 21:51:25 +00002111href="#intrinsics">intrinsic function</a> because it takes an type as an
2112argument.</p>
2113
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002114<h5>Example:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002115
2116<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
2117
Misha Brukman9d0919f2003-11-08 01:05:38 +00002118</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002119
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002120<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00002121<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
2122<!-- *********************************************************************** -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002123
Misha Brukman9d0919f2003-11-08 01:05:38 +00002124<div class="doc_text">
Chris Lattner33aec9e2004-02-12 17:01:32 +00002125
2126<p>LLVM supports the notion of an "intrinsic function". These functions have
2127well known names and semantics, and are required to follow certain
2128restrictions. Overall, these instructions represent an extension mechanism for
2129the LLVM language that does not require changing all of the transformations in
2130LLVM to add to the language (or the bytecode reader/writer, the parser,
2131etc...).</p>
2132
2133<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix, this
2134prefix is reserved in LLVM for intrinsic names, thus functions may not be named
2135this. Intrinsic functions must always be external functions: you cannot define
2136the body of intrinsic functions. Intrinsic functions may only be used in call
2137or invoke instructions: it is illegal to take the address of an intrinsic
2138function. Additionally, because intrinsic functions are part of the LLVM
2139language, it is required that they all be documented here if any are added.</p>
2140
2141
2142<p>
2143Adding an intrinsic to LLVM is straight-forward if it is possible to express the
2144concept in LLVM directly (ie, code generator support is not _required_). To do
2145this, extend the default implementation of the IntrinsicLowering class to handle
2146the intrinsic. Code generators use this class to lower intrinsics they do not
2147understand to raw LLVM instructions that they do.
2148</p>
2149
Misha Brukman9d0919f2003-11-08 01:05:38 +00002150</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002151
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002152<!-- ======================================================================= -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002153<div class="doc_subsection">
2154 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
2155</div>
2156
Misha Brukman9d0919f2003-11-08 01:05:38 +00002157<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00002158
Misha Brukman9d0919f2003-11-08 01:05:38 +00002159<p>Variable argument support is defined in LLVM with the <a
Chris Lattner261efe92003-11-25 01:02:51 +00002160 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
2161intrinsic functions. These functions are related to the similarly
2162named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002163
Chris Lattner261efe92003-11-25 01:02:51 +00002164<p>All of these functions operate on arguments that use a
2165target-specific value type "<tt>va_list</tt>". The LLVM assembly
2166language reference manual does not define what this type is, so all
2167transformations should be prepared to handle intrinsics with any type
2168used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002169
Misha Brukman9d0919f2003-11-08 01:05:38 +00002170<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner261efe92003-11-25 01:02:51 +00002171instruction and the variable argument handling intrinsic functions are
2172used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002173
Chris Lattner33aec9e2004-02-12 17:01:32 +00002174<pre>
2175int %test(int %X, ...) {
2176 ; Initialize variable argument processing
2177 %ap = call sbyte* %<a href="#i_va_start">llvm.va_start</a>()
2178
2179 ; Read a single integer argument
2180 %tmp = vaarg sbyte* %ap, int
2181
2182 ; Advance to the next argument
2183 %ap2 = vanext sbyte* %ap, int
2184
2185 ; Demonstrate usage of llvm.va_copy and llvm.va_end
2186 %aq = call sbyte* %<a href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2)
2187 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %aq)
2188
2189 ; Stop processing of arguments.
2190 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %ap2)
2191 ret int %tmp
2192}
2193</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002194</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002195
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002196<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002197<div class="doc_subsubsection">
2198 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
2199</div>
2200
2201
Misha Brukman9d0919f2003-11-08 01:05:38 +00002202<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002203<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002204<pre> call &lt;va_list&gt; ()* %llvm.va_start()<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002205<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002206<p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt>&lt;arglist&gt;</tt>
2207for subsequent use by the variable argument intrinsics.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002208<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002209<p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002210macro available in C. In a target-dependent way, it initializes and
2211returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt>
2212will produce the first variable argument passed to the function. Unlike
2213the C <tt>va_start</tt> macro, this intrinsic does not need to know the
2214last argument of the function, the compiler can figure that out.</p>
2215<p>Note that this intrinsic function is only legal to be called from
2216within the body of a variable argument function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002217</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002218
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002219<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002220<div class="doc_subsubsection">
2221 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
2222</div>
2223
Misha Brukman9d0919f2003-11-08 01:05:38 +00002224<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002225<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002226<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 +00002227<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002228<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
2229which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
2230or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002231<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002232<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002233<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002234<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002235macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
2236Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
2237 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
2238with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002239</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002240
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002241<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002242<div class="doc_subsubsection">
2243 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
2244</div>
2245
Misha Brukman9d0919f2003-11-08 01:05:38 +00002246<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00002247
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002248<h5>Syntax:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002249
2250<pre>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002251 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 +00002252</pre>
2253
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002254<h5>Overview:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002255
2256<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position
2257from the source argument list to the destination argument list.</p>
2258
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002259<h5>Arguments:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002260
Misha Brukman9d0919f2003-11-08 01:05:38 +00002261<p>The argument is the <tt>va_list</tt> to copy.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002262
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002263<h5>Semantics:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002264
Misha Brukman9d0919f2003-11-08 01:05:38 +00002265<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
Chris Lattnerd7923912004-05-23 21:06:01 +00002266macro available in C. In a target-dependent way, it copies the source
2267<tt>va_list</tt> element into the returned list. This intrinsic is necessary
Chris Lattnerfcd37252004-06-21 22:52:48 +00002268because the <tt><a href="#i_va_start">llvm.va_start</a></tt> intrinsic may be
Chris Lattnerd7923912004-05-23 21:06:01 +00002269arbitrarily complex and require memory allocation, for example.</p>
2270
Misha Brukman9d0919f2003-11-08 01:05:38 +00002271</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002272
Chris Lattner33aec9e2004-02-12 17:01:32 +00002273<!-- ======================================================================= -->
2274<div class="doc_subsection">
Chris Lattnerd7923912004-05-23 21:06:01 +00002275 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
2276</div>
2277
2278<div class="doc_text">
2279
2280<p>
2281LLVM support for <a href="GarbageCollection.html">Accurate Garbage
2282Collection</a> requires the implementation and generation of these intrinsics.
2283These intrinsics allow identification of <a href="#i_gcroot">GC roots on the
2284stack</a>, as well as garbage collector implementations that require <a
2285href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers.
2286Front-ends for type-safe garbage collected languages should generate these
2287intrinsics to make use of the LLVM garbage collectors. For more details, see <a
2288href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
2289</p>
2290</div>
2291
2292<!-- _______________________________________________________________________ -->
2293<div class="doc_subsubsection">
2294 <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
2295</div>
2296
2297<div class="doc_text">
2298
2299<h5>Syntax:</h5>
2300
2301<pre>
2302 call void (&lt;ty&gt;**, &lt;ty2&gt;*)* %llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
2303</pre>
2304
2305<h5>Overview:</h5>
2306
2307<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existance of a GC root to
2308the code generator, and allows some metadata to be associated with it.</p>
2309
2310<h5>Arguments:</h5>
2311
2312<p>The first argument specifies the address of a stack object that contains the
2313root pointer. The second pointer (which must be either a constant or a global
2314value address) contains the meta-data to be associated with the root.</p>
2315
2316<h5>Semantics:</h5>
2317
2318<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
2319location. At compile-time, the code generator generates information to allow
2320the runtime to find the pointer at GC safe points.
2321</p>
2322
2323</div>
2324
2325
2326<!-- _______________________________________________________________________ -->
2327<div class="doc_subsubsection">
2328 <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
2329</div>
2330
2331<div class="doc_text">
2332
2333<h5>Syntax:</h5>
2334
2335<pre>
2336 call sbyte* (sbyte**)* %llvm.gcread(sbyte** %Ptr)
2337</pre>
2338
2339<h5>Overview:</h5>
2340
2341<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
2342locations, allowing garbage collector implementations that require read
2343barriers.</p>
2344
2345<h5>Arguments:</h5>
2346
2347<p>The argument is the address to read from, which should be an address
2348allocated from the garbage collector.</p>
2349
2350<h5>Semantics:</h5>
2351
2352<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
2353instruction, but may be replaced with substantially more complex code by the
2354garbage collector runtime, as needed.</p>
2355
2356</div>
2357
2358
2359<!-- _______________________________________________________________________ -->
2360<div class="doc_subsubsection">
2361 <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
2362</div>
2363
2364<div class="doc_text">
2365
2366<h5>Syntax:</h5>
2367
2368<pre>
2369 call void (sbyte*, sbyte**)* %llvm.gcwrite(sbyte* %P1, sbyte** %P2)
2370</pre>
2371
2372<h5>Overview:</h5>
2373
2374<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
2375locations, allowing garbage collector implementations that require write
2376barriers (such as generational or reference counting collectors).</p>
2377
2378<h5>Arguments:</h5>
2379
2380<p>The first argument is the reference to store, and the second is the heap
2381location to store to.</p>
2382
2383<h5>Semantics:</h5>
2384
2385<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
2386instruction, but may be replaced with substantially more complex code by the
2387garbage collector runtime, as needed.</p>
2388
2389</div>
2390
2391
2392
2393<!-- ======================================================================= -->
2394<div class="doc_subsection">
Chris Lattner10610642004-02-14 04:08:35 +00002395 <a name="int_codegen">Code Generator Intrinsics</a>
2396</div>
2397
2398<div class="doc_text">
2399<p>
2400These intrinsics are provided by LLVM to expose special features that may only
2401be implemented with code generator support.
2402</p>
2403
2404</div>
2405
2406<!-- _______________________________________________________________________ -->
2407<div class="doc_subsubsection">
2408 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
2409</div>
2410
2411<div class="doc_text">
2412
2413<h5>Syntax:</h5>
2414<pre>
2415 call void* ()* %llvm.returnaddress(uint &lt;level&gt;)
2416</pre>
2417
2418<h5>Overview:</h5>
2419
2420<p>
2421The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
2422indicating the return address of the current function or one of its callers.
2423</p>
2424
2425<h5>Arguments:</h5>
2426
2427<p>
2428The argument to this intrinsic indicates which function to return the address
2429for. Zero indicates the calling function, one indicates its caller, etc. The
2430argument is <b>required</b> to be a constant integer value.
2431</p>
2432
2433<h5>Semantics:</h5>
2434
2435<p>
2436The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
2437the return address of the specified call frame, or zero if it cannot be
2438identified. The value returned by this intrinsic is likely to be incorrect or 0
2439for arguments other than zero, so it should only be used for debugging purposes.
2440</p>
2441
2442<p>
2443Note that calling this intrinsic does not prevent function inlining or other
2444aggressive transformations, so the value returned may not that of the obvious
2445source-language caller.
2446</p>
2447</div>
2448
2449
2450<!-- _______________________________________________________________________ -->
2451<div class="doc_subsubsection">
2452 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
2453</div>
2454
2455<div class="doc_text">
2456
2457<h5>Syntax:</h5>
2458<pre>
2459 call void* ()* %llvm.frameaddress(uint &lt;level&gt;)
2460</pre>
2461
2462<h5>Overview:</h5>
2463
2464<p>
2465The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
2466pointer value for the specified stack frame.
2467</p>
2468
2469<h5>Arguments:</h5>
2470
2471<p>
2472The argument to this intrinsic indicates which function to return the frame
2473pointer for. Zero indicates the calling function, one indicates its caller,
2474etc. The argument is <b>required</b> to be a constant integer value.
2475</p>
2476
2477<h5>Semantics:</h5>
2478
2479<p>
2480The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
2481the frame address of the specified call frame, or zero if it cannot be
2482identified. The value returned by this intrinsic is likely to be incorrect or 0
2483for arguments other than zero, so it should only be used for debugging purposes.
2484</p>
2485
2486<p>
2487Note that calling this intrinsic does not prevent function inlining or other
2488aggressive transformations, so the value returned may not that of the obvious
2489source-language caller.
2490</p>
2491</div>
2492
John Criswell7123e272004-04-09 16:43:20 +00002493<!-- ======================================================================= -->
2494<div class="doc_subsection">
2495 <a name="int_os">Operating System Intrinsics</a>
2496</div>
2497
2498<div class="doc_text">
2499<p>
2500These intrinsics are provided by LLVM to support the implementation of
2501operating system level code.
2502</p>
2503
2504</div>
John Criswell183402a2004-04-12 15:02:16 +00002505
John Criswellcfd3bac2004-04-09 15:23:37 +00002506<!-- _______________________________________________________________________ -->
2507<div class="doc_subsubsection">
2508 <a name="i_readport">'<tt>llvm.readport</tt>' Intrinsic</a>
2509</div>
2510
2511<div class="doc_text">
2512
2513<h5>Syntax:</h5>
2514<pre>
John Criswell7123e272004-04-09 16:43:20 +00002515 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 +00002516</pre>
2517
2518<h5>Overview:</h5>
2519
2520<p>
John Criswell7123e272004-04-09 16:43:20 +00002521The '<tt>llvm.readport</tt>' intrinsic reads data from the specified hardware
2522I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002523</p>
2524
2525<h5>Arguments:</h5>
2526
2527<p>
John Criswell7123e272004-04-09 16:43:20 +00002528The argument to this intrinsic indicates the hardware I/O address from which
2529to read the data. The address is in the hardware I/O address namespace (as
2530opposed to being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002531</p>
2532
2533<h5>Semantics:</h5>
2534
2535<p>
John Criswell7123e272004-04-09 16:43:20 +00002536The '<tt>llvm.readport</tt>' intrinsic reads data from the hardware I/O port
2537specified by <i>address</i> and returns the value. The address and return
2538value must be integers, but the size is dependent upon the platform upon which
2539the program is code generated. For example, on x86, the address must be an
2540unsigned 16 bit value, and the return value must be 8, 16, or 32 bits.
John Criswellcfd3bac2004-04-09 15:23:37 +00002541</p>
2542
2543</div>
2544
2545<!-- _______________________________________________________________________ -->
2546<div class="doc_subsubsection">
2547 <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a>
2548</div>
2549
2550<div class="doc_text">
2551
2552<h5>Syntax:</h5>
2553<pre>
Chris Lattnerc3f59762004-12-09 17:30:23 +00002554 call void (&lt;integer type&gt;, &lt;integer type&gt;)*
2555 %llvm.writeport (&lt;integer type&gt; &lt;value&gt;,
2556 &lt;integer type&gt; &lt;address&gt;)
John Criswellcfd3bac2004-04-09 15:23:37 +00002557</pre>
2558
2559<h5>Overview:</h5>
2560
2561<p>
John Criswell7123e272004-04-09 16:43:20 +00002562The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified hardware
2563I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002564</p>
2565
2566<h5>Arguments:</h5>
2567
2568<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002569The first argument is the value to write to the I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002570</p>
2571
2572<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002573The second argument indicates the hardware I/O address to which data should be
2574written. The address is in the hardware I/O address namespace (as opposed to
2575being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002576</p>
2577
2578<h5>Semantics:</h5>
2579
2580<p>
2581The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port
2582specified by <i>address</i>. The address and value must be integers, but the
2583size is dependent upon the platform upon which the program is code generated.
John Criswell7123e272004-04-09 16:43:20 +00002584For example, on x86, the address must be an unsigned 16 bit value, and the
2585value written must be 8, 16, or 32 bits in length.
John Criswellcfd3bac2004-04-09 15:23:37 +00002586</p>
2587
2588</div>
Chris Lattner10610642004-02-14 04:08:35 +00002589
John Criswell183402a2004-04-12 15:02:16 +00002590<!-- _______________________________________________________________________ -->
2591<div class="doc_subsubsection">
2592 <a name="i_readio">'<tt>llvm.readio</tt>' Intrinsic</a>
2593</div>
2594
2595<div class="doc_text">
2596
2597<h5>Syntax:</h5>
2598<pre>
John Criswell96db6fc2004-04-12 16:33:19 +00002599 call &lt;result&gt; (&lt;ty&gt;*)* %llvm.readio (&lt;ty&gt; * &lt;pointer&gt;)
John Criswell183402a2004-04-12 15:02:16 +00002600</pre>
2601
2602<h5>Overview:</h5>
2603
2604<p>
2605The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
2606address.
2607</p>
2608
2609<h5>Arguments:</h5>
2610
2611<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002612The argument to this intrinsic is a pointer indicating the memory address from
2613which to read the data. The data must be a
2614<a href="#t_firstclass">first class</a> type.
John Criswell183402a2004-04-12 15:02:16 +00002615</p>
2616
2617<h5>Semantics:</h5>
2618
2619<p>
2620The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
John Criswell96db6fc2004-04-12 16:33:19 +00002621location specified by <i>pointer</i> and returns the value. The argument must
2622be a pointer, and the return value must be a
2623<a href="#t_firstclass">first class</a> type. However, certain architectures
2624may not support I/O on all first class types. For example, 32 bit processors
2625may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00002626</p>
2627
2628<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002629This intrinsic enforces an in-order memory model for llvm.readio and
2630llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2631scheduled processors may execute loads and stores out of order, re-ordering at
2632run time accesses to memory mapped I/O registers. Using these intrinsics
2633ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00002634</p>
2635
2636</div>
2637
2638<!-- _______________________________________________________________________ -->
2639<div class="doc_subsubsection">
2640 <a name="i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a>
2641</div>
2642
2643<div class="doc_text">
2644
2645<h5>Syntax:</h5>
2646<pre>
John Criswell96db6fc2004-04-12 16:33:19 +00002647 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 +00002648</pre>
2649
2650<h5>Overview:</h5>
2651
2652<p>
2653The '<tt>llvm.writeio</tt>' intrinsic writes data to the specified memory
2654mapped I/O address.
2655</p>
2656
2657<h5>Arguments:</h5>
2658
2659<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002660The first argument is the value to write to the memory mapped I/O location.
2661The second argument is a pointer indicating the memory address to which the
2662data should be written.
John Criswell183402a2004-04-12 15:02:16 +00002663</p>
2664
2665<h5>Semantics:</h5>
2666
2667<p>
2668The '<tt>llvm.writeio</tt>' intrinsic writes <i>value</i> to the memory mapped
John Criswell96db6fc2004-04-12 16:33:19 +00002669I/O address specified by <i>pointer</i>. The value must be a
2670<a href="#t_firstclass">first class</a> type. However, certain architectures
2671may not support I/O on all first class types. For example, 32 bit processors
2672may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00002673</p>
2674
2675<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002676This intrinsic enforces an in-order memory model for llvm.readio and
2677llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2678scheduled processors may execute loads and stores out of order, re-ordering at
2679run time accesses to memory mapped I/O registers. Using these intrinsics
2680ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00002681</p>
2682
2683</div>
2684
Chris Lattner10610642004-02-14 04:08:35 +00002685<!-- ======================================================================= -->
2686<div class="doc_subsection">
Chris Lattner33aec9e2004-02-12 17:01:32 +00002687 <a name="int_libc">Standard C Library Intrinsics</a>
2688</div>
2689
2690<div class="doc_text">
2691<p>
Chris Lattner10610642004-02-14 04:08:35 +00002692LLVM provides intrinsics for a few important standard C library functions.
2693These intrinsics allow source-language front-ends to pass information about the
2694alignment of the pointer arguments to the code generator, providing opportunity
2695for more efficient code generation.
Chris Lattner33aec9e2004-02-12 17:01:32 +00002696</p>
2697
2698</div>
2699
2700<!-- _______________________________________________________________________ -->
2701<div class="doc_subsubsection">
2702 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
2703</div>
2704
2705<div class="doc_text">
2706
2707<h5>Syntax:</h5>
2708<pre>
2709 call void (sbyte*, sbyte*, uint, uint)* %llvm.memcpy(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2710 uint &lt;len&gt;, uint &lt;align&gt;)
2711</pre>
2712
2713<h5>Overview:</h5>
2714
2715<p>
2716The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2717location to the destination location.
2718</p>
2719
2720<p>
2721Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
2722does not return a value, and takes an extra alignment argument.
2723</p>
2724
2725<h5>Arguments:</h5>
2726
2727<p>
2728The first argument is a pointer to the destination, the second is a pointer to
2729the source. The third argument is an (arbitrarily sized) integer argument
2730specifying the number of bytes to copy, and the fourth argument is the alignment
2731of the source and destination locations.
2732</p>
2733
Chris Lattner3301ced2004-02-12 21:18:15 +00002734<p>
2735If the call to this intrinisic has an alignment value that is not 0 or 1, then
2736the caller guarantees that the size of the copy is a multiple of the alignment
2737and that both the source and destination pointers are aligned to that boundary.
2738</p>
2739
Chris Lattner33aec9e2004-02-12 17:01:32 +00002740<h5>Semantics:</h5>
2741
2742<p>
2743The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2744location to the destination location, which are not allowed to overlap. It
2745copies "len" bytes of memory over. If the argument is known to be aligned to
2746some boundary, this can be specified as the fourth argument, otherwise it should
2747be set to 0 or 1.
2748</p>
2749</div>
2750
2751
Chris Lattner0eb51b42004-02-12 18:10:10 +00002752<!-- _______________________________________________________________________ -->
2753<div class="doc_subsubsection">
2754 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
2755</div>
2756
2757<div class="doc_text">
2758
2759<h5>Syntax:</h5>
2760<pre>
2761 call void (sbyte*, sbyte*, uint, uint)* %llvm.memmove(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2762 uint &lt;len&gt;, uint &lt;align&gt;)
2763</pre>
2764
2765<h5>Overview:</h5>
2766
2767<p>
2768The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
2769location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>'
2770intrinsic but allows the two memory locations to overlap.
2771</p>
2772
2773<p>
2774Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
2775does not return a value, and takes an extra alignment argument.
2776</p>
2777
2778<h5>Arguments:</h5>
2779
2780<p>
2781The first argument is a pointer to the destination, the second is a pointer to
2782the source. The third argument is an (arbitrarily sized) integer argument
2783specifying the number of bytes to copy, and the fourth argument is the alignment
2784of the source and destination locations.
2785</p>
2786
Chris Lattner3301ced2004-02-12 21:18:15 +00002787<p>
2788If the call to this intrinisic has an alignment value that is not 0 or 1, then
2789the caller guarantees that the size of the copy is a multiple of the alignment
2790and that both the source and destination pointers are aligned to that boundary.
2791</p>
2792
Chris Lattner0eb51b42004-02-12 18:10:10 +00002793<h5>Semantics:</h5>
2794
2795<p>
2796The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
2797location to the destination location, which may overlap. It
2798copies "len" bytes of memory over. If the argument is known to be aligned to
2799some boundary, this can be specified as the fourth argument, otherwise it should
2800be set to 0 or 1.
2801</p>
2802</div>
2803
Chris Lattner8ff75902004-01-06 05:31:32 +00002804
Chris Lattner10610642004-02-14 04:08:35 +00002805<!-- _______________________________________________________________________ -->
2806<div class="doc_subsubsection">
2807 <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a>
2808</div>
2809
2810<div class="doc_text">
2811
2812<h5>Syntax:</h5>
2813<pre>
2814 call void (sbyte*, ubyte, uint, uint)* %llvm.memset(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
2815 uint &lt;len&gt;, uint &lt;align&gt;)
2816</pre>
2817
2818<h5>Overview:</h5>
2819
2820<p>
2821The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular
2822byte value.
2823</p>
2824
2825<p>
2826Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
2827does not return a value, and takes an extra alignment argument.
2828</p>
2829
2830<h5>Arguments:</h5>
2831
2832<p>
2833The first argument is a pointer to the destination to fill, the second is the
2834byte value to fill it with, the third argument is an (arbitrarily sized) integer
2835argument specifying the number of bytes to fill, and the fourth argument is the
2836known alignment of destination location.
2837</p>
2838
2839<p>
2840If the call to this intrinisic has an alignment value that is not 0 or 1, then
2841the caller guarantees that the size of the copy is a multiple of the alignment
2842and that the destination pointer is aligned to that boundary.
2843</p>
2844
2845<h5>Semantics:</h5>
2846
2847<p>
2848The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the
2849destination location. If the argument is known to be aligned to some boundary,
2850this can be specified as the fourth argument, otherwise it should be set to 0 or
28511.
2852</p>
2853</div>
2854
2855
Chris Lattner32006282004-06-11 02:28:03 +00002856<!-- _______________________________________________________________________ -->
2857<div class="doc_subsubsection">
Alkis Evlogimenos26bbe932004-06-13 01:16:15 +00002858 <a name="i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a>
2859</div>
2860
2861<div class="doc_text">
2862
2863<h5>Syntax:</h5>
2864<pre>
2865 call bool (&lt;float or double&gt;, &lt;float or double&gt;)* %llvm.isunordered(&lt;float or double&gt; Val1,
2866 &lt;float or double&gt; Val2)
2867</pre>
2868
2869<h5>Overview:</h5>
2870
2871<p>
2872The '<tt>llvm.isunordered</tt>' intrinsic returns true if either or both of the
2873specified floating point values is a NAN.
2874</p>
2875
2876<h5>Arguments:</h5>
2877
2878<p>
2879The arguments are floating point numbers of the same type.
2880</p>
2881
2882<h5>Semantics:</h5>
2883
2884<p>
2885If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise
2886false.
2887</p>
2888</div>
2889
2890
Chris Lattner32006282004-06-11 02:28:03 +00002891
2892
Chris Lattner8ff75902004-01-06 05:31:32 +00002893<!-- ======================================================================= -->
2894<div class="doc_subsection">
2895 <a name="int_debugger">Debugger Intrinsics</a>
2896</div>
2897
2898<div class="doc_text">
2899<p>
2900The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
2901are described in the <a
2902href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
2903Debugging</a> document.
2904</p>
2905</div>
2906
2907
Chris Lattner00950542001-06-06 20:29:01 +00002908<!-- *********************************************************************** -->
Chris Lattner00950542001-06-06 20:29:01 +00002909<hr>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002910<address>
2911 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
2912 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
2913 <a href="http://validator.w3.org/check/referer"><img
2914 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
2915
2916 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
2917 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
2918 Last modified: $Date$
2919</address>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002920</body>
2921</html>