blob: b7bbac34c9e17b795427a2c4ec08a92174683fb0 [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>
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +0000129 <li><a href="#i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a></li>
John Criswell7123e272004-04-09 16:43:20 +0000130 </ol>
131 </li>
132 <li><a href="#int_os">Operating System Intrinsics</a>
133 <ol>
Chris Lattner32006282004-06-11 02:28:03 +0000134 <li><a href="#i_readport">'<tt>llvm.readport</tt>' Intrinsic</a></li>
135 <li><a href="#i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a></li>
John Criswell183402a2004-04-12 15:02:16 +0000136 <li><a href="#i_readio">'<tt>llvm.readio</tt>' Intrinsic</a></li>
137 <li><a href="#i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000138 </ol>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000139 <li><a href="#int_libc">Standard C Library Intrinsics</a>
140 <ol>
141 <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li>
Chris Lattner0eb51b42004-02-12 18:10:10 +0000142 <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000143 <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li>
Alkis Evlogimenos96853722004-06-12 19:19:14 +0000144 <li><a href="#i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a></li>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000145 </ol>
146 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000147 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000148 </ol>
149 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000150</ol>
Chris Lattnerd7923912004-05-23 21:06:01 +0000151
152<div class="doc_author">
153 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
154 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000155</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000156
Chris Lattner00950542001-06-06 20:29:01 +0000157<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000158<div class="doc_section"> <a name="abstract">Abstract </a></div>
159<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000160
Misha Brukman9d0919f2003-11-08 01:05:38 +0000161<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000162<p>This document is a reference manual for the LLVM assembly language.
163LLVM is an SSA based representation that provides type safety,
164low-level operations, flexibility, and the capability of representing
165'all' high-level languages cleanly. It is the common code
166representation used throughout all phases of the LLVM compilation
167strategy.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000168</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000169
Chris Lattner00950542001-06-06 20:29:01 +0000170<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000171<div class="doc_section"> <a name="introduction">Introduction</a> </div>
172<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000173
Misha Brukman9d0919f2003-11-08 01:05:38 +0000174<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000175
Chris Lattner261efe92003-11-25 01:02:51 +0000176<p>The LLVM code representation is designed to be used in three
177different forms: as an in-memory compiler IR, as an on-disk bytecode
178representation (suitable for fast loading by a Just-In-Time compiler),
179and as a human readable assembly language representation. This allows
180LLVM to provide a powerful intermediate representation for efficient
181compiler transformations and analysis, while providing a natural means
182to debug and visualize the transformations. The three different forms
183of LLVM are all equivalent. This document describes the human readable
184representation and notation.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000185
Chris Lattner261efe92003-11-25 01:02:51 +0000186<p>The LLVM representation aims to be a light-weight and low-level
187while being expressive, typed, and extensible at the same time. It
188aims to be a "universal IR" of sorts, by being at a low enough level
189that high-level ideas may be cleanly mapped to it (similar to how
190microprocessors are "universal IR's", allowing many source languages to
191be mapped to them). By providing type information, LLVM can be used as
192the target of optimizations: for example, through pointer analysis, it
193can be proven that a C automatic variable is never accessed outside of
194the current function... allowing it to be promoted to a simple SSA
195value instead of a memory location.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000196
Misha Brukman9d0919f2003-11-08 01:05:38 +0000197</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000198
Chris Lattner00950542001-06-06 20:29:01 +0000199<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000200<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000201
Misha Brukman9d0919f2003-11-08 01:05:38 +0000202<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000203
Chris Lattner261efe92003-11-25 01:02:51 +0000204<p>It is important to note that this document describes 'well formed'
205LLVM assembly language. There is a difference between what the parser
206accepts and what is considered 'well formed'. For example, the
207following instruction is syntactically okay, but not well formed:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000208
209<pre>
210 %x = <a href="#i_add">add</a> int 1, %x
211</pre>
212
Chris Lattner261efe92003-11-25 01:02:51 +0000213<p>...because the definition of <tt>%x</tt> does not dominate all of
214its uses. The LLVM infrastructure provides a verification pass that may
215be used to verify that an LLVM module is well formed. This pass is
216automatically run by the parser after parsing input assembly, and by
217the optimizer before it outputs bytecode. The violations pointed out
218by the verifier pass indicate bugs in transformation passes or input to
219the parser.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000220
Chris Lattner261efe92003-11-25 01:02:51 +0000221<!-- Describe the typesetting conventions here. --> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000222
Chris Lattner00950542001-06-06 20:29:01 +0000223<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000224<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000225<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000226
Misha Brukman9d0919f2003-11-08 01:05:38 +0000227<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000228
Chris Lattner261efe92003-11-25 01:02:51 +0000229<p>LLVM uses three different forms of identifiers, for different
230purposes:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000231
Chris Lattner00950542001-06-06 20:29:01 +0000232<ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000233 <li>Named values are represented as a string of characters with a '%' prefix.
234 For example, %foo, %DivisionByZero, %a.really.long.identifier. The actual
235 regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
236 Identifiers which require other characters in their names can be surrounded
237 with quotes. In this way, anything except a <tt>"</tt> character can be used
238 in a name.</li>
239
240 <li>Unnamed values are represented as an unsigned numeric value with a '%'
241 prefix. For example, %12, %2, %44.</li>
242
Reid Spencercc16dc32004-12-09 18:02:53 +0000243 <li>Constants, which are described in a <a href="#constants">section about
244 constants</a>, below.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000245</ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000246
247<p>LLVM requires that values start with a '%' sign for two reasons: Compilers
248don't need to worry about name clashes with reserved words, and the set of
249reserved words may be expanded in the future without penalty. Additionally,
250unnamed identifiers allow a compiler to quickly come up with a temporary
251variable without having to avoid symbol table conflicts.</p>
252
Chris Lattner261efe92003-11-25 01:02:51 +0000253<p>Reserved words in LLVM are very similar to reserved words in other
254languages. There are keywords for different opcodes ('<tt><a
Chris Lattnere5d947b2004-12-09 16:36:40 +0000255href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
256href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
257href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>', etc...),
258and others. These reserved words cannot conflict with variable names, because
259none of them start with a '%' character.</p>
260
261<p>Here is an example of LLVM code to multiply the integer variable
262'<tt>%X</tt>' by 8:</p>
263
Misha Brukman9d0919f2003-11-08 01:05:38 +0000264<p>The easy way:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000265
266<pre>
267 %result = <a href="#i_mul">mul</a> uint %X, 8
268</pre>
269
Misha Brukman9d0919f2003-11-08 01:05:38 +0000270<p>After strength reduction:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000271
272<pre>
273 %result = <a href="#i_shl">shl</a> uint %X, ubyte 3
274</pre>
275
Misha Brukman9d0919f2003-11-08 01:05:38 +0000276<p>And the hard way:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000277
278<pre>
279 <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
280 <a href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
281 %result = <a href="#i_add">add</a> uint %1, %1
282</pre>
283
Chris Lattner261efe92003-11-25 01:02:51 +0000284<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
285important lexical features of LLVM:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000286
Chris Lattner00950542001-06-06 20:29:01 +0000287<ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000288
289 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
290 line.</li>
291
292 <li>Unnamed temporaries are created when the result of a computation is not
293 assigned to a named value.</li>
294
Misha Brukman9d0919f2003-11-08 01:05:38 +0000295 <li>Unnamed temporaries are numbered sequentially</li>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000296
Misha Brukman9d0919f2003-11-08 01:05:38 +0000297</ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000298
299<p>...and it also show a convention that we follow in this document. When
300demonstrating instructions, we will follow an instruction with a comment that
301defines the type and name of value produced. Comments are shown in italic
302text.</p>
303
Misha Brukman9d0919f2003-11-08 01:05:38 +0000304</div>
Chris Lattnerfa730212004-12-09 16:11:40 +0000305
306<!-- *********************************************************************** -->
307<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
308<!-- *********************************************************************** -->
309
310<!-- ======================================================================= -->
311<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
312</div>
313
314<div class="doc_text">
315
316<p>LLVM programs are composed of "Module"s, each of which is a
317translation unit of the input programs. Each module consists of
318functions, global variables, and symbol table entries. Modules may be
319combined together with the LLVM linker, which merges function (and
320global variable) definitions, resolves forward declarations, and merges
321symbol table entries. Here is an example of the "hello world" module:</p>
322
323<pre><i>; Declare the string constant as a global constant...</i>
324<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
325 href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00" <i>; [13 x sbyte]*</i>
326
327<i>; External declaration of the puts function</i>
328<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
329
330<i>; Definition of main function</i>
331int %main() { <i>; int()* </i>
332 <i>; Convert [13x sbyte]* to sbyte *...</i>
333 %cast210 = <a
334 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
335
336 <i>; Call puts function to write out the string to stdout...</i>
337 <a
338 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
339 <a
340 href="#i_ret">ret</a> int 0<br>}<br></pre>
341
342<p>This example is made up of a <a href="#globalvars">global variable</a>
343named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
344function, and a <a href="#functionstructure">function definition</a>
345for "<tt>main</tt>".</p>
346
Chris Lattnere5d947b2004-12-09 16:36:40 +0000347<p>In general, a module is made up of a list of global values,
348where both functions and global variables are global values. Global values are
349represented by a pointer to a memory location (in this case, a pointer to an
350array of char, and a pointer to a function), and have one of the following <a
351href="#linkage">linkage types</a>.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000352
Chris Lattnere5d947b2004-12-09 16:36:40 +0000353</div>
354
355<!-- ======================================================================= -->
356<div class="doc_subsection">
357 <a name="linkage">Linkage Types</a>
358</div>
359
360<div class="doc_text">
361
362<p>
363All Global Variables and Functions have one of the following types of linkage:
364</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000365
366<dl>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000367
Chris Lattnerfa730212004-12-09 16:11:40 +0000368 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000369
370 <dd>Global values with internal linkage are only directly accessible by
371 objects in the current module. In particular, linking code into a module with
372 an internal global value may cause the internal to be renamed as necessary to
373 avoid collisions. Because the symbol is internal to the module, all
374 references can be updated. This corresponds to the notion of the
375 '<tt>static</tt>' keyword in C, or the idea of "anonymous namespaces" in C++.
Chris Lattnerfa730212004-12-09 16:11:40 +0000376 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000377
Chris Lattnerfa730212004-12-09 16:11:40 +0000378 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000379
380 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt> linkage, with
381 the twist that linking together two modules defining the same
382 <tt>linkonce</tt> globals will cause one of the globals to be discarded. This
383 is typically used to implement inline functions. Unreferenced
384 <tt>linkonce</tt> globals are allowed to be discarded.
Chris Lattnerfa730212004-12-09 16:11:40 +0000385 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000386
Chris Lattnerfa730212004-12-09 16:11:40 +0000387 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000388
389 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage,
390 except that unreferenced <tt>weak</tt> globals may not be discarded. This is
391 used to implement constructs in C such as "<tt>int X;</tt>" at global scope.
Chris Lattnerfa730212004-12-09 16:11:40 +0000392 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000393
Chris Lattnerfa730212004-12-09 16:11:40 +0000394 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000395
396 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
397 pointer to array type. When two global variables with appending linkage are
398 linked together, the two global arrays are appended together. This is the
399 LLVM, typesafe, equivalent of having the system linker append together
400 "sections" with identical names when .o files are linked.
Chris Lattnerfa730212004-12-09 16:11:40 +0000401 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000402
Chris Lattnerfa730212004-12-09 16:11:40 +0000403 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000404
405 <dd>If none of the above identifiers are used, the global is externally
406 visible, meaning that it participates in linkage and can be used to resolve
407 external symbol references.
Chris Lattnerfa730212004-12-09 16:11:40 +0000408 </dd>
409</dl>
410
Chris Lattnerfa730212004-12-09 16:11:40 +0000411<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
412variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
413variable and was linked with this one, one of the two would be renamed,
414preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
415external (i.e., lacking any linkage declarations), they are accessible
416outside of the current module. It is illegal for a function <i>declaration</i>
417to have any linkage type other than "externally visible".</a></p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000418
Chris Lattnerfa730212004-12-09 16:11:40 +0000419</div>
420
421<!-- ======================================================================= -->
422<div class="doc_subsection">
423 <a name="globalvars">Global Variables</a>
424</div>
425
426<div class="doc_text">
427
Chris Lattner3689a342005-02-12 19:30:21 +0000428<p>Global variables define regions of memory allocated at compilation time
429instead of run-time. Global variables may optionally be initialized. A
430variable may be defined as a global "constant", which indicates that the
431contents of the variable will <b>never</b> be modified (enabling better
432optimization, allowing the global data to be placed in the read-only section of
433an executable, etc). Note that variables that need runtime initialization
434cannot be marked "constant", as there is a store to the variable.</p>
435
436<p>
437LLVM explicitly allows <em>declarations</em> of global variables to be marked
438constant, even if the final definition of the global is not. This capability
439can be used to enable slightly better optimization of the program, but requires
440the language definition to guarantee that optimizations based on the
441'constantness' are valid for the translation units that do not include the
442definition.
443</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000444
445<p>As SSA values, global variables define pointer values that are in
446scope (i.e. they dominate) all basic blocks in the program. Global
447variables always define a pointer to their "content" type because they
448describe a region of memory, and all memory objects in LLVM are
449accessed through pointers.</p>
450
451</div>
452
453
454<!-- ======================================================================= -->
455<div class="doc_subsection">
456 <a name="functionstructure">Functions</a>
457</div>
458
459<div class="doc_text">
460
461<p>LLVM function definitions are composed of a (possibly empty) argument list,
462an opening curly brace, a list of basic blocks, and a closing curly brace. LLVM
463function declarations are defined with the "<tt>declare</tt>" keyword, a
464function name, and a function signature.</p>
465
466<p>A function definition contains a list of basic blocks, forming the CFG for
467the function. Each basic block may optionally start with a label (giving the
468basic block a symbol table entry), contains a list of instructions, and ends
469with a <a href="#terminators">terminator</a> instruction (such as a branch or
470function return).</p>
471
472<p>The first basic block in program is special in two ways: it is immediately
473executed on entrance to the function, and it is not allowed to have predecessor
474basic blocks (i.e. there can not be any branches to the entry block of a
475function). Because the block can have no predecessors, it also cannot have any
476<a href="#i_phi">PHI nodes</a>.</p>
477
478<p>LLVM functions are identified by their name and type signature. Hence, two
479functions with the same name but different parameter lists or return values are
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000480considered different functions, and LLVM will resolve references to each
Chris Lattnerfa730212004-12-09 16:11:40 +0000481appropriately.</p>
482
483</div>
484
485
486
Chris Lattner00950542001-06-06 20:29:01 +0000487<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000488<div class="doc_section"> <a name="typesystem">Type System</a> </div>
489<!-- *********************************************************************** -->
Chris Lattnerfa730212004-12-09 16:11:40 +0000490
Misha Brukman9d0919f2003-11-08 01:05:38 +0000491<div class="doc_text">
Chris Lattnerfa730212004-12-09 16:11:40 +0000492
Misha Brukman9d0919f2003-11-08 01:05:38 +0000493<p>The LLVM type system is one of the most important features of the
Chris Lattner261efe92003-11-25 01:02:51 +0000494intermediate representation. Being typed enables a number of
495optimizations to be performed on the IR directly, without having to do
496extra analyses on the side before the transformation. A strong type
497system makes it easier to read the generated code and enables novel
498analyses and transformations that are not feasible to perform on normal
499three address code representations.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000500
501</div>
502
Chris Lattner00950542001-06-06 20:29:01 +0000503<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000504<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000505<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +0000506<p>The primitive types are the fundamental building blocks of the LLVM
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000507system. The current set of primitive types is as follows:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000508
Reid Spencerd3f876c2004-11-01 08:19:36 +0000509<table class="layout">
510 <tr class="layout">
511 <td class="left">
512 <table>
Chris Lattner261efe92003-11-25 01:02:51 +0000513 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000514 <tr><th>Type</th><th>Description</th></tr>
515 <tr><td><tt>void</tt></td><td>No value</td></tr>
516 <tr><td><tt>ubyte</tt></td><td>Unsigned 8 bit value</td></tr>
517 <tr><td><tt>ushort</tt></td><td>Unsigned 16 bit value</td></tr>
518 <tr><td><tt>uint</tt></td><td>Unsigned 32 bit value</td></tr>
519 <tr><td><tt>ulong</tt></td><td>Unsigned 64 bit value</td></tr>
520 <tr><td><tt>float</tt></td><td>32 bit floating point value</td></tr>
521 <tr><td><tt>label</tt></td><td>Branch destination</td></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000522 </tbody>
523 </table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000524 </td>
525 <td class="right">
526 <table>
Chris Lattner261efe92003-11-25 01:02:51 +0000527 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000528 <tr><th>Type</th><th>Description</th></tr>
529 <tr><td><tt>bool</tt></td><td>True or False value</td></tr>
530 <tr><td><tt>sbyte</tt></td><td>Signed 8 bit value</td></tr>
531 <tr><td><tt>short</tt></td><td>Signed 16 bit value</td></tr>
532 <tr><td><tt>int</tt></td><td>Signed 32 bit value</td></tr>
533 <tr><td><tt>long</tt></td><td>Signed 64 bit value</td></tr>
534 <tr><td><tt>double</tt></td><td>64 bit floating point value</td></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000535 </tbody>
536 </table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000537 </td>
538 </tr>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000539</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000540</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000541
Chris Lattner00950542001-06-06 20:29:01 +0000542<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000543<div class="doc_subsubsection"> <a name="t_classifications">Type
544Classifications</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000545<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000546<p>These different primitive types fall into a few useful
547classifications:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000548
549<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +0000550 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000551 <tr><th>Classification</th><th>Types</th></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000552 <tr>
553 <td><a name="t_signed">signed</a></td>
554 <td><tt>sbyte, short, int, long, float, double</tt></td>
555 </tr>
556 <tr>
557 <td><a name="t_unsigned">unsigned</a></td>
558 <td><tt>ubyte, ushort, uint, ulong</tt></td>
559 </tr>
560 <tr>
561 <td><a name="t_integer">integer</a></td>
562 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
563 </tr>
564 <tr>
565 <td><a name="t_integral">integral</a></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000566 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt>
567 </td>
Chris Lattner261efe92003-11-25 01:02:51 +0000568 </tr>
569 <tr>
570 <td><a name="t_floating">floating point</a></td>
571 <td><tt>float, double</tt></td>
572 </tr>
573 <tr>
574 <td><a name="t_firstclass">first class</a></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000575 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long,<br>
576 float, double, <a href="#t_pointer">pointer</a>,
577 <a href="#t_packed">packed</a></tt></td>
Chris Lattner261efe92003-11-25 01:02:51 +0000578 </tr>
579 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000580</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000581
Chris Lattner261efe92003-11-25 01:02:51 +0000582<p>The <a href="#t_firstclass">first class</a> types are perhaps the
583most important. Values of these types are the only ones which can be
584produced by instructions, passed as arguments, or used as operands to
585instructions. This means that all structures and arrays must be
586manipulated either by pointer or by component.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000587</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000588
Chris Lattner00950542001-06-06 20:29:01 +0000589<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000590<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000591
Misha Brukman9d0919f2003-11-08 01:05:38 +0000592<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +0000593
Chris Lattner261efe92003-11-25 01:02:51 +0000594<p>The real power in LLVM comes from the derived types in the system.
595This is what allows a programmer to represent arrays, functions,
596pointers, and other useful types. Note that these derived types may be
597recursive: For example, it is possible to have a two dimensional array.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000598
Misha Brukman9d0919f2003-11-08 01:05:38 +0000599</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000600
Chris Lattner00950542001-06-06 20:29:01 +0000601<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000602<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000603
Misha Brukman9d0919f2003-11-08 01:05:38 +0000604<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +0000605
Chris Lattner00950542001-06-06 20:29:01 +0000606<h5>Overview:</h5>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000607
Misha Brukman9d0919f2003-11-08 01:05:38 +0000608<p>The array type is a very simple derived type that arranges elements
Chris Lattner261efe92003-11-25 01:02:51 +0000609sequentially in memory. The array type requires a size (number of
610elements) and an underlying data type.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000611
Chris Lattner7faa8832002-04-14 06:13:44 +0000612<h5>Syntax:</h5>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000613
614<pre>
615 [&lt;# elements&gt; x &lt;elementtype&gt;]
616</pre>
617
Chris Lattner261efe92003-11-25 01:02:51 +0000618<p>The number of elements is a constant integer value, elementtype may
619be any type with a size.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000620
Chris Lattner7faa8832002-04-14 06:13:44 +0000621<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000622<table class="layout">
623 <tr class="layout">
624 <td class="left">
625 <tt>[40 x int ]</tt><br/>
626 <tt>[41 x int ]</tt><br/>
627 <tt>[40 x uint]</tt><br/>
628 </td>
629 <td class="left">
630 Array of 40 integer values.<br/>
631 Array of 41 integer values.<br/>
632 Array of 40 unsigned integer values.<br/>
633 </td>
634 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000635</table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000636<p>Here are some examples of multidimensional arrays:</p>
637<table class="layout">
638 <tr class="layout">
639 <td class="left">
640 <tt>[3 x [4 x int]]</tt><br/>
641 <tt>[12 x [10 x float]]</tt><br/>
642 <tt>[2 x [3 x [4 x uint]]]</tt><br/>
643 </td>
644 <td class="left">
645 3x4 array integer values.<br/>
646 12x10 array of single precision floating point values.<br/>
647 2x3x4 array of unsigned integer values.<br/>
648 </td>
649 </tr>
650</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000651</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000652
Chris Lattner00950542001-06-06 20:29:01 +0000653<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000654<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000655<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000656<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000657<p>The function type can be thought of as a function signature. It
658consists of a return type and a list of formal parameter types.
John Criswell009900b2003-11-25 21:45:46 +0000659Function types are usually used to build virtual function tables
Chris Lattner261efe92003-11-25 01:02:51 +0000660(which are structures of pointers to functions), for indirect function
661calls, and when defining a function.</p>
John Criswell009900b2003-11-25 21:45:46 +0000662<p>
663The return type of a function type cannot be an aggregate type.
664</p>
Chris Lattner00950542001-06-06 20:29:01 +0000665<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000666<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000667<p>Where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
668specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner27f71f22003-09-03 00:41:47 +0000669which indicates that the function takes a variable number of arguments.
670Variable argument functions can access their arguments with the <a
Chris Lattner261efe92003-11-25 01:02:51 +0000671 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000672<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000673<table class="layout">
674 <tr class="layout">
675 <td class="left">
676 <tt>int (int)</tt> <br/>
677 <tt>float (int, int *) *</tt><br/>
678 <tt>int (sbyte *, ...)</tt><br/>
679 </td>
680 <td class="left">
681 function taking an <tt>int</tt>, returning an <tt>int</tt><br/>
682 <a href="#t_pointer">Pointer</a> to a function that takes an
Misha Brukmanc24b7582004-08-12 20:16:08 +0000683 <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
Reid Spencerd3f876c2004-11-01 08:19:36 +0000684 returning <tt>float</tt>.<br/>
685 A vararg function that takes at least one <a href="#t_pointer">pointer</a>
686 to <tt>sbyte</tt> (signed char in C), which returns an integer. This is
687 the signature for <tt>printf</tt> in LLVM.<br/>
688 </td>
689 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000690</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000691
Misha Brukman9d0919f2003-11-08 01:05:38 +0000692</div>
Chris Lattner00950542001-06-06 20:29:01 +0000693<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000694<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000695<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000696<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000697<p>The structure type is used to represent a collection of data members
698together in memory. The packing of the field types is defined to match
699the ABI of the underlying processor. The elements of a structure may
700be any type that has a size.</p>
701<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
702and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
703field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
704instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000705<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000706<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +0000707<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000708<table class="layout">
709 <tr class="layout">
710 <td class="left">
711 <tt>{ int, int, int }</tt><br/>
712 <tt>{ float, int (int) * }</tt><br/>
713 </td>
714 <td class="left">
715 a triple of three <tt>int</tt> values<br/>
716 A pair, where the first element is a <tt>float</tt> and the second element
717 is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a>
718 that takes an <tt>int</tt>, returning an <tt>int</tt>.<br/>
719 </td>
720 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000721</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000722</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000723
Chris Lattner00950542001-06-06 20:29:01 +0000724<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000725<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000726<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +0000727<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000728<p>As in many languages, the pointer type represents a pointer or
729reference to another object, which must live in memory.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000730<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000731<pre> &lt;type&gt; *<br></pre>
Chris Lattner7faa8832002-04-14 06:13:44 +0000732<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000733<table class="layout">
734 <tr class="layout">
735 <td class="left">
736 <tt>[4x int]*</tt><br/>
737 <tt>int (int *) *</tt><br/>
738 </td>
739 <td class="left">
740 A <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of
741 four <tt>int</tt> values<br/>
742 A <a href="#t_pointer">pointer</a> to a <a
Chris Lattnera977c482005-02-19 02:22:14 +0000743 href="#t_function">function</a> that takes an <tt>int*</tt>, returning an
Reid Spencerd3f876c2004-11-01 08:19:36 +0000744 <tt>int</tt>.<br/>
745 </td>
746 </tr>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000747</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000748</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000749
Chris Lattnera58561b2004-08-12 19:12:28 +0000750<!-- _______________________________________________________________________ -->
751<div class="doc_subsubsection"> <a name="t_packed">Packed Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000752<div class="doc_text">
Chris Lattnera58561b2004-08-12 19:12:28 +0000753<h5>Overview:</h5>
754<p>A packed type is a simple derived type that represents a vector
755of elements. Packed types are used when multiple primitive data
756are operated in parallel using a single instruction (SIMD).
757A packed type requires a size (number of
758elements) and an underlying primitive data type. Packed types are
759considered <a href="#t_firstclass">first class</a>.</p>
760<h5>Syntax:</h5>
761<pre> &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;<br></pre>
762<p>The number of elements is a constant integer value, elementtype may
763be any integral or floating point type.</p>
764<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000765<table class="layout">
766 <tr class="layout">
767 <td class="left">
768 <tt>&lt;4 x int&gt;</tt><br/>
769 <tt>&lt;8 x float&gt;</tt><br/>
770 <tt>&lt;2 x uint&gt;</tt><br/>
771 </td>
772 <td class="left">
773 Packed vector of 4 integer values.<br/>
774 Packed vector of 8 floating-point values.<br/>
775 Packed vector of 2 unsigned integer values.<br/>
776 </td>
777 </tr>
778</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000779</div>
780
Chris Lattnerc3f59762004-12-09 17:30:23 +0000781<!-- *********************************************************************** -->
782<div class="doc_section"> <a name="constants">Constants</a> </div>
783<!-- *********************************************************************** -->
784
785<div class="doc_text">
786
787<p>LLVM has several different basic types of constants. This section describes
788them all and their syntax.</p>
789
790</div>
791
792<!-- ======================================================================= -->
Reid Spencercc16dc32004-12-09 18:02:53 +0000793<div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000794
795<div class="doc_text">
796
797<dl>
798 <dt><b>Boolean constants</b></dt>
799
800 <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
801 constants of the <tt><a href="#t_primitive">bool</a></tt> type.
802 </dd>
803
804 <dt><b>Integer constants</b></dt>
805
Reid Spencercc16dc32004-12-09 18:02:53 +0000806 <dd>Standard integers (such as '4') are constants of the <a
Chris Lattnerc3f59762004-12-09 17:30:23 +0000807 href="#t_integer">integer</a> type. Negative numbers may be used with signed
808 integer types.
809 </dd>
810
811 <dt><b>Floating point constants</b></dt>
812
813 <dd>Floating point constants use standard decimal notation (e.g. 123.421),
814 exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
Reid Spencercc16dc32004-12-09 18:02:53 +0000815 notation. Floating point constants have an optional hexadecimal
Chris Lattnerc3f59762004-12-09 17:30:23 +0000816 notation (see below). Floating point constants must have a <a
817 href="#t_floating">floating point</a> type. </dd>
818
819 <dt><b>Null pointer constants</b></dt>
820
John Criswell9e2485c2004-12-10 15:51:16 +0000821 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
Chris Lattnerc3f59762004-12-09 17:30:23 +0000822 and must be of <a href="#t_pointer">pointer type</a>.</dd>
823
824</dl>
825
John Criswell9e2485c2004-12-10 15:51:16 +0000826<p>The one non-intuitive notation for constants is the optional hexadecimal form
Chris Lattnerc3f59762004-12-09 17:30:23 +0000827of floating point constants. For example, the form '<tt>double
8280x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
8294.5e+15</tt>'. The only time hexadecimal floating point constants are required
Reid Spencercc16dc32004-12-09 18:02:53 +0000830(and the only time that they are generated by the disassembler) is when a
831floating point constant must be emitted but it cannot be represented as a
832decimal floating point number. For example, NaN's, infinities, and other
833special values are represented in their IEEE hexadecimal format so that
834assembly and disassembly do not cause any bits to change in the constants.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000835
836</div>
837
838<!-- ======================================================================= -->
839<div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a>
840</div>
841
842<div class="doc_text">
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000843<p>Aggregate constants arise from aggregation of simple constants
844and smaller aggregate constants.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000845
846<dl>
847 <dt><b>Structure constants</b></dt>
848
849 <dd>Structure constants are represented with notation similar to structure
850 type definitions (a comma separated list of elements, surrounded by braces
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000851 (<tt>{}</tt>)). For example: "<tt>{ int 4, float 17.0, int* %G }</tt>",
852 where "<tt>%G</tt>" is declared as "<tt>%G = external global int</tt>". Structure constants
853 must have <a href="#t_struct">structure type</a>, and the number and
Chris Lattnerc3f59762004-12-09 17:30:23 +0000854 types of elements must match those specified by the type.
855 </dd>
856
857 <dt><b>Array constants</b></dt>
858
859 <dd>Array constants are represented with notation similar to array type
860 definitions (a comma separated list of elements, surrounded by square brackets
John Criswell9e2485c2004-12-10 15:51:16 +0000861 (<tt>[]</tt>)). For example: "<tt>[ int 42, int 11, int 74 ]</tt>". Array
Chris Lattnerc3f59762004-12-09 17:30:23 +0000862 constants must have <a href="#t_array">array type</a>, and the number and
863 types of elements must match those specified by the type.
864 </dd>
865
866 <dt><b>Packed constants</b></dt>
867
868 <dd>Packed constants are represented with notation similar to packed type
869 definitions (a comma separated list of elements, surrounded by
John Criswell9e2485c2004-12-10 15:51:16 +0000870 less-than/greater-than's (<tt>&lt;&gt;</tt>)). For example: "<tt>&lt; int 42,
Chris Lattnerc3f59762004-12-09 17:30:23 +0000871 int 11, int 74, int 100 &gt;</tt>". Packed constants must have <a
872 href="#t_packed">packed type</a>, and the number and types of elements must
873 match those specified by the type.
874 </dd>
875
876 <dt><b>Zero initialization</b></dt>
877
878 <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
879 value to zero of <em>any</em> type, including scalar and aggregate types.
880 This is often used to avoid having to print large zero initializers (e.g. for
881 large arrays), and is always exactly equivalent to using explicit zero
882 initializers.
883 </dd>
884</dl>
885
886</div>
887
888<!-- ======================================================================= -->
889<div class="doc_subsection">
890 <a name="globalconstants">Global Variable and Function Addresses</a>
891</div>
892
893<div class="doc_text">
894
895<p>The addresses of <a href="#globalvars">global variables</a> and <a
896href="#functionstructure">functions</a> are always implicitly valid (link-time)
John Criswell9e2485c2004-12-10 15:51:16 +0000897constants. These constants are explicitly referenced when the <a
898href="#identifiers">identifier for the global</a> is used and always have <a
Chris Lattnerc3f59762004-12-09 17:30:23 +0000899href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
900file:</p>
901
902<pre>
903 %X = global int 17
904 %Y = global int 42
905 %Z = global [2 x int*] [ int* %X, int* %Y ]
906</pre>
907
908</div>
909
910<!-- ======================================================================= -->
Reid Spencer2dc45b82004-12-09 18:13:12 +0000911<div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000912<div class="doc_text">
Reid Spencer2dc45b82004-12-09 18:13:12 +0000913 <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has
914 no specific value. Undefined values may be of any type, and be used anywhere
915 a constant is permitted.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000916
Reid Spencer2dc45b82004-12-09 18:13:12 +0000917 <p>Undefined values indicate to the compiler that the program is well defined
918 no matter what value is used, giving the compiler more freedom to optimize.
919 </p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000920</div>
921
922<!-- ======================================================================= -->
923<div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
924</div>
925
926<div class="doc_text">
927
928<p>Constant expressions are used to allow expressions involving other constants
929to be used as constants. Constant expressions may be of any <a
930href="#t_firstclass">first class</a> type, and may involve any LLVM operation
931that does not have side effects (e.g. load and call are not supported). The
932following is the syntax for constant expressions:</p>
933
934<dl>
935 <dt><b><tt>cast ( CST to TYPE )</tt></b></dt>
936
937 <dd>Cast a constant to another type.</dd>
938
939 <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
940
941 <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
942 constants. As with the <a href="#i_getelementptr">getelementptr</a>
943 instruction, the index list may have zero or more indexes, which are required
944 to make sense for the type of "CSTPTR".</dd>
945
946 <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
947
Reid Spencer2dc45b82004-12-09 18:13:12 +0000948 <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
949 be any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise
Chris Lattnerc3f59762004-12-09 17:30:23 +0000950 binary</a> operations. The constraints on operands are the same as those for
951 the corresponding instruction (e.g. no bitwise operations on floating point
952 are allowed).</dd>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000953</dl>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000954</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000955
Chris Lattner00950542001-06-06 20:29:01 +0000956<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000957<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
958<!-- *********************************************************************** -->
Chris Lattnerc3f59762004-12-09 17:30:23 +0000959
Misha Brukman9d0919f2003-11-08 01:05:38 +0000960<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +0000961
Chris Lattner261efe92003-11-25 01:02:51 +0000962<p>The LLVM instruction set consists of several different
963classifications of instructions: <a href="#terminators">terminator
964instructions</a>, <a href="#binaryops">binary instructions</a>, <a
965 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
966instructions</a>.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000967
Misha Brukman9d0919f2003-11-08 01:05:38 +0000968</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000969
Chris Lattner00950542001-06-06 20:29:01 +0000970<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000971<div class="doc_subsection"> <a name="terminators">Terminator
972Instructions</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000973
Misha Brukman9d0919f2003-11-08 01:05:38 +0000974<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +0000975
Chris Lattner261efe92003-11-25 01:02:51 +0000976<p>As mentioned <a href="#functionstructure">previously</a>, every
977basic block in a program ends with a "Terminator" instruction, which
978indicates which block should be executed after the current block is
979finished. These terminator instructions typically yield a '<tt>void</tt>'
980value: they produce control flow, not values (the one exception being
981the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
John Criswell9e2485c2004-12-10 15:51:16 +0000982<p>There are six different terminator instructions: the '<a
Chris Lattner261efe92003-11-25 01:02:51 +0000983 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
984instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
Chris Lattner35eca582004-10-16 18:04:13 +0000985the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
986 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
987 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000988
Misha Brukman9d0919f2003-11-08 01:05:38 +0000989</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000990
Chris Lattner00950542001-06-06 20:29:01 +0000991<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000992<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
993Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000994<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000995<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000996<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 +0000997 ret void <i>; Return from void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000998</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000999<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001000<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
1001value) from a function, back to the caller.</p>
John Criswell4457dc92004-04-09 16:48:45 +00001002<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner261efe92003-11-25 01:02:51 +00001003returns a value and then causes control flow, and one that just causes
1004control flow to occur.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001005<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001006<p>The '<tt>ret</tt>' instruction may return any '<a
1007 href="#t_firstclass">first class</a>' type. Notice that a function is
1008not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
1009instruction inside of the function that returns a value that does not
1010match the return type of the function.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001011<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001012<p>When the '<tt>ret</tt>' instruction is executed, control flow
1013returns back to the calling function's context. If the caller is a "<a
John Criswellfa081872004-06-25 15:16:57 +00001014 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner261efe92003-11-25 01:02:51 +00001015the instruction after the call. If the caller was an "<a
1016 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
1017at the beginning "normal" of the destination block. If the instruction
1018returns a value, that value shall set the call or invoke instruction's
1019return value.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001020<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001021<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001022 ret void <i>; Return from a void function</i>
Chris Lattner00950542001-06-06 20:29:01 +00001023</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001024</div>
Chris Lattner00950542001-06-06 20:29:01 +00001025<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001026<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001027<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001028<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001029<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 +00001030</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001031<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001032<p>The '<tt>br</tt>' instruction is used to cause control flow to
1033transfer to a different basic block in the current function. There are
1034two forms of this instruction, corresponding to a conditional branch
1035and an unconditional branch.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001036<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001037<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
1038single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
1039unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
1040value as a target.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001041<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001042<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
1043argument is evaluated. If the value is <tt>true</tt>, control flows
1044to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
1045control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001046<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001047<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
1048 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 +00001049</div>
Chris Lattner00950542001-06-06 20:29:01 +00001050<!-- _______________________________________________________________________ -->
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001051<div class="doc_subsubsection">
1052 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
1053</div>
1054
Misha Brukman9d0919f2003-11-08 01:05:38 +00001055<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001056<h5>Syntax:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001057
1058<pre>
1059 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
1060</pre>
1061
Chris Lattner00950542001-06-06 20:29:01 +00001062<h5>Overview:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001063
1064<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
1065several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +00001066instruction, allowing a branch to occur to one of many possible
1067destinations.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001068
1069
Chris Lattner00950542001-06-06 20:29:01 +00001070<h5>Arguments:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001071
1072<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
1073comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
1074an array of pairs of comparison value constants and '<tt>label</tt>'s. The
1075table is not allowed to contain duplicate constant entries.</p>
1076
Chris Lattner00950542001-06-06 20:29:01 +00001077<h5>Semantics:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001078
Chris Lattner261efe92003-11-25 01:02:51 +00001079<p>The <tt>switch</tt> instruction specifies a table of values and
1080destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswell84114752004-06-25 16:05:06 +00001081table is searched for the given value. If the value is found, control flow is
1082transfered to the corresponding destination; otherwise, control flow is
1083transfered to the default destination.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001084
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001085<h5>Implementation:</h5>
1086
1087<p>Depending on properties of the target machine and the particular
1088<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswell84114752004-06-25 16:05:06 +00001089ways. For example, it could be generated as a series of chained conditional
1090branches or with a lookup table.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001091
1092<h5>Example:</h5>
1093
1094<pre>
1095 <i>; Emulate a conditional br instruction</i>
1096 %Val = <a href="#i_cast">cast</a> bool %value to int
1097 switch int %Val, label %truedest [int 0, label %falsedest ]
1098
1099 <i>; Emulate an unconditional br instruction</i>
1100 switch uint 0, label %dest [ ]
1101
1102 <i>; Implement a jump table:</i>
1103 switch uint %val, label %otherwise [ uint 0, label %onzero
1104 uint 1, label %onone
1105 uint 2, label %ontwo ]
Chris Lattner00950542001-06-06 20:29:01 +00001106</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001107</div>
Chris Lattner00950542001-06-06 20:29:01 +00001108<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001109<div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>'
1110Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001111<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001112<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001113<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 +00001114<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001115<p>The '<tt>invoke</tt>' instruction causes control to transfer to a
1116specified function, with the possibility of control flow transfer to
1117either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>.
1118If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>"
1119instruction, control flow will return to the "normal" label. If the
1120callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
1121instruction, control is interrupted, and continued at the dynamically
1122nearest "except" label.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001123<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001124<p>This instruction requires several arguments:</p>
Chris Lattner00950542001-06-06 20:29:01 +00001125<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00001126 <li>'<tt>ptr to function ty</tt>': shall be the signature of the
1127pointer to function value being invoked. In most cases, this is a
1128direct function invocation, but indirect <tt>invoke</tt>s are just as
1129possible, branching off an arbitrary pointer to function value. </li>
1130 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer
1131to a function to be invoked. </li>
1132 <li>'<tt>function args</tt>': argument list whose types match the
1133function signature argument types. If the function signature indicates
1134the function accepts a variable number of arguments, the extra
1135arguments can be specified. </li>
1136 <li>'<tt>normal label</tt>': the label reached when the called
1137function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
1138 <li>'<tt>exception label</tt>': the label reached when a callee
1139returns with the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
Chris Lattner00950542001-06-06 20:29:01 +00001140</ol>
Chris Lattner00950542001-06-06 20:29:01 +00001141<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001142<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner261efe92003-11-25 01:02:51 +00001143 href="#i_call">call</a></tt>' instruction in most regards. The
1144primary difference is that it establishes an association with a label,
1145which is used by the runtime library to unwind the stack.</p>
1146<p>This instruction is used in languages with destructors to ensure
1147that proper cleanup is performed in the case of either a <tt>longjmp</tt>
1148or a thrown exception. Additionally, this is important for
1149implementation of '<tt>catch</tt>' clauses in high-level languages that
1150support them.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001151<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001152<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 +00001153</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001154</div>
Chris Lattner35eca582004-10-16 18:04:13 +00001155
1156
Chris Lattner27f71f22003-09-03 00:41:47 +00001157<!-- _______________________________________________________________________ -->
Chris Lattner35eca582004-10-16 18:04:13 +00001158
Chris Lattner261efe92003-11-25 01:02:51 +00001159<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
1160Instruction</a> </div>
Chris Lattner35eca582004-10-16 18:04:13 +00001161
Misha Brukman9d0919f2003-11-08 01:05:38 +00001162<div class="doc_text">
Chris Lattner35eca582004-10-16 18:04:13 +00001163
Chris Lattner27f71f22003-09-03 00:41:47 +00001164<h5>Syntax:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001165<pre>
1166 unwind
1167</pre>
1168
Chris Lattner27f71f22003-09-03 00:41:47 +00001169<h5>Overview:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001170
1171<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
1172at the first callee in the dynamic call stack which used an <a
1173href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
1174primarily used to implement exception handling.</p>
1175
Chris Lattner27f71f22003-09-03 00:41:47 +00001176<h5>Semantics:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001177
1178<p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to
1179immediately halt. The dynamic call stack is then searched for the first <a
1180href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
1181execution continues at the "exceptional" destination block specified by the
1182<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
1183dynamic call chain, undefined behavior results.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001184</div>
Chris Lattner35eca582004-10-16 18:04:13 +00001185
1186<!-- _______________________________________________________________________ -->
1187
1188<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
1189Instruction</a> </div>
1190
1191<div class="doc_text">
1192
1193<h5>Syntax:</h5>
1194<pre>
1195 unreachable
1196</pre>
1197
1198<h5>Overview:</h5>
1199
1200<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
1201instruction is used to inform the optimizer that a particular portion of the
1202code is not reachable. This can be used to indicate that the code after a
1203no-return function cannot be reached, and other facts.</p>
1204
1205<h5>Semantics:</h5>
1206
1207<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
1208</div>
1209
1210
1211
Chris Lattner00950542001-06-06 20:29:01 +00001212<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001213<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001214<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001215<p>Binary operators are used to do most of the computation in a
1216program. They require two operands, execute an operation on them, and
John Criswell9e2485c2004-12-10 15:51:16 +00001217produce a single value. The operands might represent
Chris Lattnera58561b2004-08-12 19:12:28 +00001218multiple data, as is the case with the <a href="#t_packed">packed</a> data type.
1219The result value of a binary operator is not
Chris Lattner261efe92003-11-25 01:02:51 +00001220necessarily the same type as its operands.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001221<p>There are several different binary operators:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001222</div>
Chris Lattner00950542001-06-06 20:29:01 +00001223<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001224<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
1225Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001226<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001227<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001228<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 +00001229</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001230<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001231<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001232<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001233<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattnera58561b2004-08-12 19:12:28 +00001234 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
1235 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1236Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001237<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001238<p>The value produced is the integer or floating point sum of the two
1239operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001240<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001241<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001242</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001243</div>
Chris Lattner00950542001-06-06 20:29:01 +00001244<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001245<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
1246Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001247<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001248<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001249<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 +00001250</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001251<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001252<p>The '<tt>sub</tt>' instruction returns the difference of its two
1253operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001254<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
1255instruction present in most other intermediate representations.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001256<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001257<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001258 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001259values.
1260This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1261Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001262<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001263<p>The value produced is the integer or floating point difference of
1264the two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001265<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001266<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001267 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
1268</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001269</div>
Chris Lattner00950542001-06-06 20:29:01 +00001270<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001271<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
1272Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001273<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001274<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001275<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 +00001276</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001277<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001278<p>The '<tt>mul</tt>' instruction returns the product of its two
1279operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001280<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001281<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001282 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001283values.
1284This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1285Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001286<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001287<p>The value produced is the integer or floating point product of the
Misha Brukman9d0919f2003-11-08 01:05:38 +00001288two operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001289<p>There is no signed vs unsigned multiplication. The appropriate
1290action is taken based on the type of the operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001291<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001292<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001293</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001294</div>
Chris Lattner00950542001-06-06 20:29:01 +00001295<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001296<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
1297Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001298<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001299<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001300<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1301</pre>
1302<h5>Overview:</h5>
1303<p>The '<tt>div</tt>' instruction returns the quotient of its two
1304operands.</p>
1305<h5>Arguments:</h5>
1306<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
1307 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001308values.
1309This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1310Both arguments must have identical types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001311<h5>Semantics:</h5>
1312<p>The value produced is the integer or floating point quotient of the
1313two operands.</p>
1314<h5>Example:</h5>
1315<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
1316</pre>
1317</div>
1318<!-- _______________________________________________________________________ -->
1319<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
1320Instruction</a> </div>
1321<div class="doc_text">
1322<h5>Syntax:</h5>
1323<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1324</pre>
1325<h5>Overview:</h5>
1326<p>The '<tt>rem</tt>' instruction returns the remainder from the
1327division of its two operands.</p>
1328<h5>Arguments:</h5>
1329<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1330 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001331values.
1332This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1333Both arguments must have identical types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001334<h5>Semantics:</h5>
1335<p>This returns the <i>remainder</i> of a division (where the result
1336has the same sign as the divisor), not the <i>modulus</i> (where the
1337result has the same sign as the dividend) of a value. For more
1338information about the difference, see: <a
1339 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1340Math Forum</a>.</p>
1341<h5>Example:</h5>
1342<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1343</pre>
1344</div>
1345<!-- _______________________________________________________________________ -->
1346<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1347Instructions</a> </div>
1348<div class="doc_text">
1349<h5>Syntax:</h5>
1350<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 +00001351 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1352 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1353 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1354 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1355 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1356</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001357<h5>Overview:</h5>
1358<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1359value based on a comparison of their two operands.</p>
1360<h5>Arguments:</h5>
1361<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1362be of <a href="#t_firstclass">first class</a> type (it is not possible
1363to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1364or '<tt>void</tt>' values, etc...). Both arguments must have identical
1365types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001366<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001367<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1368value if both operands are equal.<br>
1369The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1370value if both operands are unequal.<br>
1371The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1372value if the first operand is less than the second operand.<br>
1373The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1374value if the first operand is greater than the second operand.<br>
1375The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1376value if the first operand is less than or equal to the second operand.<br>
1377The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1378value if the first operand is greater than or equal to the second
1379operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001380<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001381<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner00950542001-06-06 20:29:01 +00001382 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
1383 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1384 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1385 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1386 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1387</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001388</div>
Chris Lattner00950542001-06-06 20:29:01 +00001389<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001390<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1391Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001392<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001393<p>Bitwise binary operators are used to do various forms of
1394bit-twiddling in a program. They are generally very efficient
John Criswell9e2485c2004-12-10 15:51:16 +00001395instructions and can commonly be strength reduced from other
Chris Lattner261efe92003-11-25 01:02:51 +00001396instructions. They require two operands, execute an operation on them,
1397and produce a single value. The resulting value of the bitwise binary
1398operators is always the same type as its first operand.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001399</div>
Chris Lattner00950542001-06-06 20:29:01 +00001400<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001401<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1402Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001403<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001404<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001405<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 +00001406</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001407<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001408<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1409its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001410<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001411<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001412 href="#t_integral">integral</a> values. Both arguments must have
1413identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001414<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001415<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001416<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001417<div style="align: center">
Misha Brukman9d0919f2003-11-08 01:05:38 +00001418<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +00001419 <tbody>
1420 <tr>
1421 <td>In0</td>
1422 <td>In1</td>
1423 <td>Out</td>
1424 </tr>
1425 <tr>
1426 <td>0</td>
1427 <td>0</td>
1428 <td>0</td>
1429 </tr>
1430 <tr>
1431 <td>0</td>
1432 <td>1</td>
1433 <td>0</td>
1434 </tr>
1435 <tr>
1436 <td>1</td>
1437 <td>0</td>
1438 <td>0</td>
1439 </tr>
1440 <tr>
1441 <td>1</td>
1442 <td>1</td>
1443 <td>1</td>
1444 </tr>
1445 </tbody>
1446</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001447</div>
Chris Lattner00950542001-06-06 20:29:01 +00001448<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001449<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001450 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1451 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1452</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001453</div>
Chris Lattner00950542001-06-06 20:29:01 +00001454<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001455<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001456<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001457<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001458<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 +00001459</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001460<h5>Overview:</h5>
1461<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1462or of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001463<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001464<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001465 href="#t_integral">integral</a> values. Both arguments must have
1466identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001467<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001468<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001469<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001470<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001471<table border="1" cellspacing="0" cellpadding="4">
1472 <tbody>
1473 <tr>
1474 <td>In0</td>
1475 <td>In1</td>
1476 <td>Out</td>
1477 </tr>
1478 <tr>
1479 <td>0</td>
1480 <td>0</td>
1481 <td>0</td>
1482 </tr>
1483 <tr>
1484 <td>0</td>
1485 <td>1</td>
1486 <td>1</td>
1487 </tr>
1488 <tr>
1489 <td>1</td>
1490 <td>0</td>
1491 <td>1</td>
1492 </tr>
1493 <tr>
1494 <td>1</td>
1495 <td>1</td>
1496 <td>1</td>
1497 </tr>
1498 </tbody>
1499</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001500</div>
Chris Lattner00950542001-06-06 20:29:01 +00001501<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001502<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001503 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1504 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1505</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001506</div>
Chris Lattner00950542001-06-06 20:29:01 +00001507<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001508<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1509Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001510<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001511<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001512<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 +00001513</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001514<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001515<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1516or of its two operands. The <tt>xor</tt> is used to implement the
1517"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001518<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001519<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001520 href="#t_integral">integral</a> values. Both arguments must have
1521identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001522<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001523<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001524<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001525<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001526<table border="1" cellspacing="0" cellpadding="4">
1527 <tbody>
1528 <tr>
1529 <td>In0</td>
1530 <td>In1</td>
1531 <td>Out</td>
1532 </tr>
1533 <tr>
1534 <td>0</td>
1535 <td>0</td>
1536 <td>0</td>
1537 </tr>
1538 <tr>
1539 <td>0</td>
1540 <td>1</td>
1541 <td>1</td>
1542 </tr>
1543 <tr>
1544 <td>1</td>
1545 <td>0</td>
1546 <td>1</td>
1547 </tr>
1548 <tr>
1549 <td>1</td>
1550 <td>1</td>
1551 <td>0</td>
1552 </tr>
1553 </tbody>
1554</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001555</div>
Chris Lattner261efe92003-11-25 01:02:51 +00001556<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001557<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001558<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001559 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1560 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner27f71f22003-09-03 00:41:47 +00001561 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner00950542001-06-06 20:29:01 +00001562</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001563</div>
Chris Lattner00950542001-06-06 20:29:01 +00001564<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001565<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1566Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001567<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001568<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001569<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 +00001570</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001571<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001572<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1573the left a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001574<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001575<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001576 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1577type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001578<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001579<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001580<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001581<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 +00001582 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1583 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1584</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001585</div>
Chris Lattner00950542001-06-06 20:29:01 +00001586<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001587<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1588Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001589<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001590<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001591<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 +00001592</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001593<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001594<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1595the right a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001596<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001597<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001598 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1599type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001600<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001601<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1602most significant bit is duplicated in the newly free'd bit positions.
1603If the first argument is unsigned, zero bits shall fill the empty
1604positions.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001605<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001606<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 +00001607 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001608 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner8c6bb902003-06-18 21:30:51 +00001609 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1610 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner00950542001-06-06 20:29:01 +00001611</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001612</div>
Chris Lattner00950542001-06-06 20:29:01 +00001613<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001614<div class="doc_subsection"> <a name="memoryops">Memory Access
1615Operations</a></div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001616<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001617<p>A key design point of an SSA-based representation is how it
1618represents memory. In LLVM, no memory locations are in SSA form, which
1619makes things very simple. This section describes how to read, write,
John Criswell9e2485c2004-12-10 15:51:16 +00001620allocate, and free memory in LLVM.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001621</div>
Chris Lattner00950542001-06-06 20:29:01 +00001622<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001623<div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>'
1624Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001625<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001626<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001627<pre> &lt;result&gt; = malloc &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001628 &lt;result&gt; = malloc &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001629</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001630<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001631<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1632heap and returns a pointer to it.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001633<h5>Arguments:</h5>
John Criswell6e4ca612004-02-24 16:13:56 +00001634<p>The '<tt>malloc</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1635bytes of memory from the operating system and returns a pointer of the
Chris Lattner261efe92003-11-25 01:02:51 +00001636appropriate type to the program. The second form of the instruction is
1637a shorter version of the first instruction that defaults to allocating
1638one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001639<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001640<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001641<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1642a pointer is returned.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001643<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001644<pre> %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001645
Chris Lattner261efe92003-11-25 01:02:51 +00001646 %size = <a
1647 href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001648 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1649 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001650</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001651</div>
Chris Lattner00950542001-06-06 20:29:01 +00001652<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001653<div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>'
1654Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001655<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001656<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001657<pre> free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner00950542001-06-06 20:29:01 +00001658</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001659<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001660<p>The '<tt>free</tt>' instruction returns memory back to the unused
1661memory heap, to be reallocated in the future.</p>
1662<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001663<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001664<p>'<tt>value</tt>' shall be a pointer value that points to a value
1665that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1666instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001667<h5>Semantics:</h5>
John Criswell9e2485c2004-12-10 15:51:16 +00001668<p>Access to the memory pointed to by the pointer is no longer defined
Chris Lattner261efe92003-11-25 01:02:51 +00001669after this instruction executes.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001670<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001671<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 +00001672 free [4 x ubyte]* %array
1673</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001674</div>
Chris Lattner00950542001-06-06 20:29:01 +00001675<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001676<div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>'
1677Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001678<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001679<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001680<pre> &lt;result&gt; = alloca &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001681 &lt;result&gt; = alloca &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001682</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001683<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001684<p>The '<tt>alloca</tt>' instruction allocates memory on the current
1685stack frame of the procedure that is live until the current function
1686returns to its caller.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001687<h5>Arguments:</h5>
John Criswell9e2485c2004-12-10 15:51:16 +00001688<p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001689bytes of memory on the runtime stack, returning a pointer of the
1690appropriate type to the program. The second form of the instruction is
1691a shorter version of the first that defaults to allocating one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001692<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001693<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001694<p>Memory is allocated, a pointer is returned. '<tt>alloca</tt>'d
1695memory is automatically released when the function returns. The '<tt>alloca</tt>'
1696instruction is commonly used to represent automatic variables that must
1697have an address available. When the function returns (either with the <tt><a
1698 href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001699instructions), the memory is reclaimed.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001700<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001701<pre> %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001702 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner00950542001-06-06 20:29:01 +00001703</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001704</div>
Chris Lattner00950542001-06-06 20:29:01 +00001705<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001706<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1707Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001708<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00001709<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001710<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 +00001711<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001712<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001713<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001714<p>The argument to the '<tt>load</tt>' instruction specifies the memory
1715address to load from. The pointer must point to a <a
Chris Lattnere53e5082004-06-03 22:57:15 +00001716 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
Chris Lattner261efe92003-11-25 01:02:51 +00001717marked as <tt>volatile</tt> then the optimizer is not allowed to modify
1718the number or order of execution of this <tt>load</tt> with other
1719volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1720instructions. </p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001721<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001722<p>The location of memory pointed to is loaded.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001723<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001724<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1725 <a
1726 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001727 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1728</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001729</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001730<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001731<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1732Instruction</a> </div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001733<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001734<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 +00001735 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 +00001736</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001737<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001738<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001739<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001740<p>There are two arguments to the '<tt>store</tt>' instruction: a value
1741to store and an address to store it into. The type of the '<tt>&lt;pointer&gt;</tt>'
1742operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
1743operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the
1744optimizer is not allowed to modify the number or order of execution of
1745this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1746 href="#i_store">store</a></tt> instructions.</p>
1747<h5>Semantics:</h5>
1748<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
1749at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001750<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001751<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1752 <a
1753 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001754 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1755</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001756<!-- _______________________________________________________________________ -->
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001757<div class="doc_subsubsection">
1758 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
1759</div>
1760
Misha Brukman9d0919f2003-11-08 01:05:38 +00001761<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00001762<h5>Syntax:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001763<pre>
1764 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
1765</pre>
1766
Chris Lattner7faa8832002-04-14 06:13:44 +00001767<h5>Overview:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001768
1769<p>
1770The '<tt>getelementptr</tt>' instruction is used to get the address of a
1771subelement of an aggregate data structure.</p>
1772
Chris Lattner7faa8832002-04-14 06:13:44 +00001773<h5>Arguments:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001774
1775<p>This instruction takes a list of integer constants that indicate what
1776elements of the aggregate object to index to. The actual types of the arguments
1777provided depend on the type of the first pointer argument. The
1778'<tt>getelementptr</tt>' instruction is used to index down through the type
1779levels of a structure. When indexing into a structure, only <tt>uint</tt>
1780integer constants are allowed. When indexing into an array or pointer
1781<tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
1782
Chris Lattner261efe92003-11-25 01:02:51 +00001783<p>For example, let's consider a C code fragment and how it gets
1784compiled to LLVM:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001785
1786<pre>
1787 struct RT {
1788 char A;
1789 int B[10][20];
1790 char C;
1791 };
1792 struct ST {
1793 int X;
1794 double Y;
1795 struct RT Z;
1796 };
1797
1798 int *foo(struct ST *s) {
1799 return &amp;s[1].Z.B[5][13];
1800 }
1801</pre>
1802
Misha Brukman9d0919f2003-11-08 01:05:38 +00001803<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001804
1805<pre>
1806 %RT = type { sbyte, [10 x [20 x int]], sbyte }
1807 %ST = type { int, double, %RT }
1808
Brian Gaeke7283e7c2004-07-02 21:08:14 +00001809 implementation
1810
1811 int* %foo(%ST* %s) {
1812 entry:
1813 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001814 ret int* %reg
1815 }
1816</pre>
1817
Chris Lattner7faa8832002-04-14 06:13:44 +00001818<h5>Semantics:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001819
1820<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
Chris Lattnere53e5082004-06-03 22:57:15 +00001821on the pointer type that is being index into. <a href="#t_pointer">Pointer</a>
1822and <a href="#t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
1823<tt>ulong</tt>, or <tt>long</tt> values, and <a href="#t_struct">structure</a>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001824types require <tt>uint</tt> <b>constants</b>.</p>
1825
Misha Brukman9d0919f2003-11-08 01:05:38 +00001826<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001827type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
1828}</tt>' type, a structure. The second index indexes into the third element of
1829the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
1830sbyte }</tt>' type, another structure. The third index indexes into the second
1831element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
1832array. The two dimensions of the array are subscripted into, yielding an
1833'<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction return a pointer
1834to this element, thus computing a value of '<tt>int*</tt>' type.</p>
1835
Chris Lattner261efe92003-11-25 01:02:51 +00001836<p>Note that it is perfectly legal to index partially through a
1837structure, returning a pointer to an inner element. Because of this,
1838the LLVM code for the given testcase is equivalent to:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001839
1840<pre>
Chris Lattnerd4f6b172005-03-07 22:13:59 +00001841 int* %foo(%ST* %s) {
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001842 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
1843 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
1844 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
1845 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
1846 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
1847 ret int* %t5
1848 }
Chris Lattner6536cfe2002-05-06 22:08:29 +00001849</pre>
Chris Lattner7faa8832002-04-14 06:13:44 +00001850<h5>Example:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001851<pre>
1852 <i>; yields [12 x ubyte]*:aptr</i>
1853 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
1854</pre>
1855
1856</div>
Chris Lattner00950542001-06-06 20:29:01 +00001857<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001858<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001859<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +00001860<p>The instructions in this category are the "miscellaneous"
Chris Lattner261efe92003-11-25 01:02:51 +00001861instructions, which defy better classification.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001862</div>
Chris Lattner00950542001-06-06 20:29:01 +00001863<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001864<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
1865Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001866<div class="doc_text">
Chris Lattner33ba0d92001-07-09 00:26:23 +00001867<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001868<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001869<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001870<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
1871the SSA graph representing the function.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001872<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001873<p>The type of the incoming values are specified with the first type
1874field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
1875as arguments, with one pair for each predecessor basic block of the
1876current block. Only values of <a href="#t_firstclass">first class</a>
1877type may be used as the value arguments to the PHI node. Only labels
1878may be used as the label arguments.</p>
1879<p>There must be no non-phi instructions between the start of a basic
1880block and the PHI instructions: i.e. PHI instructions must be first in
1881a basic block.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001882<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001883<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
1884value specified by the parameter, depending on which basic block we
1885came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001886<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001887<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 +00001888</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001889
Chris Lattner6536cfe2002-05-06 22:08:29 +00001890<!-- _______________________________________________________________________ -->
Chris Lattnercc37aae2004-03-12 05:50:16 +00001891<div class="doc_subsubsection">
1892 <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
1893</div>
1894
Misha Brukman9d0919f2003-11-08 01:05:38 +00001895<div class="doc_text">
Chris Lattnercc37aae2004-03-12 05:50:16 +00001896
Chris Lattner6536cfe2002-05-06 22:08:29 +00001897<h5>Syntax:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001898
1899<pre>
1900 &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 +00001901</pre>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001902
Chris Lattner6536cfe2002-05-06 22:08:29 +00001903<h5>Overview:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001904
1905<p>
1906The '<tt>cast</tt>' instruction is used as the primitive means to convert
1907integers to floating point, change data type sizes, and break type safety (by
1908casting pointers).
1909</p>
1910
1911
Chris Lattner6536cfe2002-05-06 22:08:29 +00001912<h5>Arguments:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001913
1914<p>
1915The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
1916class value, and a type to cast it to, which must also be a <a
1917href="#t_firstclass">first class</a> type.
1918</p>
1919
Chris Lattner6536cfe2002-05-06 22:08:29 +00001920<h5>Semantics:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001921
1922<p>
1923This instruction follows the C rules for explicit casts when determining how the
1924data being cast must change to fit in its new container.
1925</p>
1926
1927<p>
1928When casting to bool, any value that would be considered true in the context of
1929a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
1930all else are '<tt>false</tt>'.
1931</p>
1932
1933<p>
1934When extending an integral value from a type of one signness to another (for
1935example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
1936<b>source</b> value is signed, and zero-extended if the source value is
1937unsigned. <tt>bool</tt> values are always zero extended into either zero or
1938one.
1939</p>
1940
Chris Lattner33ba0d92001-07-09 00:26:23 +00001941<h5>Example:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001942
1943<pre>
1944 %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattner7bae3952002-06-25 18:03:17 +00001945 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001946</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001947</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001948
1949<!-- _______________________________________________________________________ -->
1950<div class="doc_subsubsection">
1951 <a name="i_select">'<tt>select</tt>' Instruction</a>
1952</div>
1953
1954<div class="doc_text">
1955
1956<h5>Syntax:</h5>
1957
1958<pre>
1959 &lt;result&gt; = select bool &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
1960</pre>
1961
1962<h5>Overview:</h5>
1963
1964<p>
1965The '<tt>select</tt>' instruction is used to choose one value based on a
1966condition, without branching.
1967</p>
1968
1969
1970<h5>Arguments:</h5>
1971
1972<p>
1973The '<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.
1974</p>
1975
1976<h5>Semantics:</h5>
1977
1978<p>
1979If the boolean condition evaluates to true, the instruction returns the first
1980value argument, otherwise it returns the second value argument.
1981</p>
1982
1983<h5>Example:</h5>
1984
1985<pre>
1986 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
1987</pre>
1988</div>
1989
1990
1991
1992
1993
Chris Lattner33ba0d92001-07-09 00:26:23 +00001994<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001995<div class="doc_subsubsection"> <a name="i_call">'<tt>call</tt>'
1996Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001997<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001998<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001999<pre> &lt;result&gt; = call &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +00002000<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002001<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002002<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002003<p>This instruction requires several arguments:</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00002004<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00002005 <li>
2006 <p>'<tt>ty</tt>': shall be the signature of the pointer to function
2007value being invoked. The argument types must match the types implied
2008by this signature.</p>
2009 </li>
2010 <li>
2011 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a
2012function to be invoked. In most cases, this is a direct function
2013invocation, but indirect <tt>call</tt>s are just as possible,
2014calling an arbitrary pointer to function values.</p>
2015 </li>
2016 <li>
2017 <p>'<tt>function args</tt>': argument list whose types match the
2018function signature argument types. If the function signature
2019indicates the function accepts a variable number of arguments, the
2020extra arguments can be specified.</p>
2021 </li>
Chris Lattner6536cfe2002-05-06 22:08:29 +00002022</ol>
Chris Lattner00950542001-06-06 20:29:01 +00002023<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002024<p>The '<tt>call</tt>' instruction is used to cause control flow to
2025transfer to a specified function, with its incoming arguments bound to
2026the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
2027instruction in the called function, control flow continues with the
2028instruction after the function call, and the return value of the
2029function is bound to the result argument. This is a simpler case of
2030the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002031<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002032<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 +00002033</div>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002034
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002035<!-- _______________________________________________________________________ -->
Chris Lattnere19d7a72004-09-27 21:51:25 +00002036<div class="doc_subsubsection">
2037 <a name="i_vanext">'<tt>vanext</tt>' Instruction</a>
2038</div>
2039
Misha Brukman9d0919f2003-11-08 01:05:38 +00002040<div class="doc_text">
Chris Lattnere19d7a72004-09-27 21:51:25 +00002041
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002042<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002043
2044<pre>
2045 &lt;resultarglist&gt; = vanext &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;
2046</pre>
2047
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002048<h5>Overview:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002049
Chris Lattner261efe92003-11-25 01:02:51 +00002050<p>The '<tt>vanext</tt>' instruction is used to access arguments passed
2051through the "variable argument" area of a function call. It is used to
2052implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002053
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002054<h5>Arguments:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002055
2056<p>This instruction takes a <tt>va_list</tt> value and the type of the
2057argument. It returns another <tt>va_list</tt>. The actual type of
2058<tt>va_list</tt> may be defined differently for different targets. Most targets
2059use a <tt>va_list</tt> type of <tt>sbyte*</tt> or some other pointer type.</p>
2060
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002061<h5>Semantics:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002062
2063<p>The '<tt>vanext</tt>' instruction advances the specified <tt>va_list</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002064past an argument of the specified type. In conjunction with the <a
2065 href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement
2066the <tt>va_arg</tt> macro available in C. For more information, see
2067the variable argument handling <a href="#int_varargs">Intrinsic
2068Functions</a>.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002069
Chris Lattner261efe92003-11-25 01:02:51 +00002070<p>It is legal for this instruction to be called in a function which
2071does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002072function.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002073
Misha Brukman9d0919f2003-11-08 01:05:38 +00002074<p><tt>vanext</tt> is an LLVM instruction instead of an <a
Chris Lattnere19d7a72004-09-27 21:51:25 +00002075href="#intrinsics">intrinsic function</a> because it takes a type as an
2076argument. The type refers to the current argument in the <tt>va_list</tt>, it
2077tells the compiler how far on the stack it needs to advance to find the next
2078argument</p>
2079
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002080<h5>Example:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002081
Chris Lattner261efe92003-11-25 01:02:51 +00002082<p>See the <a href="#int_varargs">variable argument processing</a>
2083section.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002084
Misha Brukman9d0919f2003-11-08 01:05:38 +00002085</div>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002086
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002087<!-- _______________________________________________________________________ -->
Chris Lattnere19d7a72004-09-27 21:51:25 +00002088<div class="doc_subsubsection">
2089 <a name="i_vaarg">'<tt>vaarg</tt>' Instruction</a>
2090</div>
2091
Misha Brukman9d0919f2003-11-08 01:05:38 +00002092<div class="doc_text">
Chris Lattnere19d7a72004-09-27 21:51:25 +00002093
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002094<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002095
2096<pre>
2097 &lt;resultval&gt; = vaarg &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;
2098</pre>
2099
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002100<h5>Overview:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002101
2102<p>The '<tt>vaarg</tt>' instruction is used to access arguments passed through
2103the "variable argument" area of a function call. It is used to implement the
2104<tt>va_arg</tt> macro in C.</p>
2105
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002106<h5>Arguments:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002107
2108<p>This instruction takes a <tt>va_list</tt> value and the type of the
2109argument. It returns a value of the specified argument type. Again, the actual
2110type of <tt>va_list</tt> is target specific.</p>
2111
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002112<h5>Semantics:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002113
2114<p>The '<tt>vaarg</tt>' instruction loads an argument of the specified type from
2115the specified <tt>va_list</tt>. In conjunction with the <a
2116href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to implement the
2117<tt>va_arg</tt> macro available in C. For more information, see the variable
2118argument handling <a href="#int_varargs">Intrinsic Functions</a>.</p>
2119
2120<p>It is legal for this instruction to be called in a function which does not
2121take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002122function.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002123
Misha Brukman9d0919f2003-11-08 01:05:38 +00002124<p><tt>vaarg</tt> is an LLVM instruction instead of an <a
Chris Lattnere19d7a72004-09-27 21:51:25 +00002125href="#intrinsics">intrinsic function</a> because it takes an type as an
2126argument.</p>
2127
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002128<h5>Example:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002129
2130<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
2131
Misha Brukman9d0919f2003-11-08 01:05:38 +00002132</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002133
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002134<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00002135<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
2136<!-- *********************************************************************** -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002137
Misha Brukman9d0919f2003-11-08 01:05:38 +00002138<div class="doc_text">
Chris Lattner33aec9e2004-02-12 17:01:32 +00002139
2140<p>LLVM supports the notion of an "intrinsic function". These functions have
2141well known names and semantics, and are required to follow certain
2142restrictions. Overall, these instructions represent an extension mechanism for
2143the LLVM language that does not require changing all of the transformations in
2144LLVM to add to the language (or the bytecode reader/writer, the parser,
2145etc...).</p>
2146
2147<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix, this
2148prefix is reserved in LLVM for intrinsic names, thus functions may not be named
2149this. Intrinsic functions must always be external functions: you cannot define
2150the body of intrinsic functions. Intrinsic functions may only be used in call
2151or invoke instructions: it is illegal to take the address of an intrinsic
2152function. Additionally, because intrinsic functions are part of the LLVM
2153language, it is required that they all be documented here if any are added.</p>
2154
2155
2156<p>
2157Adding an intrinsic to LLVM is straight-forward if it is possible to express the
2158concept in LLVM directly (ie, code generator support is not _required_). To do
2159this, extend the default implementation of the IntrinsicLowering class to handle
2160the intrinsic. Code generators use this class to lower intrinsics they do not
2161understand to raw LLVM instructions that they do.
2162</p>
2163
Misha Brukman9d0919f2003-11-08 01:05:38 +00002164</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002165
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002166<!-- ======================================================================= -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002167<div class="doc_subsection">
2168 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
2169</div>
2170
Misha Brukman9d0919f2003-11-08 01:05:38 +00002171<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00002172
Misha Brukman9d0919f2003-11-08 01:05:38 +00002173<p>Variable argument support is defined in LLVM with the <a
Chris Lattner261efe92003-11-25 01:02:51 +00002174 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
2175intrinsic functions. These functions are related to the similarly
2176named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002177
Chris Lattner261efe92003-11-25 01:02:51 +00002178<p>All of these functions operate on arguments that use a
2179target-specific value type "<tt>va_list</tt>". The LLVM assembly
2180language reference manual does not define what this type is, so all
2181transformations should be prepared to handle intrinsics with any type
2182used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002183
Misha Brukman9d0919f2003-11-08 01:05:38 +00002184<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner261efe92003-11-25 01:02:51 +00002185instruction and the variable argument handling intrinsic functions are
2186used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002187
Chris Lattner33aec9e2004-02-12 17:01:32 +00002188<pre>
2189int %test(int %X, ...) {
2190 ; Initialize variable argument processing
2191 %ap = call sbyte* %<a href="#i_va_start">llvm.va_start</a>()
2192
2193 ; Read a single integer argument
2194 %tmp = vaarg sbyte* %ap, int
2195
2196 ; Advance to the next argument
2197 %ap2 = vanext sbyte* %ap, int
2198
2199 ; Demonstrate usage of llvm.va_copy and llvm.va_end
2200 %aq = call sbyte* %<a href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2)
2201 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %aq)
2202
2203 ; Stop processing of arguments.
2204 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %ap2)
2205 ret int %tmp
2206}
2207</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002208</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002209
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002210<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002211<div class="doc_subsubsection">
2212 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
2213</div>
2214
2215
Misha Brukman9d0919f2003-11-08 01:05:38 +00002216<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002217<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002218<pre> call &lt;va_list&gt; ()* %llvm.va_start()<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002219<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002220<p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt>&lt;arglist&gt;</tt>
2221for subsequent use by the variable argument intrinsics.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002222<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002223<p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002224macro available in C. In a target-dependent way, it initializes and
2225returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt>
2226will produce the first variable argument passed to the function. Unlike
2227the C <tt>va_start</tt> macro, this intrinsic does not need to know the
2228last argument of the function, the compiler can figure that out.</p>
2229<p>Note that this intrinsic function is only legal to be called from
2230within the body of a variable argument function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002231</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002232
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002233<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002234<div class="doc_subsubsection">
2235 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
2236</div>
2237
Misha Brukman9d0919f2003-11-08 01:05:38 +00002238<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002239<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002240<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 +00002241<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002242<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
2243which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
2244or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002245<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002246<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002247<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002248<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002249macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
2250Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
2251 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
2252with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002253</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002254
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002255<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002256<div class="doc_subsubsection">
2257 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
2258</div>
2259
Misha Brukman9d0919f2003-11-08 01:05:38 +00002260<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00002261
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002262<h5>Syntax:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002263
2264<pre>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002265 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 +00002266</pre>
2267
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002268<h5>Overview:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002269
2270<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position
2271from the source argument list to the destination argument list.</p>
2272
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002273<h5>Arguments:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002274
Misha Brukman9d0919f2003-11-08 01:05:38 +00002275<p>The argument is the <tt>va_list</tt> to copy.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002276
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002277<h5>Semantics:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002278
Misha Brukman9d0919f2003-11-08 01:05:38 +00002279<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
Chris Lattnerd7923912004-05-23 21:06:01 +00002280macro available in C. In a target-dependent way, it copies the source
2281<tt>va_list</tt> element into the returned list. This intrinsic is necessary
Chris Lattnerfcd37252004-06-21 22:52:48 +00002282because the <tt><a href="#i_va_start">llvm.va_start</a></tt> intrinsic may be
Chris Lattnerd7923912004-05-23 21:06:01 +00002283arbitrarily complex and require memory allocation, for example.</p>
2284
Misha Brukman9d0919f2003-11-08 01:05:38 +00002285</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002286
Chris Lattner33aec9e2004-02-12 17:01:32 +00002287<!-- ======================================================================= -->
2288<div class="doc_subsection">
Chris Lattnerd7923912004-05-23 21:06:01 +00002289 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
2290</div>
2291
2292<div class="doc_text">
2293
2294<p>
2295LLVM support for <a href="GarbageCollection.html">Accurate Garbage
2296Collection</a> requires the implementation and generation of these intrinsics.
2297These intrinsics allow identification of <a href="#i_gcroot">GC roots on the
2298stack</a>, as well as garbage collector implementations that require <a
2299href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers.
2300Front-ends for type-safe garbage collected languages should generate these
2301intrinsics to make use of the LLVM garbage collectors. For more details, see <a
2302href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
2303</p>
2304</div>
2305
2306<!-- _______________________________________________________________________ -->
2307<div class="doc_subsubsection">
2308 <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
2309</div>
2310
2311<div class="doc_text">
2312
2313<h5>Syntax:</h5>
2314
2315<pre>
2316 call void (&lt;ty&gt;**, &lt;ty2&gt;*)* %llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
2317</pre>
2318
2319<h5>Overview:</h5>
2320
John Criswell9e2485c2004-12-10 15:51:16 +00002321<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
Chris Lattnerd7923912004-05-23 21:06:01 +00002322the code generator, and allows some metadata to be associated with it.</p>
2323
2324<h5>Arguments:</h5>
2325
2326<p>The first argument specifies the address of a stack object that contains the
2327root pointer. The second pointer (which must be either a constant or a global
2328value address) contains the meta-data to be associated with the root.</p>
2329
2330<h5>Semantics:</h5>
2331
2332<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
2333location. At compile-time, the code generator generates information to allow
2334the runtime to find the pointer at GC safe points.
2335</p>
2336
2337</div>
2338
2339
2340<!-- _______________________________________________________________________ -->
2341<div class="doc_subsubsection">
2342 <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
2343</div>
2344
2345<div class="doc_text">
2346
2347<h5>Syntax:</h5>
2348
2349<pre>
2350 call sbyte* (sbyte**)* %llvm.gcread(sbyte** %Ptr)
2351</pre>
2352
2353<h5>Overview:</h5>
2354
2355<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
2356locations, allowing garbage collector implementations that require read
2357barriers.</p>
2358
2359<h5>Arguments:</h5>
2360
2361<p>The argument is the address to read from, which should be an address
2362allocated from the garbage collector.</p>
2363
2364<h5>Semantics:</h5>
2365
2366<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
2367instruction, but may be replaced with substantially more complex code by the
2368garbage collector runtime, as needed.</p>
2369
2370</div>
2371
2372
2373<!-- _______________________________________________________________________ -->
2374<div class="doc_subsubsection">
2375 <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
2376</div>
2377
2378<div class="doc_text">
2379
2380<h5>Syntax:</h5>
2381
2382<pre>
2383 call void (sbyte*, sbyte**)* %llvm.gcwrite(sbyte* %P1, sbyte** %P2)
2384</pre>
2385
2386<h5>Overview:</h5>
2387
2388<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
2389locations, allowing garbage collector implementations that require write
2390barriers (such as generational or reference counting collectors).</p>
2391
2392<h5>Arguments:</h5>
2393
2394<p>The first argument is the reference to store, and the second is the heap
2395location to store to.</p>
2396
2397<h5>Semantics:</h5>
2398
2399<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
2400instruction, but may be replaced with substantially more complex code by the
2401garbage collector runtime, as needed.</p>
2402
2403</div>
2404
2405
2406
2407<!-- ======================================================================= -->
2408<div class="doc_subsection">
Chris Lattner10610642004-02-14 04:08:35 +00002409 <a name="int_codegen">Code Generator Intrinsics</a>
2410</div>
2411
2412<div class="doc_text">
2413<p>
2414These intrinsics are provided by LLVM to expose special features that may only
2415be implemented with code generator support.
2416</p>
2417
2418</div>
2419
2420<!-- _______________________________________________________________________ -->
2421<div class="doc_subsubsection">
2422 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
2423</div>
2424
2425<div class="doc_text">
2426
2427<h5>Syntax:</h5>
2428<pre>
2429 call void* ()* %llvm.returnaddress(uint &lt;level&gt;)
2430</pre>
2431
2432<h5>Overview:</h5>
2433
2434<p>
2435The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
2436indicating the return address of the current function or one of its callers.
2437</p>
2438
2439<h5>Arguments:</h5>
2440
2441<p>
2442The argument to this intrinsic indicates which function to return the address
2443for. Zero indicates the calling function, one indicates its caller, etc. The
2444argument is <b>required</b> to be a constant integer value.
2445</p>
2446
2447<h5>Semantics:</h5>
2448
2449<p>
2450The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
2451the return address of the specified call frame, or zero if it cannot be
2452identified. The value returned by this intrinsic is likely to be incorrect or 0
2453for arguments other than zero, so it should only be used for debugging purposes.
2454</p>
2455
2456<p>
2457Note that calling this intrinsic does not prevent function inlining or other
Chris Lattnerb40bb382005-03-07 20:30:51 +00002458aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner10610642004-02-14 04:08:35 +00002459source-language caller.
2460</p>
2461</div>
2462
2463
2464<!-- _______________________________________________________________________ -->
2465<div class="doc_subsubsection">
2466 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
2467</div>
2468
2469<div class="doc_text">
2470
2471<h5>Syntax:</h5>
2472<pre>
2473 call void* ()* %llvm.frameaddress(uint &lt;level&gt;)
2474</pre>
2475
2476<h5>Overview:</h5>
2477
2478<p>
2479The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
2480pointer value for the specified stack frame.
2481</p>
2482
2483<h5>Arguments:</h5>
2484
2485<p>
2486The argument to this intrinsic indicates which function to return the frame
2487pointer for. Zero indicates the calling function, one indicates its caller,
2488etc. The argument is <b>required</b> to be a constant integer value.
2489</p>
2490
2491<h5>Semantics:</h5>
2492
2493<p>
2494The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
2495the frame address of the specified call frame, or zero if it cannot be
2496identified. The value returned by this intrinsic is likely to be incorrect or 0
2497for arguments other than zero, so it should only be used for debugging purposes.
2498</p>
2499
2500<p>
2501Note that calling this intrinsic does not prevent function inlining or other
Chris Lattnerb40bb382005-03-07 20:30:51 +00002502aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner10610642004-02-14 04:08:35 +00002503source-language caller.
2504</p>
2505</div>
2506
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00002507<!-- _______________________________________________________________________ -->
2508<div class="doc_subsubsection">
2509 <a name="i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a>
2510</div>
2511
2512<div class="doc_text">
2513
2514<h5>Syntax:</h5>
2515<pre>
2516 call void (sbyte *, uint, uint)* %llvm.prefetch(sbyte * &lt;address&gt;,
2517 uint &lt;rw&gt;,
2518 uint &lt;locality&gt;)
2519</pre>
2520
2521<h5>Overview:</h5>
2522
2523
2524<p>
2525The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to insert
2526a prefetch instruction if supported, otherwise it is a noop. Prefetches have no
Chris Lattner2a615362005-02-28 19:47:14 +00002527effect on the behavior of the program, but can change its performance
2528characteristics.
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00002529</p>
2530
2531<h5>Arguments:</h5>
2532
2533<p>
2534<tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier
2535determining if the fetch should be for a read (0) or write (1), and
2536<tt>locality</tt> is a temporal locality specifier ranging from (0) - no
Chris Lattneraeffb4a2005-03-07 20:31:38 +00002537locality, to (3) - extremely local keep in cache. The <tt>rw</tt> and
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00002538<tt>locality</tt> arguments must be constant integers.
2539</p>
2540
2541<h5>Semantics:</h5>
2542
2543<p>
2544This intrinsic does not modify the behavior of the program. In particular,
2545prefetches cannot trap and do not produce a value. On targets that support this
2546intrinsic, the prefetch can provide hints to the processor cache for better
2547performance.
2548</p>
2549
2550</div>
2551
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00002552<!-- _______________________________________________________________________ -->
2553<div class="doc_subsubsection">
2554 <a name="i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a>
2555</div>
2556
2557<div class="doc_text">
2558
2559<h5>Syntax:</h5>
2560<pre>
2561 call void (uint)* %llvm.pcmarker( uint &lt;id&gt; )
2562</pre>
2563
2564<h5>Overview:</h5>
2565
2566
2567<p>
2568The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a PC in a region of
2569code to simulators and other tools. The method is target specific, but it is
2570expected that the marker will use exported symbols to transmit the PC of the marker.
2571The marker makes no guaranties that it will remain with any specific instruction
2572after optimizations. It is possible that the presense of a marker will inhibit
2573optimizations. The intended use is to be inserted after optmizations to allow
2574corrolations of simulation runs.
2575</p>
2576
2577<h5>Arguments:</h5>
2578
2579<p>
2580<tt>id</tt> is a numerical id identifying the marker.
2581</p>
2582
2583<h5>Semantics:</h5>
2584
2585<p>
2586This intrinsic does not modify the behavior of the program. Backends that do not
2587support this intrinisic may ignore it.
2588</p>
2589
2590</div>
2591
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00002592
John Criswell7123e272004-04-09 16:43:20 +00002593<!-- ======================================================================= -->
2594<div class="doc_subsection">
2595 <a name="int_os">Operating System Intrinsics</a>
2596</div>
2597
2598<div class="doc_text">
2599<p>
2600These intrinsics are provided by LLVM to support the implementation of
2601operating system level code.
2602</p>
2603
2604</div>
John Criswell183402a2004-04-12 15:02:16 +00002605
John Criswellcfd3bac2004-04-09 15:23:37 +00002606<!-- _______________________________________________________________________ -->
2607<div class="doc_subsubsection">
2608 <a name="i_readport">'<tt>llvm.readport</tt>' Intrinsic</a>
2609</div>
2610
2611<div class="doc_text">
2612
2613<h5>Syntax:</h5>
2614<pre>
John Criswell7123e272004-04-09 16:43:20 +00002615 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 +00002616</pre>
2617
2618<h5>Overview:</h5>
2619
2620<p>
John Criswell7123e272004-04-09 16:43:20 +00002621The '<tt>llvm.readport</tt>' intrinsic reads data from the specified hardware
2622I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002623</p>
2624
2625<h5>Arguments:</h5>
2626
2627<p>
John Criswell7123e272004-04-09 16:43:20 +00002628The argument to this intrinsic indicates the hardware I/O address from which
2629to read the data. The address is in the hardware I/O address namespace (as
2630opposed to being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002631</p>
2632
2633<h5>Semantics:</h5>
2634
2635<p>
John Criswell7123e272004-04-09 16:43:20 +00002636The '<tt>llvm.readport</tt>' intrinsic reads data from the hardware I/O port
2637specified by <i>address</i> and returns the value. The address and return
2638value must be integers, but the size is dependent upon the platform upon which
2639the program is code generated. For example, on x86, the address must be an
2640unsigned 16 bit value, and the return value must be 8, 16, or 32 bits.
John Criswellcfd3bac2004-04-09 15:23:37 +00002641</p>
2642
2643</div>
2644
2645<!-- _______________________________________________________________________ -->
2646<div class="doc_subsubsection">
2647 <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a>
2648</div>
2649
2650<div class="doc_text">
2651
2652<h5>Syntax:</h5>
2653<pre>
Chris Lattnerc3f59762004-12-09 17:30:23 +00002654 call void (&lt;integer type&gt;, &lt;integer type&gt;)*
2655 %llvm.writeport (&lt;integer type&gt; &lt;value&gt;,
2656 &lt;integer type&gt; &lt;address&gt;)
John Criswellcfd3bac2004-04-09 15:23:37 +00002657</pre>
2658
2659<h5>Overview:</h5>
2660
2661<p>
John Criswell7123e272004-04-09 16:43:20 +00002662The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified hardware
2663I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002664</p>
2665
2666<h5>Arguments:</h5>
2667
2668<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002669The first argument is the value to write to the I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002670</p>
2671
2672<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002673The second argument indicates the hardware I/O address to which data should be
2674written. The address is in the hardware I/O address namespace (as opposed to
2675being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002676</p>
2677
2678<h5>Semantics:</h5>
2679
2680<p>
2681The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port
2682specified by <i>address</i>. The address and value must be integers, but the
2683size is dependent upon the platform upon which the program is code generated.
John Criswell7123e272004-04-09 16:43:20 +00002684For example, on x86, the address must be an unsigned 16 bit value, and the
2685value written must be 8, 16, or 32 bits in length.
John Criswellcfd3bac2004-04-09 15:23:37 +00002686</p>
2687
2688</div>
Chris Lattner10610642004-02-14 04:08:35 +00002689
John Criswell183402a2004-04-12 15:02:16 +00002690<!-- _______________________________________________________________________ -->
2691<div class="doc_subsubsection">
2692 <a name="i_readio">'<tt>llvm.readio</tt>' Intrinsic</a>
2693</div>
2694
2695<div class="doc_text">
2696
2697<h5>Syntax:</h5>
2698<pre>
John Criswell96db6fc2004-04-12 16:33:19 +00002699 call &lt;result&gt; (&lt;ty&gt;*)* %llvm.readio (&lt;ty&gt; * &lt;pointer&gt;)
John Criswell183402a2004-04-12 15:02:16 +00002700</pre>
2701
2702<h5>Overview:</h5>
2703
2704<p>
2705The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
2706address.
2707</p>
2708
2709<h5>Arguments:</h5>
2710
2711<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002712The argument to this intrinsic is a pointer indicating the memory address from
2713which to read the data. The data must be a
2714<a href="#t_firstclass">first class</a> type.
John Criswell183402a2004-04-12 15:02:16 +00002715</p>
2716
2717<h5>Semantics:</h5>
2718
2719<p>
2720The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
John Criswell96db6fc2004-04-12 16:33:19 +00002721location specified by <i>pointer</i> and returns the value. The argument must
2722be a pointer, and the return value must be a
2723<a href="#t_firstclass">first class</a> type. However, certain architectures
2724may not support I/O on all first class types. For example, 32 bit processors
2725may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00002726</p>
2727
2728<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002729This intrinsic enforces an in-order memory model for llvm.readio and
2730llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2731scheduled processors may execute loads and stores out of order, re-ordering at
2732run time accesses to memory mapped I/O registers. Using these intrinsics
2733ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00002734</p>
2735
2736</div>
2737
2738<!-- _______________________________________________________________________ -->
2739<div class="doc_subsubsection">
2740 <a name="i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a>
2741</div>
2742
2743<div class="doc_text">
2744
2745<h5>Syntax:</h5>
2746<pre>
John Criswell96db6fc2004-04-12 16:33:19 +00002747 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 +00002748</pre>
2749
2750<h5>Overview:</h5>
2751
2752<p>
2753The '<tt>llvm.writeio</tt>' intrinsic writes data to the specified memory
2754mapped I/O address.
2755</p>
2756
2757<h5>Arguments:</h5>
2758
2759<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002760The first argument is the value to write to the memory mapped I/O location.
2761The second argument is a pointer indicating the memory address to which the
2762data should be written.
John Criswell183402a2004-04-12 15:02:16 +00002763</p>
2764
2765<h5>Semantics:</h5>
2766
2767<p>
2768The '<tt>llvm.writeio</tt>' intrinsic writes <i>value</i> to the memory mapped
John Criswell96db6fc2004-04-12 16:33:19 +00002769I/O address specified by <i>pointer</i>. The value must be a
2770<a href="#t_firstclass">first class</a> type. However, certain architectures
2771may not support I/O on all first class types. For example, 32 bit processors
2772may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00002773</p>
2774
2775<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002776This intrinsic enforces an in-order memory model for llvm.readio and
2777llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2778scheduled processors may execute loads and stores out of order, re-ordering at
2779run time accesses to memory mapped I/O registers. Using these intrinsics
2780ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00002781</p>
2782
2783</div>
2784
Chris Lattner10610642004-02-14 04:08:35 +00002785<!-- ======================================================================= -->
2786<div class="doc_subsection">
Chris Lattner33aec9e2004-02-12 17:01:32 +00002787 <a name="int_libc">Standard C Library Intrinsics</a>
2788</div>
2789
2790<div class="doc_text">
2791<p>
Chris Lattner10610642004-02-14 04:08:35 +00002792LLVM provides intrinsics for a few important standard C library functions.
2793These intrinsics allow source-language front-ends to pass information about the
2794alignment of the pointer arguments to the code generator, providing opportunity
2795for more efficient code generation.
Chris Lattner33aec9e2004-02-12 17:01:32 +00002796</p>
2797
2798</div>
2799
2800<!-- _______________________________________________________________________ -->
2801<div class="doc_subsubsection">
2802 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
2803</div>
2804
2805<div class="doc_text">
2806
2807<h5>Syntax:</h5>
2808<pre>
2809 call void (sbyte*, sbyte*, uint, uint)* %llvm.memcpy(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2810 uint &lt;len&gt;, uint &lt;align&gt;)
2811</pre>
2812
2813<h5>Overview:</h5>
2814
2815<p>
2816The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2817location to the destination location.
2818</p>
2819
2820<p>
2821Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
2822does not return a value, and takes an extra alignment argument.
2823</p>
2824
2825<h5>Arguments:</h5>
2826
2827<p>
2828The first argument is a pointer to the destination, the second is a pointer to
2829the source. The third argument is an (arbitrarily sized) integer argument
2830specifying the number of bytes to copy, and the fourth argument is the alignment
2831of the source and destination locations.
2832</p>
2833
Chris Lattner3301ced2004-02-12 21:18:15 +00002834<p>
2835If the call to this intrinisic has an alignment value that is not 0 or 1, then
2836the caller guarantees that the size of the copy is a multiple of the alignment
2837and that both the source and destination pointers are aligned to that boundary.
2838</p>
2839
Chris Lattner33aec9e2004-02-12 17:01:32 +00002840<h5>Semantics:</h5>
2841
2842<p>
2843The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2844location to the destination location, which are not allowed to overlap. It
2845copies "len" bytes of memory over. If the argument is known to be aligned to
2846some boundary, this can be specified as the fourth argument, otherwise it should
2847be set to 0 or 1.
2848</p>
2849</div>
2850
2851
Chris Lattner0eb51b42004-02-12 18:10:10 +00002852<!-- _______________________________________________________________________ -->
2853<div class="doc_subsubsection">
2854 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
2855</div>
2856
2857<div class="doc_text">
2858
2859<h5>Syntax:</h5>
2860<pre>
2861 call void (sbyte*, sbyte*, uint, uint)* %llvm.memmove(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2862 uint &lt;len&gt;, uint &lt;align&gt;)
2863</pre>
2864
2865<h5>Overview:</h5>
2866
2867<p>
2868The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
2869location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>'
2870intrinsic but allows the two memory locations to overlap.
2871</p>
2872
2873<p>
2874Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
2875does not return a value, and takes an extra alignment argument.
2876</p>
2877
2878<h5>Arguments:</h5>
2879
2880<p>
2881The first argument is a pointer to the destination, the second is a pointer to
2882the source. The third argument is an (arbitrarily sized) integer argument
2883specifying the number of bytes to copy, and the fourth argument is the alignment
2884of the source and destination locations.
2885</p>
2886
Chris Lattner3301ced2004-02-12 21:18:15 +00002887<p>
2888If the call to this intrinisic has an alignment value that is not 0 or 1, then
2889the caller guarantees that the size of the copy is a multiple of the alignment
2890and that both the source and destination pointers are aligned to that boundary.
2891</p>
2892
Chris Lattner0eb51b42004-02-12 18:10:10 +00002893<h5>Semantics:</h5>
2894
2895<p>
2896The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
2897location to the destination location, which may overlap. It
2898copies "len" bytes of memory over. If the argument is known to be aligned to
2899some boundary, this can be specified as the fourth argument, otherwise it should
2900be set to 0 or 1.
2901</p>
2902</div>
2903
Chris Lattner8ff75902004-01-06 05:31:32 +00002904
Chris Lattner10610642004-02-14 04:08:35 +00002905<!-- _______________________________________________________________________ -->
2906<div class="doc_subsubsection">
2907 <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a>
2908</div>
2909
2910<div class="doc_text">
2911
2912<h5>Syntax:</h5>
2913<pre>
2914 call void (sbyte*, ubyte, uint, uint)* %llvm.memset(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
2915 uint &lt;len&gt;, uint &lt;align&gt;)
2916</pre>
2917
2918<h5>Overview:</h5>
2919
2920<p>
2921The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular
2922byte value.
2923</p>
2924
2925<p>
2926Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
2927does not return a value, and takes an extra alignment argument.
2928</p>
2929
2930<h5>Arguments:</h5>
2931
2932<p>
2933The first argument is a pointer to the destination to fill, the second is the
2934byte value to fill it with, the third argument is an (arbitrarily sized) integer
2935argument specifying the number of bytes to fill, and the fourth argument is the
2936known alignment of destination location.
2937</p>
2938
2939<p>
2940If the call to this intrinisic has an alignment value that is not 0 or 1, then
2941the caller guarantees that the size of the copy is a multiple of the alignment
2942and that the destination pointer is aligned to that boundary.
2943</p>
2944
2945<h5>Semantics:</h5>
2946
2947<p>
2948The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the
2949destination location. If the argument is known to be aligned to some boundary,
2950this can be specified as the fourth argument, otherwise it should be set to 0 or
29511.
2952</p>
2953</div>
2954
2955
Chris Lattner32006282004-06-11 02:28:03 +00002956<!-- _______________________________________________________________________ -->
2957<div class="doc_subsubsection">
Alkis Evlogimenos26bbe932004-06-13 01:16:15 +00002958 <a name="i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a>
2959</div>
2960
2961<div class="doc_text">
2962
2963<h5>Syntax:</h5>
2964<pre>
2965 call bool (&lt;float or double&gt;, &lt;float or double&gt;)* %llvm.isunordered(&lt;float or double&gt; Val1,
2966 &lt;float or double&gt; Val2)
2967</pre>
2968
2969<h5>Overview:</h5>
2970
2971<p>
2972The '<tt>llvm.isunordered</tt>' intrinsic returns true if either or both of the
2973specified floating point values is a NAN.
2974</p>
2975
2976<h5>Arguments:</h5>
2977
2978<p>
2979The arguments are floating point numbers of the same type.
2980</p>
2981
2982<h5>Semantics:</h5>
2983
2984<p>
2985If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise
2986false.
2987</p>
2988</div>
2989
2990
Chris Lattner32006282004-06-11 02:28:03 +00002991
2992
Chris Lattner8ff75902004-01-06 05:31:32 +00002993<!-- ======================================================================= -->
2994<div class="doc_subsection">
2995 <a name="int_debugger">Debugger Intrinsics</a>
2996</div>
2997
2998<div class="doc_text">
2999<p>
3000The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
3001are described in the <a
3002href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
3003Debugging</a> document.
3004</p>
3005</div>
3006
3007
Chris Lattner00950542001-06-06 20:29:01 +00003008<!-- *********************************************************************** -->
Chris Lattner00950542001-06-06 20:29:01 +00003009<hr>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00003010<address>
3011 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
3012 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
3013 <a href="http://validator.w3.org/check/referer"><img
3014 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
3015
3016 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
3017 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
3018 Last modified: $Date$
3019</address>
Misha Brukman9d0919f2003-11-08 01:05:38 +00003020</body>
3021</html>