blob: 807c7515b49cff67fbd38597f5492abdb02d4c84 [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>
Chris Lattner9a9d7ac2005-02-28 19:24:19 +0000128 <li><a href="#i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a></li>
John Criswell7123e272004-04-09 16:43:20 +0000129 </ol>
130 </li>
131 <li><a href="#int_os">Operating System Intrinsics</a>
132 <ol>
Chris Lattner32006282004-06-11 02:28:03 +0000133 <li><a href="#i_readport">'<tt>llvm.readport</tt>' Intrinsic</a></li>
134 <li><a href="#i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a></li>
John Criswell183402a2004-04-12 15:02:16 +0000135 <li><a href="#i_readio">'<tt>llvm.readio</tt>' Intrinsic</a></li>
136 <li><a href="#i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000137 </ol>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000138 <li><a href="#int_libc">Standard C Library Intrinsics</a>
139 <ol>
140 <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li>
Chris Lattner0eb51b42004-02-12 18:10:10 +0000141 <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000142 <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li>
Alkis Evlogimenos96853722004-06-12 19:19:14 +0000143 <li><a href="#i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a></li>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000144 </ol>
145 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000146 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000147 </ol>
148 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000149</ol>
Chris Lattnerd7923912004-05-23 21:06:01 +0000150
151<div class="doc_author">
152 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
153 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000154</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000155
Chris Lattner00950542001-06-06 20:29:01 +0000156<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000157<div class="doc_section"> <a name="abstract">Abstract </a></div>
158<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000159
Misha Brukman9d0919f2003-11-08 01:05:38 +0000160<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000161<p>This document is a reference manual for the LLVM assembly language.
162LLVM is an SSA based representation that provides type safety,
163low-level operations, flexibility, and the capability of representing
164'all' high-level languages cleanly. It is the common code
165representation used throughout all phases of the LLVM compilation
166strategy.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000167</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000168
Chris Lattner00950542001-06-06 20:29:01 +0000169<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000170<div class="doc_section"> <a name="introduction">Introduction</a> </div>
171<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000172
Misha Brukman9d0919f2003-11-08 01:05:38 +0000173<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000174
Chris Lattner261efe92003-11-25 01:02:51 +0000175<p>The LLVM code representation is designed to be used in three
176different forms: as an in-memory compiler IR, as an on-disk bytecode
177representation (suitable for fast loading by a Just-In-Time compiler),
178and as a human readable assembly language representation. This allows
179LLVM to provide a powerful intermediate representation for efficient
180compiler transformations and analysis, while providing a natural means
181to debug and visualize the transformations. The three different forms
182of LLVM are all equivalent. This document describes the human readable
183representation and notation.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000184
Chris Lattner261efe92003-11-25 01:02:51 +0000185<p>The LLVM representation aims to be a light-weight and low-level
186while being expressive, typed, and extensible at the same time. It
187aims to be a "universal IR" of sorts, by being at a low enough level
188that high-level ideas may be cleanly mapped to it (similar to how
189microprocessors are "universal IR's", allowing many source languages to
190be mapped to them). By providing type information, LLVM can be used as
191the target of optimizations: for example, through pointer analysis, it
192can be proven that a C automatic variable is never accessed outside of
193the current function... allowing it to be promoted to a simple SSA
194value instead of a memory location.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000195
Misha Brukman9d0919f2003-11-08 01:05:38 +0000196</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000197
Chris Lattner00950542001-06-06 20:29:01 +0000198<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000199<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000200
Misha Brukman9d0919f2003-11-08 01:05:38 +0000201<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000202
Chris Lattner261efe92003-11-25 01:02:51 +0000203<p>It is important to note that this document describes 'well formed'
204LLVM assembly language. There is a difference between what the parser
205accepts and what is considered 'well formed'. For example, the
206following instruction is syntactically okay, but not well formed:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000207
208<pre>
209 %x = <a href="#i_add">add</a> int 1, %x
210</pre>
211
Chris Lattner261efe92003-11-25 01:02:51 +0000212<p>...because the definition of <tt>%x</tt> does not dominate all of
213its uses. The LLVM infrastructure provides a verification pass that may
214be used to verify that an LLVM module is well formed. This pass is
215automatically run by the parser after parsing input assembly, and by
216the optimizer before it outputs bytecode. The violations pointed out
217by the verifier pass indicate bugs in transformation passes or input to
218the parser.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000219
Chris Lattner261efe92003-11-25 01:02:51 +0000220<!-- Describe the typesetting conventions here. --> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000221
Chris Lattner00950542001-06-06 20:29:01 +0000222<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000223<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000224<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000225
Misha Brukman9d0919f2003-11-08 01:05:38 +0000226<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000227
Chris Lattner261efe92003-11-25 01:02:51 +0000228<p>LLVM uses three different forms of identifiers, for different
229purposes:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000230
Chris Lattner00950542001-06-06 20:29:01 +0000231<ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000232 <li>Named values are represented as a string of characters with a '%' prefix.
233 For example, %foo, %DivisionByZero, %a.really.long.identifier. The actual
234 regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
235 Identifiers which require other characters in their names can be surrounded
236 with quotes. In this way, anything except a <tt>"</tt> character can be used
237 in a name.</li>
238
239 <li>Unnamed values are represented as an unsigned numeric value with a '%'
240 prefix. For example, %12, %2, %44.</li>
241
Reid Spencercc16dc32004-12-09 18:02:53 +0000242 <li>Constants, which are described in a <a href="#constants">section about
243 constants</a>, below.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000244</ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000245
246<p>LLVM requires that values start with a '%' sign for two reasons: Compilers
247don't need to worry about name clashes with reserved words, and the set of
248reserved words may be expanded in the future without penalty. Additionally,
249unnamed identifiers allow a compiler to quickly come up with a temporary
250variable without having to avoid symbol table conflicts.</p>
251
Chris Lattner261efe92003-11-25 01:02:51 +0000252<p>Reserved words in LLVM are very similar to reserved words in other
253languages. There are keywords for different opcodes ('<tt><a
Chris Lattnere5d947b2004-12-09 16:36:40 +0000254href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
255href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
256href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>', etc...),
257and others. These reserved words cannot conflict with variable names, because
258none of them start with a '%' character.</p>
259
260<p>Here is an example of LLVM code to multiply the integer variable
261'<tt>%X</tt>' by 8:</p>
262
Misha Brukman9d0919f2003-11-08 01:05:38 +0000263<p>The easy way:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000264
265<pre>
266 %result = <a href="#i_mul">mul</a> uint %X, 8
267</pre>
268
Misha Brukman9d0919f2003-11-08 01:05:38 +0000269<p>After strength reduction:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000270
271<pre>
272 %result = <a href="#i_shl">shl</a> uint %X, ubyte 3
273</pre>
274
Misha Brukman9d0919f2003-11-08 01:05:38 +0000275<p>And the hard way:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000276
277<pre>
278 <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
279 <a href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
280 %result = <a href="#i_add">add</a> uint %1, %1
281</pre>
282
Chris Lattner261efe92003-11-25 01:02:51 +0000283<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
284important lexical features of LLVM:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000285
Chris Lattner00950542001-06-06 20:29:01 +0000286<ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000287
288 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
289 line.</li>
290
291 <li>Unnamed temporaries are created when the result of a computation is not
292 assigned to a named value.</li>
293
Misha Brukman9d0919f2003-11-08 01:05:38 +0000294 <li>Unnamed temporaries are numbered sequentially</li>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000295
Misha Brukman9d0919f2003-11-08 01:05:38 +0000296</ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000297
298<p>...and it also show a convention that we follow in this document. When
299demonstrating instructions, we will follow an instruction with a comment that
300defines the type and name of value produced. Comments are shown in italic
301text.</p>
302
Misha Brukman9d0919f2003-11-08 01:05:38 +0000303</div>
Chris Lattnerfa730212004-12-09 16:11:40 +0000304
305<!-- *********************************************************************** -->
306<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
307<!-- *********************************************************************** -->
308
309<!-- ======================================================================= -->
310<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
311</div>
312
313<div class="doc_text">
314
315<p>LLVM programs are composed of "Module"s, each of which is a
316translation unit of the input programs. Each module consists of
317functions, global variables, and symbol table entries. Modules may be
318combined together with the LLVM linker, which merges function (and
319global variable) definitions, resolves forward declarations, and merges
320symbol table entries. Here is an example of the "hello world" module:</p>
321
322<pre><i>; Declare the string constant as a global constant...</i>
323<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
324 href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00" <i>; [13 x sbyte]*</i>
325
326<i>; External declaration of the puts function</i>
327<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
328
329<i>; Definition of main function</i>
330int %main() { <i>; int()* </i>
331 <i>; Convert [13x sbyte]* to sbyte *...</i>
332 %cast210 = <a
333 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
334
335 <i>; Call puts function to write out the string to stdout...</i>
336 <a
337 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
338 <a
339 href="#i_ret">ret</a> int 0<br>}<br></pre>
340
341<p>This example is made up of a <a href="#globalvars">global variable</a>
342named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
343function, and a <a href="#functionstructure">function definition</a>
344for "<tt>main</tt>".</p>
345
Chris Lattnere5d947b2004-12-09 16:36:40 +0000346<p>In general, a module is made up of a list of global values,
347where both functions and global variables are global values. Global values are
348represented by a pointer to a memory location (in this case, a pointer to an
349array of char, and a pointer to a function), and have one of the following <a
350href="#linkage">linkage types</a>.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000351
Chris Lattnere5d947b2004-12-09 16:36:40 +0000352</div>
353
354<!-- ======================================================================= -->
355<div class="doc_subsection">
356 <a name="linkage">Linkage Types</a>
357</div>
358
359<div class="doc_text">
360
361<p>
362All Global Variables and Functions have one of the following types of linkage:
363</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000364
365<dl>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000366
Chris Lattnerfa730212004-12-09 16:11:40 +0000367 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000368
369 <dd>Global values with internal linkage are only directly accessible by
370 objects in the current module. In particular, linking code into a module with
371 an internal global value may cause the internal to be renamed as necessary to
372 avoid collisions. Because the symbol is internal to the module, all
373 references can be updated. This corresponds to the notion of the
374 '<tt>static</tt>' keyword in C, or the idea of "anonymous namespaces" in C++.
Chris Lattnerfa730212004-12-09 16:11:40 +0000375 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000376
Chris Lattnerfa730212004-12-09 16:11:40 +0000377 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000378
379 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt> linkage, with
380 the twist that linking together two modules defining the same
381 <tt>linkonce</tt> globals will cause one of the globals to be discarded. This
382 is typically used to implement inline functions. Unreferenced
383 <tt>linkonce</tt> globals are allowed to be discarded.
Chris Lattnerfa730212004-12-09 16:11:40 +0000384 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000385
Chris Lattnerfa730212004-12-09 16:11:40 +0000386 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000387
388 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage,
389 except that unreferenced <tt>weak</tt> globals may not be discarded. This is
390 used to implement constructs in C such as "<tt>int X;</tt>" at global scope.
Chris Lattnerfa730212004-12-09 16:11:40 +0000391 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000392
Chris Lattnerfa730212004-12-09 16:11:40 +0000393 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000394
395 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
396 pointer to array type. When two global variables with appending linkage are
397 linked together, the two global arrays are appended together. This is the
398 LLVM, typesafe, equivalent of having the system linker append together
399 "sections" with identical names when .o files are linked.
Chris Lattnerfa730212004-12-09 16:11:40 +0000400 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000401
Chris Lattnerfa730212004-12-09 16:11:40 +0000402 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000403
404 <dd>If none of the above identifiers are used, the global is externally
405 visible, meaning that it participates in linkage and can be used to resolve
406 external symbol references.
Chris Lattnerfa730212004-12-09 16:11:40 +0000407 </dd>
408</dl>
409
Chris Lattnerfa730212004-12-09 16:11:40 +0000410<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
411variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
412variable and was linked with this one, one of the two would be renamed,
413preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
414external (i.e., lacking any linkage declarations), they are accessible
415outside of the current module. It is illegal for a function <i>declaration</i>
416to have any linkage type other than "externally visible".</a></p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000417
Chris Lattnerfa730212004-12-09 16:11:40 +0000418</div>
419
420<!-- ======================================================================= -->
421<div class="doc_subsection">
422 <a name="globalvars">Global Variables</a>
423</div>
424
425<div class="doc_text">
426
Chris Lattner3689a342005-02-12 19:30:21 +0000427<p>Global variables define regions of memory allocated at compilation time
428instead of run-time. Global variables may optionally be initialized. A
429variable may be defined as a global "constant", which indicates that the
430contents of the variable will <b>never</b> be modified (enabling better
431optimization, allowing the global data to be placed in the read-only section of
432an executable, etc). Note that variables that need runtime initialization
433cannot be marked "constant", as there is a store to the variable.</p>
434
435<p>
436LLVM explicitly allows <em>declarations</em> of global variables to be marked
437constant, even if the final definition of the global is not. This capability
438can be used to enable slightly better optimization of the program, but requires
439the language definition to guarantee that optimizations based on the
440'constantness' are valid for the translation units that do not include the
441definition.
442</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000443
444<p>As SSA values, global variables define pointer values that are in
445scope (i.e. they dominate) all basic blocks in the program. Global
446variables always define a pointer to their "content" type because they
447describe a region of memory, and all memory objects in LLVM are
448accessed through pointers.</p>
449
450</div>
451
452
453<!-- ======================================================================= -->
454<div class="doc_subsection">
455 <a name="functionstructure">Functions</a>
456</div>
457
458<div class="doc_text">
459
460<p>LLVM function definitions are composed of a (possibly empty) argument list,
461an opening curly brace, a list of basic blocks, and a closing curly brace. LLVM
462function declarations are defined with the "<tt>declare</tt>" keyword, a
463function name, and a function signature.</p>
464
465<p>A function definition contains a list of basic blocks, forming the CFG for
466the function. Each basic block may optionally start with a label (giving the
467basic block a symbol table entry), contains a list of instructions, and ends
468with a <a href="#terminators">terminator</a> instruction (such as a branch or
469function return).</p>
470
471<p>The first basic block in program is special in two ways: it is immediately
472executed on entrance to the function, and it is not allowed to have predecessor
473basic blocks (i.e. there can not be any branches to the entry block of a
474function). Because the block can have no predecessors, it also cannot have any
475<a href="#i_phi">PHI nodes</a>.</p>
476
477<p>LLVM functions are identified by their name and type signature. Hence, two
478functions with the same name but different parameter lists or return values are
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000479considered different functions, and LLVM will resolve references to each
Chris Lattnerfa730212004-12-09 16:11:40 +0000480appropriately.</p>
481
482</div>
483
484
485
Chris Lattner00950542001-06-06 20:29:01 +0000486<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000487<div class="doc_section"> <a name="typesystem">Type System</a> </div>
488<!-- *********************************************************************** -->
Chris Lattnerfa730212004-12-09 16:11:40 +0000489
Misha Brukman9d0919f2003-11-08 01:05:38 +0000490<div class="doc_text">
Chris Lattnerfa730212004-12-09 16:11:40 +0000491
Misha Brukman9d0919f2003-11-08 01:05:38 +0000492<p>The LLVM type system is one of the most important features of the
Chris Lattner261efe92003-11-25 01:02:51 +0000493intermediate representation. Being typed enables a number of
494optimizations to be performed on the IR directly, without having to do
495extra analyses on the side before the transformation. A strong type
496system makes it easier to read the generated code and enables novel
497analyses and transformations that are not feasible to perform on normal
498three address code representations.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000499
500</div>
501
Chris Lattner00950542001-06-06 20:29:01 +0000502<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000503<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000504<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +0000505<p>The primitive types are the fundamental building blocks of the LLVM
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000506system. The current set of primitive types is as follows:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000507
Reid Spencerd3f876c2004-11-01 08:19:36 +0000508<table class="layout">
509 <tr class="layout">
510 <td class="left">
511 <table>
Chris Lattner261efe92003-11-25 01:02:51 +0000512 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000513 <tr><th>Type</th><th>Description</th></tr>
514 <tr><td><tt>void</tt></td><td>No value</td></tr>
515 <tr><td><tt>ubyte</tt></td><td>Unsigned 8 bit value</td></tr>
516 <tr><td><tt>ushort</tt></td><td>Unsigned 16 bit value</td></tr>
517 <tr><td><tt>uint</tt></td><td>Unsigned 32 bit value</td></tr>
518 <tr><td><tt>ulong</tt></td><td>Unsigned 64 bit value</td></tr>
519 <tr><td><tt>float</tt></td><td>32 bit floating point value</td></tr>
520 <tr><td><tt>label</tt></td><td>Branch destination</td></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000521 </tbody>
522 </table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000523 </td>
524 <td class="right">
525 <table>
Chris Lattner261efe92003-11-25 01:02:51 +0000526 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000527 <tr><th>Type</th><th>Description</th></tr>
528 <tr><td><tt>bool</tt></td><td>True or False value</td></tr>
529 <tr><td><tt>sbyte</tt></td><td>Signed 8 bit value</td></tr>
530 <tr><td><tt>short</tt></td><td>Signed 16 bit value</td></tr>
531 <tr><td><tt>int</tt></td><td>Signed 32 bit value</td></tr>
532 <tr><td><tt>long</tt></td><td>Signed 64 bit value</td></tr>
533 <tr><td><tt>double</tt></td><td>64 bit floating point value</td></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000534 </tbody>
535 </table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000536 </td>
537 </tr>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000538</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000539</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000540
Chris Lattner00950542001-06-06 20:29:01 +0000541<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000542<div class="doc_subsubsection"> <a name="t_classifications">Type
543Classifications</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000544<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000545<p>These different primitive types fall into a few useful
546classifications:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000547
548<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +0000549 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000550 <tr><th>Classification</th><th>Types</th></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000551 <tr>
552 <td><a name="t_signed">signed</a></td>
553 <td><tt>sbyte, short, int, long, float, double</tt></td>
554 </tr>
555 <tr>
556 <td><a name="t_unsigned">unsigned</a></td>
557 <td><tt>ubyte, ushort, uint, ulong</tt></td>
558 </tr>
559 <tr>
560 <td><a name="t_integer">integer</a></td>
561 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
562 </tr>
563 <tr>
564 <td><a name="t_integral">integral</a></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000565 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt>
566 </td>
Chris Lattner261efe92003-11-25 01:02:51 +0000567 </tr>
568 <tr>
569 <td><a name="t_floating">floating point</a></td>
570 <td><tt>float, double</tt></td>
571 </tr>
572 <tr>
573 <td><a name="t_firstclass">first class</a></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000574 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long,<br>
575 float, double, <a href="#t_pointer">pointer</a>,
576 <a href="#t_packed">packed</a></tt></td>
Chris Lattner261efe92003-11-25 01:02:51 +0000577 </tr>
578 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000579</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000580
Chris Lattner261efe92003-11-25 01:02:51 +0000581<p>The <a href="#t_firstclass">first class</a> types are perhaps the
582most important. Values of these types are the only ones which can be
583produced by instructions, passed as arguments, or used as operands to
584instructions. This means that all structures and arrays must be
585manipulated either by pointer or by component.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000586</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000587
Chris Lattner00950542001-06-06 20:29:01 +0000588<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000589<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000590
Misha Brukman9d0919f2003-11-08 01:05:38 +0000591<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +0000592
Chris Lattner261efe92003-11-25 01:02:51 +0000593<p>The real power in LLVM comes from the derived types in the system.
594This is what allows a programmer to represent arrays, functions,
595pointers, and other useful types. Note that these derived types may be
596recursive: For example, it is possible to have a two dimensional array.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000597
Misha Brukman9d0919f2003-11-08 01:05:38 +0000598</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000599
Chris Lattner00950542001-06-06 20:29:01 +0000600<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000601<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000602
Misha Brukman9d0919f2003-11-08 01:05:38 +0000603<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +0000604
Chris Lattner00950542001-06-06 20:29:01 +0000605<h5>Overview:</h5>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000606
Misha Brukman9d0919f2003-11-08 01:05:38 +0000607<p>The array type is a very simple derived type that arranges elements
Chris Lattner261efe92003-11-25 01:02:51 +0000608sequentially in memory. The array type requires a size (number of
609elements) and an underlying data type.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000610
Chris Lattner7faa8832002-04-14 06:13:44 +0000611<h5>Syntax:</h5>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000612
613<pre>
614 [&lt;# elements&gt; x &lt;elementtype&gt;]
615</pre>
616
Chris Lattner261efe92003-11-25 01:02:51 +0000617<p>The number of elements is a constant integer value, elementtype may
618be any type with a size.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000619
Chris Lattner7faa8832002-04-14 06:13:44 +0000620<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000621<table class="layout">
622 <tr class="layout">
623 <td class="left">
624 <tt>[40 x int ]</tt><br/>
625 <tt>[41 x int ]</tt><br/>
626 <tt>[40 x uint]</tt><br/>
627 </td>
628 <td class="left">
629 Array of 40 integer values.<br/>
630 Array of 41 integer values.<br/>
631 Array of 40 unsigned integer values.<br/>
632 </td>
633 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000634</table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000635<p>Here are some examples of multidimensional arrays:</p>
636<table class="layout">
637 <tr class="layout">
638 <td class="left">
639 <tt>[3 x [4 x int]]</tt><br/>
640 <tt>[12 x [10 x float]]</tt><br/>
641 <tt>[2 x [3 x [4 x uint]]]</tt><br/>
642 </td>
643 <td class="left">
644 3x4 array integer values.<br/>
645 12x10 array of single precision floating point values.<br/>
646 2x3x4 array of unsigned integer values.<br/>
647 </td>
648 </tr>
649</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000650</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000651
Chris Lattner00950542001-06-06 20:29:01 +0000652<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000653<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000654<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000655<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000656<p>The function type can be thought of as a function signature. It
657consists of a return type and a list of formal parameter types.
John Criswell009900b2003-11-25 21:45:46 +0000658Function types are usually used to build virtual function tables
Chris Lattner261efe92003-11-25 01:02:51 +0000659(which are structures of pointers to functions), for indirect function
660calls, and when defining a function.</p>
John Criswell009900b2003-11-25 21:45:46 +0000661<p>
662The return type of a function type cannot be an aggregate type.
663</p>
Chris Lattner00950542001-06-06 20:29:01 +0000664<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000665<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000666<p>Where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
667specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner27f71f22003-09-03 00:41:47 +0000668which indicates that the function takes a variable number of arguments.
669Variable argument functions can access their arguments with the <a
Chris Lattner261efe92003-11-25 01:02:51 +0000670 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000671<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000672<table class="layout">
673 <tr class="layout">
674 <td class="left">
675 <tt>int (int)</tt> <br/>
676 <tt>float (int, int *) *</tt><br/>
677 <tt>int (sbyte *, ...)</tt><br/>
678 </td>
679 <td class="left">
680 function taking an <tt>int</tt>, returning an <tt>int</tt><br/>
681 <a href="#t_pointer">Pointer</a> to a function that takes an
Misha Brukmanc24b7582004-08-12 20:16:08 +0000682 <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
Reid Spencerd3f876c2004-11-01 08:19:36 +0000683 returning <tt>float</tt>.<br/>
684 A vararg function that takes at least one <a href="#t_pointer">pointer</a>
685 to <tt>sbyte</tt> (signed char in C), which returns an integer. This is
686 the signature for <tt>printf</tt> in LLVM.<br/>
687 </td>
688 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000689</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000690
Misha Brukman9d0919f2003-11-08 01:05:38 +0000691</div>
Chris Lattner00950542001-06-06 20:29:01 +0000692<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000693<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000694<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000695<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000696<p>The structure type is used to represent a collection of data members
697together in memory. The packing of the field types is defined to match
698the ABI of the underlying processor. The elements of a structure may
699be any type that has a size.</p>
700<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
701and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
702field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
703instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000704<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000705<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +0000706<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000707<table class="layout">
708 <tr class="layout">
709 <td class="left">
710 <tt>{ int, int, int }</tt><br/>
711 <tt>{ float, int (int) * }</tt><br/>
712 </td>
713 <td class="left">
714 a triple of three <tt>int</tt> values<br/>
715 A pair, where the first element is a <tt>float</tt> and the second element
716 is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a>
717 that takes an <tt>int</tt>, returning an <tt>int</tt>.<br/>
718 </td>
719 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000720</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000721</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000722
Chris Lattner00950542001-06-06 20:29:01 +0000723<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000724<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000725<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +0000726<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000727<p>As in many languages, the pointer type represents a pointer or
728reference to another object, which must live in memory.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000729<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000730<pre> &lt;type&gt; *<br></pre>
Chris Lattner7faa8832002-04-14 06:13:44 +0000731<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000732<table class="layout">
733 <tr class="layout">
734 <td class="left">
735 <tt>[4x int]*</tt><br/>
736 <tt>int (int *) *</tt><br/>
737 </td>
738 <td class="left">
739 A <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of
740 four <tt>int</tt> values<br/>
741 A <a href="#t_pointer">pointer</a> to a <a
Chris Lattnera977c482005-02-19 02:22:14 +0000742 href="#t_function">function</a> that takes an <tt>int*</tt>, returning an
Reid Spencerd3f876c2004-11-01 08:19:36 +0000743 <tt>int</tt>.<br/>
744 </td>
745 </tr>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000746</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000747</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000748
Chris Lattnera58561b2004-08-12 19:12:28 +0000749<!-- _______________________________________________________________________ -->
750<div class="doc_subsubsection"> <a name="t_packed">Packed Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000751<div class="doc_text">
Chris Lattnera58561b2004-08-12 19:12:28 +0000752<h5>Overview:</h5>
753<p>A packed type is a simple derived type that represents a vector
754of elements. Packed types are used when multiple primitive data
755are operated in parallel using a single instruction (SIMD).
756A packed type requires a size (number of
757elements) and an underlying primitive data type. Packed types are
758considered <a href="#t_firstclass">first class</a>.</p>
759<h5>Syntax:</h5>
760<pre> &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;<br></pre>
761<p>The number of elements is a constant integer value, elementtype may
762be any integral or floating point type.</p>
763<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000764<table class="layout">
765 <tr class="layout">
766 <td class="left">
767 <tt>&lt;4 x int&gt;</tt><br/>
768 <tt>&lt;8 x float&gt;</tt><br/>
769 <tt>&lt;2 x uint&gt;</tt><br/>
770 </td>
771 <td class="left">
772 Packed vector of 4 integer values.<br/>
773 Packed vector of 8 floating-point values.<br/>
774 Packed vector of 2 unsigned integer values.<br/>
775 </td>
776 </tr>
777</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000778</div>
779
Chris Lattnerc3f59762004-12-09 17:30:23 +0000780<!-- *********************************************************************** -->
781<div class="doc_section"> <a name="constants">Constants</a> </div>
782<!-- *********************************************************************** -->
783
784<div class="doc_text">
785
786<p>LLVM has several different basic types of constants. This section describes
787them all and their syntax.</p>
788
789</div>
790
791<!-- ======================================================================= -->
Reid Spencercc16dc32004-12-09 18:02:53 +0000792<div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000793
794<div class="doc_text">
795
796<dl>
797 <dt><b>Boolean constants</b></dt>
798
799 <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
800 constants of the <tt><a href="#t_primitive">bool</a></tt> type.
801 </dd>
802
803 <dt><b>Integer constants</b></dt>
804
Reid Spencercc16dc32004-12-09 18:02:53 +0000805 <dd>Standard integers (such as '4') are constants of the <a
Chris Lattnerc3f59762004-12-09 17:30:23 +0000806 href="#t_integer">integer</a> type. Negative numbers may be used with signed
807 integer types.
808 </dd>
809
810 <dt><b>Floating point constants</b></dt>
811
812 <dd>Floating point constants use standard decimal notation (e.g. 123.421),
813 exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
Reid Spencercc16dc32004-12-09 18:02:53 +0000814 notation. Floating point constants have an optional hexadecimal
Chris Lattnerc3f59762004-12-09 17:30:23 +0000815 notation (see below). Floating point constants must have a <a
816 href="#t_floating">floating point</a> type. </dd>
817
818 <dt><b>Null pointer constants</b></dt>
819
John Criswell9e2485c2004-12-10 15:51:16 +0000820 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
Chris Lattnerc3f59762004-12-09 17:30:23 +0000821 and must be of <a href="#t_pointer">pointer type</a>.</dd>
822
823</dl>
824
John Criswell9e2485c2004-12-10 15:51:16 +0000825<p>The one non-intuitive notation for constants is the optional hexadecimal form
Chris Lattnerc3f59762004-12-09 17:30:23 +0000826of floating point constants. For example, the form '<tt>double
8270x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
8284.5e+15</tt>'. The only time hexadecimal floating point constants are required
Reid Spencercc16dc32004-12-09 18:02:53 +0000829(and the only time that they are generated by the disassembler) is when a
830floating point constant must be emitted but it cannot be represented as a
831decimal floating point number. For example, NaN's, infinities, and other
832special values are represented in their IEEE hexadecimal format so that
833assembly and disassembly do not cause any bits to change in the constants.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000834
835</div>
836
837<!-- ======================================================================= -->
838<div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a>
839</div>
840
841<div class="doc_text">
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000842<p>Aggregate constants arise from aggregation of simple constants
843and smaller aggregate constants.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000844
845<dl>
846 <dt><b>Structure constants</b></dt>
847
848 <dd>Structure constants are represented with notation similar to structure
849 type definitions (a comma separated list of elements, surrounded by braces
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000850 (<tt>{}</tt>)). For example: "<tt>{ int 4, float 17.0, int* %G }</tt>",
851 where "<tt>%G</tt>" is declared as "<tt>%G = external global int</tt>". Structure constants
852 must have <a href="#t_struct">structure type</a>, and the number and
Chris Lattnerc3f59762004-12-09 17:30:23 +0000853 types of elements must match those specified by the type.
854 </dd>
855
856 <dt><b>Array constants</b></dt>
857
858 <dd>Array constants are represented with notation similar to array type
859 definitions (a comma separated list of elements, surrounded by square brackets
John Criswell9e2485c2004-12-10 15:51:16 +0000860 (<tt>[]</tt>)). For example: "<tt>[ int 42, int 11, int 74 ]</tt>". Array
Chris Lattnerc3f59762004-12-09 17:30:23 +0000861 constants must have <a href="#t_array">array type</a>, and the number and
862 types of elements must match those specified by the type.
863 </dd>
864
865 <dt><b>Packed constants</b></dt>
866
867 <dd>Packed constants are represented with notation similar to packed type
868 definitions (a comma separated list of elements, surrounded by
John Criswell9e2485c2004-12-10 15:51:16 +0000869 less-than/greater-than's (<tt>&lt;&gt;</tt>)). For example: "<tt>&lt; int 42,
Chris Lattnerc3f59762004-12-09 17:30:23 +0000870 int 11, int 74, int 100 &gt;</tt>". Packed constants must have <a
871 href="#t_packed">packed type</a>, and the number and types of elements must
872 match those specified by the type.
873 </dd>
874
875 <dt><b>Zero initialization</b></dt>
876
877 <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
878 value to zero of <em>any</em> type, including scalar and aggregate types.
879 This is often used to avoid having to print large zero initializers (e.g. for
880 large arrays), and is always exactly equivalent to using explicit zero
881 initializers.
882 </dd>
883</dl>
884
885</div>
886
887<!-- ======================================================================= -->
888<div class="doc_subsection">
889 <a name="globalconstants">Global Variable and Function Addresses</a>
890</div>
891
892<div class="doc_text">
893
894<p>The addresses of <a href="#globalvars">global variables</a> and <a
895href="#functionstructure">functions</a> are always implicitly valid (link-time)
John Criswell9e2485c2004-12-10 15:51:16 +0000896constants. These constants are explicitly referenced when the <a
897href="#identifiers">identifier for the global</a> is used and always have <a
Chris Lattnerc3f59762004-12-09 17:30:23 +0000898href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
899file:</p>
900
901<pre>
902 %X = global int 17
903 %Y = global int 42
904 %Z = global [2 x int*] [ int* %X, int* %Y ]
905</pre>
906
907</div>
908
909<!-- ======================================================================= -->
Reid Spencer2dc45b82004-12-09 18:13:12 +0000910<div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000911<div class="doc_text">
Reid Spencer2dc45b82004-12-09 18:13:12 +0000912 <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has
913 no specific value. Undefined values may be of any type, and be used anywhere
914 a constant is permitted.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000915
Reid Spencer2dc45b82004-12-09 18:13:12 +0000916 <p>Undefined values indicate to the compiler that the program is well defined
917 no matter what value is used, giving the compiler more freedom to optimize.
918 </p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000919</div>
920
921<!-- ======================================================================= -->
922<div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
923</div>
924
925<div class="doc_text">
926
927<p>Constant expressions are used to allow expressions involving other constants
928to be used as constants. Constant expressions may be of any <a
929href="#t_firstclass">first class</a> type, and may involve any LLVM operation
930that does not have side effects (e.g. load and call are not supported). The
931following is the syntax for constant expressions:</p>
932
933<dl>
934 <dt><b><tt>cast ( CST to TYPE )</tt></b></dt>
935
936 <dd>Cast a constant to another type.</dd>
937
938 <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
939
940 <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
941 constants. As with the <a href="#i_getelementptr">getelementptr</a>
942 instruction, the index list may have zero or more indexes, which are required
943 to make sense for the type of "CSTPTR".</dd>
944
945 <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
946
Reid Spencer2dc45b82004-12-09 18:13:12 +0000947 <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
948 be any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise
Chris Lattnerc3f59762004-12-09 17:30:23 +0000949 binary</a> operations. The constraints on operands are the same as those for
950 the corresponding instruction (e.g. no bitwise operations on floating point
951 are allowed).</dd>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000952</dl>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000953</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000954
Chris Lattner00950542001-06-06 20:29:01 +0000955<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000956<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
957<!-- *********************************************************************** -->
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>The LLVM instruction set consists of several different
962classifications of instructions: <a href="#terminators">terminator
963instructions</a>, <a href="#binaryops">binary instructions</a>, <a
964 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
965instructions</a>.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000966
Misha Brukman9d0919f2003-11-08 01:05:38 +0000967</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000968
Chris Lattner00950542001-06-06 20:29:01 +0000969<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000970<div class="doc_subsection"> <a name="terminators">Terminator
971Instructions</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000972
Misha Brukman9d0919f2003-11-08 01:05:38 +0000973<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +0000974
Chris Lattner261efe92003-11-25 01:02:51 +0000975<p>As mentioned <a href="#functionstructure">previously</a>, every
976basic block in a program ends with a "Terminator" instruction, which
977indicates which block should be executed after the current block is
978finished. These terminator instructions typically yield a '<tt>void</tt>'
979value: they produce control flow, not values (the one exception being
980the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
John Criswell9e2485c2004-12-10 15:51:16 +0000981<p>There are six different terminator instructions: the '<a
Chris Lattner261efe92003-11-25 01:02:51 +0000982 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
983instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
Chris Lattner35eca582004-10-16 18:04:13 +0000984the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
985 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
986 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000987
Misha Brukman9d0919f2003-11-08 01:05:38 +0000988</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000989
Chris Lattner00950542001-06-06 20:29:01 +0000990<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000991<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
992Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000993<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000994<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000995<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 +0000996 ret void <i>; Return from void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000997</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000998<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000999<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
1000value) from a function, back to the caller.</p>
John Criswell4457dc92004-04-09 16:48:45 +00001001<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner261efe92003-11-25 01:02:51 +00001002returns a value and then causes control flow, and one that just causes
1003control flow to occur.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001004<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001005<p>The '<tt>ret</tt>' instruction may return any '<a
1006 href="#t_firstclass">first class</a>' type. Notice that a function is
1007not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
1008instruction inside of the function that returns a value that does not
1009match the return type of the function.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001010<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001011<p>When the '<tt>ret</tt>' instruction is executed, control flow
1012returns back to the calling function's context. If the caller is a "<a
John Criswellfa081872004-06-25 15:16:57 +00001013 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner261efe92003-11-25 01:02:51 +00001014the instruction after the call. If the caller was an "<a
1015 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
1016at the beginning "normal" of the destination block. If the instruction
1017returns a value, that value shall set the call or invoke instruction's
1018return value.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001019<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001020<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001021 ret void <i>; Return from a void function</i>
Chris Lattner00950542001-06-06 20:29:01 +00001022</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001023</div>
Chris Lattner00950542001-06-06 20:29:01 +00001024<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001025<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001026<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001027<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001028<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 +00001029</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001030<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001031<p>The '<tt>br</tt>' instruction is used to cause control flow to
1032transfer to a different basic block in the current function. There are
1033two forms of this instruction, corresponding to a conditional branch
1034and an unconditional branch.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001035<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001036<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
1037single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
1038unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
1039value as a target.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001040<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001041<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
1042argument is evaluated. If the value is <tt>true</tt>, control flows
1043to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
1044control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001045<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001046<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
1047 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 +00001048</div>
Chris Lattner00950542001-06-06 20:29:01 +00001049<!-- _______________________________________________________________________ -->
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001050<div class="doc_subsubsection">
1051 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
1052</div>
1053
Misha Brukman9d0919f2003-11-08 01:05:38 +00001054<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001055<h5>Syntax:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001056
1057<pre>
1058 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
1059</pre>
1060
Chris Lattner00950542001-06-06 20:29:01 +00001061<h5>Overview:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001062
1063<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
1064several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +00001065instruction, allowing a branch to occur to one of many possible
1066destinations.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001067
1068
Chris Lattner00950542001-06-06 20:29:01 +00001069<h5>Arguments:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001070
1071<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
1072comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
1073an array of pairs of comparison value constants and '<tt>label</tt>'s. The
1074table is not allowed to contain duplicate constant entries.</p>
1075
Chris Lattner00950542001-06-06 20:29:01 +00001076<h5>Semantics:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001077
Chris Lattner261efe92003-11-25 01:02:51 +00001078<p>The <tt>switch</tt> instruction specifies a table of values and
1079destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswell84114752004-06-25 16:05:06 +00001080table is searched for the given value. If the value is found, control flow is
1081transfered to the corresponding destination; otherwise, control flow is
1082transfered to the default destination.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001083
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001084<h5>Implementation:</h5>
1085
1086<p>Depending on properties of the target machine and the particular
1087<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswell84114752004-06-25 16:05:06 +00001088ways. For example, it could be generated as a series of chained conditional
1089branches or with a lookup table.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001090
1091<h5>Example:</h5>
1092
1093<pre>
1094 <i>; Emulate a conditional br instruction</i>
1095 %Val = <a href="#i_cast">cast</a> bool %value to int
1096 switch int %Val, label %truedest [int 0, label %falsedest ]
1097
1098 <i>; Emulate an unconditional br instruction</i>
1099 switch uint 0, label %dest [ ]
1100
1101 <i>; Implement a jump table:</i>
1102 switch uint %val, label %otherwise [ uint 0, label %onzero
1103 uint 1, label %onone
1104 uint 2, label %ontwo ]
Chris Lattner00950542001-06-06 20:29:01 +00001105</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001106</div>
Chris Lattner00950542001-06-06 20:29:01 +00001107<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001108<div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>'
1109Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001110<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001111<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001112<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 +00001113<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001114<p>The '<tt>invoke</tt>' instruction causes control to transfer to a
1115specified function, with the possibility of control flow transfer to
1116either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>.
1117If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>"
1118instruction, control flow will return to the "normal" label. If the
1119callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
1120instruction, control is interrupted, and continued at the dynamically
1121nearest "except" label.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001122<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001123<p>This instruction requires several arguments:</p>
Chris Lattner00950542001-06-06 20:29:01 +00001124<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00001125 <li>'<tt>ptr to function ty</tt>': shall be the signature of the
1126pointer to function value being invoked. In most cases, this is a
1127direct function invocation, but indirect <tt>invoke</tt>s are just as
1128possible, branching off an arbitrary pointer to function value. </li>
1129 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer
1130to a function to be invoked. </li>
1131 <li>'<tt>function args</tt>': argument list whose types match the
1132function signature argument types. If the function signature indicates
1133the function accepts a variable number of arguments, the extra
1134arguments can be specified. </li>
1135 <li>'<tt>normal label</tt>': the label reached when the called
1136function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
1137 <li>'<tt>exception label</tt>': the label reached when a callee
1138returns with the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
Chris Lattner00950542001-06-06 20:29:01 +00001139</ol>
Chris Lattner00950542001-06-06 20:29:01 +00001140<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001141<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner261efe92003-11-25 01:02:51 +00001142 href="#i_call">call</a></tt>' instruction in most regards. The
1143primary difference is that it establishes an association with a label,
1144which is used by the runtime library to unwind the stack.</p>
1145<p>This instruction is used in languages with destructors to ensure
1146that proper cleanup is performed in the case of either a <tt>longjmp</tt>
1147or a thrown exception. Additionally, this is important for
1148implementation of '<tt>catch</tt>' clauses in high-level languages that
1149support them.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001150<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001151<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 +00001152</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001153</div>
Chris Lattner35eca582004-10-16 18:04:13 +00001154
1155
Chris Lattner27f71f22003-09-03 00:41:47 +00001156<!-- _______________________________________________________________________ -->
Chris Lattner35eca582004-10-16 18:04:13 +00001157
Chris Lattner261efe92003-11-25 01:02:51 +00001158<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
1159Instruction</a> </div>
Chris Lattner35eca582004-10-16 18:04:13 +00001160
Misha Brukman9d0919f2003-11-08 01:05:38 +00001161<div class="doc_text">
Chris Lattner35eca582004-10-16 18:04:13 +00001162
Chris Lattner27f71f22003-09-03 00:41:47 +00001163<h5>Syntax:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001164<pre>
1165 unwind
1166</pre>
1167
Chris Lattner27f71f22003-09-03 00:41:47 +00001168<h5>Overview:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001169
1170<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
1171at the first callee in the dynamic call stack which used an <a
1172href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
1173primarily used to implement exception handling.</p>
1174
Chris Lattner27f71f22003-09-03 00:41:47 +00001175<h5>Semantics:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001176
1177<p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to
1178immediately halt. The dynamic call stack is then searched for the first <a
1179href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
1180execution continues at the "exceptional" destination block specified by the
1181<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
1182dynamic call chain, undefined behavior results.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001183</div>
Chris Lattner35eca582004-10-16 18:04:13 +00001184
1185<!-- _______________________________________________________________________ -->
1186
1187<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
1188Instruction</a> </div>
1189
1190<div class="doc_text">
1191
1192<h5>Syntax:</h5>
1193<pre>
1194 unreachable
1195</pre>
1196
1197<h5>Overview:</h5>
1198
1199<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
1200instruction is used to inform the optimizer that a particular portion of the
1201code is not reachable. This can be used to indicate that the code after a
1202no-return function cannot be reached, and other facts.</p>
1203
1204<h5>Semantics:</h5>
1205
1206<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
1207</div>
1208
1209
1210
Chris Lattner00950542001-06-06 20:29:01 +00001211<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001212<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001213<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001214<p>Binary operators are used to do most of the computation in a
1215program. They require two operands, execute an operation on them, and
John Criswell9e2485c2004-12-10 15:51:16 +00001216produce a single value. The operands might represent
Chris Lattnera58561b2004-08-12 19:12:28 +00001217multiple data, as is the case with the <a href="#t_packed">packed</a> data type.
1218The result value of a binary operator is not
Chris Lattner261efe92003-11-25 01:02:51 +00001219necessarily the same type as its operands.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001220<p>There are several different binary operators:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001221</div>
Chris Lattner00950542001-06-06 20:29:01 +00001222<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001223<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
1224Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001225<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001226<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001227<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 +00001228</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001229<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001230<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001231<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001232<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattnera58561b2004-08-12 19:12:28 +00001233 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
1234 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1235Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001236<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001237<p>The value produced is the integer or floating point sum of the two
1238operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001239<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001240<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001241</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001242</div>
Chris Lattner00950542001-06-06 20:29:01 +00001243<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001244<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
1245Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001246<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001247<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001248<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 +00001249</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001250<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001251<p>The '<tt>sub</tt>' instruction returns the difference of its two
1252operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001253<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
1254instruction present in most other intermediate representations.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001255<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001256<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001257 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001258values.
1259This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1260Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001261<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001262<p>The value produced is the integer or floating point difference of
1263the two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001264<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001265<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001266 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
1267</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001268</div>
Chris Lattner00950542001-06-06 20:29:01 +00001269<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001270<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
1271Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001272<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001273<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001274<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 +00001275</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001276<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001277<p>The '<tt>mul</tt>' instruction returns the product of its two
1278operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001279<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001280<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001281 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001282values.
1283This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1284Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001285<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001286<p>The value produced is the integer or floating point product of the
Misha Brukman9d0919f2003-11-08 01:05:38 +00001287two operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001288<p>There is no signed vs unsigned multiplication. The appropriate
1289action is taken based on the type of the operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001290<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001291<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001292</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001293</div>
Chris Lattner00950542001-06-06 20:29:01 +00001294<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001295<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
1296Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001297<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001298<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001299<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1300</pre>
1301<h5>Overview:</h5>
1302<p>The '<tt>div</tt>' instruction returns the quotient of its two
1303operands.</p>
1304<h5>Arguments:</h5>
1305<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
1306 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001307values.
1308This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1309Both arguments must have identical types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001310<h5>Semantics:</h5>
1311<p>The value produced is the integer or floating point quotient of the
1312two operands.</p>
1313<h5>Example:</h5>
1314<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
1315</pre>
1316</div>
1317<!-- _______________________________________________________________________ -->
1318<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
1319Instruction</a> </div>
1320<div class="doc_text">
1321<h5>Syntax:</h5>
1322<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1323</pre>
1324<h5>Overview:</h5>
1325<p>The '<tt>rem</tt>' instruction returns the remainder from the
1326division of its two operands.</p>
1327<h5>Arguments:</h5>
1328<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1329 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001330values.
1331This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1332Both arguments must have identical types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001333<h5>Semantics:</h5>
1334<p>This returns the <i>remainder</i> of a division (where the result
1335has the same sign as the divisor), not the <i>modulus</i> (where the
1336result has the same sign as the dividend) of a value. For more
1337information about the difference, see: <a
1338 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1339Math Forum</a>.</p>
1340<h5>Example:</h5>
1341<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1342</pre>
1343</div>
1344<!-- _______________________________________________________________________ -->
1345<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1346Instructions</a> </div>
1347<div class="doc_text">
1348<h5>Syntax:</h5>
1349<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 +00001350 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1351 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1352 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1353 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1354 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1355</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001356<h5>Overview:</h5>
1357<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1358value based on a comparison of their two operands.</p>
1359<h5>Arguments:</h5>
1360<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1361be of <a href="#t_firstclass">first class</a> type (it is not possible
1362to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1363or '<tt>void</tt>' values, etc...). Both arguments must have identical
1364types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001365<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001366<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1367value if both operands are equal.<br>
1368The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1369value if both operands are unequal.<br>
1370The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1371value if the first operand is less than the second operand.<br>
1372The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1373value if the first operand is greater than the second operand.<br>
1374The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1375value if the first operand is less than or equal to the second operand.<br>
1376The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1377value if the first operand is greater than or equal to the second
1378operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001379<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001380<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner00950542001-06-06 20:29:01 +00001381 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
1382 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1383 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1384 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1385 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1386</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001387</div>
Chris Lattner00950542001-06-06 20:29:01 +00001388<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001389<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1390Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001391<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001392<p>Bitwise binary operators are used to do various forms of
1393bit-twiddling in a program. They are generally very efficient
John Criswell9e2485c2004-12-10 15:51:16 +00001394instructions and can commonly be strength reduced from other
Chris Lattner261efe92003-11-25 01:02:51 +00001395instructions. They require two operands, execute an operation on them,
1396and produce a single value. The resulting value of the bitwise binary
1397operators is always the same type as its first operand.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001398</div>
Chris Lattner00950542001-06-06 20:29:01 +00001399<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001400<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1401Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001402<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001403<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001404<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 +00001405</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001406<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001407<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1408its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001409<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001410<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001411 href="#t_integral">integral</a> values. Both arguments must have
1412identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001413<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001414<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001415<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001416<div style="align: center">
Misha Brukman9d0919f2003-11-08 01:05:38 +00001417<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +00001418 <tbody>
1419 <tr>
1420 <td>In0</td>
1421 <td>In1</td>
1422 <td>Out</td>
1423 </tr>
1424 <tr>
1425 <td>0</td>
1426 <td>0</td>
1427 <td>0</td>
1428 </tr>
1429 <tr>
1430 <td>0</td>
1431 <td>1</td>
1432 <td>0</td>
1433 </tr>
1434 <tr>
1435 <td>1</td>
1436 <td>0</td>
1437 <td>0</td>
1438 </tr>
1439 <tr>
1440 <td>1</td>
1441 <td>1</td>
1442 <td>1</td>
1443 </tr>
1444 </tbody>
1445</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001446</div>
Chris Lattner00950542001-06-06 20:29:01 +00001447<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001448<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001449 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1450 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1451</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001452</div>
Chris Lattner00950542001-06-06 20:29:01 +00001453<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001454<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001455<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001456<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001457<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 +00001458</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001459<h5>Overview:</h5>
1460<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1461or of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001462<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001463<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001464 href="#t_integral">integral</a> values. Both arguments must have
1465identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001466<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001467<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001468<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001469<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001470<table border="1" cellspacing="0" cellpadding="4">
1471 <tbody>
1472 <tr>
1473 <td>In0</td>
1474 <td>In1</td>
1475 <td>Out</td>
1476 </tr>
1477 <tr>
1478 <td>0</td>
1479 <td>0</td>
1480 <td>0</td>
1481 </tr>
1482 <tr>
1483 <td>0</td>
1484 <td>1</td>
1485 <td>1</td>
1486 </tr>
1487 <tr>
1488 <td>1</td>
1489 <td>0</td>
1490 <td>1</td>
1491 </tr>
1492 <tr>
1493 <td>1</td>
1494 <td>1</td>
1495 <td>1</td>
1496 </tr>
1497 </tbody>
1498</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001499</div>
Chris Lattner00950542001-06-06 20:29:01 +00001500<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001501<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001502 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1503 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1504</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001505</div>
Chris Lattner00950542001-06-06 20:29:01 +00001506<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001507<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1508Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001509<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001510<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001511<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 +00001512</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001513<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001514<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1515or of its two operands. The <tt>xor</tt> is used to implement the
1516"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001517<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001518<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001519 href="#t_integral">integral</a> values. Both arguments must have
1520identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001521<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001522<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001523<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001524<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001525<table border="1" cellspacing="0" cellpadding="4">
1526 <tbody>
1527 <tr>
1528 <td>In0</td>
1529 <td>In1</td>
1530 <td>Out</td>
1531 </tr>
1532 <tr>
1533 <td>0</td>
1534 <td>0</td>
1535 <td>0</td>
1536 </tr>
1537 <tr>
1538 <td>0</td>
1539 <td>1</td>
1540 <td>1</td>
1541 </tr>
1542 <tr>
1543 <td>1</td>
1544 <td>0</td>
1545 <td>1</td>
1546 </tr>
1547 <tr>
1548 <td>1</td>
1549 <td>1</td>
1550 <td>0</td>
1551 </tr>
1552 </tbody>
1553</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001554</div>
Chris Lattner261efe92003-11-25 01:02:51 +00001555<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001556<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001557<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001558 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1559 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner27f71f22003-09-03 00:41:47 +00001560 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner00950542001-06-06 20:29:01 +00001561</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001562</div>
Chris Lattner00950542001-06-06 20:29:01 +00001563<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001564<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1565Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001566<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001567<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001568<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 +00001569</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001570<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001571<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1572the left a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001573<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001574<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001575 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1576type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001577<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001578<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001579<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001580<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 +00001581 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1582 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1583</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001584</div>
Chris Lattner00950542001-06-06 20:29:01 +00001585<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001586<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1587Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001588<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001589<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001590<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 +00001591</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001592<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001593<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1594the right a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001595<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001596<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001597 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1598type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001599<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001600<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1601most significant bit is duplicated in the newly free'd bit positions.
1602If the first argument is unsigned, zero bits shall fill the empty
1603positions.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001604<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001605<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 +00001606 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001607 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner8c6bb902003-06-18 21:30:51 +00001608 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1609 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner00950542001-06-06 20:29:01 +00001610</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001611</div>
Chris Lattner00950542001-06-06 20:29:01 +00001612<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001613<div class="doc_subsection"> <a name="memoryops">Memory Access
1614Operations</a></div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001615<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001616<p>A key design point of an SSA-based representation is how it
1617represents memory. In LLVM, no memory locations are in SSA form, which
1618makes things very simple. This section describes how to read, write,
John Criswell9e2485c2004-12-10 15:51:16 +00001619allocate, and free memory in LLVM.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001620</div>
Chris Lattner00950542001-06-06 20:29:01 +00001621<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001622<div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>'
1623Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001624<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001625<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001626<pre> &lt;result&gt; = malloc &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001627 &lt;result&gt; = malloc &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001628</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001629<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001630<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1631heap and returns a pointer to it.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001632<h5>Arguments:</h5>
John Criswell6e4ca612004-02-24 16:13:56 +00001633<p>The '<tt>malloc</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1634bytes of memory from the operating system and returns a pointer of the
Chris Lattner261efe92003-11-25 01:02:51 +00001635appropriate type to the program. The second form of the instruction is
1636a shorter version of the first instruction that defaults to allocating
1637one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001638<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001639<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001640<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1641a pointer is returned.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001642<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001643<pre> %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001644
Chris Lattner261efe92003-11-25 01:02:51 +00001645 %size = <a
1646 href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001647 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1648 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001649</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001650</div>
Chris Lattner00950542001-06-06 20:29:01 +00001651<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001652<div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>'
1653Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001654<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001655<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001656<pre> free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner00950542001-06-06 20:29:01 +00001657</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001658<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001659<p>The '<tt>free</tt>' instruction returns memory back to the unused
1660memory heap, to be reallocated in the future.</p>
1661<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001662<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001663<p>'<tt>value</tt>' shall be a pointer value that points to a value
1664that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1665instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001666<h5>Semantics:</h5>
John Criswell9e2485c2004-12-10 15:51:16 +00001667<p>Access to the memory pointed to by the pointer is no longer defined
Chris Lattner261efe92003-11-25 01:02:51 +00001668after this instruction executes.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001669<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001670<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 +00001671 free [4 x ubyte]* %array
1672</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001673</div>
Chris Lattner00950542001-06-06 20:29:01 +00001674<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001675<div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>'
1676Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001677<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001678<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001679<pre> &lt;result&gt; = alloca &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001680 &lt;result&gt; = alloca &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001681</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001682<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001683<p>The '<tt>alloca</tt>' instruction allocates memory on the current
1684stack frame of the procedure that is live until the current function
1685returns to its caller.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001686<h5>Arguments:</h5>
John Criswell9e2485c2004-12-10 15:51:16 +00001687<p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001688bytes of memory on the runtime stack, returning a pointer of the
1689appropriate type to the program. The second form of the instruction is
1690a shorter version of the first that defaults to allocating one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001691<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001692<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001693<p>Memory is allocated, a pointer is returned. '<tt>alloca</tt>'d
1694memory is automatically released when the function returns. The '<tt>alloca</tt>'
1695instruction is commonly used to represent automatic variables that must
1696have an address available. When the function returns (either with the <tt><a
1697 href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001698instructions), the memory is reclaimed.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001699<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001700<pre> %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001701 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner00950542001-06-06 20:29:01 +00001702</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001703</div>
Chris Lattner00950542001-06-06 20:29:01 +00001704<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001705<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1706Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001707<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00001708<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001709<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 +00001710<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001711<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001712<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001713<p>The argument to the '<tt>load</tt>' instruction specifies the memory
1714address to load from. The pointer must point to a <a
Chris Lattnere53e5082004-06-03 22:57:15 +00001715 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
Chris Lattner261efe92003-11-25 01:02:51 +00001716marked as <tt>volatile</tt> then the optimizer is not allowed to modify
1717the number or order of execution of this <tt>load</tt> with other
1718volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1719instructions. </p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001720<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001721<p>The location of memory pointed to is loaded.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001722<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001723<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1724 <a
1725 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001726 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1727</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001728</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001729<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001730<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1731Instruction</a> </div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001732<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001733<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 +00001734 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 +00001735</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001736<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001737<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001738<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001739<p>There are two arguments to the '<tt>store</tt>' instruction: a value
1740to store and an address to store it into. The type of the '<tt>&lt;pointer&gt;</tt>'
1741operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
1742operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the
1743optimizer is not allowed to modify the number or order of execution of
1744this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1745 href="#i_store">store</a></tt> instructions.</p>
1746<h5>Semantics:</h5>
1747<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
1748at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001749<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001750<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1751 <a
1752 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001753 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1754</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001755<!-- _______________________________________________________________________ -->
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001756<div class="doc_subsubsection">
1757 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
1758</div>
1759
Misha Brukman9d0919f2003-11-08 01:05:38 +00001760<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00001761<h5>Syntax:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001762<pre>
1763 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
1764</pre>
1765
Chris Lattner7faa8832002-04-14 06:13:44 +00001766<h5>Overview:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001767
1768<p>
1769The '<tt>getelementptr</tt>' instruction is used to get the address of a
1770subelement of an aggregate data structure.</p>
1771
Chris Lattner7faa8832002-04-14 06:13:44 +00001772<h5>Arguments:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001773
1774<p>This instruction takes a list of integer constants that indicate what
1775elements of the aggregate object to index to. The actual types of the arguments
1776provided depend on the type of the first pointer argument. The
1777'<tt>getelementptr</tt>' instruction is used to index down through the type
1778levels of a structure. When indexing into a structure, only <tt>uint</tt>
1779integer constants are allowed. When indexing into an array or pointer
1780<tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
1781
Chris Lattner261efe92003-11-25 01:02:51 +00001782<p>For example, let's consider a C code fragment and how it gets
1783compiled to LLVM:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001784
1785<pre>
1786 struct RT {
1787 char A;
1788 int B[10][20];
1789 char C;
1790 };
1791 struct ST {
1792 int X;
1793 double Y;
1794 struct RT Z;
1795 };
1796
1797 int *foo(struct ST *s) {
1798 return &amp;s[1].Z.B[5][13];
1799 }
1800</pre>
1801
Misha Brukman9d0919f2003-11-08 01:05:38 +00001802<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001803
1804<pre>
1805 %RT = type { sbyte, [10 x [20 x int]], sbyte }
1806 %ST = type { int, double, %RT }
1807
Brian Gaeke7283e7c2004-07-02 21:08:14 +00001808 implementation
1809
1810 int* %foo(%ST* %s) {
1811 entry:
1812 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001813 ret int* %reg
1814 }
1815</pre>
1816
Chris Lattner7faa8832002-04-14 06:13:44 +00001817<h5>Semantics:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001818
1819<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
Chris Lattnere53e5082004-06-03 22:57:15 +00001820on the pointer type that is being index into. <a href="#t_pointer">Pointer</a>
1821and <a href="#t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
1822<tt>ulong</tt>, or <tt>long</tt> values, and <a href="#t_struct">structure</a>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001823types require <tt>uint</tt> <b>constants</b>.</p>
1824
Misha Brukman9d0919f2003-11-08 01:05:38 +00001825<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001826type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
1827}</tt>' type, a structure. The second index indexes into the third element of
1828the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
1829sbyte }</tt>' type, another structure. The third index indexes into the second
1830element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
1831array. The two dimensions of the array are subscripted into, yielding an
1832'<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction return a pointer
1833to this element, thus computing a value of '<tt>int*</tt>' type.</p>
1834
Chris Lattner261efe92003-11-25 01:02:51 +00001835<p>Note that it is perfectly legal to index partially through a
1836structure, returning a pointer to an inner element. Because of this,
1837the LLVM code for the given testcase is equivalent to:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001838
1839<pre>
Chris Lattnerd4f6b172005-03-07 22:13:59 +00001840 int* %foo(%ST* %s) {
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001841 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
1842 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
1843 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
1844 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
1845 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
1846 ret int* %t5
1847 }
Chris Lattner6536cfe2002-05-06 22:08:29 +00001848</pre>
Chris Lattner7faa8832002-04-14 06:13:44 +00001849<h5>Example:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001850<pre>
1851 <i>; yields [12 x ubyte]*:aptr</i>
1852 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
1853</pre>
1854
1855</div>
Chris Lattner00950542001-06-06 20:29:01 +00001856<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001857<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001858<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +00001859<p>The instructions in this category are the "miscellaneous"
Chris Lattner261efe92003-11-25 01:02:51 +00001860instructions, which defy better classification.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001861</div>
Chris Lattner00950542001-06-06 20:29:01 +00001862<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001863<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
1864Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001865<div class="doc_text">
Chris Lattner33ba0d92001-07-09 00:26:23 +00001866<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001867<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001868<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001869<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
1870the SSA graph representing the function.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001871<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001872<p>The type of the incoming values are specified with the first type
1873field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
1874as arguments, with one pair for each predecessor basic block of the
1875current block. Only values of <a href="#t_firstclass">first class</a>
1876type may be used as the value arguments to the PHI node. Only labels
1877may be used as the label arguments.</p>
1878<p>There must be no non-phi instructions between the start of a basic
1879block and the PHI instructions: i.e. PHI instructions must be first in
1880a basic block.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001881<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001882<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
1883value specified by the parameter, depending on which basic block we
1884came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001885<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001886<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 +00001887</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001888
Chris Lattner6536cfe2002-05-06 22:08:29 +00001889<!-- _______________________________________________________________________ -->
Chris Lattnercc37aae2004-03-12 05:50:16 +00001890<div class="doc_subsubsection">
1891 <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
1892</div>
1893
Misha Brukman9d0919f2003-11-08 01:05:38 +00001894<div class="doc_text">
Chris Lattnercc37aae2004-03-12 05:50:16 +00001895
Chris Lattner6536cfe2002-05-06 22:08:29 +00001896<h5>Syntax:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001897
1898<pre>
1899 &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 +00001900</pre>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001901
Chris Lattner6536cfe2002-05-06 22:08:29 +00001902<h5>Overview:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001903
1904<p>
1905The '<tt>cast</tt>' instruction is used as the primitive means to convert
1906integers to floating point, change data type sizes, and break type safety (by
1907casting pointers).
1908</p>
1909
1910
Chris Lattner6536cfe2002-05-06 22:08:29 +00001911<h5>Arguments:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001912
1913<p>
1914The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
1915class value, and a type to cast it to, which must also be a <a
1916href="#t_firstclass">first class</a> type.
1917</p>
1918
Chris Lattner6536cfe2002-05-06 22:08:29 +00001919<h5>Semantics:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001920
1921<p>
1922This instruction follows the C rules for explicit casts when determining how the
1923data being cast must change to fit in its new container.
1924</p>
1925
1926<p>
1927When casting to bool, any value that would be considered true in the context of
1928a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
1929all else are '<tt>false</tt>'.
1930</p>
1931
1932<p>
1933When extending an integral value from a type of one signness to another (for
1934example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
1935<b>source</b> value is signed, and zero-extended if the source value is
1936unsigned. <tt>bool</tt> values are always zero extended into either zero or
1937one.
1938</p>
1939
Chris Lattner33ba0d92001-07-09 00:26:23 +00001940<h5>Example:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001941
1942<pre>
1943 %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattner7bae3952002-06-25 18:03:17 +00001944 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001945</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001946</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001947
1948<!-- _______________________________________________________________________ -->
1949<div class="doc_subsubsection">
1950 <a name="i_select">'<tt>select</tt>' Instruction</a>
1951</div>
1952
1953<div class="doc_text">
1954
1955<h5>Syntax:</h5>
1956
1957<pre>
1958 &lt;result&gt; = select bool &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
1959</pre>
1960
1961<h5>Overview:</h5>
1962
1963<p>
1964The '<tt>select</tt>' instruction is used to choose one value based on a
1965condition, without branching.
1966</p>
1967
1968
1969<h5>Arguments:</h5>
1970
1971<p>
1972The '<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.
1973</p>
1974
1975<h5>Semantics:</h5>
1976
1977<p>
1978If the boolean condition evaluates to true, the instruction returns the first
1979value argument, otherwise it returns the second value argument.
1980</p>
1981
1982<h5>Example:</h5>
1983
1984<pre>
1985 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
1986</pre>
1987</div>
1988
1989
1990
1991
1992
Chris Lattner33ba0d92001-07-09 00:26:23 +00001993<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001994<div class="doc_subsubsection"> <a name="i_call">'<tt>call</tt>'
1995Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001996<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001997<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001998<pre> &lt;result&gt; = call &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +00001999<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002000<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002001<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002002<p>This instruction requires several arguments:</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00002003<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00002004 <li>
2005 <p>'<tt>ty</tt>': shall be the signature of the pointer to function
2006value being invoked. The argument types must match the types implied
2007by this signature.</p>
2008 </li>
2009 <li>
2010 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a
2011function to be invoked. In most cases, this is a direct function
2012invocation, but indirect <tt>call</tt>s are just as possible,
2013calling an arbitrary pointer to function values.</p>
2014 </li>
2015 <li>
2016 <p>'<tt>function args</tt>': argument list whose types match the
2017function signature argument types. If the function signature
2018indicates the function accepts a variable number of arguments, the
2019extra arguments can be specified.</p>
2020 </li>
Chris Lattner6536cfe2002-05-06 22:08:29 +00002021</ol>
Chris Lattner00950542001-06-06 20:29:01 +00002022<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002023<p>The '<tt>call</tt>' instruction is used to cause control flow to
2024transfer to a specified function, with its incoming arguments bound to
2025the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
2026instruction in the called function, control flow continues with the
2027instruction after the function call, and the return value of the
2028function is bound to the result argument. This is a simpler case of
2029the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002030<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002031<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 +00002032</div>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002033
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002034<!-- _______________________________________________________________________ -->
Chris Lattnere19d7a72004-09-27 21:51:25 +00002035<div class="doc_subsubsection">
2036 <a name="i_vanext">'<tt>vanext</tt>' Instruction</a>
2037</div>
2038
Misha Brukman9d0919f2003-11-08 01:05:38 +00002039<div class="doc_text">
Chris Lattnere19d7a72004-09-27 21:51:25 +00002040
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002041<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002042
2043<pre>
2044 &lt;resultarglist&gt; = vanext &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;
2045</pre>
2046
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002047<h5>Overview:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002048
Chris Lattner261efe92003-11-25 01:02:51 +00002049<p>The '<tt>vanext</tt>' instruction is used to access arguments passed
2050through the "variable argument" area of a function call. It is used to
2051implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002052
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002053<h5>Arguments:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002054
2055<p>This instruction takes a <tt>va_list</tt> value and the type of the
2056argument. It returns another <tt>va_list</tt>. The actual type of
2057<tt>va_list</tt> may be defined differently for different targets. Most targets
2058use a <tt>va_list</tt> type of <tt>sbyte*</tt> or some other pointer type.</p>
2059
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002060<h5>Semantics:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002061
2062<p>The '<tt>vanext</tt>' instruction advances the specified <tt>va_list</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002063past an argument of the specified type. In conjunction with the <a
2064 href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement
2065the <tt>va_arg</tt> macro available in C. For more information, see
2066the variable argument handling <a href="#int_varargs">Intrinsic
2067Functions</a>.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002068
Chris Lattner261efe92003-11-25 01:02:51 +00002069<p>It is legal for this instruction to be called in a function which
2070does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002071function.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002072
Misha Brukman9d0919f2003-11-08 01:05:38 +00002073<p><tt>vanext</tt> is an LLVM instruction instead of an <a
Chris Lattnere19d7a72004-09-27 21:51:25 +00002074href="#intrinsics">intrinsic function</a> because it takes a type as an
2075argument. The type refers to the current argument in the <tt>va_list</tt>, it
2076tells the compiler how far on the stack it needs to advance to find the next
2077argument</p>
2078
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002079<h5>Example:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002080
Chris Lattner261efe92003-11-25 01:02:51 +00002081<p>See the <a href="#int_varargs">variable argument processing</a>
2082section.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002083
Misha Brukman9d0919f2003-11-08 01:05:38 +00002084</div>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002085
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002086<!-- _______________________________________________________________________ -->
Chris Lattnere19d7a72004-09-27 21:51:25 +00002087<div class="doc_subsubsection">
2088 <a name="i_vaarg">'<tt>vaarg</tt>' Instruction</a>
2089</div>
2090
Misha Brukman9d0919f2003-11-08 01:05:38 +00002091<div class="doc_text">
Chris Lattnere19d7a72004-09-27 21:51:25 +00002092
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002093<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002094
2095<pre>
2096 &lt;resultval&gt; = vaarg &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;
2097</pre>
2098
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002099<h5>Overview:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002100
2101<p>The '<tt>vaarg</tt>' instruction is used to access arguments passed through
2102the "variable argument" area of a function call. It is used to implement the
2103<tt>va_arg</tt> macro in C.</p>
2104
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002105<h5>Arguments:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002106
2107<p>This instruction takes a <tt>va_list</tt> value and the type of the
2108argument. It returns a value of the specified argument type. Again, the actual
2109type of <tt>va_list</tt> is target specific.</p>
2110
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002111<h5>Semantics:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002112
2113<p>The '<tt>vaarg</tt>' instruction loads an argument of the specified type from
2114the specified <tt>va_list</tt>. In conjunction with the <a
2115href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to implement the
2116<tt>va_arg</tt> macro available in C. For more information, see the variable
2117argument handling <a href="#int_varargs">Intrinsic Functions</a>.</p>
2118
2119<p>It is legal for this instruction to be called in a function which does not
2120take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002121function.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002122
Misha Brukman9d0919f2003-11-08 01:05:38 +00002123<p><tt>vaarg</tt> is an LLVM instruction instead of an <a
Chris Lattnere19d7a72004-09-27 21:51:25 +00002124href="#intrinsics">intrinsic function</a> because it takes an type as an
2125argument.</p>
2126
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002127<h5>Example:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002128
2129<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
2130
Misha Brukman9d0919f2003-11-08 01:05:38 +00002131</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002132
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002133<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00002134<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
2135<!-- *********************************************************************** -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002136
Misha Brukman9d0919f2003-11-08 01:05:38 +00002137<div class="doc_text">
Chris Lattner33aec9e2004-02-12 17:01:32 +00002138
2139<p>LLVM supports the notion of an "intrinsic function". These functions have
2140well known names and semantics, and are required to follow certain
2141restrictions. Overall, these instructions represent an extension mechanism for
2142the LLVM language that does not require changing all of the transformations in
2143LLVM to add to the language (or the bytecode reader/writer, the parser,
2144etc...).</p>
2145
2146<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix, this
2147prefix is reserved in LLVM for intrinsic names, thus functions may not be named
2148this. Intrinsic functions must always be external functions: you cannot define
2149the body of intrinsic functions. Intrinsic functions may only be used in call
2150or invoke instructions: it is illegal to take the address of an intrinsic
2151function. Additionally, because intrinsic functions are part of the LLVM
2152language, it is required that they all be documented here if any are added.</p>
2153
2154
2155<p>
2156Adding an intrinsic to LLVM is straight-forward if it is possible to express the
2157concept in LLVM directly (ie, code generator support is not _required_). To do
2158this, extend the default implementation of the IntrinsicLowering class to handle
2159the intrinsic. Code generators use this class to lower intrinsics they do not
2160understand to raw LLVM instructions that they do.
2161</p>
2162
Misha Brukman9d0919f2003-11-08 01:05:38 +00002163</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002164
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002165<!-- ======================================================================= -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002166<div class="doc_subsection">
2167 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
2168</div>
2169
Misha Brukman9d0919f2003-11-08 01:05:38 +00002170<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00002171
Misha Brukman9d0919f2003-11-08 01:05:38 +00002172<p>Variable argument support is defined in LLVM with the <a
Chris Lattner261efe92003-11-25 01:02:51 +00002173 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
2174intrinsic functions. These functions are related to the similarly
2175named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002176
Chris Lattner261efe92003-11-25 01:02:51 +00002177<p>All of these functions operate on arguments that use a
2178target-specific value type "<tt>va_list</tt>". The LLVM assembly
2179language reference manual does not define what this type is, so all
2180transformations should be prepared to handle intrinsics with any type
2181used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002182
Misha Brukman9d0919f2003-11-08 01:05:38 +00002183<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner261efe92003-11-25 01:02:51 +00002184instruction and the variable argument handling intrinsic functions are
2185used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002186
Chris Lattner33aec9e2004-02-12 17:01:32 +00002187<pre>
2188int %test(int %X, ...) {
2189 ; Initialize variable argument processing
2190 %ap = call sbyte* %<a href="#i_va_start">llvm.va_start</a>()
2191
2192 ; Read a single integer argument
2193 %tmp = vaarg sbyte* %ap, int
2194
2195 ; Advance to the next argument
2196 %ap2 = vanext sbyte* %ap, int
2197
2198 ; Demonstrate usage of llvm.va_copy and llvm.va_end
2199 %aq = call sbyte* %<a href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2)
2200 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %aq)
2201
2202 ; Stop processing of arguments.
2203 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %ap2)
2204 ret int %tmp
2205}
2206</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002207</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002208
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002209<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002210<div class="doc_subsubsection">
2211 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
2212</div>
2213
2214
Misha Brukman9d0919f2003-11-08 01:05:38 +00002215<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002216<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002217<pre> call &lt;va_list&gt; ()* %llvm.va_start()<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002218<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002219<p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt>&lt;arglist&gt;</tt>
2220for subsequent use by the variable argument intrinsics.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002221<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002222<p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002223macro available in C. In a target-dependent way, it initializes and
2224returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt>
2225will produce the first variable argument passed to the function. Unlike
2226the C <tt>va_start</tt> macro, this intrinsic does not need to know the
2227last argument of the function, the compiler can figure that out.</p>
2228<p>Note that this intrinsic function is only legal to be called from
2229within the body of a variable argument function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002230</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002231
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002232<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002233<div class="doc_subsubsection">
2234 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
2235</div>
2236
Misha Brukman9d0919f2003-11-08 01:05:38 +00002237<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002238<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002239<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 +00002240<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002241<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
2242which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
2243or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002244<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002245<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002246<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002247<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002248macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
2249Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
2250 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
2251with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002252</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002253
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002254<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002255<div class="doc_subsubsection">
2256 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
2257</div>
2258
Misha Brukman9d0919f2003-11-08 01:05:38 +00002259<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00002260
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002261<h5>Syntax:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002262
2263<pre>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002264 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 +00002265</pre>
2266
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002267<h5>Overview:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002268
2269<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position
2270from the source argument list to the destination argument list.</p>
2271
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002272<h5>Arguments:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002273
Misha Brukman9d0919f2003-11-08 01:05:38 +00002274<p>The argument is the <tt>va_list</tt> to copy.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002275
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002276<h5>Semantics:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002277
Misha Brukman9d0919f2003-11-08 01:05:38 +00002278<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
Chris Lattnerd7923912004-05-23 21:06:01 +00002279macro available in C. In a target-dependent way, it copies the source
2280<tt>va_list</tt> element into the returned list. This intrinsic is necessary
Chris Lattnerfcd37252004-06-21 22:52:48 +00002281because the <tt><a href="#i_va_start">llvm.va_start</a></tt> intrinsic may be
Chris Lattnerd7923912004-05-23 21:06:01 +00002282arbitrarily complex and require memory allocation, for example.</p>
2283
Misha Brukman9d0919f2003-11-08 01:05:38 +00002284</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002285
Chris Lattner33aec9e2004-02-12 17:01:32 +00002286<!-- ======================================================================= -->
2287<div class="doc_subsection">
Chris Lattnerd7923912004-05-23 21:06:01 +00002288 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
2289</div>
2290
2291<div class="doc_text">
2292
2293<p>
2294LLVM support for <a href="GarbageCollection.html">Accurate Garbage
2295Collection</a> requires the implementation and generation of these intrinsics.
2296These intrinsics allow identification of <a href="#i_gcroot">GC roots on the
2297stack</a>, as well as garbage collector implementations that require <a
2298href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers.
2299Front-ends for type-safe garbage collected languages should generate these
2300intrinsics to make use of the LLVM garbage collectors. For more details, see <a
2301href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
2302</p>
2303</div>
2304
2305<!-- _______________________________________________________________________ -->
2306<div class="doc_subsubsection">
2307 <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
2308</div>
2309
2310<div class="doc_text">
2311
2312<h5>Syntax:</h5>
2313
2314<pre>
2315 call void (&lt;ty&gt;**, &lt;ty2&gt;*)* %llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
2316</pre>
2317
2318<h5>Overview:</h5>
2319
John Criswell9e2485c2004-12-10 15:51:16 +00002320<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
Chris Lattnerd7923912004-05-23 21:06:01 +00002321the code generator, and allows some metadata to be associated with it.</p>
2322
2323<h5>Arguments:</h5>
2324
2325<p>The first argument specifies the address of a stack object that contains the
2326root pointer. The second pointer (which must be either a constant or a global
2327value address) contains the meta-data to be associated with the root.</p>
2328
2329<h5>Semantics:</h5>
2330
2331<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
2332location. At compile-time, the code generator generates information to allow
2333the runtime to find the pointer at GC safe points.
2334</p>
2335
2336</div>
2337
2338
2339<!-- _______________________________________________________________________ -->
2340<div class="doc_subsubsection">
2341 <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
2342</div>
2343
2344<div class="doc_text">
2345
2346<h5>Syntax:</h5>
2347
2348<pre>
2349 call sbyte* (sbyte**)* %llvm.gcread(sbyte** %Ptr)
2350</pre>
2351
2352<h5>Overview:</h5>
2353
2354<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
2355locations, allowing garbage collector implementations that require read
2356barriers.</p>
2357
2358<h5>Arguments:</h5>
2359
2360<p>The argument is the address to read from, which should be an address
2361allocated from the garbage collector.</p>
2362
2363<h5>Semantics:</h5>
2364
2365<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
2366instruction, but may be replaced with substantially more complex code by the
2367garbage collector runtime, as needed.</p>
2368
2369</div>
2370
2371
2372<!-- _______________________________________________________________________ -->
2373<div class="doc_subsubsection">
2374 <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
2375</div>
2376
2377<div class="doc_text">
2378
2379<h5>Syntax:</h5>
2380
2381<pre>
2382 call void (sbyte*, sbyte**)* %llvm.gcwrite(sbyte* %P1, sbyte** %P2)
2383</pre>
2384
2385<h5>Overview:</h5>
2386
2387<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
2388locations, allowing garbage collector implementations that require write
2389barriers (such as generational or reference counting collectors).</p>
2390
2391<h5>Arguments:</h5>
2392
2393<p>The first argument is the reference to store, and the second is the heap
2394location to store to.</p>
2395
2396<h5>Semantics:</h5>
2397
2398<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
2399instruction, but may be replaced with substantially more complex code by the
2400garbage collector runtime, as needed.</p>
2401
2402</div>
2403
2404
2405
2406<!-- ======================================================================= -->
2407<div class="doc_subsection">
Chris Lattner10610642004-02-14 04:08:35 +00002408 <a name="int_codegen">Code Generator Intrinsics</a>
2409</div>
2410
2411<div class="doc_text">
2412<p>
2413These intrinsics are provided by LLVM to expose special features that may only
2414be implemented with code generator support.
2415</p>
2416
2417</div>
2418
2419<!-- _______________________________________________________________________ -->
2420<div class="doc_subsubsection">
2421 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
2422</div>
2423
2424<div class="doc_text">
2425
2426<h5>Syntax:</h5>
2427<pre>
2428 call void* ()* %llvm.returnaddress(uint &lt;level&gt;)
2429</pre>
2430
2431<h5>Overview:</h5>
2432
2433<p>
2434The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
2435indicating the return address of the current function or one of its callers.
2436</p>
2437
2438<h5>Arguments:</h5>
2439
2440<p>
2441The argument to this intrinsic indicates which function to return the address
2442for. Zero indicates the calling function, one indicates its caller, etc. The
2443argument is <b>required</b> to be a constant integer value.
2444</p>
2445
2446<h5>Semantics:</h5>
2447
2448<p>
2449The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
2450the return address of the specified call frame, or zero if it cannot be
2451identified. The value returned by this intrinsic is likely to be incorrect or 0
2452for arguments other than zero, so it should only be used for debugging purposes.
2453</p>
2454
2455<p>
2456Note that calling this intrinsic does not prevent function inlining or other
Chris Lattnerb40bb382005-03-07 20:30:51 +00002457aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner10610642004-02-14 04:08:35 +00002458source-language caller.
2459</p>
2460</div>
2461
2462
2463<!-- _______________________________________________________________________ -->
2464<div class="doc_subsubsection">
2465 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
2466</div>
2467
2468<div class="doc_text">
2469
2470<h5>Syntax:</h5>
2471<pre>
2472 call void* ()* %llvm.frameaddress(uint &lt;level&gt;)
2473</pre>
2474
2475<h5>Overview:</h5>
2476
2477<p>
2478The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
2479pointer value for the specified stack frame.
2480</p>
2481
2482<h5>Arguments:</h5>
2483
2484<p>
2485The argument to this intrinsic indicates which function to return the frame
2486pointer for. Zero indicates the calling function, one indicates its caller,
2487etc. The argument is <b>required</b> to be a constant integer value.
2488</p>
2489
2490<h5>Semantics:</h5>
2491
2492<p>
2493The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
2494the frame address of the specified call frame, or zero if it cannot be
2495identified. The value returned by this intrinsic is likely to be incorrect or 0
2496for arguments other than zero, so it should only be used for debugging purposes.
2497</p>
2498
2499<p>
2500Note that calling this intrinsic does not prevent function inlining or other
Chris Lattnerb40bb382005-03-07 20:30:51 +00002501aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner10610642004-02-14 04:08:35 +00002502source-language caller.
2503</p>
2504</div>
2505
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00002506<!-- _______________________________________________________________________ -->
2507<div class="doc_subsubsection">
2508 <a name="i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a>
2509</div>
2510
2511<div class="doc_text">
2512
2513<h5>Syntax:</h5>
2514<pre>
2515 call void (sbyte *, uint, uint)* %llvm.prefetch(sbyte * &lt;address&gt;,
2516 uint &lt;rw&gt;,
2517 uint &lt;locality&gt;)
2518</pre>
2519
2520<h5>Overview:</h5>
2521
2522
2523<p>
2524The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to insert
2525a prefetch instruction if supported, otherwise it is a noop. Prefetches have no
Chris Lattner2a615362005-02-28 19:47:14 +00002526effect on the behavior of the program, but can change its performance
2527characteristics.
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00002528</p>
2529
2530<h5>Arguments:</h5>
2531
2532<p>
2533<tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier
2534determining if the fetch should be for a read (0) or write (1), and
2535<tt>locality</tt> is a temporal locality specifier ranging from (0) - no
Chris Lattneraeffb4a2005-03-07 20:31:38 +00002536locality, to (3) - extremely local keep in cache. The <tt>rw</tt> and
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00002537<tt>locality</tt> arguments must be constant integers.
2538</p>
2539
2540<h5>Semantics:</h5>
2541
2542<p>
2543This intrinsic does not modify the behavior of the program. In particular,
2544prefetches cannot trap and do not produce a value. On targets that support this
2545intrinsic, the prefetch can provide hints to the processor cache for better
2546performance.
2547</p>
2548
2549</div>
2550
2551
John Criswell7123e272004-04-09 16:43:20 +00002552<!-- ======================================================================= -->
2553<div class="doc_subsection">
2554 <a name="int_os">Operating System Intrinsics</a>
2555</div>
2556
2557<div class="doc_text">
2558<p>
2559These intrinsics are provided by LLVM to support the implementation of
2560operating system level code.
2561</p>
2562
2563</div>
John Criswell183402a2004-04-12 15:02:16 +00002564
John Criswellcfd3bac2004-04-09 15:23:37 +00002565<!-- _______________________________________________________________________ -->
2566<div class="doc_subsubsection">
2567 <a name="i_readport">'<tt>llvm.readport</tt>' Intrinsic</a>
2568</div>
2569
2570<div class="doc_text">
2571
2572<h5>Syntax:</h5>
2573<pre>
John Criswell7123e272004-04-09 16:43:20 +00002574 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 +00002575</pre>
2576
2577<h5>Overview:</h5>
2578
2579<p>
John Criswell7123e272004-04-09 16:43:20 +00002580The '<tt>llvm.readport</tt>' intrinsic reads data from the specified hardware
2581I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002582</p>
2583
2584<h5>Arguments:</h5>
2585
2586<p>
John Criswell7123e272004-04-09 16:43:20 +00002587The argument to this intrinsic indicates the hardware I/O address from which
2588to read the data. The address is in the hardware I/O address namespace (as
2589opposed to being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002590</p>
2591
2592<h5>Semantics:</h5>
2593
2594<p>
John Criswell7123e272004-04-09 16:43:20 +00002595The '<tt>llvm.readport</tt>' intrinsic reads data from the hardware I/O port
2596specified by <i>address</i> and returns the value. The address and return
2597value must be integers, but the size is dependent upon the platform upon which
2598the program is code generated. For example, on x86, the address must be an
2599unsigned 16 bit value, and the return value must be 8, 16, or 32 bits.
John Criswellcfd3bac2004-04-09 15:23:37 +00002600</p>
2601
2602</div>
2603
2604<!-- _______________________________________________________________________ -->
2605<div class="doc_subsubsection">
2606 <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a>
2607</div>
2608
2609<div class="doc_text">
2610
2611<h5>Syntax:</h5>
2612<pre>
Chris Lattnerc3f59762004-12-09 17:30:23 +00002613 call void (&lt;integer type&gt;, &lt;integer type&gt;)*
2614 %llvm.writeport (&lt;integer type&gt; &lt;value&gt;,
2615 &lt;integer type&gt; &lt;address&gt;)
John Criswellcfd3bac2004-04-09 15:23:37 +00002616</pre>
2617
2618<h5>Overview:</h5>
2619
2620<p>
John Criswell7123e272004-04-09 16:43:20 +00002621The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified hardware
2622I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002623</p>
2624
2625<h5>Arguments:</h5>
2626
2627<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002628The first argument is the value to write to the I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002629</p>
2630
2631<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002632The second argument indicates the hardware I/O address to which data should be
2633written. The address is in the hardware I/O address namespace (as opposed to
2634being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002635</p>
2636
2637<h5>Semantics:</h5>
2638
2639<p>
2640The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port
2641specified by <i>address</i>. The address and value must be integers, but the
2642size is dependent upon the platform upon which the program is code generated.
John Criswell7123e272004-04-09 16:43:20 +00002643For example, on x86, the address must be an unsigned 16 bit value, and the
2644value written must be 8, 16, or 32 bits in length.
John Criswellcfd3bac2004-04-09 15:23:37 +00002645</p>
2646
2647</div>
Chris Lattner10610642004-02-14 04:08:35 +00002648
John Criswell183402a2004-04-12 15:02:16 +00002649<!-- _______________________________________________________________________ -->
2650<div class="doc_subsubsection">
2651 <a name="i_readio">'<tt>llvm.readio</tt>' Intrinsic</a>
2652</div>
2653
2654<div class="doc_text">
2655
2656<h5>Syntax:</h5>
2657<pre>
John Criswell96db6fc2004-04-12 16:33:19 +00002658 call &lt;result&gt; (&lt;ty&gt;*)* %llvm.readio (&lt;ty&gt; * &lt;pointer&gt;)
John Criswell183402a2004-04-12 15:02:16 +00002659</pre>
2660
2661<h5>Overview:</h5>
2662
2663<p>
2664The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
2665address.
2666</p>
2667
2668<h5>Arguments:</h5>
2669
2670<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002671The argument to this intrinsic is a pointer indicating the memory address from
2672which to read the data. The data must be a
2673<a href="#t_firstclass">first class</a> type.
John Criswell183402a2004-04-12 15:02:16 +00002674</p>
2675
2676<h5>Semantics:</h5>
2677
2678<p>
2679The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
John Criswell96db6fc2004-04-12 16:33:19 +00002680location specified by <i>pointer</i> and returns the value. The argument must
2681be a pointer, and the return value must be a
2682<a href="#t_firstclass">first class</a> type. However, certain architectures
2683may not support I/O on all first class types. For example, 32 bit processors
2684may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00002685</p>
2686
2687<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002688This intrinsic enforces an in-order memory model for llvm.readio and
2689llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2690scheduled processors may execute loads and stores out of order, re-ordering at
2691run time accesses to memory mapped I/O registers. Using these intrinsics
2692ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00002693</p>
2694
2695</div>
2696
2697<!-- _______________________________________________________________________ -->
2698<div class="doc_subsubsection">
2699 <a name="i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a>
2700</div>
2701
2702<div class="doc_text">
2703
2704<h5>Syntax:</h5>
2705<pre>
John Criswell96db6fc2004-04-12 16:33:19 +00002706 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 +00002707</pre>
2708
2709<h5>Overview:</h5>
2710
2711<p>
2712The '<tt>llvm.writeio</tt>' intrinsic writes data to the specified memory
2713mapped I/O address.
2714</p>
2715
2716<h5>Arguments:</h5>
2717
2718<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002719The first argument is the value to write to the memory mapped I/O location.
2720The second argument is a pointer indicating the memory address to which the
2721data should be written.
John Criswell183402a2004-04-12 15:02:16 +00002722</p>
2723
2724<h5>Semantics:</h5>
2725
2726<p>
2727The '<tt>llvm.writeio</tt>' intrinsic writes <i>value</i> to the memory mapped
John Criswell96db6fc2004-04-12 16:33:19 +00002728I/O address specified by <i>pointer</i>. The value must be a
2729<a href="#t_firstclass">first class</a> type. However, certain architectures
2730may not support I/O on all first class types. For example, 32 bit processors
2731may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00002732</p>
2733
2734<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002735This intrinsic enforces an in-order memory model for llvm.readio and
2736llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2737scheduled processors may execute loads and stores out of order, re-ordering at
2738run time accesses to memory mapped I/O registers. Using these intrinsics
2739ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00002740</p>
2741
2742</div>
2743
Chris Lattner10610642004-02-14 04:08:35 +00002744<!-- ======================================================================= -->
2745<div class="doc_subsection">
Chris Lattner33aec9e2004-02-12 17:01:32 +00002746 <a name="int_libc">Standard C Library Intrinsics</a>
2747</div>
2748
2749<div class="doc_text">
2750<p>
Chris Lattner10610642004-02-14 04:08:35 +00002751LLVM provides intrinsics for a few important standard C library functions.
2752These intrinsics allow source-language front-ends to pass information about the
2753alignment of the pointer arguments to the code generator, providing opportunity
2754for more efficient code generation.
Chris Lattner33aec9e2004-02-12 17:01:32 +00002755</p>
2756
2757</div>
2758
2759<!-- _______________________________________________________________________ -->
2760<div class="doc_subsubsection">
2761 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
2762</div>
2763
2764<div class="doc_text">
2765
2766<h5>Syntax:</h5>
2767<pre>
2768 call void (sbyte*, sbyte*, uint, uint)* %llvm.memcpy(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2769 uint &lt;len&gt;, uint &lt;align&gt;)
2770</pre>
2771
2772<h5>Overview:</h5>
2773
2774<p>
2775The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2776location to the destination location.
2777</p>
2778
2779<p>
2780Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
2781does not return a value, and takes an extra alignment argument.
2782</p>
2783
2784<h5>Arguments:</h5>
2785
2786<p>
2787The first argument is a pointer to the destination, the second is a pointer to
2788the source. The third argument is an (arbitrarily sized) integer argument
2789specifying the number of bytes to copy, and the fourth argument is the alignment
2790of the source and destination locations.
2791</p>
2792
Chris Lattner3301ced2004-02-12 21:18:15 +00002793<p>
2794If the call to this intrinisic has an alignment value that is not 0 or 1, then
2795the caller guarantees that the size of the copy is a multiple of the alignment
2796and that both the source and destination pointers are aligned to that boundary.
2797</p>
2798
Chris Lattner33aec9e2004-02-12 17:01:32 +00002799<h5>Semantics:</h5>
2800
2801<p>
2802The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2803location to the destination location, which are not allowed to overlap. It
2804copies "len" bytes of memory over. If the argument is known to be aligned to
2805some boundary, this can be specified as the fourth argument, otherwise it should
2806be set to 0 or 1.
2807</p>
2808</div>
2809
2810
Chris Lattner0eb51b42004-02-12 18:10:10 +00002811<!-- _______________________________________________________________________ -->
2812<div class="doc_subsubsection">
2813 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
2814</div>
2815
2816<div class="doc_text">
2817
2818<h5>Syntax:</h5>
2819<pre>
2820 call void (sbyte*, sbyte*, uint, uint)* %llvm.memmove(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2821 uint &lt;len&gt;, uint &lt;align&gt;)
2822</pre>
2823
2824<h5>Overview:</h5>
2825
2826<p>
2827The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
2828location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>'
2829intrinsic but allows the two memory locations to overlap.
2830</p>
2831
2832<p>
2833Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
2834does not return a value, and takes an extra alignment argument.
2835</p>
2836
2837<h5>Arguments:</h5>
2838
2839<p>
2840The first argument is a pointer to the destination, the second is a pointer to
2841the source. The third argument is an (arbitrarily sized) integer argument
2842specifying the number of bytes to copy, and the fourth argument is the alignment
2843of the source and destination locations.
2844</p>
2845
Chris Lattner3301ced2004-02-12 21:18:15 +00002846<p>
2847If the call to this intrinisic has an alignment value that is not 0 or 1, then
2848the caller guarantees that the size of the copy is a multiple of the alignment
2849and that both the source and destination pointers are aligned to that boundary.
2850</p>
2851
Chris Lattner0eb51b42004-02-12 18:10:10 +00002852<h5>Semantics:</h5>
2853
2854<p>
2855The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
2856location to the destination location, which may overlap. It
2857copies "len" bytes of memory over. If the argument is known to be aligned to
2858some boundary, this can be specified as the fourth argument, otherwise it should
2859be set to 0 or 1.
2860</p>
2861</div>
2862
Chris Lattner8ff75902004-01-06 05:31:32 +00002863
Chris Lattner10610642004-02-14 04:08:35 +00002864<!-- _______________________________________________________________________ -->
2865<div class="doc_subsubsection">
2866 <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a>
2867</div>
2868
2869<div class="doc_text">
2870
2871<h5>Syntax:</h5>
2872<pre>
2873 call void (sbyte*, ubyte, uint, uint)* %llvm.memset(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
2874 uint &lt;len&gt;, uint &lt;align&gt;)
2875</pre>
2876
2877<h5>Overview:</h5>
2878
2879<p>
2880The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular
2881byte value.
2882</p>
2883
2884<p>
2885Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
2886does not return a value, and takes an extra alignment argument.
2887</p>
2888
2889<h5>Arguments:</h5>
2890
2891<p>
2892The first argument is a pointer to the destination to fill, the second is the
2893byte value to fill it with, the third argument is an (arbitrarily sized) integer
2894argument specifying the number of bytes to fill, and the fourth argument is the
2895known alignment of destination location.
2896</p>
2897
2898<p>
2899If the call to this intrinisic has an alignment value that is not 0 or 1, then
2900the caller guarantees that the size of the copy is a multiple of the alignment
2901and that the destination pointer is aligned to that boundary.
2902</p>
2903
2904<h5>Semantics:</h5>
2905
2906<p>
2907The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the
2908destination location. If the argument is known to be aligned to some boundary,
2909this can be specified as the fourth argument, otherwise it should be set to 0 or
29101.
2911</p>
2912</div>
2913
2914
Chris Lattner32006282004-06-11 02:28:03 +00002915<!-- _______________________________________________________________________ -->
2916<div class="doc_subsubsection">
Alkis Evlogimenos26bbe932004-06-13 01:16:15 +00002917 <a name="i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a>
2918</div>
2919
2920<div class="doc_text">
2921
2922<h5>Syntax:</h5>
2923<pre>
2924 call bool (&lt;float or double&gt;, &lt;float or double&gt;)* %llvm.isunordered(&lt;float or double&gt; Val1,
2925 &lt;float or double&gt; Val2)
2926</pre>
2927
2928<h5>Overview:</h5>
2929
2930<p>
2931The '<tt>llvm.isunordered</tt>' intrinsic returns true if either or both of the
2932specified floating point values is a NAN.
2933</p>
2934
2935<h5>Arguments:</h5>
2936
2937<p>
2938The arguments are floating point numbers of the same type.
2939</p>
2940
2941<h5>Semantics:</h5>
2942
2943<p>
2944If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise
2945false.
2946</p>
2947</div>
2948
2949
Chris Lattner32006282004-06-11 02:28:03 +00002950
2951
Chris Lattner8ff75902004-01-06 05:31:32 +00002952<!-- ======================================================================= -->
2953<div class="doc_subsection">
2954 <a name="int_debugger">Debugger Intrinsics</a>
2955</div>
2956
2957<div class="doc_text">
2958<p>
2959The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
2960are described in the <a
2961href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
2962Debugging</a> document.
2963</p>
2964</div>
2965
2966
Chris Lattner00950542001-06-06 20:29:01 +00002967<!-- *********************************************************************** -->
Chris Lattner00950542001-06-06 20:29:01 +00002968<hr>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002969<address>
2970 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
2971 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
2972 <a href="http://validator.w3.org/check/referer"><img
2973 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
2974
2975 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
2976 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
2977 Last modified: $Date$
2978</address>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002979</body>
2980</html>