blob: e4e2d44afbe22c0706b911b6e8a364db6c3ac898 [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
John Criswell9e2485c2004-12-10 15:51:16 +0000809 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
Chris Lattnerc3f59762004-12-09 17:30:23 +0000810 and must be of <a href="#t_pointer">pointer type</a>.</dd>
811
812</dl>
813
John Criswell9e2485c2004-12-10 15:51:16 +0000814<p>The one non-intuitive notation for constants is the optional hexadecimal form
Chris Lattnerc3f59762004-12-09 17:30:23 +0000815of 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
John Criswell9e2485c2004-12-10 15:51:16 +0000837 (<tt>{}</tt>)). For example: "<tt>{ int 4, float 17.0 }</tt>". Structure
Chris Lattnerc3f59762004-12-09 17:30:23 +0000838 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
John Criswell9e2485c2004-12-10 15:51:16 +0000846 (<tt>[]</tt>)). For example: "<tt>[ int 42, int 11, int 74 ]</tt>". Array
Chris Lattnerc3f59762004-12-09 17:30:23 +0000847 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
John Criswell9e2485c2004-12-10 15:51:16 +0000855 less-than/greater-than's (<tt>&lt;&gt;</tt>)). For example: "<tt>&lt; int 42,
Chris Lattnerc3f59762004-12-09 17:30:23 +0000856 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)
John Criswell9e2485c2004-12-10 15:51:16 +0000882constants. These constants are explicitly referenced when the <a
883href="#identifiers">identifier for the global</a> is used and always have <a
Chris Lattnerc3f59762004-12-09 17:30:23 +0000884href="#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>
John Criswell9e2485c2004-12-10 15:51:16 +0000967<p>There are six different terminator instructions: the '<a
Chris Lattner261efe92003-11-25 01:02:51 +0000968 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
969instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
Chris Lattner35eca582004-10-16 18:04:13 +0000970the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
971 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
972 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000973
Misha Brukman9d0919f2003-11-08 01:05:38 +0000974</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000975
Chris Lattner00950542001-06-06 20:29:01 +0000976<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000977<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
978Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000979<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000980<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000981<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 +0000982 ret void <i>; Return from void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000983</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000984<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000985<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
986value) from a function, back to the caller.</p>
John Criswell4457dc92004-04-09 16:48:45 +0000987<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner261efe92003-11-25 01:02:51 +0000988returns a value and then causes control flow, and one that just causes
989control flow to occur.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000990<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000991<p>The '<tt>ret</tt>' instruction may return any '<a
992 href="#t_firstclass">first class</a>' type. Notice that a function is
993not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
994instruction inside of the function that returns a value that does not
995match the return type of the function.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000996<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000997<p>When the '<tt>ret</tt>' instruction is executed, control flow
998returns back to the calling function's context. If the caller is a "<a
John Criswellfa081872004-06-25 15:16:57 +0000999 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner261efe92003-11-25 01:02:51 +00001000the instruction after the call. If the caller was an "<a
1001 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
1002at the beginning "normal" of the destination block. If the instruction
1003returns a value, that value shall set the call or invoke instruction's
1004return value.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001005<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001006<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001007 ret void <i>; Return from a void function</i>
Chris Lattner00950542001-06-06 20:29:01 +00001008</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001009</div>
Chris Lattner00950542001-06-06 20:29:01 +00001010<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001011<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001012<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001013<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001014<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 +00001015</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001016<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001017<p>The '<tt>br</tt>' instruction is used to cause control flow to
1018transfer to a different basic block in the current function. There are
1019two forms of this instruction, corresponding to a conditional branch
1020and an unconditional branch.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001021<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001022<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
1023single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
1024unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
1025value as a target.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001026<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001027<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
1028argument is evaluated. If the value is <tt>true</tt>, control flows
1029to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
1030control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001031<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001032<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
1033 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 +00001034</div>
Chris Lattner00950542001-06-06 20:29:01 +00001035<!-- _______________________________________________________________________ -->
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001036<div class="doc_subsubsection">
1037 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
1038</div>
1039
Misha Brukman9d0919f2003-11-08 01:05:38 +00001040<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001041<h5>Syntax:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001042
1043<pre>
1044 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
1045</pre>
1046
Chris Lattner00950542001-06-06 20:29:01 +00001047<h5>Overview:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001048
1049<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
1050several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +00001051instruction, allowing a branch to occur to one of many possible
1052destinations.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001053
1054
Chris Lattner00950542001-06-06 20:29:01 +00001055<h5>Arguments:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001056
1057<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
1058comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
1059an array of pairs of comparison value constants and '<tt>label</tt>'s. The
1060table is not allowed to contain duplicate constant entries.</p>
1061
Chris Lattner00950542001-06-06 20:29:01 +00001062<h5>Semantics:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001063
Chris Lattner261efe92003-11-25 01:02:51 +00001064<p>The <tt>switch</tt> instruction specifies a table of values and
1065destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswell84114752004-06-25 16:05:06 +00001066table is searched for the given value. If the value is found, control flow is
1067transfered to the corresponding destination; otherwise, control flow is
1068transfered to the default destination.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001069
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001070<h5>Implementation:</h5>
1071
1072<p>Depending on properties of the target machine and the particular
1073<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswell84114752004-06-25 16:05:06 +00001074ways. For example, it could be generated as a series of chained conditional
1075branches or with a lookup table.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001076
1077<h5>Example:</h5>
1078
1079<pre>
1080 <i>; Emulate a conditional br instruction</i>
1081 %Val = <a href="#i_cast">cast</a> bool %value to int
1082 switch int %Val, label %truedest [int 0, label %falsedest ]
1083
1084 <i>; Emulate an unconditional br instruction</i>
1085 switch uint 0, label %dest [ ]
1086
1087 <i>; Implement a jump table:</i>
1088 switch uint %val, label %otherwise [ uint 0, label %onzero
1089 uint 1, label %onone
1090 uint 2, label %ontwo ]
Chris Lattner00950542001-06-06 20:29:01 +00001091</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001092</div>
Chris Lattner00950542001-06-06 20:29:01 +00001093<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001094<div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>'
1095Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001096<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001097<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001098<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 +00001099<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001100<p>The '<tt>invoke</tt>' instruction causes control to transfer to a
1101specified function, with the possibility of control flow transfer to
1102either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>.
1103If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>"
1104instruction, control flow will return to the "normal" label. If the
1105callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
1106instruction, control is interrupted, and continued at the dynamically
1107nearest "except" label.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001108<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001109<p>This instruction requires several arguments:</p>
Chris Lattner00950542001-06-06 20:29:01 +00001110<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00001111 <li>'<tt>ptr to function ty</tt>': shall be the signature of the
1112pointer to function value being invoked. In most cases, this is a
1113direct function invocation, but indirect <tt>invoke</tt>s are just as
1114possible, branching off an arbitrary pointer to function value. </li>
1115 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer
1116to a function to be invoked. </li>
1117 <li>'<tt>function args</tt>': argument list whose types match the
1118function signature argument types. If the function signature indicates
1119the function accepts a variable number of arguments, the extra
1120arguments can be specified. </li>
1121 <li>'<tt>normal label</tt>': the label reached when the called
1122function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
1123 <li>'<tt>exception label</tt>': the label reached when a callee
1124returns with the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
Chris Lattner00950542001-06-06 20:29:01 +00001125</ol>
Chris Lattner00950542001-06-06 20:29:01 +00001126<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001127<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner261efe92003-11-25 01:02:51 +00001128 href="#i_call">call</a></tt>' instruction in most regards. The
1129primary difference is that it establishes an association with a label,
1130which is used by the runtime library to unwind the stack.</p>
1131<p>This instruction is used in languages with destructors to ensure
1132that proper cleanup is performed in the case of either a <tt>longjmp</tt>
1133or a thrown exception. Additionally, this is important for
1134implementation of '<tt>catch</tt>' clauses in high-level languages that
1135support them.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001136<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001137<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 +00001138</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001139</div>
Chris Lattner35eca582004-10-16 18:04:13 +00001140
1141
Chris Lattner27f71f22003-09-03 00:41:47 +00001142<!-- _______________________________________________________________________ -->
Chris Lattner35eca582004-10-16 18:04:13 +00001143
Chris Lattner261efe92003-11-25 01:02:51 +00001144<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
1145Instruction</a> </div>
Chris Lattner35eca582004-10-16 18:04:13 +00001146
Misha Brukman9d0919f2003-11-08 01:05:38 +00001147<div class="doc_text">
Chris Lattner35eca582004-10-16 18:04:13 +00001148
Chris Lattner27f71f22003-09-03 00:41:47 +00001149<h5>Syntax:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001150<pre>
1151 unwind
1152</pre>
1153
Chris Lattner27f71f22003-09-03 00:41:47 +00001154<h5>Overview:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001155
1156<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
1157at the first callee in the dynamic call stack which used an <a
1158href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
1159primarily used to implement exception handling.</p>
1160
Chris Lattner27f71f22003-09-03 00:41:47 +00001161<h5>Semantics:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001162
1163<p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to
1164immediately halt. The dynamic call stack is then searched for the first <a
1165href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
1166execution continues at the "exceptional" destination block specified by the
1167<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
1168dynamic call chain, undefined behavior results.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001169</div>
Chris Lattner35eca582004-10-16 18:04:13 +00001170
1171<!-- _______________________________________________________________________ -->
1172
1173<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
1174Instruction</a> </div>
1175
1176<div class="doc_text">
1177
1178<h5>Syntax:</h5>
1179<pre>
1180 unreachable
1181</pre>
1182
1183<h5>Overview:</h5>
1184
1185<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
1186instruction is used to inform the optimizer that a particular portion of the
1187code is not reachable. This can be used to indicate that the code after a
1188no-return function cannot be reached, and other facts.</p>
1189
1190<h5>Semantics:</h5>
1191
1192<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
1193</div>
1194
1195
1196
Chris Lattner00950542001-06-06 20:29:01 +00001197<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001198<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001199<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001200<p>Binary operators are used to do most of the computation in a
1201program. They require two operands, execute an operation on them, and
John Criswell9e2485c2004-12-10 15:51:16 +00001202produce a single value. The operands might represent
Chris Lattnera58561b2004-08-12 19:12:28 +00001203multiple data, as is the case with the <a href="#t_packed">packed</a> data type.
1204The result value of a binary operator is not
Chris Lattner261efe92003-11-25 01:02:51 +00001205necessarily the same type as its operands.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001206<p>There are several different binary operators:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001207</div>
Chris Lattner00950542001-06-06 20:29:01 +00001208<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001209<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
1210Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001211<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001212<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001213<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 +00001214</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001215<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001216<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001217<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001218<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattnera58561b2004-08-12 19:12:28 +00001219 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
1220 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1221Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001222<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001223<p>The value produced is the integer or floating point sum of the two
1224operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001225<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001226<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001227</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001228</div>
Chris Lattner00950542001-06-06 20:29:01 +00001229<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001230<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
1231Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001232<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001233<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001234<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 +00001235</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001236<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001237<p>The '<tt>sub</tt>' instruction returns the difference of its two
1238operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001239<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
1240instruction present in most other intermediate representations.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001241<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001242<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001243 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001244values.
1245This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1246Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001247<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001248<p>The value produced is the integer or floating point difference of
1249the two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001250<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001251<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001252 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
1253</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001254</div>
Chris Lattner00950542001-06-06 20:29:01 +00001255<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001256<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
1257Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001258<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001259<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001260<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 +00001261</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001262<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001263<p>The '<tt>mul</tt>' instruction returns the product of its two
1264operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001265<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001266<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001267 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001268values.
1269This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1270Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001271<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001272<p>The value produced is the integer or floating point product of the
Misha Brukman9d0919f2003-11-08 01:05:38 +00001273two operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001274<p>There is no signed vs unsigned multiplication. The appropriate
1275action is taken based on the type of the operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001276<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001277<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001278</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001279</div>
Chris Lattner00950542001-06-06 20:29:01 +00001280<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001281<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
1282Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001283<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001284<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001285<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1286</pre>
1287<h5>Overview:</h5>
1288<p>The '<tt>div</tt>' instruction returns the quotient of its two
1289operands.</p>
1290<h5>Arguments:</h5>
1291<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
1292 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001293values.
1294This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1295Both arguments must have identical types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001296<h5>Semantics:</h5>
1297<p>The value produced is the integer or floating point quotient of the
1298two operands.</p>
1299<h5>Example:</h5>
1300<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
1301</pre>
1302</div>
1303<!-- _______________________________________________________________________ -->
1304<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
1305Instruction</a> </div>
1306<div class="doc_text">
1307<h5>Syntax:</h5>
1308<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1309</pre>
1310<h5>Overview:</h5>
1311<p>The '<tt>rem</tt>' instruction returns the remainder from the
1312division of its two operands.</p>
1313<h5>Arguments:</h5>
1314<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1315 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001316values.
1317This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1318Both arguments must have identical types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001319<h5>Semantics:</h5>
1320<p>This returns the <i>remainder</i> of a division (where the result
1321has the same sign as the divisor), not the <i>modulus</i> (where the
1322result has the same sign as the dividend) of a value. For more
1323information about the difference, see: <a
1324 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1325Math Forum</a>.</p>
1326<h5>Example:</h5>
1327<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1328</pre>
1329</div>
1330<!-- _______________________________________________________________________ -->
1331<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1332Instructions</a> </div>
1333<div class="doc_text">
1334<h5>Syntax:</h5>
1335<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 +00001336 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1337 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1338 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1339 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1340 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1341</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001342<h5>Overview:</h5>
1343<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1344value based on a comparison of their two operands.</p>
1345<h5>Arguments:</h5>
1346<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1347be of <a href="#t_firstclass">first class</a> type (it is not possible
1348to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1349or '<tt>void</tt>' values, etc...). Both arguments must have identical
1350types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001351<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001352<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1353value if both operands are equal.<br>
1354The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1355value if both operands are unequal.<br>
1356The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1357value if the first operand is less than the second operand.<br>
1358The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1359value if the first operand is greater than the second operand.<br>
1360The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1361value if the first operand is less than or equal to the second operand.<br>
1362The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1363value if the first operand is greater than or equal to the second
1364operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001365<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001366<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner00950542001-06-06 20:29:01 +00001367 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
1368 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1369 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1370 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1371 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1372</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001373</div>
Chris Lattner00950542001-06-06 20:29:01 +00001374<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001375<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1376Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001377<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001378<p>Bitwise binary operators are used to do various forms of
1379bit-twiddling in a program. They are generally very efficient
John Criswell9e2485c2004-12-10 15:51:16 +00001380instructions and can commonly be strength reduced from other
Chris Lattner261efe92003-11-25 01:02:51 +00001381instructions. They require two operands, execute an operation on them,
1382and produce a single value. The resulting value of the bitwise binary
1383operators is always the same type as its first operand.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001384</div>
Chris Lattner00950542001-06-06 20:29:01 +00001385<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001386<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1387Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001388<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001389<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001390<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 +00001391</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001392<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001393<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1394its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001395<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001396<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001397 href="#t_integral">integral</a> values. Both arguments must have
1398identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001399<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001400<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001401<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001402<div style="align: center">
Misha Brukman9d0919f2003-11-08 01:05:38 +00001403<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +00001404 <tbody>
1405 <tr>
1406 <td>In0</td>
1407 <td>In1</td>
1408 <td>Out</td>
1409 </tr>
1410 <tr>
1411 <td>0</td>
1412 <td>0</td>
1413 <td>0</td>
1414 </tr>
1415 <tr>
1416 <td>0</td>
1417 <td>1</td>
1418 <td>0</td>
1419 </tr>
1420 <tr>
1421 <td>1</td>
1422 <td>0</td>
1423 <td>0</td>
1424 </tr>
1425 <tr>
1426 <td>1</td>
1427 <td>1</td>
1428 <td>1</td>
1429 </tr>
1430 </tbody>
1431</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001432</div>
Chris Lattner00950542001-06-06 20:29:01 +00001433<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001434<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001435 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1436 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1437</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001438</div>
Chris Lattner00950542001-06-06 20:29:01 +00001439<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001440<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001441<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001442<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001443<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 +00001444</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001445<h5>Overview:</h5>
1446<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1447or of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001448<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001449<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001450 href="#t_integral">integral</a> values. Both arguments must have
1451identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001452<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001453<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001454<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001455<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001456<table border="1" cellspacing="0" cellpadding="4">
1457 <tbody>
1458 <tr>
1459 <td>In0</td>
1460 <td>In1</td>
1461 <td>Out</td>
1462 </tr>
1463 <tr>
1464 <td>0</td>
1465 <td>0</td>
1466 <td>0</td>
1467 </tr>
1468 <tr>
1469 <td>0</td>
1470 <td>1</td>
1471 <td>1</td>
1472 </tr>
1473 <tr>
1474 <td>1</td>
1475 <td>0</td>
1476 <td>1</td>
1477 </tr>
1478 <tr>
1479 <td>1</td>
1480 <td>1</td>
1481 <td>1</td>
1482 </tr>
1483 </tbody>
1484</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001485</div>
Chris Lattner00950542001-06-06 20:29:01 +00001486<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001487<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001488 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1489 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1490</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001491</div>
Chris Lattner00950542001-06-06 20:29:01 +00001492<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001493<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1494Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001495<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001496<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001497<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 +00001498</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001499<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001500<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1501or of its two operands. The <tt>xor</tt> is used to implement the
1502"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001503<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001504<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001505 href="#t_integral">integral</a> values. Both arguments must have
1506identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001507<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001508<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001509<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001510<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001511<table border="1" cellspacing="0" cellpadding="4">
1512 <tbody>
1513 <tr>
1514 <td>In0</td>
1515 <td>In1</td>
1516 <td>Out</td>
1517 </tr>
1518 <tr>
1519 <td>0</td>
1520 <td>0</td>
1521 <td>0</td>
1522 </tr>
1523 <tr>
1524 <td>0</td>
1525 <td>1</td>
1526 <td>1</td>
1527 </tr>
1528 <tr>
1529 <td>1</td>
1530 <td>0</td>
1531 <td>1</td>
1532 </tr>
1533 <tr>
1534 <td>1</td>
1535 <td>1</td>
1536 <td>0</td>
1537 </tr>
1538 </tbody>
1539</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001540</div>
Chris Lattner261efe92003-11-25 01:02:51 +00001541<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001542<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001543<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001544 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1545 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner27f71f22003-09-03 00:41:47 +00001546 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner00950542001-06-06 20:29:01 +00001547</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001548</div>
Chris Lattner00950542001-06-06 20:29:01 +00001549<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001550<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1551Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001552<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001553<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001554<pre> &lt;result&gt; = shl &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001555</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001556<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001557<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1558the left a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001559<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001560<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001561 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1562type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001563<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001564<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001565<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001566<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 +00001567 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1568 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1569</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001570</div>
Chris Lattner00950542001-06-06 20:29:01 +00001571<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001572<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1573Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001574<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001575<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001576<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 +00001577</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001578<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001579<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1580the right a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001581<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001582<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001583 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1584type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001585<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001586<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1587most significant bit is duplicated in the newly free'd bit positions.
1588If the first argument is unsigned, zero bits shall fill the empty
1589positions.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001590<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001591<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 +00001592 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001593 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner8c6bb902003-06-18 21:30:51 +00001594 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1595 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner00950542001-06-06 20:29:01 +00001596</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001597</div>
Chris Lattner00950542001-06-06 20:29:01 +00001598<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001599<div class="doc_subsection"> <a name="memoryops">Memory Access
1600Operations</a></div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001601<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001602<p>A key design point of an SSA-based representation is how it
1603represents memory. In LLVM, no memory locations are in SSA form, which
1604makes things very simple. This section describes how to read, write,
John Criswell9e2485c2004-12-10 15:51:16 +00001605allocate, and free memory in LLVM.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001606</div>
Chris Lattner00950542001-06-06 20:29:01 +00001607<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001608<div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>'
1609Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001610<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001611<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001612<pre> &lt;result&gt; = malloc &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001613 &lt;result&gt; = malloc &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001614</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001615<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001616<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1617heap and returns a pointer to it.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001618<h5>Arguments:</h5>
John Criswell6e4ca612004-02-24 16:13:56 +00001619<p>The '<tt>malloc</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1620bytes of memory from the operating system and returns a pointer of the
Chris Lattner261efe92003-11-25 01:02:51 +00001621appropriate type to the program. The second form of the instruction is
1622a shorter version of the first instruction that defaults to allocating
1623one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001624<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001625<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001626<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1627a pointer is returned.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001628<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001629<pre> %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001630
Chris Lattner261efe92003-11-25 01:02:51 +00001631 %size = <a
1632 href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001633 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1634 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001635</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001636</div>
Chris Lattner00950542001-06-06 20:29:01 +00001637<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001638<div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>'
1639Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001640<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001641<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001642<pre> free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner00950542001-06-06 20:29:01 +00001643</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001644<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001645<p>The '<tt>free</tt>' instruction returns memory back to the unused
1646memory heap, to be reallocated in the future.</p>
1647<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001648<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001649<p>'<tt>value</tt>' shall be a pointer value that points to a value
1650that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1651instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001652<h5>Semantics:</h5>
John Criswell9e2485c2004-12-10 15:51:16 +00001653<p>Access to the memory pointed to by the pointer is no longer defined
Chris Lattner261efe92003-11-25 01:02:51 +00001654after this instruction executes.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001655<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001656<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 +00001657 free [4 x ubyte]* %array
1658</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001659</div>
Chris Lattner00950542001-06-06 20:29:01 +00001660<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001661<div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>'
1662Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001663<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001664<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001665<pre> &lt;result&gt; = alloca &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001666 &lt;result&gt; = alloca &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001667</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001668<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001669<p>The '<tt>alloca</tt>' instruction allocates memory on the current
1670stack frame of the procedure that is live until the current function
1671returns to its caller.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001672<h5>Arguments:</h5>
John Criswell9e2485c2004-12-10 15:51:16 +00001673<p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001674bytes of memory on the runtime stack, returning a pointer of the
1675appropriate type to the program. The second form of the instruction is
1676a shorter version of the first that defaults to allocating one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001677<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001678<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001679<p>Memory is allocated, a pointer is returned. '<tt>alloca</tt>'d
1680memory is automatically released when the function returns. The '<tt>alloca</tt>'
1681instruction is commonly used to represent automatic variables that must
1682have an address available. When the function returns (either with the <tt><a
1683 href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001684instructions), the memory is reclaimed.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001685<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001686<pre> %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001687 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner00950542001-06-06 20:29:01 +00001688</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001689</div>
Chris Lattner00950542001-06-06 20:29:01 +00001690<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001691<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1692Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001693<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00001694<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001695<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 +00001696<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001697<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001698<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001699<p>The argument to the '<tt>load</tt>' instruction specifies the memory
1700address to load from. The pointer must point to a <a
Chris Lattnere53e5082004-06-03 22:57:15 +00001701 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
Chris Lattner261efe92003-11-25 01:02:51 +00001702marked as <tt>volatile</tt> then the optimizer is not allowed to modify
1703the number or order of execution of this <tt>load</tt> with other
1704volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1705instructions. </p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001706<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001707<p>The location of memory pointed to is loaded.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001708<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001709<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1710 <a
1711 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001712 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1713</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001714</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001715<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001716<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1717Instruction</a> </div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001718<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001719<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 +00001720 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 +00001721</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001722<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001723<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001724<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001725<p>There are two arguments to the '<tt>store</tt>' instruction: a value
1726to store and an address to store it into. The type of the '<tt>&lt;pointer&gt;</tt>'
1727operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
1728operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the
1729optimizer is not allowed to modify the number or order of execution of
1730this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1731 href="#i_store">store</a></tt> instructions.</p>
1732<h5>Semantics:</h5>
1733<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
1734at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001735<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001736<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1737 <a
1738 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001739 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1740</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001741<!-- _______________________________________________________________________ -->
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001742<div class="doc_subsubsection">
1743 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
1744</div>
1745
Misha Brukman9d0919f2003-11-08 01:05:38 +00001746<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00001747<h5>Syntax:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001748<pre>
1749 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
1750</pre>
1751
Chris Lattner7faa8832002-04-14 06:13:44 +00001752<h5>Overview:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001753
1754<p>
1755The '<tt>getelementptr</tt>' instruction is used to get the address of a
1756subelement of an aggregate data structure.</p>
1757
Chris Lattner7faa8832002-04-14 06:13:44 +00001758<h5>Arguments:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001759
1760<p>This instruction takes a list of integer constants that indicate what
1761elements of the aggregate object to index to. The actual types of the arguments
1762provided depend on the type of the first pointer argument. The
1763'<tt>getelementptr</tt>' instruction is used to index down through the type
1764levels of a structure. When indexing into a structure, only <tt>uint</tt>
1765integer constants are allowed. When indexing into an array or pointer
1766<tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
1767
Chris Lattner261efe92003-11-25 01:02:51 +00001768<p>For example, let's consider a C code fragment and how it gets
1769compiled to LLVM:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001770
1771<pre>
1772 struct RT {
1773 char A;
1774 int B[10][20];
1775 char C;
1776 };
1777 struct ST {
1778 int X;
1779 double Y;
1780 struct RT Z;
1781 };
1782
1783 int *foo(struct ST *s) {
1784 return &amp;s[1].Z.B[5][13];
1785 }
1786</pre>
1787
Misha Brukman9d0919f2003-11-08 01:05:38 +00001788<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001789
1790<pre>
1791 %RT = type { sbyte, [10 x [20 x int]], sbyte }
1792 %ST = type { int, double, %RT }
1793
Brian Gaeke7283e7c2004-07-02 21:08:14 +00001794 implementation
1795
1796 int* %foo(%ST* %s) {
1797 entry:
1798 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001799 ret int* %reg
1800 }
1801</pre>
1802
Chris Lattner7faa8832002-04-14 06:13:44 +00001803<h5>Semantics:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001804
1805<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
Chris Lattnere53e5082004-06-03 22:57:15 +00001806on the pointer type that is being index into. <a href="#t_pointer">Pointer</a>
1807and <a href="#t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
1808<tt>ulong</tt>, or <tt>long</tt> values, and <a href="#t_struct">structure</a>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001809types require <tt>uint</tt> <b>constants</b>.</p>
1810
Misha Brukman9d0919f2003-11-08 01:05:38 +00001811<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001812type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
1813}</tt>' type, a structure. The second index indexes into the third element of
1814the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
1815sbyte }</tt>' type, another structure. The third index indexes into the second
1816element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
1817array. The two dimensions of the array are subscripted into, yielding an
1818'<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction return a pointer
1819to this element, thus computing a value of '<tt>int*</tt>' type.</p>
1820
Chris Lattner261efe92003-11-25 01:02:51 +00001821<p>Note that it is perfectly legal to index partially through a
1822structure, returning a pointer to an inner element. Because of this,
1823the LLVM code for the given testcase is equivalent to:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001824
1825<pre>
1826 int* "foo"(%ST* %s) {
1827 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
1828 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
1829 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
1830 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
1831 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
1832 ret int* %t5
1833 }
Chris Lattner6536cfe2002-05-06 22:08:29 +00001834</pre>
Chris Lattner7faa8832002-04-14 06:13:44 +00001835<h5>Example:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001836<pre>
1837 <i>; yields [12 x ubyte]*:aptr</i>
1838 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
1839</pre>
1840
1841</div>
Chris Lattner00950542001-06-06 20:29:01 +00001842<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001843<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001844<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +00001845<p>The instructions in this category are the "miscellaneous"
Chris Lattner261efe92003-11-25 01:02:51 +00001846instructions, which defy better classification.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001847</div>
Chris Lattner00950542001-06-06 20:29:01 +00001848<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001849<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
1850Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001851<div class="doc_text">
Chris Lattner33ba0d92001-07-09 00:26:23 +00001852<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001853<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001854<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001855<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
1856the SSA graph representing the function.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001857<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001858<p>The type of the incoming values are specified with the first type
1859field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
1860as arguments, with one pair for each predecessor basic block of the
1861current block. Only values of <a href="#t_firstclass">first class</a>
1862type may be used as the value arguments to the PHI node. Only labels
1863may be used as the label arguments.</p>
1864<p>There must be no non-phi instructions between the start of a basic
1865block and the PHI instructions: i.e. PHI instructions must be first in
1866a basic block.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001867<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001868<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
1869value specified by the parameter, depending on which basic block we
1870came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001871<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001872<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 +00001873</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001874
Chris Lattner6536cfe2002-05-06 22:08:29 +00001875<!-- _______________________________________________________________________ -->
Chris Lattnercc37aae2004-03-12 05:50:16 +00001876<div class="doc_subsubsection">
1877 <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
1878</div>
1879
Misha Brukman9d0919f2003-11-08 01:05:38 +00001880<div class="doc_text">
Chris Lattnercc37aae2004-03-12 05:50:16 +00001881
Chris Lattner6536cfe2002-05-06 22:08:29 +00001882<h5>Syntax:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001883
1884<pre>
1885 &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 +00001886</pre>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001887
Chris Lattner6536cfe2002-05-06 22:08:29 +00001888<h5>Overview:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001889
1890<p>
1891The '<tt>cast</tt>' instruction is used as the primitive means to convert
1892integers to floating point, change data type sizes, and break type safety (by
1893casting pointers).
1894</p>
1895
1896
Chris Lattner6536cfe2002-05-06 22:08:29 +00001897<h5>Arguments:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001898
1899<p>
1900The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
1901class value, and a type to cast it to, which must also be a <a
1902href="#t_firstclass">first class</a> type.
1903</p>
1904
Chris Lattner6536cfe2002-05-06 22:08:29 +00001905<h5>Semantics:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001906
1907<p>
1908This instruction follows the C rules for explicit casts when determining how the
1909data being cast must change to fit in its new container.
1910</p>
1911
1912<p>
1913When casting to bool, any value that would be considered true in the context of
1914a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
1915all else are '<tt>false</tt>'.
1916</p>
1917
1918<p>
1919When extending an integral value from a type of one signness to another (for
1920example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
1921<b>source</b> value is signed, and zero-extended if the source value is
1922unsigned. <tt>bool</tt> values are always zero extended into either zero or
1923one.
1924</p>
1925
Chris Lattner33ba0d92001-07-09 00:26:23 +00001926<h5>Example:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001927
1928<pre>
1929 %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattner7bae3952002-06-25 18:03:17 +00001930 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001931</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001932</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001933
1934<!-- _______________________________________________________________________ -->
1935<div class="doc_subsubsection">
1936 <a name="i_select">'<tt>select</tt>' Instruction</a>
1937</div>
1938
1939<div class="doc_text">
1940
1941<h5>Syntax:</h5>
1942
1943<pre>
1944 &lt;result&gt; = select bool &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
1945</pre>
1946
1947<h5>Overview:</h5>
1948
1949<p>
1950The '<tt>select</tt>' instruction is used to choose one value based on a
1951condition, without branching.
1952</p>
1953
1954
1955<h5>Arguments:</h5>
1956
1957<p>
1958The '<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.
1959</p>
1960
1961<h5>Semantics:</h5>
1962
1963<p>
1964If the boolean condition evaluates to true, the instruction returns the first
1965value argument, otherwise it returns the second value argument.
1966</p>
1967
1968<h5>Example:</h5>
1969
1970<pre>
1971 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
1972</pre>
1973</div>
1974
1975
1976
1977
1978
Chris Lattner33ba0d92001-07-09 00:26:23 +00001979<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001980<div class="doc_subsubsection"> <a name="i_call">'<tt>call</tt>'
1981Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001982<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001983<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001984<pre> &lt;result&gt; = call &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +00001985<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001986<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001987<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001988<p>This instruction requires several arguments:</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001989<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00001990 <li>
1991 <p>'<tt>ty</tt>': shall be the signature of the pointer to function
1992value being invoked. The argument types must match the types implied
1993by this signature.</p>
1994 </li>
1995 <li>
1996 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a
1997function to be invoked. In most cases, this is a direct function
1998invocation, but indirect <tt>call</tt>s are just as possible,
1999calling an arbitrary pointer to function values.</p>
2000 </li>
2001 <li>
2002 <p>'<tt>function args</tt>': argument list whose types match the
2003function signature argument types. If the function signature
2004indicates the function accepts a variable number of arguments, the
2005extra arguments can be specified.</p>
2006 </li>
Chris Lattner6536cfe2002-05-06 22:08:29 +00002007</ol>
Chris Lattner00950542001-06-06 20:29:01 +00002008<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002009<p>The '<tt>call</tt>' instruction is used to cause control flow to
2010transfer to a specified function, with its incoming arguments bound to
2011the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
2012instruction in the called function, control flow continues with the
2013instruction after the function call, and the return value of the
2014function is bound to the result argument. This is a simpler case of
2015the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002016<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002017<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 +00002018</div>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002019
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002020<!-- _______________________________________________________________________ -->
Chris Lattnere19d7a72004-09-27 21:51:25 +00002021<div class="doc_subsubsection">
2022 <a name="i_vanext">'<tt>vanext</tt>' Instruction</a>
2023</div>
2024
Misha Brukman9d0919f2003-11-08 01:05:38 +00002025<div class="doc_text">
Chris Lattnere19d7a72004-09-27 21:51:25 +00002026
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002027<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002028
2029<pre>
2030 &lt;resultarglist&gt; = vanext &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;
2031</pre>
2032
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002033<h5>Overview:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002034
Chris Lattner261efe92003-11-25 01:02:51 +00002035<p>The '<tt>vanext</tt>' instruction is used to access arguments passed
2036through the "variable argument" area of a function call. It is used to
2037implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002038
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002039<h5>Arguments:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002040
2041<p>This instruction takes a <tt>va_list</tt> value and the type of the
2042argument. It returns another <tt>va_list</tt>. The actual type of
2043<tt>va_list</tt> may be defined differently for different targets. Most targets
2044use a <tt>va_list</tt> type of <tt>sbyte*</tt> or some other pointer type.</p>
2045
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002046<h5>Semantics:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002047
2048<p>The '<tt>vanext</tt>' instruction advances the specified <tt>va_list</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002049past an argument of the specified type. In conjunction with the <a
2050 href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement
2051the <tt>va_arg</tt> macro available in C. For more information, see
2052the variable argument handling <a href="#int_varargs">Intrinsic
2053Functions</a>.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002054
Chris Lattner261efe92003-11-25 01:02:51 +00002055<p>It is legal for this instruction to be called in a function which
2056does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002057function.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002058
Misha Brukman9d0919f2003-11-08 01:05:38 +00002059<p><tt>vanext</tt> is an LLVM instruction instead of an <a
Chris Lattnere19d7a72004-09-27 21:51:25 +00002060href="#intrinsics">intrinsic function</a> because it takes a type as an
2061argument. The type refers to the current argument in the <tt>va_list</tt>, it
2062tells the compiler how far on the stack it needs to advance to find the next
2063argument</p>
2064
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002065<h5>Example:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002066
Chris Lattner261efe92003-11-25 01:02:51 +00002067<p>See the <a href="#int_varargs">variable argument processing</a>
2068section.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002069
Misha Brukman9d0919f2003-11-08 01:05:38 +00002070</div>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002071
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002072<!-- _______________________________________________________________________ -->
Chris Lattnere19d7a72004-09-27 21:51:25 +00002073<div class="doc_subsubsection">
2074 <a name="i_vaarg">'<tt>vaarg</tt>' Instruction</a>
2075</div>
2076
Misha Brukman9d0919f2003-11-08 01:05:38 +00002077<div class="doc_text">
Chris Lattnere19d7a72004-09-27 21:51:25 +00002078
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002079<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002080
2081<pre>
2082 &lt;resultval&gt; = vaarg &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;
2083</pre>
2084
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002085<h5>Overview:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002086
2087<p>The '<tt>vaarg</tt>' instruction is used to access arguments passed through
2088the "variable argument" area of a function call. It is used to implement the
2089<tt>va_arg</tt> macro in C.</p>
2090
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002091<h5>Arguments:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002092
2093<p>This instruction takes a <tt>va_list</tt> value and the type of the
2094argument. It returns a value of the specified argument type. Again, the actual
2095type of <tt>va_list</tt> is target specific.</p>
2096
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002097<h5>Semantics:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002098
2099<p>The '<tt>vaarg</tt>' instruction loads an argument of the specified type from
2100the specified <tt>va_list</tt>. In conjunction with the <a
2101href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to implement the
2102<tt>va_arg</tt> macro available in C. For more information, see the variable
2103argument handling <a href="#int_varargs">Intrinsic Functions</a>.</p>
2104
2105<p>It is legal for this instruction to be called in a function which does not
2106take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002107function.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002108
Misha Brukman9d0919f2003-11-08 01:05:38 +00002109<p><tt>vaarg</tt> is an LLVM instruction instead of an <a
Chris Lattnere19d7a72004-09-27 21:51:25 +00002110href="#intrinsics">intrinsic function</a> because it takes an type as an
2111argument.</p>
2112
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002113<h5>Example:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002114
2115<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
2116
Misha Brukman9d0919f2003-11-08 01:05:38 +00002117</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002118
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002119<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00002120<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
2121<!-- *********************************************************************** -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002122
Misha Brukman9d0919f2003-11-08 01:05:38 +00002123<div class="doc_text">
Chris Lattner33aec9e2004-02-12 17:01:32 +00002124
2125<p>LLVM supports the notion of an "intrinsic function". These functions have
2126well known names and semantics, and are required to follow certain
2127restrictions. Overall, these instructions represent an extension mechanism for
2128the LLVM language that does not require changing all of the transformations in
2129LLVM to add to the language (or the bytecode reader/writer, the parser,
2130etc...).</p>
2131
2132<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix, this
2133prefix is reserved in LLVM for intrinsic names, thus functions may not be named
2134this. Intrinsic functions must always be external functions: you cannot define
2135the body of intrinsic functions. Intrinsic functions may only be used in call
2136or invoke instructions: it is illegal to take the address of an intrinsic
2137function. Additionally, because intrinsic functions are part of the LLVM
2138language, it is required that they all be documented here if any are added.</p>
2139
2140
2141<p>
2142Adding an intrinsic to LLVM is straight-forward if it is possible to express the
2143concept in LLVM directly (ie, code generator support is not _required_). To do
2144this, extend the default implementation of the IntrinsicLowering class to handle
2145the intrinsic. Code generators use this class to lower intrinsics they do not
2146understand to raw LLVM instructions that they do.
2147</p>
2148
Misha Brukman9d0919f2003-11-08 01:05:38 +00002149</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002150
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002151<!-- ======================================================================= -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002152<div class="doc_subsection">
2153 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
2154</div>
2155
Misha Brukman9d0919f2003-11-08 01:05:38 +00002156<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00002157
Misha Brukman9d0919f2003-11-08 01:05:38 +00002158<p>Variable argument support is defined in LLVM with the <a
Chris Lattner261efe92003-11-25 01:02:51 +00002159 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
2160intrinsic functions. These functions are related to the similarly
2161named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002162
Chris Lattner261efe92003-11-25 01:02:51 +00002163<p>All of these functions operate on arguments that use a
2164target-specific value type "<tt>va_list</tt>". The LLVM assembly
2165language reference manual does not define what this type is, so all
2166transformations should be prepared to handle intrinsics with any type
2167used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002168
Misha Brukman9d0919f2003-11-08 01:05:38 +00002169<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner261efe92003-11-25 01:02:51 +00002170instruction and the variable argument handling intrinsic functions are
2171used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002172
Chris Lattner33aec9e2004-02-12 17:01:32 +00002173<pre>
2174int %test(int %X, ...) {
2175 ; Initialize variable argument processing
2176 %ap = call sbyte* %<a href="#i_va_start">llvm.va_start</a>()
2177
2178 ; Read a single integer argument
2179 %tmp = vaarg sbyte* %ap, int
2180
2181 ; Advance to the next argument
2182 %ap2 = vanext sbyte* %ap, int
2183
2184 ; Demonstrate usage of llvm.va_copy and llvm.va_end
2185 %aq = call sbyte* %<a href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2)
2186 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %aq)
2187
2188 ; Stop processing of arguments.
2189 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %ap2)
2190 ret int %tmp
2191}
2192</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002193</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002194
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002195<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002196<div class="doc_subsubsection">
2197 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
2198</div>
2199
2200
Misha Brukman9d0919f2003-11-08 01:05:38 +00002201<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002202<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002203<pre> call &lt;va_list&gt; ()* %llvm.va_start()<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002204<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002205<p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt>&lt;arglist&gt;</tt>
2206for subsequent use by the variable argument intrinsics.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002207<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002208<p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002209macro available in C. In a target-dependent way, it initializes and
2210returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt>
2211will produce the first variable argument passed to the function. Unlike
2212the C <tt>va_start</tt> macro, this intrinsic does not need to know the
2213last argument of the function, the compiler can figure that out.</p>
2214<p>Note that this intrinsic function is only legal to be called from
2215within the body of a variable argument function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002216</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002217
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002218<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002219<div class="doc_subsubsection">
2220 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
2221</div>
2222
Misha Brukman9d0919f2003-11-08 01:05:38 +00002223<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002224<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002225<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 +00002226<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002227<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
2228which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
2229or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002230<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002231<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002232<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002233<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002234macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
2235Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
2236 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
2237with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002238</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002239
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002240<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002241<div class="doc_subsubsection">
2242 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
2243</div>
2244
Misha Brukman9d0919f2003-11-08 01:05:38 +00002245<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00002246
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002247<h5>Syntax:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002248
2249<pre>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002250 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 +00002251</pre>
2252
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002253<h5>Overview:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002254
2255<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position
2256from the source argument list to the destination argument list.</p>
2257
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002258<h5>Arguments:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002259
Misha Brukman9d0919f2003-11-08 01:05:38 +00002260<p>The argument is the <tt>va_list</tt> to copy.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002261
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002262<h5>Semantics:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002263
Misha Brukman9d0919f2003-11-08 01:05:38 +00002264<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
Chris Lattnerd7923912004-05-23 21:06:01 +00002265macro available in C. In a target-dependent way, it copies the source
2266<tt>va_list</tt> element into the returned list. This intrinsic is necessary
Chris Lattnerfcd37252004-06-21 22:52:48 +00002267because the <tt><a href="#i_va_start">llvm.va_start</a></tt> intrinsic may be
Chris Lattnerd7923912004-05-23 21:06:01 +00002268arbitrarily complex and require memory allocation, for example.</p>
2269
Misha Brukman9d0919f2003-11-08 01:05:38 +00002270</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002271
Chris Lattner33aec9e2004-02-12 17:01:32 +00002272<!-- ======================================================================= -->
2273<div class="doc_subsection">
Chris Lattnerd7923912004-05-23 21:06:01 +00002274 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
2275</div>
2276
2277<div class="doc_text">
2278
2279<p>
2280LLVM support for <a href="GarbageCollection.html">Accurate Garbage
2281Collection</a> requires the implementation and generation of these intrinsics.
2282These intrinsics allow identification of <a href="#i_gcroot">GC roots on the
2283stack</a>, as well as garbage collector implementations that require <a
2284href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers.
2285Front-ends for type-safe garbage collected languages should generate these
2286intrinsics to make use of the LLVM garbage collectors. For more details, see <a
2287href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
2288</p>
2289</div>
2290
2291<!-- _______________________________________________________________________ -->
2292<div class="doc_subsubsection">
2293 <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
2294</div>
2295
2296<div class="doc_text">
2297
2298<h5>Syntax:</h5>
2299
2300<pre>
2301 call void (&lt;ty&gt;**, &lt;ty2&gt;*)* %llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
2302</pre>
2303
2304<h5>Overview:</h5>
2305
John Criswell9e2485c2004-12-10 15:51:16 +00002306<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
Chris Lattnerd7923912004-05-23 21:06:01 +00002307the code generator, and allows some metadata to be associated with it.</p>
2308
2309<h5>Arguments:</h5>
2310
2311<p>The first argument specifies the address of a stack object that contains the
2312root pointer. The second pointer (which must be either a constant or a global
2313value address) contains the meta-data to be associated with the root.</p>
2314
2315<h5>Semantics:</h5>
2316
2317<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
2318location. At compile-time, the code generator generates information to allow
2319the runtime to find the pointer at GC safe points.
2320</p>
2321
2322</div>
2323
2324
2325<!-- _______________________________________________________________________ -->
2326<div class="doc_subsubsection">
2327 <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
2328</div>
2329
2330<div class="doc_text">
2331
2332<h5>Syntax:</h5>
2333
2334<pre>
2335 call sbyte* (sbyte**)* %llvm.gcread(sbyte** %Ptr)
2336</pre>
2337
2338<h5>Overview:</h5>
2339
2340<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
2341locations, allowing garbage collector implementations that require read
2342barriers.</p>
2343
2344<h5>Arguments:</h5>
2345
2346<p>The argument is the address to read from, which should be an address
2347allocated from the garbage collector.</p>
2348
2349<h5>Semantics:</h5>
2350
2351<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
2352instruction, but may be replaced with substantially more complex code by the
2353garbage collector runtime, as needed.</p>
2354
2355</div>
2356
2357
2358<!-- _______________________________________________________________________ -->
2359<div class="doc_subsubsection">
2360 <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
2361</div>
2362
2363<div class="doc_text">
2364
2365<h5>Syntax:</h5>
2366
2367<pre>
2368 call void (sbyte*, sbyte**)* %llvm.gcwrite(sbyte* %P1, sbyte** %P2)
2369</pre>
2370
2371<h5>Overview:</h5>
2372
2373<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
2374locations, allowing garbage collector implementations that require write
2375barriers (such as generational or reference counting collectors).</p>
2376
2377<h5>Arguments:</h5>
2378
2379<p>The first argument is the reference to store, and the second is the heap
2380location to store to.</p>
2381
2382<h5>Semantics:</h5>
2383
2384<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
2385instruction, but may be replaced with substantially more complex code by the
2386garbage collector runtime, as needed.</p>
2387
2388</div>
2389
2390
2391
2392<!-- ======================================================================= -->
2393<div class="doc_subsection">
Chris Lattner10610642004-02-14 04:08:35 +00002394 <a name="int_codegen">Code Generator Intrinsics</a>
2395</div>
2396
2397<div class="doc_text">
2398<p>
2399These intrinsics are provided by LLVM to expose special features that may only
2400be implemented with code generator support.
2401</p>
2402
2403</div>
2404
2405<!-- _______________________________________________________________________ -->
2406<div class="doc_subsubsection">
2407 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
2408</div>
2409
2410<div class="doc_text">
2411
2412<h5>Syntax:</h5>
2413<pre>
2414 call void* ()* %llvm.returnaddress(uint &lt;level&gt;)
2415</pre>
2416
2417<h5>Overview:</h5>
2418
2419<p>
2420The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
2421indicating the return address of the current function or one of its callers.
2422</p>
2423
2424<h5>Arguments:</h5>
2425
2426<p>
2427The argument to this intrinsic indicates which function to return the address
2428for. Zero indicates the calling function, one indicates its caller, etc. The
2429argument is <b>required</b> to be a constant integer value.
2430</p>
2431
2432<h5>Semantics:</h5>
2433
2434<p>
2435The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
2436the return address of the specified call frame, or zero if it cannot be
2437identified. The value returned by this intrinsic is likely to be incorrect or 0
2438for arguments other than zero, so it should only be used for debugging purposes.
2439</p>
2440
2441<p>
2442Note that calling this intrinsic does not prevent function inlining or other
2443aggressive transformations, so the value returned may not that of the obvious
2444source-language caller.
2445</p>
2446</div>
2447
2448
2449<!-- _______________________________________________________________________ -->
2450<div class="doc_subsubsection">
2451 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
2452</div>
2453
2454<div class="doc_text">
2455
2456<h5>Syntax:</h5>
2457<pre>
2458 call void* ()* %llvm.frameaddress(uint &lt;level&gt;)
2459</pre>
2460
2461<h5>Overview:</h5>
2462
2463<p>
2464The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
2465pointer value for the specified stack frame.
2466</p>
2467
2468<h5>Arguments:</h5>
2469
2470<p>
2471The argument to this intrinsic indicates which function to return the frame
2472pointer for. Zero indicates the calling function, one indicates its caller,
2473etc. The argument is <b>required</b> to be a constant integer value.
2474</p>
2475
2476<h5>Semantics:</h5>
2477
2478<p>
2479The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
2480the frame address of the specified call frame, or zero if it cannot be
2481identified. The value returned by this intrinsic is likely to be incorrect or 0
2482for arguments other than zero, so it should only be used for debugging purposes.
2483</p>
2484
2485<p>
2486Note that calling this intrinsic does not prevent function inlining or other
2487aggressive transformations, so the value returned may not that of the obvious
2488source-language caller.
2489</p>
2490</div>
2491
John Criswell7123e272004-04-09 16:43:20 +00002492<!-- ======================================================================= -->
2493<div class="doc_subsection">
2494 <a name="int_os">Operating System Intrinsics</a>
2495</div>
2496
2497<div class="doc_text">
2498<p>
2499These intrinsics are provided by LLVM to support the implementation of
2500operating system level code.
2501</p>
2502
2503</div>
John Criswell183402a2004-04-12 15:02:16 +00002504
John Criswellcfd3bac2004-04-09 15:23:37 +00002505<!-- _______________________________________________________________________ -->
2506<div class="doc_subsubsection">
2507 <a name="i_readport">'<tt>llvm.readport</tt>' Intrinsic</a>
2508</div>
2509
2510<div class="doc_text">
2511
2512<h5>Syntax:</h5>
2513<pre>
John Criswell7123e272004-04-09 16:43:20 +00002514 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 +00002515</pre>
2516
2517<h5>Overview:</h5>
2518
2519<p>
John Criswell7123e272004-04-09 16:43:20 +00002520The '<tt>llvm.readport</tt>' intrinsic reads data from the specified hardware
2521I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002522</p>
2523
2524<h5>Arguments:</h5>
2525
2526<p>
John Criswell7123e272004-04-09 16:43:20 +00002527The argument to this intrinsic indicates the hardware I/O address from which
2528to read the data. The address is in the hardware I/O address namespace (as
2529opposed to being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002530</p>
2531
2532<h5>Semantics:</h5>
2533
2534<p>
John Criswell7123e272004-04-09 16:43:20 +00002535The '<tt>llvm.readport</tt>' intrinsic reads data from the hardware I/O port
2536specified by <i>address</i> and returns the value. The address and return
2537value must be integers, but the size is dependent upon the platform upon which
2538the program is code generated. For example, on x86, the address must be an
2539unsigned 16 bit value, and the return value must be 8, 16, or 32 bits.
John Criswellcfd3bac2004-04-09 15:23:37 +00002540</p>
2541
2542</div>
2543
2544<!-- _______________________________________________________________________ -->
2545<div class="doc_subsubsection">
2546 <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a>
2547</div>
2548
2549<div class="doc_text">
2550
2551<h5>Syntax:</h5>
2552<pre>
Chris Lattnerc3f59762004-12-09 17:30:23 +00002553 call void (&lt;integer type&gt;, &lt;integer type&gt;)*
2554 %llvm.writeport (&lt;integer type&gt; &lt;value&gt;,
2555 &lt;integer type&gt; &lt;address&gt;)
John Criswellcfd3bac2004-04-09 15:23:37 +00002556</pre>
2557
2558<h5>Overview:</h5>
2559
2560<p>
John Criswell7123e272004-04-09 16:43:20 +00002561The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified hardware
2562I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002563</p>
2564
2565<h5>Arguments:</h5>
2566
2567<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002568The first argument is the value to write to the I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002569</p>
2570
2571<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002572The second argument indicates the hardware I/O address to which data should be
2573written. The address is in the hardware I/O address namespace (as opposed to
2574being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002575</p>
2576
2577<h5>Semantics:</h5>
2578
2579<p>
2580The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port
2581specified by <i>address</i>. The address and value must be integers, but the
2582size is dependent upon the platform upon which the program is code generated.
John Criswell7123e272004-04-09 16:43:20 +00002583For example, on x86, the address must be an unsigned 16 bit value, and the
2584value written must be 8, 16, or 32 bits in length.
John Criswellcfd3bac2004-04-09 15:23:37 +00002585</p>
2586
2587</div>
Chris Lattner10610642004-02-14 04:08:35 +00002588
John Criswell183402a2004-04-12 15:02:16 +00002589<!-- _______________________________________________________________________ -->
2590<div class="doc_subsubsection">
2591 <a name="i_readio">'<tt>llvm.readio</tt>' Intrinsic</a>
2592</div>
2593
2594<div class="doc_text">
2595
2596<h5>Syntax:</h5>
2597<pre>
John Criswell96db6fc2004-04-12 16:33:19 +00002598 call &lt;result&gt; (&lt;ty&gt;*)* %llvm.readio (&lt;ty&gt; * &lt;pointer&gt;)
John Criswell183402a2004-04-12 15:02:16 +00002599</pre>
2600
2601<h5>Overview:</h5>
2602
2603<p>
2604The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
2605address.
2606</p>
2607
2608<h5>Arguments:</h5>
2609
2610<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002611The argument to this intrinsic is a pointer indicating the memory address from
2612which to read the data. The data must be a
2613<a href="#t_firstclass">first class</a> type.
John Criswell183402a2004-04-12 15:02:16 +00002614</p>
2615
2616<h5>Semantics:</h5>
2617
2618<p>
2619The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
John Criswell96db6fc2004-04-12 16:33:19 +00002620location specified by <i>pointer</i> and returns the value. The argument must
2621be a pointer, and the return value must be a
2622<a href="#t_firstclass">first class</a> type. However, certain architectures
2623may not support I/O on all first class types. For example, 32 bit processors
2624may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00002625</p>
2626
2627<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002628This intrinsic enforces an in-order memory model for llvm.readio and
2629llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2630scheduled processors may execute loads and stores out of order, re-ordering at
2631run time accesses to memory mapped I/O registers. Using these intrinsics
2632ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00002633</p>
2634
2635</div>
2636
2637<!-- _______________________________________________________________________ -->
2638<div class="doc_subsubsection">
2639 <a name="i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a>
2640</div>
2641
2642<div class="doc_text">
2643
2644<h5>Syntax:</h5>
2645<pre>
John Criswell96db6fc2004-04-12 16:33:19 +00002646 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 +00002647</pre>
2648
2649<h5>Overview:</h5>
2650
2651<p>
2652The '<tt>llvm.writeio</tt>' intrinsic writes data to the specified memory
2653mapped I/O address.
2654</p>
2655
2656<h5>Arguments:</h5>
2657
2658<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002659The first argument is the value to write to the memory mapped I/O location.
2660The second argument is a pointer indicating the memory address to which the
2661data should be written.
John Criswell183402a2004-04-12 15:02:16 +00002662</p>
2663
2664<h5>Semantics:</h5>
2665
2666<p>
2667The '<tt>llvm.writeio</tt>' intrinsic writes <i>value</i> to the memory mapped
John Criswell96db6fc2004-04-12 16:33:19 +00002668I/O address specified by <i>pointer</i>. The value must be a
2669<a href="#t_firstclass">first class</a> type. However, certain architectures
2670may not support I/O on all first class types. For example, 32 bit processors
2671may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00002672</p>
2673
2674<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002675This intrinsic enforces an in-order memory model for llvm.readio and
2676llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2677scheduled processors may execute loads and stores out of order, re-ordering at
2678run time accesses to memory mapped I/O registers. Using these intrinsics
2679ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00002680</p>
2681
2682</div>
2683
Chris Lattner10610642004-02-14 04:08:35 +00002684<!-- ======================================================================= -->
2685<div class="doc_subsection">
Chris Lattner33aec9e2004-02-12 17:01:32 +00002686 <a name="int_libc">Standard C Library Intrinsics</a>
2687</div>
2688
2689<div class="doc_text">
2690<p>
Chris Lattner10610642004-02-14 04:08:35 +00002691LLVM provides intrinsics for a few important standard C library functions.
2692These intrinsics allow source-language front-ends to pass information about the
2693alignment of the pointer arguments to the code generator, providing opportunity
2694for more efficient code generation.
Chris Lattner33aec9e2004-02-12 17:01:32 +00002695</p>
2696
2697</div>
2698
2699<!-- _______________________________________________________________________ -->
2700<div class="doc_subsubsection">
2701 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
2702</div>
2703
2704<div class="doc_text">
2705
2706<h5>Syntax:</h5>
2707<pre>
2708 call void (sbyte*, sbyte*, uint, uint)* %llvm.memcpy(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2709 uint &lt;len&gt;, uint &lt;align&gt;)
2710</pre>
2711
2712<h5>Overview:</h5>
2713
2714<p>
2715The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2716location to the destination location.
2717</p>
2718
2719<p>
2720Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
2721does not return a value, and takes an extra alignment argument.
2722</p>
2723
2724<h5>Arguments:</h5>
2725
2726<p>
2727The first argument is a pointer to the destination, the second is a pointer to
2728the source. The third argument is an (arbitrarily sized) integer argument
2729specifying the number of bytes to copy, and the fourth argument is the alignment
2730of the source and destination locations.
2731</p>
2732
Chris Lattner3301ced2004-02-12 21:18:15 +00002733<p>
2734If the call to this intrinisic has an alignment value that is not 0 or 1, then
2735the caller guarantees that the size of the copy is a multiple of the alignment
2736and that both the source and destination pointers are aligned to that boundary.
2737</p>
2738
Chris Lattner33aec9e2004-02-12 17:01:32 +00002739<h5>Semantics:</h5>
2740
2741<p>
2742The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2743location to the destination location, which are not allowed to overlap. It
2744copies "len" bytes of memory over. If the argument is known to be aligned to
2745some boundary, this can be specified as the fourth argument, otherwise it should
2746be set to 0 or 1.
2747</p>
2748</div>
2749
2750
Chris Lattner0eb51b42004-02-12 18:10:10 +00002751<!-- _______________________________________________________________________ -->
2752<div class="doc_subsubsection">
2753 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
2754</div>
2755
2756<div class="doc_text">
2757
2758<h5>Syntax:</h5>
2759<pre>
2760 call void (sbyte*, sbyte*, uint, uint)* %llvm.memmove(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2761 uint &lt;len&gt;, uint &lt;align&gt;)
2762</pre>
2763
2764<h5>Overview:</h5>
2765
2766<p>
2767The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
2768location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>'
2769intrinsic but allows the two memory locations to overlap.
2770</p>
2771
2772<p>
2773Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
2774does not return a value, and takes an extra alignment argument.
2775</p>
2776
2777<h5>Arguments:</h5>
2778
2779<p>
2780The first argument is a pointer to the destination, the second is a pointer to
2781the source. The third argument is an (arbitrarily sized) integer argument
2782specifying the number of bytes to copy, and the fourth argument is the alignment
2783of the source and destination locations.
2784</p>
2785
Chris Lattner3301ced2004-02-12 21:18:15 +00002786<p>
2787If the call to this intrinisic has an alignment value that is not 0 or 1, then
2788the caller guarantees that the size of the copy is a multiple of the alignment
2789and that both the source and destination pointers are aligned to that boundary.
2790</p>
2791
Chris Lattner0eb51b42004-02-12 18:10:10 +00002792<h5>Semantics:</h5>
2793
2794<p>
2795The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
2796location to the destination location, which may overlap. It
2797copies "len" bytes of memory over. If the argument is known to be aligned to
2798some boundary, this can be specified as the fourth argument, otherwise it should
2799be set to 0 or 1.
2800</p>
2801</div>
2802
Chris Lattner8ff75902004-01-06 05:31:32 +00002803
Chris Lattner10610642004-02-14 04:08:35 +00002804<!-- _______________________________________________________________________ -->
2805<div class="doc_subsubsection">
2806 <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a>
2807</div>
2808
2809<div class="doc_text">
2810
2811<h5>Syntax:</h5>
2812<pre>
2813 call void (sbyte*, ubyte, uint, uint)* %llvm.memset(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
2814 uint &lt;len&gt;, uint &lt;align&gt;)
2815</pre>
2816
2817<h5>Overview:</h5>
2818
2819<p>
2820The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular
2821byte value.
2822</p>
2823
2824<p>
2825Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
2826does not return a value, and takes an extra alignment argument.
2827</p>
2828
2829<h5>Arguments:</h5>
2830
2831<p>
2832The first argument is a pointer to the destination to fill, the second is the
2833byte value to fill it with, the third argument is an (arbitrarily sized) integer
2834argument specifying the number of bytes to fill, and the fourth argument is the
2835known alignment of destination location.
2836</p>
2837
2838<p>
2839If the call to this intrinisic has an alignment value that is not 0 or 1, then
2840the caller guarantees that the size of the copy is a multiple of the alignment
2841and that the destination pointer is aligned to that boundary.
2842</p>
2843
2844<h5>Semantics:</h5>
2845
2846<p>
2847The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the
2848destination location. If the argument is known to be aligned to some boundary,
2849this can be specified as the fourth argument, otherwise it should be set to 0 or
28501.
2851</p>
2852</div>
2853
2854
Chris Lattner32006282004-06-11 02:28:03 +00002855<!-- _______________________________________________________________________ -->
2856<div class="doc_subsubsection">
Alkis Evlogimenos26bbe932004-06-13 01:16:15 +00002857 <a name="i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a>
2858</div>
2859
2860<div class="doc_text">
2861
2862<h5>Syntax:</h5>
2863<pre>
2864 call bool (&lt;float or double&gt;, &lt;float or double&gt;)* %llvm.isunordered(&lt;float or double&gt; Val1,
2865 &lt;float or double&gt; Val2)
2866</pre>
2867
2868<h5>Overview:</h5>
2869
2870<p>
2871The '<tt>llvm.isunordered</tt>' intrinsic returns true if either or both of the
2872specified floating point values is a NAN.
2873</p>
2874
2875<h5>Arguments:</h5>
2876
2877<p>
2878The arguments are floating point numbers of the same type.
2879</p>
2880
2881<h5>Semantics:</h5>
2882
2883<p>
2884If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise
2885false.
2886</p>
2887</div>
2888
2889
Chris Lattner32006282004-06-11 02:28:03 +00002890
2891
Chris Lattner8ff75902004-01-06 05:31:32 +00002892<!-- ======================================================================= -->
2893<div class="doc_subsection">
2894 <a name="int_debugger">Debugger Intrinsics</a>
2895</div>
2896
2897<div class="doc_text">
2898<p>
2899The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
2900are described in the <a
2901href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
2902Debugging</a> document.
2903</p>
2904</div>
2905
2906
Chris Lattner00950542001-06-06 20:29:01 +00002907<!-- *********************************************************************** -->
Chris Lattner00950542001-06-06 20:29:01 +00002908<hr>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002909<address>
2910 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
2911 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
2912 <a href="http://validator.w3.org/check/referer"><img
2913 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
2914
2915 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
2916 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
2917 Last modified: $Date$
2918</address>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002919</body>
2920</html>