blob: dd02a9e4a297956f6327a4a9f76e4e26bf6fba3c [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 Lattnerbad10ee2005-05-06 22:57:40 +000024 <li><a href="#callingconv">Calling Conventions</a></li>
Chris Lattnerfa730212004-12-09 16:11:40 +000025 <li><a href="#globalvars">Global Variables</a></li>
26 <li><a href="#functionstructure">Function Structure</a></li>
27 </ol>
28 </li>
Chris Lattner00950542001-06-06 20:29:01 +000029 <li><a href="#typesystem">Type System</a>
30 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000031 <li><a href="#t_primitive">Primitive Types</a>
32 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000033 <li><a href="#t_classifications">Type Classifications</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000034 </ol>
35 </li>
Chris Lattner00950542001-06-06 20:29:01 +000036 <li><a href="#t_derived">Derived Types</a>
37 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000038 <li><a href="#t_array">Array Type</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000039 <li><a href="#t_function">Function Type</a></li>
40 <li><a href="#t_pointer">Pointer Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000041 <li><a href="#t_struct">Structure Type</a></li>
Chris Lattnera58561b2004-08-12 19:12:28 +000042 <li><a href="#t_packed">Packed Type</a></li>
Chris Lattner69c11bb2005-04-25 17:34:15 +000043 <li><a href="#t_opaque">Opaque Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000044 </ol>
45 </li>
46 </ol>
47 </li>
Chris Lattnerfa730212004-12-09 16:11:40 +000048 <li><a href="#constants">Constants</a>
Chris Lattnerc3f59762004-12-09 17:30:23 +000049 <ol>
50 <li><a href="#simpleconstants">Simple Constants</a>
51 <li><a href="#aggregateconstants">Aggregate Constants</a>
52 <li><a href="#globalconstants">Global Variable and Function Addresses</a>
53 <li><a href="#undefvalues">Undefined Values</a>
54 <li><a href="#constantexprs">Constant Expressions</a>
55 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +000056 </li>
Chris Lattner00950542001-06-06 20:29:01 +000057 <li><a href="#instref">Instruction Reference</a>
58 <ol>
59 <li><a href="#terminators">Terminator Instructions</a>
60 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000061 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
62 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000063 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
64 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000065 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
Chris Lattner35eca582004-10-16 18:04:13 +000066 <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000067 </ol>
68 </li>
Chris Lattner00950542001-06-06 20:29:01 +000069 <li><a href="#binaryops">Binary Operations</a>
70 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000071 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
72 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
73 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
74 <li><a href="#i_div">'<tt>div</tt>' Instruction</a></li>
75 <li><a href="#i_rem">'<tt>rem</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000076 <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000077 </ol>
78 </li>
Chris Lattner00950542001-06-06 20:29:01 +000079 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
80 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000081 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000082 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000083 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
84 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
85 <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000086 </ol>
87 </li>
Chris Lattner00950542001-06-06 20:29:01 +000088 <li><a href="#memoryops">Memory Access Operations</a>
89 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000090 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
91 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
92 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
93 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
94 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
95 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
96 </ol>
97 </li>
Chris Lattner00950542001-06-06 20:29:01 +000098 <li><a href="#otherops">Other Operations</a>
99 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000100 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000101 <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li>
Chris Lattnercc37aae2004-03-12 05:50:16 +0000102 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000103 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000104 <li><a href="#i_vaarg">'<tt>vaarg</tt>' Instruction</a></li>
Chris Lattner00950542001-06-06 20:29:01 +0000105 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000106 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000107 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000108 </li>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +0000109 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +0000110 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000111 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
112 <ol>
113 <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
114 <li><a href="#i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
115 <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
116 </ol>
117 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000118 <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
119 <ol>
120 <li><a href="#i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li>
121 <li><a href="#i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li>
122 <li><a href="#i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li>
123 </ol>
124 </li>
Chris Lattner10610642004-02-14 04:08:35 +0000125 <li><a href="#int_codegen">Code Generator Intrinsics</a>
126 <ol>
127 <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
128 <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
Chris Lattner9a9d7ac2005-02-28 19:24:19 +0000129 <li><a href="#i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a></li>
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +0000130 <li><a href="#i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a></li>
Andrew Lenharth51b8d542005-11-11 16:47:30 +0000131 <li><a href="#i_readcyclecounter"><tt>llvm.readcyclecounter</tt>' Intrinsic</a></li>
John Criswell7123e272004-04-09 16:43:20 +0000132 </ol>
133 </li>
134 <li><a href="#int_os">Operating System Intrinsics</a>
135 <ol>
Chris Lattner32006282004-06-11 02:28:03 +0000136 <li><a href="#i_readport">'<tt>llvm.readport</tt>' Intrinsic</a></li>
137 <li><a href="#i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a></li>
John Criswell183402a2004-04-12 15:02:16 +0000138 <li><a href="#i_readio">'<tt>llvm.readio</tt>' Intrinsic</a></li>
139 <li><a href="#i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000140 </ol>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000141 <li><a href="#int_libc">Standard C Library Intrinsics</a>
142 <ol>
143 <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li>
Chris Lattner0eb51b42004-02-12 18:10:10 +0000144 <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000145 <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li>
Alkis Evlogimenos96853722004-06-12 19:19:14 +0000146 <li><a href="#i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a></li>
Chris Lattnera4d74142005-07-21 01:29:16 +0000147 <li><a href="#i_sqrt">'<tt>llvm.sqrt</tt>' Intrinsic</a></li>
148
Chris Lattner33aec9e2004-02-12 17:01:32 +0000149 </ol>
150 </li>
Andrew Lenharthec370fd2005-05-03 18:01:48 +0000151 <li><a href="#int_count">Bit counting Intrinsics</a>
152 <ol>
153 <li><a href="#int_ctpop">'<tt>llvm.ctpop</tt>' Intrinsic </a></li>
Andrew Lenharthec370fd2005-05-03 18:01:48 +0000154 <li><a href="#int_ctlz">'<tt>llvm.ctlz</tt>' Intrinsic </a></li>
Chris Lattnereff29ab2005-05-15 19:39:26 +0000155 <li><a href="#int_cttz">'<tt>llvm.cttz</tt>' Intrinsic </a></li>
Andrew Lenharthec370fd2005-05-03 18:01:48 +0000156 </ol>
157 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000158 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000159 </ol>
160 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000161</ol>
Chris Lattnerd7923912004-05-23 21:06:01 +0000162
163<div class="doc_author">
164 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
165 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000166</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000167
Chris Lattner00950542001-06-06 20:29:01 +0000168<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000169<div class="doc_section"> <a name="abstract">Abstract </a></div>
170<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000171
Misha Brukman9d0919f2003-11-08 01:05:38 +0000172<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000173<p>This document is a reference manual for the LLVM assembly language.
174LLVM is an SSA based representation that provides type safety,
175low-level operations, flexibility, and the capability of representing
176'all' high-level languages cleanly. It is the common code
177representation used throughout all phases of the LLVM compilation
178strategy.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000179</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000180
Chris Lattner00950542001-06-06 20:29:01 +0000181<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000182<div class="doc_section"> <a name="introduction">Introduction</a> </div>
183<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000184
Misha Brukman9d0919f2003-11-08 01:05:38 +0000185<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000186
Chris Lattner261efe92003-11-25 01:02:51 +0000187<p>The LLVM code representation is designed to be used in three
188different forms: as an in-memory compiler IR, as an on-disk bytecode
189representation (suitable for fast loading by a Just-In-Time compiler),
190and as a human readable assembly language representation. This allows
191LLVM to provide a powerful intermediate representation for efficient
192compiler transformations and analysis, while providing a natural means
193to debug and visualize the transformations. The three different forms
194of LLVM are all equivalent. This document describes the human readable
195representation and notation.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000196
John Criswellc1f786c2005-05-13 22:25:59 +0000197<p>The LLVM representation aims to be light-weight and low-level
Chris Lattner261efe92003-11-25 01:02:51 +0000198while being expressive, typed, and extensible at the same time. It
199aims to be a "universal IR" of sorts, by being at a low enough level
200that high-level ideas may be cleanly mapped to it (similar to how
201microprocessors are "universal IR's", allowing many source languages to
202be mapped to them). By providing type information, LLVM can be used as
203the target of optimizations: for example, through pointer analysis, it
204can be proven that a C automatic variable is never accessed outside of
205the current function... allowing it to be promoted to a simple SSA
206value instead of a memory location.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000207
Misha Brukman9d0919f2003-11-08 01:05:38 +0000208</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000209
Chris Lattner00950542001-06-06 20:29:01 +0000210<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000211<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000212
Misha Brukman9d0919f2003-11-08 01:05:38 +0000213<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000214
Chris Lattner261efe92003-11-25 01:02:51 +0000215<p>It is important to note that this document describes 'well formed'
216LLVM assembly language. There is a difference between what the parser
217accepts and what is considered 'well formed'. For example, the
218following instruction is syntactically okay, but not well formed:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000219
220<pre>
221 %x = <a href="#i_add">add</a> int 1, %x
222</pre>
223
Chris Lattner261efe92003-11-25 01:02:51 +0000224<p>...because the definition of <tt>%x</tt> does not dominate all of
225its uses. The LLVM infrastructure provides a verification pass that may
226be used to verify that an LLVM module is well formed. This pass is
John Criswellc1f786c2005-05-13 22:25:59 +0000227automatically run by the parser after parsing input assembly and by
Chris Lattner261efe92003-11-25 01:02:51 +0000228the optimizer before it outputs bytecode. The violations pointed out
229by the verifier pass indicate bugs in transformation passes or input to
230the parser.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000231
Chris Lattner261efe92003-11-25 01:02:51 +0000232<!-- Describe the typesetting conventions here. --> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000233
Chris Lattner00950542001-06-06 20:29:01 +0000234<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000235<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000236<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000237
Misha Brukman9d0919f2003-11-08 01:05:38 +0000238<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000239
Chris Lattner261efe92003-11-25 01:02:51 +0000240<p>LLVM uses three different forms of identifiers, for different
241purposes:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000242
Chris Lattner00950542001-06-06 20:29:01 +0000243<ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000244 <li>Named values are represented as a string of characters with a '%' prefix.
245 For example, %foo, %DivisionByZero, %a.really.long.identifier. The actual
246 regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
247 Identifiers which require other characters in their names can be surrounded
248 with quotes. In this way, anything except a <tt>"</tt> character can be used
249 in a name.</li>
250
251 <li>Unnamed values are represented as an unsigned numeric value with a '%'
252 prefix. For example, %12, %2, %44.</li>
253
Reid Spencercc16dc32004-12-09 18:02:53 +0000254 <li>Constants, which are described in a <a href="#constants">section about
255 constants</a>, below.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000256</ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000257
258<p>LLVM requires that values start with a '%' sign for two reasons: Compilers
259don't need to worry about name clashes with reserved words, and the set of
260reserved words may be expanded in the future without penalty. Additionally,
261unnamed identifiers allow a compiler to quickly come up with a temporary
262variable without having to avoid symbol table conflicts.</p>
263
Chris Lattner261efe92003-11-25 01:02:51 +0000264<p>Reserved words in LLVM are very similar to reserved words in other
265languages. There are keywords for different opcodes ('<tt><a
Chris Lattnere5d947b2004-12-09 16:36:40 +0000266href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
267href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
268href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>', etc...),
269and others. These reserved words cannot conflict with variable names, because
270none of them start with a '%' character.</p>
271
272<p>Here is an example of LLVM code to multiply the integer variable
273'<tt>%X</tt>' by 8:</p>
274
Misha Brukman9d0919f2003-11-08 01:05:38 +0000275<p>The easy way:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000276
277<pre>
278 %result = <a href="#i_mul">mul</a> uint %X, 8
279</pre>
280
Misha Brukman9d0919f2003-11-08 01:05:38 +0000281<p>After strength reduction:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000282
283<pre>
284 %result = <a href="#i_shl">shl</a> uint %X, ubyte 3
285</pre>
286
Misha Brukman9d0919f2003-11-08 01:05:38 +0000287<p>And the hard way:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000288
289<pre>
290 <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
291 <a href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
292 %result = <a href="#i_add">add</a> uint %1, %1
293</pre>
294
Chris Lattner261efe92003-11-25 01:02:51 +0000295<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
296important lexical features of LLVM:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000297
Chris Lattner00950542001-06-06 20:29:01 +0000298<ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000299
300 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
301 line.</li>
302
303 <li>Unnamed temporaries are created when the result of a computation is not
304 assigned to a named value.</li>
305
Misha Brukman9d0919f2003-11-08 01:05:38 +0000306 <li>Unnamed temporaries are numbered sequentially</li>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000307
Misha Brukman9d0919f2003-11-08 01:05:38 +0000308</ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000309
John Criswelle4c57cc2005-05-12 16:52:32 +0000310<p>...and it also shows a convention that we follow in this document. When
Chris Lattnere5d947b2004-12-09 16:36:40 +0000311demonstrating instructions, we will follow an instruction with a comment that
312defines the type and name of value produced. Comments are shown in italic
313text.</p>
314
Misha Brukman9d0919f2003-11-08 01:05:38 +0000315</div>
Chris Lattnerfa730212004-12-09 16:11:40 +0000316
317<!-- *********************************************************************** -->
318<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
319<!-- *********************************************************************** -->
320
321<!-- ======================================================================= -->
322<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
323</div>
324
325<div class="doc_text">
326
327<p>LLVM programs are composed of "Module"s, each of which is a
328translation unit of the input programs. Each module consists of
329functions, global variables, and symbol table entries. Modules may be
330combined together with the LLVM linker, which merges function (and
331global variable) definitions, resolves forward declarations, and merges
332symbol table entries. Here is an example of the "hello world" module:</p>
333
334<pre><i>; Declare the string constant as a global constant...</i>
335<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
336 href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00" <i>; [13 x sbyte]*</i>
337
338<i>; External declaration of the puts function</i>
339<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
340
341<i>; Definition of main function</i>
342int %main() { <i>; int()* </i>
343 <i>; Convert [13x sbyte]* to sbyte *...</i>
344 %cast210 = <a
345 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
346
347 <i>; Call puts function to write out the string to stdout...</i>
348 <a
349 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
350 <a
351 href="#i_ret">ret</a> int 0<br>}<br></pre>
352
353<p>This example is made up of a <a href="#globalvars">global variable</a>
354named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
355function, and a <a href="#functionstructure">function definition</a>
356for "<tt>main</tt>".</p>
357
Chris Lattnere5d947b2004-12-09 16:36:40 +0000358<p>In general, a module is made up of a list of global values,
359where both functions and global variables are global values. Global values are
360represented by a pointer to a memory location (in this case, a pointer to an
361array of char, and a pointer to a function), and have one of the following <a
362href="#linkage">linkage types</a>.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000363
Chris Lattnere5d947b2004-12-09 16:36:40 +0000364</div>
365
366<!-- ======================================================================= -->
367<div class="doc_subsection">
368 <a name="linkage">Linkage Types</a>
369</div>
370
371<div class="doc_text">
372
373<p>
374All Global Variables and Functions have one of the following types of linkage:
375</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000376
377<dl>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000378
Chris Lattnerfa730212004-12-09 16:11:40 +0000379 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000380
381 <dd>Global values with internal linkage are only directly accessible by
382 objects in the current module. In particular, linking code into a module with
383 an internal global value may cause the internal to be renamed as necessary to
384 avoid collisions. Because the symbol is internal to the module, all
385 references can be updated. This corresponds to the notion of the
386 '<tt>static</tt>' keyword in C, or the idea of "anonymous namespaces" in C++.
Chris Lattnerfa730212004-12-09 16:11:40 +0000387 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000388
Chris Lattnerfa730212004-12-09 16:11:40 +0000389 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000390
391 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt> linkage, with
392 the twist that linking together two modules defining the same
393 <tt>linkonce</tt> globals will cause one of the globals to be discarded. This
394 is typically used to implement inline functions. Unreferenced
395 <tt>linkonce</tt> globals are allowed to be discarded.
Chris Lattnerfa730212004-12-09 16:11:40 +0000396 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000397
Chris Lattnerfa730212004-12-09 16:11:40 +0000398 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000399
400 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage,
401 except that unreferenced <tt>weak</tt> globals may not be discarded. This is
402 used to implement constructs in C such as "<tt>int X;</tt>" at global scope.
Chris Lattnerfa730212004-12-09 16:11:40 +0000403 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000404
Chris Lattnerfa730212004-12-09 16:11:40 +0000405 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000406
407 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
408 pointer to array type. When two global variables with appending linkage are
409 linked together, the two global arrays are appended together. This is the
410 LLVM, typesafe, equivalent of having the system linker append together
411 "sections" with identical names when .o files are linked.
Chris Lattnerfa730212004-12-09 16:11:40 +0000412 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000413
Chris Lattnerfa730212004-12-09 16:11:40 +0000414 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000415
416 <dd>If none of the above identifiers are used, the global is externally
417 visible, meaning that it participates in linkage and can be used to resolve
418 external symbol references.
Chris Lattnerfa730212004-12-09 16:11:40 +0000419 </dd>
420</dl>
421
Chris Lattnerfa730212004-12-09 16:11:40 +0000422<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
423variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
424variable and was linked with this one, one of the two would be renamed,
425preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
426external (i.e., lacking any linkage declarations), they are accessible
427outside of the current module. It is illegal for a function <i>declaration</i>
428to have any linkage type other than "externally visible".</a></p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000429
Chris Lattnerfa730212004-12-09 16:11:40 +0000430</div>
431
432<!-- ======================================================================= -->
433<div class="doc_subsection">
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000434 <a name="callingconv">Calling Conventions</a>
435</div>
436
437<div class="doc_text">
438
439<p>LLVM <a href="#functionstructure">functions</a>, <a href="#i_call">calls</a>
440and <a href="#i_invoke">invokes</a> can all have an optional calling convention
441specified for the call. The calling convention of any pair of dynamic
442caller/callee must match, or the behavior of the program is undefined. The
443following calling conventions are supported by LLVM, and more may be added in
444the future:</p>
445
446<dl>
447 <dt><b>"<tt>ccc</tt>" - The C calling convention</b>:</dt>
448
449 <dd>This calling convention (the default if no other calling convention is
450 specified) matches the target C calling conventions. This calling convention
John Criswelle4c57cc2005-05-12 16:52:32 +0000451 supports varargs function calls and tolerates some mismatch in the declared
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000452 prototype and implemented declaration of the function (as does normal C).
453 </dd>
454
455 <dt><b>"<tt>fastcc</tt>" - The fast calling convention</b>:</dt>
456
457 <dd>This calling convention attempts to make calls as fast as possible
458 (e.g. by passing things in registers). This calling convention allows the
459 target to use whatever tricks it wants to produce fast code for the target,
Chris Lattner8cdc5bc2005-05-06 23:08:23 +0000460 without having to conform to an externally specified ABI. Implementations of
461 this convention should allow arbitrary tail call optimization to be supported.
462 This calling convention does not support varargs and requires the prototype of
463 all callees to exactly match the prototype of the function definition.
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000464 </dd>
465
466 <dt><b>"<tt>coldcc</tt>" - The cold calling convention</b>:</dt>
467
468 <dd>This calling convention attempts to make code in the caller as efficient
469 as possible under the assumption that the call is not commonly executed. As
470 such, these calls often preserve all registers so that the call does not break
471 any live ranges in the caller side. This calling convention does not support
472 varargs and requires the prototype of all callees to exactly match the
473 prototype of the function definition.
474 </dd>
475
Chris Lattnercfe6b372005-05-07 01:46:40 +0000476 <dt><b>"<tt>cc &lt;<em>n</em>&gt;</tt>" - Numbered convention</b>:</dt>
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000477
478 <dd>Any calling convention may be specified by number, allowing
479 target-specific calling conventions to be used. Target specific calling
480 conventions start at 64.
481 </dd>
Chris Lattnercfe6b372005-05-07 01:46:40 +0000482</dl>
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000483
484<p>More calling conventions can be added/defined on an as-needed basis, to
485support pascal conventions or any other well-known target-independent
486convention.</p>
487
488</div>
489
490<!-- ======================================================================= -->
491<div class="doc_subsection">
Chris Lattnerfa730212004-12-09 16:11:40 +0000492 <a name="globalvars">Global Variables</a>
493</div>
494
495<div class="doc_text">
496
Chris Lattner3689a342005-02-12 19:30:21 +0000497<p>Global variables define regions of memory allocated at compilation time
Chris Lattner2cbdc452005-11-06 08:02:57 +0000498instead of run-time. Global variables may optionally be initialized, and may
499have an optional explicit alignment specified. A
John Criswell0ec250c2005-10-24 16:17:18 +0000500variable may be defined as a global "constant," which indicates that the
Chris Lattner3689a342005-02-12 19:30:21 +0000501contents of the variable will <b>never</b> be modified (enabling better
502optimization, allowing the global data to be placed in the read-only section of
503an executable, etc). Note that variables that need runtime initialization
John Criswell0ec250c2005-10-24 16:17:18 +0000504cannot be marked "constant" as there is a store to the variable.</p>
Chris Lattner3689a342005-02-12 19:30:21 +0000505
506<p>
507LLVM explicitly allows <em>declarations</em> of global variables to be marked
508constant, even if the final definition of the global is not. This capability
509can be used to enable slightly better optimization of the program, but requires
510the language definition to guarantee that optimizations based on the
511'constantness' are valid for the translation units that do not include the
512definition.
513</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000514
515<p>As SSA values, global variables define pointer values that are in
516scope (i.e. they dominate) all basic blocks in the program. Global
517variables always define a pointer to their "content" type because they
518describe a region of memory, and all memory objects in LLVM are
519accessed through pointers.</p>
520
Chris Lattner2cbdc452005-11-06 08:02:57 +0000521<p>An explicit alignment may be specified for a global. If not present, or if
522the alignment is set to zero, the alignment of the global is set by the target
523to whatever it feels convenient. If an explicit alignment is specified, the
524global is forced to have at least that much alignment. All alignments must be
525a power of 2.</p>
526
Chris Lattnerfa730212004-12-09 16:11:40 +0000527</div>
528
529
530<!-- ======================================================================= -->
531<div class="doc_subsection">
532 <a name="functionstructure">Functions</a>
533</div>
534
535<div class="doc_text">
536
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000537<p>LLVM function definitions consist of an optional <a href="#linkage">linkage
538type</a>, an optional <a href="#callingconv">calling convention</a>, a return
Chris Lattner2cbdc452005-11-06 08:02:57 +0000539type, a function name, a (possibly empty) argument list, an optional alignment,
540an opening curly brace,
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000541a list of basic blocks, and a closing curly brace. LLVM function declarations
542are defined with the "<tt>declare</tt>" keyword, an optional <a
Chris Lattner2cbdc452005-11-06 08:02:57 +0000543href="#callingconv">calling convention</a>, a return type, a function name,
544a possibly empty list of arguments, and an optional alignment.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000545
546<p>A function definition contains a list of basic blocks, forming the CFG for
547the function. Each basic block may optionally start with a label (giving the
548basic block a symbol table entry), contains a list of instructions, and ends
549with a <a href="#terminators">terminator</a> instruction (such as a branch or
550function return).</p>
551
John Criswelle4c57cc2005-05-12 16:52:32 +0000552<p>The first basic block in a program is special in two ways: it is immediately
Chris Lattnerfa730212004-12-09 16:11:40 +0000553executed on entrance to the function, and it is not allowed to have predecessor
554basic blocks (i.e. there can not be any branches to the entry block of a
555function). Because the block can have no predecessors, it also cannot have any
556<a href="#i_phi">PHI nodes</a>.</p>
557
558<p>LLVM functions are identified by their name and type signature. Hence, two
559functions with the same name but different parameter lists or return values are
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000560considered different functions, and LLVM will resolve references to each
Chris Lattnerfa730212004-12-09 16:11:40 +0000561appropriately.</p>
562
Chris Lattner2cbdc452005-11-06 08:02:57 +0000563<p>An explicit alignment may be specified for a function. If not present, or if
564the alignment is set to zero, the alignment of the function is set by the target
565to whatever it feels convenient. If an explicit alignment is specified, the
566function is forced to have at least that much alignment. All alignments must be
567a power of 2.</p>
568
Chris Lattnerfa730212004-12-09 16:11:40 +0000569</div>
570
571
572
Chris Lattner00950542001-06-06 20:29:01 +0000573<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000574<div class="doc_section"> <a name="typesystem">Type System</a> </div>
575<!-- *********************************************************************** -->
Chris Lattnerfa730212004-12-09 16:11:40 +0000576
Misha Brukman9d0919f2003-11-08 01:05:38 +0000577<div class="doc_text">
Chris Lattnerfa730212004-12-09 16:11:40 +0000578
Misha Brukman9d0919f2003-11-08 01:05:38 +0000579<p>The LLVM type system is one of the most important features of the
Chris Lattner261efe92003-11-25 01:02:51 +0000580intermediate representation. Being typed enables a number of
581optimizations to be performed on the IR directly, without having to do
582extra analyses on the side before the transformation. A strong type
583system makes it easier to read the generated code and enables novel
584analyses and transformations that are not feasible to perform on normal
585three address code representations.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000586
587</div>
588
Chris Lattner00950542001-06-06 20:29:01 +0000589<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000590<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000591<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +0000592<p>The primitive types are the fundamental building blocks of the LLVM
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000593system. The current set of primitive types is as follows:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000594
Reid Spencerd3f876c2004-11-01 08:19:36 +0000595<table class="layout">
596 <tr class="layout">
597 <td class="left">
598 <table>
Chris Lattner261efe92003-11-25 01:02:51 +0000599 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000600 <tr><th>Type</th><th>Description</th></tr>
601 <tr><td><tt>void</tt></td><td>No value</td></tr>
Misha Brukmancfa87bc2005-04-22 18:02:52 +0000602 <tr><td><tt>ubyte</tt></td><td>Unsigned 8-bit value</td></tr>
603 <tr><td><tt>ushort</tt></td><td>Unsigned 16-bit value</td></tr>
604 <tr><td><tt>uint</tt></td><td>Unsigned 32-bit value</td></tr>
605 <tr><td><tt>ulong</tt></td><td>Unsigned 64-bit value</td></tr>
606 <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000607 <tr><td><tt>label</tt></td><td>Branch destination</td></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000608 </tbody>
609 </table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000610 </td>
611 <td class="right">
612 <table>
Chris Lattner261efe92003-11-25 01:02:51 +0000613 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000614 <tr><th>Type</th><th>Description</th></tr>
615 <tr><td><tt>bool</tt></td><td>True or False value</td></tr>
Misha Brukmancfa87bc2005-04-22 18:02:52 +0000616 <tr><td><tt>sbyte</tt></td><td>Signed 8-bit value</td></tr>
617 <tr><td><tt>short</tt></td><td>Signed 16-bit value</td></tr>
618 <tr><td><tt>int</tt></td><td>Signed 32-bit value</td></tr>
619 <tr><td><tt>long</tt></td><td>Signed 64-bit value</td></tr>
620 <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000621 </tbody>
622 </table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000623 </td>
624 </tr>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000625</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000626</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000627
Chris Lattner00950542001-06-06 20:29:01 +0000628<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000629<div class="doc_subsubsection"> <a name="t_classifications">Type
630Classifications</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000631<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000632<p>These different primitive types fall into a few useful
633classifications:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000634
635<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +0000636 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000637 <tr><th>Classification</th><th>Types</th></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000638 <tr>
639 <td><a name="t_signed">signed</a></td>
640 <td><tt>sbyte, short, int, long, float, double</tt></td>
641 </tr>
642 <tr>
643 <td><a name="t_unsigned">unsigned</a></td>
644 <td><tt>ubyte, ushort, uint, ulong</tt></td>
645 </tr>
646 <tr>
647 <td><a name="t_integer">integer</a></td>
648 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
649 </tr>
650 <tr>
651 <td><a name="t_integral">integral</a></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000652 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt>
653 </td>
Chris Lattner261efe92003-11-25 01:02:51 +0000654 </tr>
655 <tr>
656 <td><a name="t_floating">floating point</a></td>
657 <td><tt>float, double</tt></td>
658 </tr>
659 <tr>
660 <td><a name="t_firstclass">first class</a></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000661 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long,<br>
662 float, double, <a href="#t_pointer">pointer</a>,
663 <a href="#t_packed">packed</a></tt></td>
Chris Lattner261efe92003-11-25 01:02:51 +0000664 </tr>
665 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000666</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000667
Chris Lattner261efe92003-11-25 01:02:51 +0000668<p>The <a href="#t_firstclass">first class</a> types are perhaps the
669most important. Values of these types are the only ones which can be
670produced by instructions, passed as arguments, or used as operands to
671instructions. This means that all structures and arrays must be
672manipulated either by pointer or by component.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000673</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000674
Chris Lattner00950542001-06-06 20:29:01 +0000675<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000676<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000677
Misha Brukman9d0919f2003-11-08 01:05:38 +0000678<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +0000679
Chris Lattner261efe92003-11-25 01:02:51 +0000680<p>The real power in LLVM comes from the derived types in the system.
681This is what allows a programmer to represent arrays, functions,
682pointers, and other useful types. Note that these derived types may be
683recursive: For example, it is possible to have a two dimensional array.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000684
Misha Brukman9d0919f2003-11-08 01:05:38 +0000685</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000686
Chris Lattner00950542001-06-06 20:29:01 +0000687<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000688<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000689
Misha Brukman9d0919f2003-11-08 01:05:38 +0000690<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +0000691
Chris Lattner00950542001-06-06 20:29:01 +0000692<h5>Overview:</h5>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000693
Misha Brukman9d0919f2003-11-08 01:05:38 +0000694<p>The array type is a very simple derived type that arranges elements
Chris Lattner261efe92003-11-25 01:02:51 +0000695sequentially in memory. The array type requires a size (number of
696elements) and an underlying data type.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000697
Chris Lattner7faa8832002-04-14 06:13:44 +0000698<h5>Syntax:</h5>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000699
700<pre>
701 [&lt;# elements&gt; x &lt;elementtype&gt;]
702</pre>
703
John Criswelle4c57cc2005-05-12 16:52:32 +0000704<p>The number of elements is a constant integer value; elementtype may
Chris Lattner261efe92003-11-25 01:02:51 +0000705be any type with a size.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000706
Chris Lattner7faa8832002-04-14 06:13:44 +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>[40 x int ]</tt><br/>
712 <tt>[41 x int ]</tt><br/>
713 <tt>[40 x uint]</tt><br/>
714 </td>
715 <td class="left">
716 Array of 40 integer values.<br/>
717 Array of 41 integer values.<br/>
718 Array of 40 unsigned integer values.<br/>
719 </td>
720 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000721</table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000722<p>Here are some examples of multidimensional arrays:</p>
723<table class="layout">
724 <tr class="layout">
725 <td class="left">
726 <tt>[3 x [4 x int]]</tt><br/>
727 <tt>[12 x [10 x float]]</tt><br/>
728 <tt>[2 x [3 x [4 x uint]]]</tt><br/>
729 </td>
730 <td class="left">
John Criswellc1f786c2005-05-13 22:25:59 +0000731 3x4 array of integer values.<br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000732 12x10 array of single precision floating point values.<br/>
733 2x3x4 array of unsigned integer values.<br/>
734 </td>
735 </tr>
736</table>
Chris Lattnere67a9512005-06-24 17:22:57 +0000737
John Criswell0ec250c2005-10-24 16:17:18 +0000738<p>Note that 'variable sized arrays' can be implemented in LLVM with a zero
739length array. Normally, accesses past the end of an array are undefined in
Chris Lattnere67a9512005-06-24 17:22:57 +0000740LLVM (e.g. it is illegal to access the 5th element of a 3 element array).
741As a special case, however, zero length arrays are recognized to be variable
742length. This allows implementation of 'pascal style arrays' with the LLVM
743type "{ int, [0 x float]}", for example.</p>
744
Misha Brukman9d0919f2003-11-08 01:05:38 +0000745</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000746
Chris Lattner00950542001-06-06 20:29:01 +0000747<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000748<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000749<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000750<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000751<p>The function type can be thought of as a function signature. It
752consists of a return type and a list of formal parameter types.
John Criswell009900b2003-11-25 21:45:46 +0000753Function types are usually used to build virtual function tables
Chris Lattner261efe92003-11-25 01:02:51 +0000754(which are structures of pointers to functions), for indirect function
755calls, and when defining a function.</p>
John Criswell009900b2003-11-25 21:45:46 +0000756<p>
757The return type of a function type cannot be an aggregate type.
758</p>
Chris Lattner00950542001-06-06 20:29:01 +0000759<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000760<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
John Criswell0ec250c2005-10-24 16:17:18 +0000761<p>...where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
Misha Brukmanc24b7582004-08-12 20:16:08 +0000762specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner27f71f22003-09-03 00:41:47 +0000763which indicates that the function takes a variable number of arguments.
764Variable argument functions can access their arguments with the <a
Chris Lattner261efe92003-11-25 01:02:51 +0000765 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000766<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000767<table class="layout">
768 <tr class="layout">
769 <td class="left">
770 <tt>int (int)</tt> <br/>
771 <tt>float (int, int *) *</tt><br/>
772 <tt>int (sbyte *, ...)</tt><br/>
773 </td>
774 <td class="left">
775 function taking an <tt>int</tt>, returning an <tt>int</tt><br/>
776 <a href="#t_pointer">Pointer</a> to a function that takes an
Misha Brukmanc24b7582004-08-12 20:16:08 +0000777 <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
Reid Spencerd3f876c2004-11-01 08:19:36 +0000778 returning <tt>float</tt>.<br/>
779 A vararg function that takes at least one <a href="#t_pointer">pointer</a>
780 to <tt>sbyte</tt> (signed char in C), which returns an integer. This is
781 the signature for <tt>printf</tt> in LLVM.<br/>
782 </td>
783 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000784</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000785
Misha Brukman9d0919f2003-11-08 01:05:38 +0000786</div>
Chris Lattner00950542001-06-06 20:29:01 +0000787<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000788<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000789<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000790<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000791<p>The structure type is used to represent a collection of data members
792together in memory. The packing of the field types is defined to match
793the ABI of the underlying processor. The elements of a structure may
794be any type that has a size.</p>
795<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
796and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
797field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
798instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000799<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000800<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +0000801<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000802<table class="layout">
803 <tr class="layout">
804 <td class="left">
805 <tt>{ int, int, int }</tt><br/>
806 <tt>{ float, int (int) * }</tt><br/>
807 </td>
808 <td class="left">
809 a triple of three <tt>int</tt> values<br/>
810 A pair, where the first element is a <tt>float</tt> and the second element
811 is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a>
812 that takes an <tt>int</tt>, returning an <tt>int</tt>.<br/>
813 </td>
814 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000815</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000816</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000817
Chris Lattner00950542001-06-06 20:29:01 +0000818<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000819<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000820<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +0000821<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000822<p>As in many languages, the pointer type represents a pointer or
823reference to another object, which must live in memory.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000824<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000825<pre> &lt;type&gt; *<br></pre>
Chris Lattner7faa8832002-04-14 06:13:44 +0000826<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000827<table class="layout">
828 <tr class="layout">
829 <td class="left">
830 <tt>[4x int]*</tt><br/>
831 <tt>int (int *) *</tt><br/>
832 </td>
833 <td class="left">
834 A <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of
835 four <tt>int</tt> values<br/>
836 A <a href="#t_pointer">pointer</a> to a <a
Chris Lattnera977c482005-02-19 02:22:14 +0000837 href="#t_function">function</a> that takes an <tt>int*</tt>, returning an
Reid Spencerd3f876c2004-11-01 08:19:36 +0000838 <tt>int</tt>.<br/>
839 </td>
840 </tr>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000841</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000842</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000843
Chris Lattnera58561b2004-08-12 19:12:28 +0000844<!-- _______________________________________________________________________ -->
845<div class="doc_subsubsection"> <a name="t_packed">Packed Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000846<div class="doc_text">
Chris Lattner69c11bb2005-04-25 17:34:15 +0000847
Chris Lattnera58561b2004-08-12 19:12:28 +0000848<h5>Overview:</h5>
Chris Lattner69c11bb2005-04-25 17:34:15 +0000849
Chris Lattnera58561b2004-08-12 19:12:28 +0000850<p>A packed type is a simple derived type that represents a vector
851of elements. Packed types are used when multiple primitive data
852are operated in parallel using a single instruction (SIMD).
853A packed type requires a size (number of
Chris Lattnerb8d172f2005-11-10 01:44:22 +0000854elements) and an underlying primitive data type. Vectors must have a power
855of two length (1, 2, 4, 8, 16 ...). Packed types are
Chris Lattnera58561b2004-08-12 19:12:28 +0000856considered <a href="#t_firstclass">first class</a>.</p>
Chris Lattner69c11bb2005-04-25 17:34:15 +0000857
Chris Lattnera58561b2004-08-12 19:12:28 +0000858<h5>Syntax:</h5>
Chris Lattner69c11bb2005-04-25 17:34:15 +0000859
860<pre>
861 &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;
862</pre>
863
John Criswellc1f786c2005-05-13 22:25:59 +0000864<p>The number of elements is a constant integer value; elementtype may
Chris Lattnera58561b2004-08-12 19:12:28 +0000865be any integral or floating point type.</p>
Chris Lattner69c11bb2005-04-25 17:34:15 +0000866
Chris Lattnera58561b2004-08-12 19:12:28 +0000867<h5>Examples:</h5>
Chris Lattner69c11bb2005-04-25 17:34:15 +0000868
Reid Spencerd3f876c2004-11-01 08:19:36 +0000869<table class="layout">
870 <tr class="layout">
871 <td class="left">
872 <tt>&lt;4 x int&gt;</tt><br/>
873 <tt>&lt;8 x float&gt;</tt><br/>
874 <tt>&lt;2 x uint&gt;</tt><br/>
875 </td>
876 <td class="left">
877 Packed vector of 4 integer values.<br/>
878 Packed vector of 8 floating-point values.<br/>
879 Packed vector of 2 unsigned integer values.<br/>
880 </td>
881 </tr>
882</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000883</div>
884
Chris Lattner69c11bb2005-04-25 17:34:15 +0000885<!-- _______________________________________________________________________ -->
886<div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div>
887<div class="doc_text">
888
889<h5>Overview:</h5>
890
891<p>Opaque types are used to represent unknown types in the system. This
892corresponds (for example) to the C notion of a foward declared structure type.
893In LLVM, opaque types can eventually be resolved to any type (not just a
894structure type).</p>
895
896<h5>Syntax:</h5>
897
898<pre>
899 opaque
900</pre>
901
902<h5>Examples:</h5>
903
904<table class="layout">
905 <tr class="layout">
906 <td class="left">
907 <tt>opaque</tt>
908 </td>
909 <td class="left">
910 An opaque type.<br/>
911 </td>
912 </tr>
913</table>
914</div>
915
916
Chris Lattnerc3f59762004-12-09 17:30:23 +0000917<!-- *********************************************************************** -->
918<div class="doc_section"> <a name="constants">Constants</a> </div>
919<!-- *********************************************************************** -->
920
921<div class="doc_text">
922
923<p>LLVM has several different basic types of constants. This section describes
924them all and their syntax.</p>
925
926</div>
927
928<!-- ======================================================================= -->
Reid Spencercc16dc32004-12-09 18:02:53 +0000929<div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000930
931<div class="doc_text">
932
933<dl>
934 <dt><b>Boolean constants</b></dt>
935
936 <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
937 constants of the <tt><a href="#t_primitive">bool</a></tt> type.
938 </dd>
939
940 <dt><b>Integer constants</b></dt>
941
Reid Spencercc16dc32004-12-09 18:02:53 +0000942 <dd>Standard integers (such as '4') are constants of the <a
Chris Lattnerc3f59762004-12-09 17:30:23 +0000943 href="#t_integer">integer</a> type. Negative numbers may be used with signed
944 integer types.
945 </dd>
946
947 <dt><b>Floating point constants</b></dt>
948
949 <dd>Floating point constants use standard decimal notation (e.g. 123.421),
950 exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
Chris Lattnerc3f59762004-12-09 17:30:23 +0000951 notation (see below). Floating point constants must have a <a
952 href="#t_floating">floating point</a> type. </dd>
953
954 <dt><b>Null pointer constants</b></dt>
955
John Criswell9e2485c2004-12-10 15:51:16 +0000956 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
Chris Lattnerc3f59762004-12-09 17:30:23 +0000957 and must be of <a href="#t_pointer">pointer type</a>.</dd>
958
959</dl>
960
John Criswell9e2485c2004-12-10 15:51:16 +0000961<p>The one non-intuitive notation for constants is the optional hexadecimal form
Chris Lattnerc3f59762004-12-09 17:30:23 +0000962of floating point constants. For example, the form '<tt>double
9630x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
9644.5e+15</tt>'. The only time hexadecimal floating point constants are required
Reid Spencercc16dc32004-12-09 18:02:53 +0000965(and the only time that they are generated by the disassembler) is when a
966floating point constant must be emitted but it cannot be represented as a
967decimal floating point number. For example, NaN's, infinities, and other
968special values are represented in their IEEE hexadecimal format so that
969assembly and disassembly do not cause any bits to change in the constants.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000970
971</div>
972
973<!-- ======================================================================= -->
974<div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a>
975</div>
976
977<div class="doc_text">
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000978<p>Aggregate constants arise from aggregation of simple constants
979and smaller aggregate constants.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000980
981<dl>
982 <dt><b>Structure constants</b></dt>
983
984 <dd>Structure constants are represented with notation similar to structure
985 type definitions (a comma separated list of elements, surrounded by braces
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000986 (<tt>{}</tt>)). For example: "<tt>{ int 4, float 17.0, int* %G }</tt>",
987 where "<tt>%G</tt>" is declared as "<tt>%G = external global int</tt>". Structure constants
988 must have <a href="#t_struct">structure type</a>, and the number and
Chris Lattnerc3f59762004-12-09 17:30:23 +0000989 types of elements must match those specified by the type.
990 </dd>
991
992 <dt><b>Array constants</b></dt>
993
994 <dd>Array constants are represented with notation similar to array type
995 definitions (a comma separated list of elements, surrounded by square brackets
John Criswell9e2485c2004-12-10 15:51:16 +0000996 (<tt>[]</tt>)). For example: "<tt>[ int 42, int 11, int 74 ]</tt>". Array
Chris Lattnerc3f59762004-12-09 17:30:23 +0000997 constants must have <a href="#t_array">array type</a>, and the number and
998 types of elements must match those specified by the type.
999 </dd>
1000
1001 <dt><b>Packed constants</b></dt>
1002
1003 <dd>Packed constants are represented with notation similar to packed type
1004 definitions (a comma separated list of elements, surrounded by
John Criswell9e2485c2004-12-10 15:51:16 +00001005 less-than/greater-than's (<tt>&lt;&gt;</tt>)). For example: "<tt>&lt; int 42,
Chris Lattnerc3f59762004-12-09 17:30:23 +00001006 int 11, int 74, int 100 &gt;</tt>". Packed constants must have <a
1007 href="#t_packed">packed type</a>, and the number and types of elements must
1008 match those specified by the type.
1009 </dd>
1010
1011 <dt><b>Zero initialization</b></dt>
1012
1013 <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
1014 value to zero of <em>any</em> type, including scalar and aggregate types.
1015 This is often used to avoid having to print large zero initializers (e.g. for
John Criswell0ec250c2005-10-24 16:17:18 +00001016 large arrays) and is always exactly equivalent to using explicit zero
Chris Lattnerc3f59762004-12-09 17:30:23 +00001017 initializers.
1018 </dd>
1019</dl>
1020
1021</div>
1022
1023<!-- ======================================================================= -->
1024<div class="doc_subsection">
1025 <a name="globalconstants">Global Variable and Function Addresses</a>
1026</div>
1027
1028<div class="doc_text">
1029
1030<p>The addresses of <a href="#globalvars">global variables</a> and <a
1031href="#functionstructure">functions</a> are always implicitly valid (link-time)
John Criswell9e2485c2004-12-10 15:51:16 +00001032constants. These constants are explicitly referenced when the <a
1033href="#identifiers">identifier for the global</a> is used and always have <a
Chris Lattnerc3f59762004-12-09 17:30:23 +00001034href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
1035file:</p>
1036
1037<pre>
1038 %X = global int 17
1039 %Y = global int 42
1040 %Z = global [2 x int*] [ int* %X, int* %Y ]
1041</pre>
1042
1043</div>
1044
1045<!-- ======================================================================= -->
Reid Spencer2dc45b82004-12-09 18:13:12 +00001046<div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001047<div class="doc_text">
Reid Spencer2dc45b82004-12-09 18:13:12 +00001048 <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has
John Criswellc1f786c2005-05-13 22:25:59 +00001049 no specific value. Undefined values may be of any type and be used anywhere
Reid Spencer2dc45b82004-12-09 18:13:12 +00001050 a constant is permitted.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001051
Reid Spencer2dc45b82004-12-09 18:13:12 +00001052 <p>Undefined values indicate to the compiler that the program is well defined
1053 no matter what value is used, giving the compiler more freedom to optimize.
1054 </p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001055</div>
1056
1057<!-- ======================================================================= -->
1058<div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
1059</div>
1060
1061<div class="doc_text">
1062
1063<p>Constant expressions are used to allow expressions involving other constants
1064to be used as constants. Constant expressions may be of any <a
John Criswellc1f786c2005-05-13 22:25:59 +00001065href="#t_firstclass">first class</a> type and may involve any LLVM operation
Chris Lattnerc3f59762004-12-09 17:30:23 +00001066that does not have side effects (e.g. load and call are not supported). The
1067following is the syntax for constant expressions:</p>
1068
1069<dl>
1070 <dt><b><tt>cast ( CST to TYPE )</tt></b></dt>
1071
1072 <dd>Cast a constant to another type.</dd>
1073
1074 <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
1075
1076 <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
1077 constants. As with the <a href="#i_getelementptr">getelementptr</a>
1078 instruction, the index list may have zero or more indexes, which are required
1079 to make sense for the type of "CSTPTR".</dd>
1080
1081 <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
1082
Reid Spencer2dc45b82004-12-09 18:13:12 +00001083 <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
1084 be any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise
Chris Lattnerc3f59762004-12-09 17:30:23 +00001085 binary</a> operations. The constraints on operands are the same as those for
1086 the corresponding instruction (e.g. no bitwise operations on floating point
John Criswelle4c57cc2005-05-12 16:52:32 +00001087 values are allowed).</dd>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001088</dl>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001089</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +00001090
Chris Lattner00950542001-06-06 20:29:01 +00001091<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00001092<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
1093<!-- *********************************************************************** -->
Chris Lattnerc3f59762004-12-09 17:30:23 +00001094
Misha Brukman9d0919f2003-11-08 01:05:38 +00001095<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +00001096
Chris Lattner261efe92003-11-25 01:02:51 +00001097<p>The LLVM instruction set consists of several different
1098classifications of instructions: <a href="#terminators">terminator
John Criswellc1f786c2005-05-13 22:25:59 +00001099instructions</a>, <a href="#binaryops">binary instructions</a>,
1100<a href="#bitwiseops">bitwise binary instructions</a>, <a
Chris Lattner261efe92003-11-25 01:02:51 +00001101 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
1102instructions</a>.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001103
Misha Brukman9d0919f2003-11-08 01:05:38 +00001104</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001105
Chris Lattner00950542001-06-06 20:29:01 +00001106<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001107<div class="doc_subsection"> <a name="terminators">Terminator
1108Instructions</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001109
Misha Brukman9d0919f2003-11-08 01:05:38 +00001110<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +00001111
Chris Lattner261efe92003-11-25 01:02:51 +00001112<p>As mentioned <a href="#functionstructure">previously</a>, every
1113basic block in a program ends with a "Terminator" instruction, which
1114indicates which block should be executed after the current block is
1115finished. These terminator instructions typically yield a '<tt>void</tt>'
1116value: they produce control flow, not values (the one exception being
1117the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
John Criswell9e2485c2004-12-10 15:51:16 +00001118<p>There are six different terminator instructions: the '<a
Chris Lattner261efe92003-11-25 01:02:51 +00001119 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
1120instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
Chris Lattner35eca582004-10-16 18:04:13 +00001121the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
1122 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
1123 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001124
Misha Brukman9d0919f2003-11-08 01:05:38 +00001125</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001126
Chris Lattner00950542001-06-06 20:29:01 +00001127<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001128<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
1129Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001130<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001131<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001132<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 +00001133 ret void <i>; Return from void function</i>
Chris Lattner00950542001-06-06 20:29:01 +00001134</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001135<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001136<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
John Criswellc1f786c2005-05-13 22:25:59 +00001137value) from a function back to the caller.</p>
John Criswell4457dc92004-04-09 16:48:45 +00001138<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner261efe92003-11-25 01:02:51 +00001139returns a value and then causes control flow, and one that just causes
1140control flow to occur.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001141<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001142<p>The '<tt>ret</tt>' instruction may return any '<a
1143 href="#t_firstclass">first class</a>' type. Notice that a function is
1144not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
1145instruction inside of the function that returns a value that does not
1146match the return type of the function.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001147<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001148<p>When the '<tt>ret</tt>' instruction is executed, control flow
1149returns back to the calling function's context. If the caller is a "<a
John Criswellfa081872004-06-25 15:16:57 +00001150 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner261efe92003-11-25 01:02:51 +00001151the instruction after the call. If the caller was an "<a
1152 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
John Criswelle4c57cc2005-05-12 16:52:32 +00001153at the beginning of the "normal" destination block. If the instruction
Chris Lattner261efe92003-11-25 01:02:51 +00001154returns a value, that value shall set the call or invoke instruction's
1155return value.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001156<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001157<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001158 ret void <i>; Return from a void function</i>
Chris Lattner00950542001-06-06 20:29:01 +00001159</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001160</div>
Chris Lattner00950542001-06-06 20:29:01 +00001161<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001162<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001163<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001164<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001165<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 +00001166</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001167<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001168<p>The '<tt>br</tt>' instruction is used to cause control flow to
1169transfer to a different basic block in the current function. There are
1170two forms of this instruction, corresponding to a conditional branch
1171and an unconditional branch.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001172<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001173<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
1174single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
1175unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
1176value as a target.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001177<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001178<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
1179argument is evaluated. If the value is <tt>true</tt>, control flows
1180to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
1181control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001182<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001183<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
1184 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 +00001185</div>
Chris Lattner00950542001-06-06 20:29:01 +00001186<!-- _______________________________________________________________________ -->
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001187<div class="doc_subsubsection">
1188 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
1189</div>
1190
Misha Brukman9d0919f2003-11-08 01:05:38 +00001191<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001192<h5>Syntax:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001193
1194<pre>
1195 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
1196</pre>
1197
Chris Lattner00950542001-06-06 20:29:01 +00001198<h5>Overview:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001199
1200<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
1201several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +00001202instruction, allowing a branch to occur to one of many possible
1203destinations.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001204
1205
Chris Lattner00950542001-06-06 20:29:01 +00001206<h5>Arguments:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001207
1208<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
1209comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
1210an array of pairs of comparison value constants and '<tt>label</tt>'s. The
1211table is not allowed to contain duplicate constant entries.</p>
1212
Chris Lattner00950542001-06-06 20:29:01 +00001213<h5>Semantics:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001214
Chris Lattner261efe92003-11-25 01:02:51 +00001215<p>The <tt>switch</tt> instruction specifies a table of values and
1216destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswell84114752004-06-25 16:05:06 +00001217table is searched for the given value. If the value is found, control flow is
1218transfered to the corresponding destination; otherwise, control flow is
1219transfered to the default destination.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001220
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001221<h5>Implementation:</h5>
1222
1223<p>Depending on properties of the target machine and the particular
1224<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswell84114752004-06-25 16:05:06 +00001225ways. For example, it could be generated as a series of chained conditional
1226branches or with a lookup table.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001227
1228<h5>Example:</h5>
1229
1230<pre>
1231 <i>; Emulate a conditional br instruction</i>
1232 %Val = <a href="#i_cast">cast</a> bool %value to int
1233 switch int %Val, label %truedest [int 0, label %falsedest ]
1234
1235 <i>; Emulate an unconditional br instruction</i>
1236 switch uint 0, label %dest [ ]
1237
1238 <i>; Implement a jump table:</i>
1239 switch uint %val, label %otherwise [ uint 0, label %onzero
1240 uint 1, label %onone
1241 uint 2, label %ontwo ]
Chris Lattner00950542001-06-06 20:29:01 +00001242</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001243</div>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001244
Chris Lattner00950542001-06-06 20:29:01 +00001245<!-- _______________________________________________________________________ -->
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001246<div class="doc_subsubsection">
1247 <a name="i_invoke">'<tt>invoke</tt>' Instruction</a>
1248</div>
1249
Misha Brukman9d0919f2003-11-08 01:05:38 +00001250<div class="doc_text">
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001251
Chris Lattner00950542001-06-06 20:29:01 +00001252<h5>Syntax:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001253
1254<pre>
1255 &lt;result&gt; = invoke [<a href="#callingconv">cconv</a>] &lt;ptr to function ty&gt; %&lt;function ptr val&gt;(&lt;function args&gt;)
1256 to label &lt;normal label&gt; except label &lt;exception label&gt;
1257</pre>
1258
Chris Lattner6536cfe2002-05-06 22:08:29 +00001259<h5>Overview:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001260
1261<p>The '<tt>invoke</tt>' instruction causes control to transfer to a specified
1262function, with the possibility of control flow transfer to either the
John Criswelle4c57cc2005-05-12 16:52:32 +00001263'<tt>normal</tt>' label or the
1264'<tt>exception</tt>' label. If the callee function returns with the
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001265"<tt><a href="#i_ret">ret</a></tt>" instruction, control flow will return to the
1266"normal" label. If the callee (or any indirect callees) returns with the "<a
John Criswelle4c57cc2005-05-12 16:52:32 +00001267href="#i_unwind"><tt>unwind</tt></a>" instruction, control is interrupted and
1268continued at the dynamically nearest "exception" label.</p>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001269
Chris Lattner00950542001-06-06 20:29:01 +00001270<h5>Arguments:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001271
Misha Brukman9d0919f2003-11-08 01:05:38 +00001272<p>This instruction requires several arguments:</p>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001273
Chris Lattner00950542001-06-06 20:29:01 +00001274<ol>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001275 <li>
John Criswellc1f786c2005-05-13 22:25:59 +00001276 The optional "cconv" marker indicates which <a href="callingconv">calling
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001277 convention</a> the call should use. If none is specified, the call defaults
1278 to using C calling conventions.
1279 </li>
1280 <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to
1281 function value being invoked. In most cases, this is a direct function
1282 invocation, but indirect <tt>invoke</tt>s are just as possible, branching off
1283 an arbitrary pointer to function value.
1284 </li>
1285
1286 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a
1287 function to be invoked. </li>
1288
1289 <li>'<tt>function args</tt>': argument list whose types match the function
1290 signature argument types. If the function signature indicates the function
1291 accepts a variable number of arguments, the extra arguments can be
1292 specified. </li>
1293
1294 <li>'<tt>normal label</tt>': the label reached when the called function
1295 executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
1296
1297 <li>'<tt>exception label</tt>': the label reached when a callee returns with
1298 the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
1299
Chris Lattner00950542001-06-06 20:29:01 +00001300</ol>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001301
Chris Lattner00950542001-06-06 20:29:01 +00001302<h5>Semantics:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001303
Misha Brukman9d0919f2003-11-08 01:05:38 +00001304<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001305href="#i_call">call</a></tt>' instruction in most regards. The primary
1306difference is that it establishes an association with a label, which is used by
1307the runtime library to unwind the stack.</p>
1308
1309<p>This instruction is used in languages with destructors to ensure that proper
1310cleanup is performed in the case of either a <tt>longjmp</tt> or a thrown
1311exception. Additionally, this is important for implementation of
1312'<tt>catch</tt>' clauses in high-level languages that support them.</p>
1313
Chris Lattner00950542001-06-06 20:29:01 +00001314<h5>Example:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001315<pre>
1316 %retval = invoke int %Test(int 15) to label %Continue
1317 except label %TestCleanup <i>; {int}:retval set</i>
1318 %retval = invoke <a href="#callingconv">coldcc</a> int %Test(int 15) to label %Continue
1319 except label %TestCleanup <i>; {int}:retval set</i>
Chris Lattner00950542001-06-06 20:29:01 +00001320</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001321</div>
Chris Lattner35eca582004-10-16 18:04:13 +00001322
1323
Chris Lattner27f71f22003-09-03 00:41:47 +00001324<!-- _______________________________________________________________________ -->
Chris Lattner35eca582004-10-16 18:04:13 +00001325
Chris Lattner261efe92003-11-25 01:02:51 +00001326<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
1327Instruction</a> </div>
Chris Lattner35eca582004-10-16 18:04:13 +00001328
Misha Brukman9d0919f2003-11-08 01:05:38 +00001329<div class="doc_text">
Chris Lattner35eca582004-10-16 18:04:13 +00001330
Chris Lattner27f71f22003-09-03 00:41:47 +00001331<h5>Syntax:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001332<pre>
1333 unwind
1334</pre>
1335
Chris Lattner27f71f22003-09-03 00:41:47 +00001336<h5>Overview:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001337
1338<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
1339at the first callee in the dynamic call stack which used an <a
1340href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
1341primarily used to implement exception handling.</p>
1342
Chris Lattner27f71f22003-09-03 00:41:47 +00001343<h5>Semantics:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001344
1345<p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to
1346immediately halt. The dynamic call stack is then searched for the first <a
1347href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
1348execution continues at the "exceptional" destination block specified by the
1349<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
1350dynamic call chain, undefined behavior results.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001351</div>
Chris Lattner35eca582004-10-16 18:04:13 +00001352
1353<!-- _______________________________________________________________________ -->
1354
1355<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
1356Instruction</a> </div>
1357
1358<div class="doc_text">
1359
1360<h5>Syntax:</h5>
1361<pre>
1362 unreachable
1363</pre>
1364
1365<h5>Overview:</h5>
1366
1367<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
1368instruction is used to inform the optimizer that a particular portion of the
1369code is not reachable. This can be used to indicate that the code after a
1370no-return function cannot be reached, and other facts.</p>
1371
1372<h5>Semantics:</h5>
1373
1374<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
1375</div>
1376
1377
1378
Chris Lattner00950542001-06-06 20:29:01 +00001379<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001380<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001381<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001382<p>Binary operators are used to do most of the computation in a
1383program. They require two operands, execute an operation on them, and
John Criswell9e2485c2004-12-10 15:51:16 +00001384produce a single value. The operands might represent
Chris Lattnera58561b2004-08-12 19:12:28 +00001385multiple data, as is the case with the <a href="#t_packed">packed</a> data type.
1386The result value of a binary operator is not
Chris Lattner261efe92003-11-25 01:02:51 +00001387necessarily the same type as its operands.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001388<p>There are several different binary operators:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001389</div>
Chris Lattner00950542001-06-06 20:29:01 +00001390<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001391<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
1392Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001393<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001394<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001395<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 +00001396</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001397<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001398<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001399<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001400<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattnera58561b2004-08-12 19:12:28 +00001401 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
1402 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1403Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001404<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001405<p>The value produced is the integer or floating point sum of the two
1406operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001407<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001408<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001409</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001410</div>
Chris Lattner00950542001-06-06 20:29:01 +00001411<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001412<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
1413Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001414<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001415<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001416<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 +00001417</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001418<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001419<p>The '<tt>sub</tt>' instruction returns the difference of its two
1420operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001421<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
1422instruction present in most other intermediate representations.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001423<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001424<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001425 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001426values.
1427This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1428Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001429<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001430<p>The value produced is the integer or floating point difference of
1431the two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001432<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001433<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001434 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
1435</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001436</div>
Chris Lattner00950542001-06-06 20:29:01 +00001437<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001438<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
1439Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001440<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001441<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001442<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 +00001443</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001444<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001445<p>The '<tt>mul</tt>' instruction returns the product of its two
1446operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001447<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001448<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001449 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001450values.
1451This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1452Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001453<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001454<p>The value produced is the integer or floating point product of the
Misha Brukman9d0919f2003-11-08 01:05:38 +00001455two operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001456<p>There is no signed vs unsigned multiplication. The appropriate
1457action is taken based on the type of the operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001458<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001459<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001460</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001461</div>
Chris Lattner00950542001-06-06 20:29:01 +00001462<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001463<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
1464Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001465<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001466<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001467<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1468</pre>
1469<h5>Overview:</h5>
1470<p>The '<tt>div</tt>' instruction returns the quotient of its two
1471operands.</p>
1472<h5>Arguments:</h5>
1473<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
1474 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001475values.
1476This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1477Both arguments must have identical types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001478<h5>Semantics:</h5>
1479<p>The value produced is the integer or floating point quotient of the
1480two operands.</p>
1481<h5>Example:</h5>
1482<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
1483</pre>
1484</div>
1485<!-- _______________________________________________________________________ -->
1486<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
1487Instruction</a> </div>
1488<div class="doc_text">
1489<h5>Syntax:</h5>
1490<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1491</pre>
1492<h5>Overview:</h5>
1493<p>The '<tt>rem</tt>' instruction returns the remainder from the
1494division of its two operands.</p>
1495<h5>Arguments:</h5>
1496<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1497 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001498values.
1499This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1500Both arguments must have identical types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001501<h5>Semantics:</h5>
1502<p>This returns the <i>remainder</i> of a division (where the result
1503has the same sign as the divisor), not the <i>modulus</i> (where the
1504result has the same sign as the dividend) of a value. For more
John Criswell0ec250c2005-10-24 16:17:18 +00001505information about the difference, see <a
Chris Lattner261efe92003-11-25 01:02:51 +00001506 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1507Math Forum</a>.</p>
1508<h5>Example:</h5>
1509<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1510</pre>
1511</div>
1512<!-- _______________________________________________________________________ -->
1513<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1514Instructions</a> </div>
1515<div class="doc_text">
1516<h5>Syntax:</h5>
1517<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 +00001518 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1519 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1520 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1521 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1522 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1523</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001524<h5>Overview:</h5>
1525<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1526value based on a comparison of their two operands.</p>
1527<h5>Arguments:</h5>
1528<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1529be of <a href="#t_firstclass">first class</a> type (it is not possible
1530to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1531or '<tt>void</tt>' values, etc...). Both arguments must have identical
1532types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001533<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001534<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1535value if both operands are equal.<br>
1536The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1537value if both operands are unequal.<br>
1538The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1539value if the first operand is less than the second operand.<br>
1540The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1541value if the first operand is greater than the second operand.<br>
1542The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1543value if the first operand is less than or equal to the second operand.<br>
1544The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1545value if the first operand is greater than or equal to the second
1546operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001547<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001548<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner00950542001-06-06 20:29:01 +00001549 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
1550 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1551 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1552 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1553 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1554</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001555</div>
Chris Lattner00950542001-06-06 20:29:01 +00001556<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001557<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1558Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001559<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001560<p>Bitwise binary operators are used to do various forms of
1561bit-twiddling in a program. They are generally very efficient
John Criswell9e2485c2004-12-10 15:51:16 +00001562instructions and can commonly be strength reduced from other
Chris Lattner261efe92003-11-25 01:02:51 +00001563instructions. They require two operands, execute an operation on them,
1564and produce a single value. The resulting value of the bitwise binary
1565operators is always the same type as its first operand.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001566</div>
Chris Lattner00950542001-06-06 20:29:01 +00001567<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001568<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1569Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001570<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001571<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001572<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 +00001573</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001574<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001575<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1576its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001577<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001578<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001579 href="#t_integral">integral</a> values. Both arguments must have
1580identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001581<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001582<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001583<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001584<div style="align: center">
Misha Brukman9d0919f2003-11-08 01:05:38 +00001585<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +00001586 <tbody>
1587 <tr>
1588 <td>In0</td>
1589 <td>In1</td>
1590 <td>Out</td>
1591 </tr>
1592 <tr>
1593 <td>0</td>
1594 <td>0</td>
1595 <td>0</td>
1596 </tr>
1597 <tr>
1598 <td>0</td>
1599 <td>1</td>
1600 <td>0</td>
1601 </tr>
1602 <tr>
1603 <td>1</td>
1604 <td>0</td>
1605 <td>0</td>
1606 </tr>
1607 <tr>
1608 <td>1</td>
1609 <td>1</td>
1610 <td>1</td>
1611 </tr>
1612 </tbody>
1613</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001614</div>
Chris Lattner00950542001-06-06 20:29:01 +00001615<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001616<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001617 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1618 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1619</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001620</div>
Chris Lattner00950542001-06-06 20:29:01 +00001621<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001622<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001623<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001624<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001625<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 +00001626</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001627<h5>Overview:</h5>
1628<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1629or of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001630<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001631<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001632 href="#t_integral">integral</a> values. Both arguments must have
1633identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001634<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001635<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001636<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001637<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001638<table border="1" cellspacing="0" cellpadding="4">
1639 <tbody>
1640 <tr>
1641 <td>In0</td>
1642 <td>In1</td>
1643 <td>Out</td>
1644 </tr>
1645 <tr>
1646 <td>0</td>
1647 <td>0</td>
1648 <td>0</td>
1649 </tr>
1650 <tr>
1651 <td>0</td>
1652 <td>1</td>
1653 <td>1</td>
1654 </tr>
1655 <tr>
1656 <td>1</td>
1657 <td>0</td>
1658 <td>1</td>
1659 </tr>
1660 <tr>
1661 <td>1</td>
1662 <td>1</td>
1663 <td>1</td>
1664 </tr>
1665 </tbody>
1666</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001667</div>
Chris Lattner00950542001-06-06 20:29:01 +00001668<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001669<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001670 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1671 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1672</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001673</div>
Chris Lattner00950542001-06-06 20:29:01 +00001674<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001675<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1676Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001677<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001678<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001679<pre> &lt;result&gt; = xor &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001680</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001681<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001682<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1683or of its two operands. The <tt>xor</tt> is used to implement the
1684"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001685<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001686<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001687 href="#t_integral">integral</a> values. Both arguments must have
1688identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001689<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001690<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001691<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001692<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001693<table border="1" cellspacing="0" cellpadding="4">
1694 <tbody>
1695 <tr>
1696 <td>In0</td>
1697 <td>In1</td>
1698 <td>Out</td>
1699 </tr>
1700 <tr>
1701 <td>0</td>
1702 <td>0</td>
1703 <td>0</td>
1704 </tr>
1705 <tr>
1706 <td>0</td>
1707 <td>1</td>
1708 <td>1</td>
1709 </tr>
1710 <tr>
1711 <td>1</td>
1712 <td>0</td>
1713 <td>1</td>
1714 </tr>
1715 <tr>
1716 <td>1</td>
1717 <td>1</td>
1718 <td>0</td>
1719 </tr>
1720 </tbody>
1721</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001722</div>
Chris Lattner261efe92003-11-25 01:02:51 +00001723<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001724<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001725<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001726 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1727 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner27f71f22003-09-03 00:41:47 +00001728 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner00950542001-06-06 20:29:01 +00001729</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001730</div>
Chris Lattner00950542001-06-06 20:29:01 +00001731<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001732<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1733Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001734<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001735<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001736<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 +00001737</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001738<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001739<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1740the left a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001741<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001742<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001743 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1744type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001745<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001746<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001747<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001748<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 +00001749 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1750 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1751</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001752</div>
Chris Lattner00950542001-06-06 20:29:01 +00001753<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001754<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1755Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001756<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001757<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001758<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 +00001759</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001760<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001761<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1762the right a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001763<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001764<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001765 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1766type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001767<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001768<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1769most significant bit is duplicated in the newly free'd bit positions.
1770If the first argument is unsigned, zero bits shall fill the empty
1771positions.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001772<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001773<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 +00001774 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001775 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner8c6bb902003-06-18 21:30:51 +00001776 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1777 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner00950542001-06-06 20:29:01 +00001778</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001779</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001780
Chris Lattner00950542001-06-06 20:29:01 +00001781<!-- ======================================================================= -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00001782<div class="doc_subsection">
1783 <a name="memoryops">Memory Access Operations</a>
1784</div>
1785
Misha Brukman9d0919f2003-11-08 01:05:38 +00001786<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00001787
Chris Lattner261efe92003-11-25 01:02:51 +00001788<p>A key design point of an SSA-based representation is how it
1789represents memory. In LLVM, no memory locations are in SSA form, which
1790makes things very simple. This section describes how to read, write,
John Criswell9e2485c2004-12-10 15:51:16 +00001791allocate, and free memory in LLVM.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001792
Misha Brukman9d0919f2003-11-08 01:05:38 +00001793</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001794
Chris Lattner00950542001-06-06 20:29:01 +00001795<!-- _______________________________________________________________________ -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00001796<div class="doc_subsubsection">
1797 <a name="i_malloc">'<tt>malloc</tt>' Instruction</a>
1798</div>
1799
Misha Brukman9d0919f2003-11-08 01:05:38 +00001800<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00001801
Chris Lattner00950542001-06-06 20:29:01 +00001802<h5>Syntax:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001803
1804<pre>
1805 &lt;result&gt; = malloc &lt;type&gt;[, uint &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001806</pre>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001807
Chris Lattner00950542001-06-06 20:29:01 +00001808<h5>Overview:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001809
Chris Lattner261efe92003-11-25 01:02:51 +00001810<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1811heap and returns a pointer to it.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001812
Chris Lattner00950542001-06-06 20:29:01 +00001813<h5>Arguments:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001814
1815<p>The '<tt>malloc</tt>' instruction allocates
1816<tt>sizeof(&lt;type&gt;)*NumElements</tt>
John Criswell6e4ca612004-02-24 16:13:56 +00001817bytes of memory from the operating system and returns a pointer of the
Chris Lattner2cbdc452005-11-06 08:02:57 +00001818appropriate type to the program. If "NumElements" is specified, it is the
1819number of elements allocated. If an alignment is specified, the value result
1820of the allocation is guaranteed to be aligned to at least that boundary. If
1821not specified, or if zero, the target can choose to align the allocation on any
1822convenient boundary.</p>
1823
Misha Brukman9d0919f2003-11-08 01:05:38 +00001824<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001825
Chris Lattner00950542001-06-06 20:29:01 +00001826<h5>Semantics:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001827
Chris Lattner261efe92003-11-25 01:02:51 +00001828<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1829a pointer is returned.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001830
Chris Lattner2cbdc452005-11-06 08:02:57 +00001831<h5>Example:</h5>
1832
1833<pre>
1834 %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
1835
1836 %size = <a href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001837 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1838 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001839 %array3 = malloc int, uint 4, align 1024 <i>; yields {int*}:array3</i>
1840 %array4 = malloc int, align 1024 <i>; yields {int*}:array4</i>
Chris Lattner00950542001-06-06 20:29:01 +00001841</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001842</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001843
Chris Lattner00950542001-06-06 20:29:01 +00001844<!-- _______________________________________________________________________ -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00001845<div class="doc_subsubsection">
1846 <a name="i_free">'<tt>free</tt>' Instruction</a>
1847</div>
1848
Misha Brukman9d0919f2003-11-08 01:05:38 +00001849<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00001850
Chris Lattner00950542001-06-06 20:29:01 +00001851<h5>Syntax:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001852
1853<pre>
1854 free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner00950542001-06-06 20:29:01 +00001855</pre>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001856
Chris Lattner00950542001-06-06 20:29:01 +00001857<h5>Overview:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001858
Chris Lattner261efe92003-11-25 01:02:51 +00001859<p>The '<tt>free</tt>' instruction returns memory back to the unused
John Criswellc1f786c2005-05-13 22:25:59 +00001860memory heap to be reallocated in the future.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001861
Chris Lattner00950542001-06-06 20:29:01 +00001862<h5>Arguments:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001863
Chris Lattner261efe92003-11-25 01:02:51 +00001864<p>'<tt>value</tt>' shall be a pointer value that points to a value
1865that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1866instruction.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001867
Chris Lattner00950542001-06-06 20:29:01 +00001868<h5>Semantics:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001869
John Criswell9e2485c2004-12-10 15:51:16 +00001870<p>Access to the memory pointed to by the pointer is no longer defined
Chris Lattner261efe92003-11-25 01:02:51 +00001871after this instruction executes.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001872
Chris Lattner00950542001-06-06 20:29:01 +00001873<h5>Example:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001874
1875<pre>
1876 %array = <a href="#i_malloc">malloc</a> [4 x ubyte] <i>; yields {[4 x ubyte]*}:array</i>
Chris Lattner00950542001-06-06 20:29:01 +00001877 free [4 x ubyte]* %array
1878</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001879</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001880
Chris Lattner00950542001-06-06 20:29:01 +00001881<!-- _______________________________________________________________________ -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00001882<div class="doc_subsubsection">
1883 <a name="i_alloca">'<tt>alloca</tt>' Instruction</a>
1884</div>
1885
Misha Brukman9d0919f2003-11-08 01:05:38 +00001886<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00001887
Chris Lattner00950542001-06-06 20:29:01 +00001888<h5>Syntax:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001889
1890<pre>
1891 &lt;result&gt; = alloca &lt;type&gt;[, uint &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001892</pre>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001893
Chris Lattner00950542001-06-06 20:29:01 +00001894<h5>Overview:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001895
Chris Lattner261efe92003-11-25 01:02:51 +00001896<p>The '<tt>alloca</tt>' instruction allocates memory on the current
1897stack frame of the procedure that is live until the current function
1898returns to its caller.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001899
Chris Lattner00950542001-06-06 20:29:01 +00001900<h5>Arguments:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001901
John Criswell9e2485c2004-12-10 15:51:16 +00001902<p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001903bytes of memory on the runtime stack, returning a pointer of the
Chris Lattner2cbdc452005-11-06 08:02:57 +00001904appropriate type to the program. If "NumElements" is specified, it is the
1905number of elements allocated. If an alignment is specified, the value result
1906of the allocation is guaranteed to be aligned to at least that boundary. If
1907not specified, or if zero, the target can choose to align the allocation on any
1908convenient boundary.</p>
1909
Misha Brukman9d0919f2003-11-08 01:05:38 +00001910<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001911
Chris Lattner00950542001-06-06 20:29:01 +00001912<h5>Semantics:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001913
John Criswellc1f786c2005-05-13 22:25:59 +00001914<p>Memory is allocated; a pointer is returned. '<tt>alloca</tt>'d
Chris Lattner261efe92003-11-25 01:02:51 +00001915memory is automatically released when the function returns. The '<tt>alloca</tt>'
1916instruction is commonly used to represent automatic variables that must
1917have an address available. When the function returns (either with the <tt><a
John Criswelldae2e932005-05-12 16:55:34 +00001918 href="#i_ret">ret</a></tt> or <tt><a href="#i_unwind">unwind</a></tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001919instructions), the memory is reclaimed.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001920
Chris Lattner00950542001-06-06 20:29:01 +00001921<h5>Example:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001922
1923<pre>
1924 %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001925 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001926 %ptr = alloca int, uint 4, align 1024 <i>; yields {int*}:ptr</i>
1927 %ptr = alloca int, align 1024 <i>; yields {int*}:ptr</i>
Chris Lattner00950542001-06-06 20:29:01 +00001928</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001929</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001930
Chris Lattner00950542001-06-06 20:29:01 +00001931<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001932<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1933Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001934<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00001935<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001936<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 +00001937<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001938<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001939<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001940<p>The argument to the '<tt>load</tt>' instruction specifies the memory
John Criswell0ec250c2005-10-24 16:17:18 +00001941address from which to load. The pointer must point to a <a
Chris Lattnere53e5082004-06-03 22:57:15 +00001942 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
John Criswell0ec250c2005-10-24 16:17:18 +00001943marked as <tt>volatile</tt>, then the optimizer is not allowed to modify
Chris Lattner261efe92003-11-25 01:02:51 +00001944the number or order of execution of this <tt>load</tt> with other
1945volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1946instructions. </p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001947<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001948<p>The location of memory pointed to is loaded.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001949<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001950<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1951 <a
1952 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001953 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1954</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001955</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001956<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001957<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1958Instruction</a> </div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001959<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001960<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 +00001961 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 +00001962</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001963<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001964<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001965<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001966<p>There are two arguments to the '<tt>store</tt>' instruction: a value
John Criswell0ec250c2005-10-24 16:17:18 +00001967to store and an address in which to store it. The type of the '<tt>&lt;pointer&gt;</tt>'
Chris Lattner261efe92003-11-25 01:02:51 +00001968operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
John Criswellc1f786c2005-05-13 22:25:59 +00001969operand. If the <tt>store</tt> is marked as <tt>volatile</tt>, then the
Chris Lattner261efe92003-11-25 01:02:51 +00001970optimizer is not allowed to modify the number or order of execution of
1971this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1972 href="#i_store">store</a></tt> instructions.</p>
1973<h5>Semantics:</h5>
1974<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
1975at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001976<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001977<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1978 <a
1979 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001980 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1981</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001982<!-- _______________________________________________________________________ -->
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001983<div class="doc_subsubsection">
1984 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
1985</div>
1986
Misha Brukman9d0919f2003-11-08 01:05:38 +00001987<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00001988<h5>Syntax:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001989<pre>
1990 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
1991</pre>
1992
Chris Lattner7faa8832002-04-14 06:13:44 +00001993<h5>Overview:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001994
1995<p>
1996The '<tt>getelementptr</tt>' instruction is used to get the address of a
1997subelement of an aggregate data structure.</p>
1998
Chris Lattner7faa8832002-04-14 06:13:44 +00001999<h5>Arguments:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002000
2001<p>This instruction takes a list of integer constants that indicate what
2002elements of the aggregate object to index to. The actual types of the arguments
2003provided depend on the type of the first pointer argument. The
2004'<tt>getelementptr</tt>' instruction is used to index down through the type
John Criswellfc6b8952005-05-16 16:17:45 +00002005levels of a structure or to a specific index in an array. When indexing into a
2006structure, only <tt>uint</tt>
John Criswellc1f786c2005-05-13 22:25:59 +00002007integer constants are allowed. When indexing into an array or pointer,
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002008<tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
2009
Chris Lattner261efe92003-11-25 01:02:51 +00002010<p>For example, let's consider a C code fragment and how it gets
2011compiled to LLVM:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002012
2013<pre>
2014 struct RT {
2015 char A;
2016 int B[10][20];
2017 char C;
2018 };
2019 struct ST {
2020 int X;
2021 double Y;
2022 struct RT Z;
2023 };
2024
2025 int *foo(struct ST *s) {
2026 return &amp;s[1].Z.B[5][13];
2027 }
2028</pre>
2029
Misha Brukman9d0919f2003-11-08 01:05:38 +00002030<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002031
2032<pre>
2033 %RT = type { sbyte, [10 x [20 x int]], sbyte }
2034 %ST = type { int, double, %RT }
2035
Brian Gaeke7283e7c2004-07-02 21:08:14 +00002036 implementation
2037
2038 int* %foo(%ST* %s) {
2039 entry:
2040 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002041 ret int* %reg
2042 }
2043</pre>
2044
Chris Lattner7faa8832002-04-14 06:13:44 +00002045<h5>Semantics:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002046
2047<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
John Criswellc1f786c2005-05-13 22:25:59 +00002048on the pointer type that is being indexed into. <a href="#t_pointer">Pointer</a>
Chris Lattnere53e5082004-06-03 22:57:15 +00002049and <a href="#t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
2050<tt>ulong</tt>, or <tt>long</tt> values, and <a href="#t_struct">structure</a>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002051types require <tt>uint</tt> <b>constants</b>.</p>
2052
Misha Brukman9d0919f2003-11-08 01:05:38 +00002053<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002054type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
2055}</tt>' type, a structure. The second index indexes into the third element of
2056the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
2057sbyte }</tt>' type, another structure. The third index indexes into the second
2058element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
2059array. The two dimensions of the array are subscripted into, yielding an
John Criswellfc6b8952005-05-16 16:17:45 +00002060'<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction returns a pointer
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002061to this element, thus computing a value of '<tt>int*</tt>' type.</p>
2062
Chris Lattner261efe92003-11-25 01:02:51 +00002063<p>Note that it is perfectly legal to index partially through a
2064structure, returning a pointer to an inner element. Because of this,
2065the LLVM code for the given testcase is equivalent to:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002066
2067<pre>
Chris Lattnerd4f6b172005-03-07 22:13:59 +00002068 int* %foo(%ST* %s) {
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002069 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
2070 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
2071 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
2072 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
2073 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
2074 ret int* %t5
2075 }
Chris Lattner6536cfe2002-05-06 22:08:29 +00002076</pre>
Chris Lattnere67a9512005-06-24 17:22:57 +00002077
2078<p>Note that it is undefined to access an array out of bounds: array and
2079pointer indexes must always be within the defined bounds of the array type.
2080The one exception for this rules is zero length arrays. These arrays are
2081defined to be accessible as variable length arrays, which requires access
2082beyond the zero'th element.</p>
2083
Chris Lattner7faa8832002-04-14 06:13:44 +00002084<h5>Example:</h5>
Chris Lattnere67a9512005-06-24 17:22:57 +00002085
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002086<pre>
2087 <i>; yields [12 x ubyte]*:aptr</i>
2088 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
2089</pre>
2090
2091</div>
Chris Lattner00950542001-06-06 20:29:01 +00002092<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00002093<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002094<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +00002095<p>The instructions in this category are the "miscellaneous"
Chris Lattner261efe92003-11-25 01:02:51 +00002096instructions, which defy better classification.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002097</div>
Chris Lattner00950542001-06-06 20:29:01 +00002098<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00002099<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
2100Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002101<div class="doc_text">
Chris Lattner33ba0d92001-07-09 00:26:23 +00002102<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002103<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner33ba0d92001-07-09 00:26:23 +00002104<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002105<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
2106the SSA graph representing the function.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00002107<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002108<p>The type of the incoming values are specified with the first type
2109field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
2110as arguments, with one pair for each predecessor basic block of the
2111current block. Only values of <a href="#t_firstclass">first class</a>
2112type may be used as the value arguments to the PHI node. Only labels
2113may be used as the label arguments.</p>
2114<p>There must be no non-phi instructions between the start of a basic
2115block and the PHI instructions: i.e. PHI instructions must be first in
2116a basic block.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00002117<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002118<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
2119value specified by the parameter, depending on which basic block we
2120came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00002121<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002122<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 +00002123</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002124
Chris Lattner6536cfe2002-05-06 22:08:29 +00002125<!-- _______________________________________________________________________ -->
Chris Lattnercc37aae2004-03-12 05:50:16 +00002126<div class="doc_subsubsection">
2127 <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
2128</div>
2129
Misha Brukman9d0919f2003-11-08 01:05:38 +00002130<div class="doc_text">
Chris Lattnercc37aae2004-03-12 05:50:16 +00002131
Chris Lattner6536cfe2002-05-06 22:08:29 +00002132<h5>Syntax:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002133
2134<pre>
2135 &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 +00002136</pre>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002137
Chris Lattner6536cfe2002-05-06 22:08:29 +00002138<h5>Overview:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002139
2140<p>
2141The '<tt>cast</tt>' instruction is used as the primitive means to convert
2142integers to floating point, change data type sizes, and break type safety (by
2143casting pointers).
2144</p>
2145
2146
Chris Lattner6536cfe2002-05-06 22:08:29 +00002147<h5>Arguments:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002148
2149<p>
2150The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
2151class value, and a type to cast it to, which must also be a <a
2152href="#t_firstclass">first class</a> type.
2153</p>
2154
Chris Lattner6536cfe2002-05-06 22:08:29 +00002155<h5>Semantics:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002156
2157<p>
2158This instruction follows the C rules for explicit casts when determining how the
2159data being cast must change to fit in its new container.
2160</p>
2161
2162<p>
2163When casting to bool, any value that would be considered true in the context of
2164a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
2165all else are '<tt>false</tt>'.
2166</p>
2167
2168<p>
2169When extending an integral value from a type of one signness to another (for
2170example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
2171<b>source</b> value is signed, and zero-extended if the source value is
2172unsigned. <tt>bool</tt> values are always zero extended into either zero or
2173one.
2174</p>
2175
Chris Lattner33ba0d92001-07-09 00:26:23 +00002176<h5>Example:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002177
2178<pre>
2179 %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattner7bae3952002-06-25 18:03:17 +00002180 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner33ba0d92001-07-09 00:26:23 +00002181</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002182</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002183
2184<!-- _______________________________________________________________________ -->
2185<div class="doc_subsubsection">
2186 <a name="i_select">'<tt>select</tt>' Instruction</a>
2187</div>
2188
2189<div class="doc_text">
2190
2191<h5>Syntax:</h5>
2192
2193<pre>
2194 &lt;result&gt; = select bool &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
2195</pre>
2196
2197<h5>Overview:</h5>
2198
2199<p>
2200The '<tt>select</tt>' instruction is used to choose one value based on a
2201condition, without branching.
2202</p>
2203
2204
2205<h5>Arguments:</h5>
2206
2207<p>
2208The '<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.
2209</p>
2210
2211<h5>Semantics:</h5>
2212
2213<p>
2214If the boolean condition evaluates to true, the instruction returns the first
John Criswellfc6b8952005-05-16 16:17:45 +00002215value argument; otherwise, it returns the second value argument.
Chris Lattnercc37aae2004-03-12 05:50:16 +00002216</p>
2217
2218<h5>Example:</h5>
2219
2220<pre>
2221 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
2222</pre>
2223</div>
2224
2225
2226
2227
2228
Chris Lattner33ba0d92001-07-09 00:26:23 +00002229<!-- _______________________________________________________________________ -->
Chris Lattner2bff5242005-05-06 05:47:36 +00002230<div class="doc_subsubsection">
2231 <a name="i_call">'<tt>call</tt>' Instruction</a>
2232</div>
2233
Misha Brukman9d0919f2003-11-08 01:05:38 +00002234<div class="doc_text">
Chris Lattner2bff5242005-05-06 05:47:36 +00002235
Chris Lattner00950542001-06-06 20:29:01 +00002236<h5>Syntax:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00002237<pre>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00002238 &lt;result&gt; = [tail] call [<a href="#callingconv">cconv</a>] &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)
Chris Lattner2bff5242005-05-06 05:47:36 +00002239</pre>
2240
Chris Lattner00950542001-06-06 20:29:01 +00002241<h5>Overview:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00002242
Misha Brukman9d0919f2003-11-08 01:05:38 +00002243<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00002244
Chris Lattner00950542001-06-06 20:29:01 +00002245<h5>Arguments:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00002246
Misha Brukman9d0919f2003-11-08 01:05:38 +00002247<p>This instruction requires several arguments:</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00002248
Chris Lattner6536cfe2002-05-06 22:08:29 +00002249<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00002250 <li>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00002251 <p>The optional "tail" marker indicates whether the callee function accesses
2252 any allocas or varargs in the caller. If the "tail" marker is present, the
Chris Lattner2bff5242005-05-06 05:47:36 +00002253 function call is eligible for tail call optimization. Note that calls may
2254 be marked "tail" even if they do not occur before a <a
2255 href="#i_ret"><tt>ret</tt></a> instruction.
Chris Lattner261efe92003-11-25 01:02:51 +00002256 </li>
2257 <li>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00002258 <p>The optional "cconv" marker indicates which <a href="callingconv">calling
2259 convention</a> the call should use. If none is specified, the call defaults
2260 to using C calling conventions.
2261 </li>
2262 <li>
Chris Lattner2bff5242005-05-06 05:47:36 +00002263 <p>'<tt>ty</tt>': shall be the signature of the pointer to function value
2264 being invoked. The argument types must match the types implied by this
John Criswellfc6b8952005-05-16 16:17:45 +00002265 signature. This type can be omitted if the function is not varargs and
2266 if the function type does not return a pointer to a function.</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00002267 </li>
2268 <li>
2269 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to
2270 be invoked. In most cases, this is a direct function invocation, but
2271 indirect <tt>call</tt>s are just as possible, calling an arbitrary pointer
John Criswellfc6b8952005-05-16 16:17:45 +00002272 to function value.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002273 </li>
2274 <li>
2275 <p>'<tt>function args</tt>': argument list whose types match the
Reid Spencera7e302a2005-05-01 22:22:57 +00002276 function signature argument types. All arguments must be of
2277 <a href="#t_firstclass">first class</a> type. If the function signature
2278 indicates the function accepts a variable number of arguments, the extra
2279 arguments can be specified.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002280 </li>
Chris Lattner6536cfe2002-05-06 22:08:29 +00002281</ol>
Chris Lattner2bff5242005-05-06 05:47:36 +00002282
Chris Lattner00950542001-06-06 20:29:01 +00002283<h5>Semantics:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00002284
Chris Lattner261efe92003-11-25 01:02:51 +00002285<p>The '<tt>call</tt>' instruction is used to cause control flow to
2286transfer to a specified function, with its incoming arguments bound to
2287the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
2288instruction in the called function, control flow continues with the
2289instruction after the function call, and the return value of the
2290function is bound to the result argument. This is a simpler case of
2291the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00002292
Chris Lattner00950542001-06-06 20:29:01 +00002293<h5>Example:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00002294
2295<pre>
2296 %retval = call int %test(int %argc)
2297 call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42);
2298 %X = tail call int %foo()
Chris Lattnerbad10ee2005-05-06 22:57:40 +00002299 %Y = tail call <a href="#callingconv">fastcc</a> int %foo()
Chris Lattner2bff5242005-05-06 05:47:36 +00002300</pre>
2301
Misha Brukman9d0919f2003-11-08 01:05:38 +00002302</div>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002303
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002304<!-- _______________________________________________________________________ -->
Chris Lattnere19d7a72004-09-27 21:51:25 +00002305<div class="doc_subsubsection">
Chris Lattnere19d7a72004-09-27 21:51:25 +00002306 <a name="i_vaarg">'<tt>vaarg</tt>' Instruction</a>
2307</div>
2308
Misha Brukman9d0919f2003-11-08 01:05:38 +00002309<div class="doc_text">
Chris Lattnere19d7a72004-09-27 21:51:25 +00002310
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002311<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002312
2313<pre>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002314 &lt;resultval&gt; = va_arg &lt;va_list*&gt; &lt;arglist&gt;, &lt;argty&gt;
Chris Lattnere19d7a72004-09-27 21:51:25 +00002315</pre>
2316
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002317<h5>Overview:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002318
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002319<p>The '<tt>va_arg</tt>' instruction is used to access arguments passed through
Chris Lattnere19d7a72004-09-27 21:51:25 +00002320the "variable argument" area of a function call. It is used to implement the
2321<tt>va_arg</tt> macro in C.</p>
2322
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002323<h5>Arguments:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002324
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002325<p>This instruction takes a <tt>va_list*</tt> value and the type of
2326the argument. It returns a value of the specified argument type and
Jeff Cohen25d4f7e2005-11-11 02:15:27 +00002327increments the <tt>va_list</tt> to point to the next argument. Again, the
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002328actual type of <tt>va_list</tt> is target specific.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002329
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002330<h5>Semantics:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002331
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002332<p>The '<tt>va_arg</tt>' instruction loads an argument of the specified
2333type from the specified <tt>va_list</tt> and causes the
2334<tt>va_list</tt> to point to the next argument. For more information,
2335see the variable argument handling <a href="#int_varargs">Intrinsic
2336Functions</a>.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002337
2338<p>It is legal for this instruction to be called in a function which does not
2339take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002340function.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002341
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002342<p><tt>va_arg</tt> is an LLVM instruction instead of an <a
John Criswellfc6b8952005-05-16 16:17:45 +00002343href="#intrinsics">intrinsic function</a> because it takes a type as an
Chris Lattnere19d7a72004-09-27 21:51:25 +00002344argument.</p>
2345
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002346<h5>Example:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002347
2348<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
2349
Misha Brukman9d0919f2003-11-08 01:05:38 +00002350</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002351
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002352<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00002353<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
2354<!-- *********************************************************************** -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002355
Misha Brukman9d0919f2003-11-08 01:05:38 +00002356<div class="doc_text">
Chris Lattner33aec9e2004-02-12 17:01:32 +00002357
2358<p>LLVM supports the notion of an "intrinsic function". These functions have
John Criswellfc6b8952005-05-16 16:17:45 +00002359well known names and semantics and are required to follow certain
Chris Lattner33aec9e2004-02-12 17:01:32 +00002360restrictions. Overall, these instructions represent an extension mechanism for
2361the LLVM language that does not require changing all of the transformations in
2362LLVM to add to the language (or the bytecode reader/writer, the parser,
2363etc...).</p>
2364
John Criswellfc6b8952005-05-16 16:17:45 +00002365<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix. This
2366prefix is reserved in LLVM for intrinsic names; thus, functions may not be named
Chris Lattner33aec9e2004-02-12 17:01:32 +00002367this. Intrinsic functions must always be external functions: you cannot define
2368the body of intrinsic functions. Intrinsic functions may only be used in call
2369or invoke instructions: it is illegal to take the address of an intrinsic
2370function. Additionally, because intrinsic functions are part of the LLVM
2371language, it is required that they all be documented here if any are added.</p>
2372
2373
John Criswellfc6b8952005-05-16 16:17:45 +00002374<p>To learn how to add an intrinsic function, please see the <a
Chris Lattner590cff32005-05-11 03:35:57 +00002375href="ExtendingLLVM.html">Extending LLVM Guide</a>.
Chris Lattner33aec9e2004-02-12 17:01:32 +00002376</p>
2377
Misha Brukman9d0919f2003-11-08 01:05:38 +00002378</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002379
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002380<!-- ======================================================================= -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002381<div class="doc_subsection">
2382 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
2383</div>
2384
Misha Brukman9d0919f2003-11-08 01:05:38 +00002385<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00002386
Misha Brukman9d0919f2003-11-08 01:05:38 +00002387<p>Variable argument support is defined in LLVM with the <a
Chris Lattner261efe92003-11-25 01:02:51 +00002388 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
2389intrinsic functions. These functions are related to the similarly
2390named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002391
Chris Lattner261efe92003-11-25 01:02:51 +00002392<p>All of these functions operate on arguments that use a
2393target-specific value type "<tt>va_list</tt>". The LLVM assembly
2394language reference manual does not define what this type is, so all
2395transformations should be prepared to handle intrinsics with any type
2396used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002397
Misha Brukman9d0919f2003-11-08 01:05:38 +00002398<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner261efe92003-11-25 01:02:51 +00002399instruction and the variable argument handling intrinsic functions are
2400used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002401
Chris Lattner33aec9e2004-02-12 17:01:32 +00002402<pre>
2403int %test(int %X, ...) {
2404 ; Initialize variable argument processing
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002405 %ap = alloca sbyte*
2406 call void %<a href="#i_va_start">llvm.va_start</a>(sbyte** %ap)
Chris Lattner33aec9e2004-02-12 17:01:32 +00002407
2408 ; Read a single integer argument
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002409 %tmp = va_arg sbyte** %ap, int
Chris Lattner33aec9e2004-02-12 17:01:32 +00002410
2411 ; Demonstrate usage of llvm.va_copy and llvm.va_end
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002412 %aq = alloca sbyte*
Andrew Lenharthd0a4c622005-06-22 20:38:11 +00002413 call void %<a href="#i_va_copy">llvm.va_copy</a>(sbyte** %aq, sbyte** %ap)
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002414 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte** %aq)
Chris Lattner33aec9e2004-02-12 17:01:32 +00002415
2416 ; Stop processing of arguments.
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002417 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte** %ap)
Chris Lattner33aec9e2004-02-12 17:01:32 +00002418 ret int %tmp
2419}
2420</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002421</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002422
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002423<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002424<div class="doc_subsubsection">
2425 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
2426</div>
2427
2428
Misha Brukman9d0919f2003-11-08 01:05:38 +00002429<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002430<h5>Syntax:</h5>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002431<pre> declare void %llvm.va_start(&lt;va_list&gt;* &lt;arglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002432<h5>Overview:</h5>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002433<P>The '<tt>llvm.va_start</tt>' intrinsic initializes
2434<tt>*&lt;arglist&gt;</tt> for subsequent use by <tt><a
2435href="#i_va_arg">va_arg</a></tt>.</p>
2436
2437<h5>Arguments:</h5>
2438
2439<P>The argument is a pointer to a <tt>va_list</tt> element to initialize.</p>
2440
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002441<h5>Semantics:</h5>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002442
2443<P>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
2444macro available in C. In a target-dependent way, it initializes the
2445<tt>va_list</tt> element the argument points to, so that the next call to
2446<tt>va_arg</tt> will produce the first variable argument passed to the function.
2447Unlike the C <tt>va_start</tt> macro, this intrinsic does not need to know the
2448last argument of the function, the compiler can figure that out.</p>
2449
Misha Brukman9d0919f2003-11-08 01:05:38 +00002450</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002451
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002452<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002453<div class="doc_subsubsection">
2454 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
2455</div>
2456
Misha Brukman9d0919f2003-11-08 01:05:38 +00002457<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002458<h5>Syntax:</h5>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002459<pre> declare void %llvm.va_end(&lt;va_list*&gt; &lt;arglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002460<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002461<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
2462which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
2463or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002464<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002465<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002466<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002467<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002468macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
2469Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
2470 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
2471with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002472</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002473
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002474<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002475<div class="doc_subsubsection">
2476 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
2477</div>
2478
Misha Brukman9d0919f2003-11-08 01:05:38 +00002479<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00002480
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002481<h5>Syntax:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002482
2483<pre>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002484 declare void %llvm.va_copy(&lt;va_list&gt;* &lt;destarglist&gt;,
Andrew Lenharthd0a4c622005-06-22 20:38:11 +00002485 &lt;va_list&gt;* &lt;srcarglist&gt;)
Chris Lattnerd7923912004-05-23 21:06:01 +00002486</pre>
2487
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002488<h5>Overview:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002489
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002490<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position from
2491the source argument list to the destination argument list.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002492
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002493<h5>Arguments:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002494
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002495<p>The first argument is a pointer to a <tt>va_list</tt> element to initialize.
Andrew Lenharthd0a4c622005-06-22 20:38:11 +00002496The second argument is a pointer to a <tt>va_list</tt> element to copy from.</p>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002497
Chris Lattnerd7923912004-05-23 21:06:01 +00002498
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002499<h5>Semantics:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002500
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002501<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt> macro
2502available in C. In a target-dependent way, it copies the source
2503<tt>va_list</tt> element into the destination list. This intrinsic is necessary
2504because the <tt><a href="i_va_begin">llvm.va_begin</a></tt> intrinsic may be
Chris Lattnerd7923912004-05-23 21:06:01 +00002505arbitrarily complex and require memory allocation, for example.</p>
2506
Misha Brukman9d0919f2003-11-08 01:05:38 +00002507</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002508
Chris Lattner33aec9e2004-02-12 17:01:32 +00002509<!-- ======================================================================= -->
2510<div class="doc_subsection">
Chris Lattnerd7923912004-05-23 21:06:01 +00002511 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
2512</div>
2513
2514<div class="doc_text">
2515
2516<p>
2517LLVM support for <a href="GarbageCollection.html">Accurate Garbage
2518Collection</a> requires the implementation and generation of these intrinsics.
2519These intrinsics allow identification of <a href="#i_gcroot">GC roots on the
2520stack</a>, as well as garbage collector implementations that require <a
2521href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers.
2522Front-ends for type-safe garbage collected languages should generate these
2523intrinsics to make use of the LLVM garbage collectors. For more details, see <a
2524href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
2525</p>
2526</div>
2527
2528<!-- _______________________________________________________________________ -->
2529<div class="doc_subsubsection">
2530 <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
2531</div>
2532
2533<div class="doc_text">
2534
2535<h5>Syntax:</h5>
2536
2537<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00002538 declare void %llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
Chris Lattnerd7923912004-05-23 21:06:01 +00002539</pre>
2540
2541<h5>Overview:</h5>
2542
John Criswell9e2485c2004-12-10 15:51:16 +00002543<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
Chris Lattnerd7923912004-05-23 21:06:01 +00002544the code generator, and allows some metadata to be associated with it.</p>
2545
2546<h5>Arguments:</h5>
2547
2548<p>The first argument specifies the address of a stack object that contains the
2549root pointer. The second pointer (which must be either a constant or a global
2550value address) contains the meta-data to be associated with the root.</p>
2551
2552<h5>Semantics:</h5>
2553
2554<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
2555location. At compile-time, the code generator generates information to allow
2556the runtime to find the pointer at GC safe points.
2557</p>
2558
2559</div>
2560
2561
2562<!-- _______________________________________________________________________ -->
2563<div class="doc_subsubsection">
2564 <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
2565</div>
2566
2567<div class="doc_text">
2568
2569<h5>Syntax:</h5>
2570
2571<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00002572 declare sbyte* %llvm.gcread(sbyte** %Ptr)
Chris Lattnerd7923912004-05-23 21:06:01 +00002573</pre>
2574
2575<h5>Overview:</h5>
2576
2577<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
2578locations, allowing garbage collector implementations that require read
2579barriers.</p>
2580
2581<h5>Arguments:</h5>
2582
2583<p>The argument is the address to read from, which should be an address
2584allocated from the garbage collector.</p>
2585
2586<h5>Semantics:</h5>
2587
2588<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
2589instruction, but may be replaced with substantially more complex code by the
2590garbage collector runtime, as needed.</p>
2591
2592</div>
2593
2594
2595<!-- _______________________________________________________________________ -->
2596<div class="doc_subsubsection">
2597 <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
2598</div>
2599
2600<div class="doc_text">
2601
2602<h5>Syntax:</h5>
2603
2604<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00002605 declare void %llvm.gcwrite(sbyte* %P1, sbyte** %P2)
Chris Lattnerd7923912004-05-23 21:06:01 +00002606</pre>
2607
2608<h5>Overview:</h5>
2609
2610<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
2611locations, allowing garbage collector implementations that require write
2612barriers (such as generational or reference counting collectors).</p>
2613
2614<h5>Arguments:</h5>
2615
2616<p>The first argument is the reference to store, and the second is the heap
2617location to store to.</p>
2618
2619<h5>Semantics:</h5>
2620
2621<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
2622instruction, but may be replaced with substantially more complex code by the
2623garbage collector runtime, as needed.</p>
2624
2625</div>
2626
2627
2628
2629<!-- ======================================================================= -->
2630<div class="doc_subsection">
Chris Lattner10610642004-02-14 04:08:35 +00002631 <a name="int_codegen">Code Generator Intrinsics</a>
2632</div>
2633
2634<div class="doc_text">
2635<p>
2636These intrinsics are provided by LLVM to expose special features that may only
2637be implemented with code generator support.
2638</p>
2639
2640</div>
2641
2642<!-- _______________________________________________________________________ -->
2643<div class="doc_subsubsection">
2644 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
2645</div>
2646
2647<div class="doc_text">
2648
2649<h5>Syntax:</h5>
2650<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00002651 declare void* %llvm.returnaddress(uint &lt;level&gt;)
Chris Lattner10610642004-02-14 04:08:35 +00002652</pre>
2653
2654<h5>Overview:</h5>
2655
2656<p>
2657The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
2658indicating the return address of the current function or one of its callers.
2659</p>
2660
2661<h5>Arguments:</h5>
2662
2663<p>
2664The argument to this intrinsic indicates which function to return the address
2665for. Zero indicates the calling function, one indicates its caller, etc. The
2666argument is <b>required</b> to be a constant integer value.
2667</p>
2668
2669<h5>Semantics:</h5>
2670
2671<p>
2672The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
2673the return address of the specified call frame, or zero if it cannot be
2674identified. The value returned by this intrinsic is likely to be incorrect or 0
2675for arguments other than zero, so it should only be used for debugging purposes.
2676</p>
2677
2678<p>
2679Note that calling this intrinsic does not prevent function inlining or other
Chris Lattnerb40bb382005-03-07 20:30:51 +00002680aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner10610642004-02-14 04:08:35 +00002681source-language caller.
2682</p>
2683</div>
2684
2685
2686<!-- _______________________________________________________________________ -->
2687<div class="doc_subsubsection">
2688 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
2689</div>
2690
2691<div class="doc_text">
2692
2693<h5>Syntax:</h5>
2694<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00002695 declare void* %llvm.frameaddress(uint &lt;level&gt;)
Chris Lattner10610642004-02-14 04:08:35 +00002696</pre>
2697
2698<h5>Overview:</h5>
2699
2700<p>
2701The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
2702pointer value for the specified stack frame.
2703</p>
2704
2705<h5>Arguments:</h5>
2706
2707<p>
2708The argument to this intrinsic indicates which function to return the frame
2709pointer for. Zero indicates the calling function, one indicates its caller,
2710etc. The argument is <b>required</b> to be a constant integer value.
2711</p>
2712
2713<h5>Semantics:</h5>
2714
2715<p>
2716The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
2717the frame address of the specified call frame, or zero if it cannot be
2718identified. The value returned by this intrinsic is likely to be incorrect or 0
2719for arguments other than zero, so it should only be used for debugging purposes.
2720</p>
2721
2722<p>
2723Note that calling this intrinsic does not prevent function inlining or other
Chris Lattnerb40bb382005-03-07 20:30:51 +00002724aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner10610642004-02-14 04:08:35 +00002725source-language caller.
2726</p>
2727</div>
2728
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00002729<!-- _______________________________________________________________________ -->
2730<div class="doc_subsubsection">
2731 <a name="i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a>
2732</div>
2733
2734<div class="doc_text">
2735
2736<h5>Syntax:</h5>
2737<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00002738 declare void %llvm.prefetch(sbyte * &lt;address&gt;,
2739 uint &lt;rw&gt;, uint &lt;locality&gt;)
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00002740</pre>
2741
2742<h5>Overview:</h5>
2743
2744
2745<p>
2746The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to insert
John Criswellfc6b8952005-05-16 16:17:45 +00002747a prefetch instruction if supported; otherwise, it is a noop. Prefetches have
2748no
2749effect on the behavior of the program but can change its performance
Chris Lattner2a615362005-02-28 19:47:14 +00002750characteristics.
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00002751</p>
2752
2753<h5>Arguments:</h5>
2754
2755<p>
2756<tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier
2757determining if the fetch should be for a read (0) or write (1), and
2758<tt>locality</tt> is a temporal locality specifier ranging from (0) - no
Chris Lattneraeffb4a2005-03-07 20:31:38 +00002759locality, to (3) - extremely local keep in cache. The <tt>rw</tt> and
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00002760<tt>locality</tt> arguments must be constant integers.
2761</p>
2762
2763<h5>Semantics:</h5>
2764
2765<p>
2766This intrinsic does not modify the behavior of the program. In particular,
2767prefetches cannot trap and do not produce a value. On targets that support this
2768intrinsic, the prefetch can provide hints to the processor cache for better
2769performance.
2770</p>
2771
2772</div>
2773
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00002774<!-- _______________________________________________________________________ -->
2775<div class="doc_subsubsection">
2776 <a name="i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a>
2777</div>
2778
2779<div class="doc_text">
2780
2781<h5>Syntax:</h5>
2782<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00002783 declare void %llvm.pcmarker( uint &lt;id&gt; )
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00002784</pre>
2785
2786<h5>Overview:</h5>
2787
2788
2789<p>
John Criswellfc6b8952005-05-16 16:17:45 +00002790The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a Program Counter
2791(PC) in a region of
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00002792code to simulators and other tools. The method is target specific, but it is
2793expected that the marker will use exported symbols to transmit the PC of the marker.
Jeff Cohen25d4f7e2005-11-11 02:15:27 +00002794The marker makes no guarantees that it will remain with any specific instruction
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00002795after optimizations. It is possible that the presense of a marker will inhibit
2796optimizations. The intended use is to be inserted after optmizations to allow
John Criswellfc6b8952005-05-16 16:17:45 +00002797correlations of simulation runs.
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00002798</p>
2799
2800<h5>Arguments:</h5>
2801
2802<p>
2803<tt>id</tt> is a numerical id identifying the marker.
2804</p>
2805
2806<h5>Semantics:</h5>
2807
2808<p>
2809This intrinsic does not modify the behavior of the program. Backends that do not
2810support this intrinisic may ignore it.
2811</p>
2812
2813</div>
2814
Andrew Lenharth51b8d542005-11-11 16:47:30 +00002815<!-- _______________________________________________________________________ -->
2816<div class="doc_subsubsection">
2817 <a name="i_readcyclecounter">'<tt>llvm.readcyclecounter</tt>' Intrinsic</a>
2818</div>
2819
2820<div class="doc_text">
2821
2822<h5>Syntax:</h5>
2823<pre>
2824 declare ulong %llvm.readcyclecounter( )
2825</pre>
2826
2827<h5>Overview:</h5>
2828
2829
2830<p>
2831The '<tt>llvm.readcyclecounter</tt>' intrinsic provides access to the cycle
2832counter register (or similar low latency, high accuracy clocks) on those targets
2833that support it. On X86, it should map to RDTSC. On Alpha, it should map to RPCC.
2834As the backing counters overflow quickly (on the order of 9 seconds on alpha), this
2835should only be used for small timings.
2836</p>
2837
2838<h5>Semantics:</h5>
2839
2840<p>
2841When directly supported, reading the cycle counter should not modify any memory.
2842Implementations are allowed to either return a application specific value or a
2843system wide value. On backends without support, this is lowered to a constant 0.
2844</p>
2845
2846</div>
2847
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00002848
John Criswell7123e272004-04-09 16:43:20 +00002849<!-- ======================================================================= -->
2850<div class="doc_subsection">
2851 <a name="int_os">Operating System Intrinsics</a>
2852</div>
2853
2854<div class="doc_text">
2855<p>
2856These intrinsics are provided by LLVM to support the implementation of
2857operating system level code.
2858</p>
2859
2860</div>
John Criswell183402a2004-04-12 15:02:16 +00002861
John Criswellcfd3bac2004-04-09 15:23:37 +00002862<!-- _______________________________________________________________________ -->
2863<div class="doc_subsubsection">
2864 <a name="i_readport">'<tt>llvm.readport</tt>' Intrinsic</a>
2865</div>
2866
2867<div class="doc_text">
2868
2869<h5>Syntax:</h5>
2870<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00002871 declare &lt;integer type&gt; %llvm.readport (&lt;integer type&gt; &lt;address&gt;)
John Criswellcfd3bac2004-04-09 15:23:37 +00002872</pre>
2873
2874<h5>Overview:</h5>
2875
2876<p>
John Criswell7123e272004-04-09 16:43:20 +00002877The '<tt>llvm.readport</tt>' intrinsic reads data from the specified hardware
2878I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002879</p>
2880
2881<h5>Arguments:</h5>
2882
2883<p>
John Criswell7123e272004-04-09 16:43:20 +00002884The argument to this intrinsic indicates the hardware I/O address from which
2885to read the data. The address is in the hardware I/O address namespace (as
2886opposed to being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002887</p>
2888
2889<h5>Semantics:</h5>
2890
2891<p>
John Criswell7123e272004-04-09 16:43:20 +00002892The '<tt>llvm.readport</tt>' intrinsic reads data from the hardware I/O port
2893specified by <i>address</i> and returns the value. The address and return
2894value must be integers, but the size is dependent upon the platform upon which
2895the program is code generated. For example, on x86, the address must be an
Misha Brukmancfa87bc2005-04-22 18:02:52 +00002896unsigned 16-bit value, and the return value must be 8, 16, or 32 bits.
John Criswellcfd3bac2004-04-09 15:23:37 +00002897</p>
2898
2899</div>
2900
2901<!-- _______________________________________________________________________ -->
2902<div class="doc_subsubsection">
2903 <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a>
2904</div>
2905
2906<div class="doc_text">
2907
2908<h5>Syntax:</h5>
2909<pre>
Chris Lattnerc3f59762004-12-09 17:30:23 +00002910 call void (&lt;integer type&gt;, &lt;integer type&gt;)*
2911 %llvm.writeport (&lt;integer type&gt; &lt;value&gt;,
2912 &lt;integer type&gt; &lt;address&gt;)
John Criswellcfd3bac2004-04-09 15:23:37 +00002913</pre>
2914
2915<h5>Overview:</h5>
2916
2917<p>
John Criswell7123e272004-04-09 16:43:20 +00002918The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified hardware
2919I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002920</p>
2921
2922<h5>Arguments:</h5>
2923
2924<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002925The first argument is the value to write to the I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002926</p>
2927
2928<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002929The second argument indicates the hardware I/O address to which data should be
2930written. The address is in the hardware I/O address namespace (as opposed to
2931being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002932</p>
2933
2934<h5>Semantics:</h5>
2935
2936<p>
2937The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port
2938specified by <i>address</i>. The address and value must be integers, but the
2939size is dependent upon the platform upon which the program is code generated.
Misha Brukmancfa87bc2005-04-22 18:02:52 +00002940For example, on x86, the address must be an unsigned 16-bit value, and the
John Criswell7123e272004-04-09 16:43:20 +00002941value written must be 8, 16, or 32 bits in length.
John Criswellcfd3bac2004-04-09 15:23:37 +00002942</p>
2943
2944</div>
Chris Lattner10610642004-02-14 04:08:35 +00002945
John Criswell183402a2004-04-12 15:02:16 +00002946<!-- _______________________________________________________________________ -->
2947<div class="doc_subsubsection">
2948 <a name="i_readio">'<tt>llvm.readio</tt>' Intrinsic</a>
2949</div>
2950
2951<div class="doc_text">
2952
2953<h5>Syntax:</h5>
2954<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00002955 declare &lt;result&gt; %llvm.readio (&lt;ty&gt; * &lt;pointer&gt;)
John Criswell183402a2004-04-12 15:02:16 +00002956</pre>
2957
2958<h5>Overview:</h5>
2959
2960<p>
2961The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
2962address.
2963</p>
2964
2965<h5>Arguments:</h5>
2966
2967<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002968The argument to this intrinsic is a pointer indicating the memory address from
2969which to read the data. The data must be a
2970<a href="#t_firstclass">first class</a> type.
John Criswell183402a2004-04-12 15:02:16 +00002971</p>
2972
2973<h5>Semantics:</h5>
2974
2975<p>
2976The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
John Criswell96db6fc2004-04-12 16:33:19 +00002977location specified by <i>pointer</i> and returns the value. The argument must
2978be a pointer, and the return value must be a
2979<a href="#t_firstclass">first class</a> type. However, certain architectures
Misha Brukmancfa87bc2005-04-22 18:02:52 +00002980may not support I/O on all first class types. For example, 32-bit processors
John Criswell96db6fc2004-04-12 16:33:19 +00002981may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00002982</p>
2983
2984<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002985This intrinsic enforces an in-order memory model for llvm.readio and
2986llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2987scheduled processors may execute loads and stores out of order, re-ordering at
2988run time accesses to memory mapped I/O registers. Using these intrinsics
2989ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00002990</p>
2991
2992</div>
2993
2994<!-- _______________________________________________________________________ -->
2995<div class="doc_subsubsection">
2996 <a name="i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a>
2997</div>
2998
2999<div class="doc_text">
3000
3001<h5>Syntax:</h5>
3002<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00003003 declare void %llvm.writeio (&lt;ty1&gt; &lt;value&gt;, &lt;ty2&gt; * &lt;pointer&gt;)
John Criswell183402a2004-04-12 15:02:16 +00003004</pre>
3005
3006<h5>Overview:</h5>
3007
3008<p>
3009The '<tt>llvm.writeio</tt>' intrinsic writes data to the specified memory
3010mapped I/O address.
3011</p>
3012
3013<h5>Arguments:</h5>
3014
3015<p>
John Criswell96db6fc2004-04-12 16:33:19 +00003016The first argument is the value to write to the memory mapped I/O location.
3017The second argument is a pointer indicating the memory address to which the
3018data should be written.
John Criswell183402a2004-04-12 15:02:16 +00003019</p>
3020
3021<h5>Semantics:</h5>
3022
3023<p>
3024The '<tt>llvm.writeio</tt>' intrinsic writes <i>value</i> to the memory mapped
John Criswell96db6fc2004-04-12 16:33:19 +00003025I/O address specified by <i>pointer</i>. The value must be a
3026<a href="#t_firstclass">first class</a> type. However, certain architectures
Misha Brukmancfa87bc2005-04-22 18:02:52 +00003027may not support I/O on all first class types. For example, 32-bit processors
John Criswell96db6fc2004-04-12 16:33:19 +00003028may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00003029</p>
3030
3031<p>
John Criswell96db6fc2004-04-12 16:33:19 +00003032This intrinsic enforces an in-order memory model for llvm.readio and
3033llvm.writeio calls on machines that use dynamic scheduling. Dynamically
3034scheduled processors may execute loads and stores out of order, re-ordering at
3035run time accesses to memory mapped I/O registers. Using these intrinsics
3036ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00003037</p>
3038
3039</div>
3040
Chris Lattner10610642004-02-14 04:08:35 +00003041<!-- ======================================================================= -->
3042<div class="doc_subsection">
Chris Lattner33aec9e2004-02-12 17:01:32 +00003043 <a name="int_libc">Standard C Library Intrinsics</a>
3044</div>
3045
3046<div class="doc_text">
3047<p>
Chris Lattner10610642004-02-14 04:08:35 +00003048LLVM provides intrinsics for a few important standard C library functions.
3049These intrinsics allow source-language front-ends to pass information about the
3050alignment of the pointer arguments to the code generator, providing opportunity
3051for more efficient code generation.
Chris Lattner33aec9e2004-02-12 17:01:32 +00003052</p>
3053
3054</div>
3055
3056<!-- _______________________________________________________________________ -->
3057<div class="doc_subsubsection">
3058 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
3059</div>
3060
3061<div class="doc_text">
3062
3063<h5>Syntax:</h5>
3064<pre>
Reid Spencerd4622352005-04-26 20:41:16 +00003065 declare void %llvm.memcpy(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
3066 uint &lt;len&gt;, uint &lt;align&gt;)
Chris Lattner33aec9e2004-02-12 17:01:32 +00003067</pre>
3068
3069<h5>Overview:</h5>
3070
3071<p>
3072The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
3073location to the destination location.
3074</p>
3075
3076<p>
3077Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
3078does not return a value, and takes an extra alignment argument.
3079</p>
3080
3081<h5>Arguments:</h5>
3082
3083<p>
3084The first argument is a pointer to the destination, the second is a pointer to
3085the source. The third argument is an (arbitrarily sized) integer argument
3086specifying the number of bytes to copy, and the fourth argument is the alignment
3087of the source and destination locations.
3088</p>
3089
Chris Lattner3301ced2004-02-12 21:18:15 +00003090<p>
3091If the call to this intrinisic has an alignment value that is not 0 or 1, then
3092the caller guarantees that the size of the copy is a multiple of the alignment
3093and that both the source and destination pointers are aligned to that boundary.
3094</p>
3095
Chris Lattner33aec9e2004-02-12 17:01:32 +00003096<h5>Semantics:</h5>
3097
3098<p>
3099The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
3100location to the destination location, which are not allowed to overlap. It
3101copies "len" bytes of memory over. If the argument is known to be aligned to
3102some boundary, this can be specified as the fourth argument, otherwise it should
3103be set to 0 or 1.
3104</p>
3105</div>
3106
3107
Chris Lattner0eb51b42004-02-12 18:10:10 +00003108<!-- _______________________________________________________________________ -->
3109<div class="doc_subsubsection">
3110 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
3111</div>
3112
3113<div class="doc_text">
3114
3115<h5>Syntax:</h5>
3116<pre>
Reid Spencerd4622352005-04-26 20:41:16 +00003117 declare void %llvm.memmove(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
3118 uint &lt;len&gt;, uint &lt;align&gt;)
Chris Lattner0eb51b42004-02-12 18:10:10 +00003119</pre>
3120
3121<h5>Overview:</h5>
3122
3123<p>
3124The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
3125location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>'
3126intrinsic but allows the two memory locations to overlap.
3127</p>
3128
3129<p>
3130Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
3131does not return a value, and takes an extra alignment argument.
3132</p>
3133
3134<h5>Arguments:</h5>
3135
3136<p>
3137The first argument is a pointer to the destination, the second is a pointer to
3138the source. The third argument is an (arbitrarily sized) integer argument
3139specifying the number of bytes to copy, and the fourth argument is the alignment
3140of the source and destination locations.
3141</p>
3142
Chris Lattner3301ced2004-02-12 21:18:15 +00003143<p>
3144If the call to this intrinisic has an alignment value that is not 0 or 1, then
3145the caller guarantees that the size of the copy is a multiple of the alignment
3146and that both the source and destination pointers are aligned to that boundary.
3147</p>
3148
Chris Lattner0eb51b42004-02-12 18:10:10 +00003149<h5>Semantics:</h5>
3150
3151<p>
3152The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
3153location to the destination location, which may overlap. It
3154copies "len" bytes of memory over. If the argument is known to be aligned to
3155some boundary, this can be specified as the fourth argument, otherwise it should
3156be set to 0 or 1.
3157</p>
3158</div>
3159
Chris Lattner8ff75902004-01-06 05:31:32 +00003160
Chris Lattner10610642004-02-14 04:08:35 +00003161<!-- _______________________________________________________________________ -->
3162<div class="doc_subsubsection">
3163 <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a>
3164</div>
3165
3166<div class="doc_text">
3167
3168<h5>Syntax:</h5>
3169<pre>
Reid Spencerd4622352005-04-26 20:41:16 +00003170 declare void %llvm.memset(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
3171 uint &lt;len&gt;, uint &lt;align&gt;)
Chris Lattner10610642004-02-14 04:08:35 +00003172</pre>
3173
3174<h5>Overview:</h5>
3175
3176<p>
3177The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular
3178byte value.
3179</p>
3180
3181<p>
3182Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
3183does not return a value, and takes an extra alignment argument.
3184</p>
3185
3186<h5>Arguments:</h5>
3187
3188<p>
3189The first argument is a pointer to the destination to fill, the second is the
3190byte value to fill it with, the third argument is an (arbitrarily sized) integer
3191argument specifying the number of bytes to fill, and the fourth argument is the
3192known alignment of destination location.
3193</p>
3194
3195<p>
3196If the call to this intrinisic has an alignment value that is not 0 or 1, then
3197the caller guarantees that the size of the copy is a multiple of the alignment
3198and that the destination pointer is aligned to that boundary.
3199</p>
3200
3201<h5>Semantics:</h5>
3202
3203<p>
3204The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the
3205destination location. If the argument is known to be aligned to some boundary,
3206this can be specified as the fourth argument, otherwise it should be set to 0 or
32071.
3208</p>
3209</div>
3210
3211
Chris Lattner32006282004-06-11 02:28:03 +00003212<!-- _______________________________________________________________________ -->
3213<div class="doc_subsubsection">
Alkis Evlogimenos26bbe932004-06-13 01:16:15 +00003214 <a name="i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a>
3215</div>
3216
3217<div class="doc_text">
3218
3219<h5>Syntax:</h5>
3220<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00003221 declare bool %llvm.isunordered(&lt;float or double&gt; Val1, &lt;float or double&gt; Val2)
Alkis Evlogimenos26bbe932004-06-13 01:16:15 +00003222</pre>
3223
3224<h5>Overview:</h5>
3225
3226<p>
3227The '<tt>llvm.isunordered</tt>' intrinsic returns true if either or both of the
3228specified floating point values is a NAN.
3229</p>
3230
3231<h5>Arguments:</h5>
3232
3233<p>
3234The arguments are floating point numbers of the same type.
3235</p>
3236
3237<h5>Semantics:</h5>
3238
3239<p>
3240If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise
3241false.
3242</p>
3243</div>
3244
3245
Chris Lattnera4d74142005-07-21 01:29:16 +00003246<!-- _______________________________________________________________________ -->
3247<div class="doc_subsubsection">
3248 <a name="i_sqrt">'<tt>llvm.sqrt</tt>' Intrinsic</a>
3249</div>
3250
3251<div class="doc_text">
3252
3253<h5>Syntax:</h5>
3254<pre>
3255 declare &lt;float or double&gt; %llvm.sqrt(&lt;float or double&gt; Val)
3256</pre>
3257
3258<h5>Overview:</h5>
3259
3260<p>
3261The '<tt>llvm.sqrt</tt>' intrinsic returns the sqrt of the specified operand,
3262returning the same value as the libm '<tt>sqrt</tt>' function would. Unlike
3263<tt>sqrt</tt> in libm, however, <tt>llvm.sqrt</tt> has undefined behavior for
3264negative numbers (which allows for better optimization).
3265</p>
3266
3267<h5>Arguments:</h5>
3268
3269<p>
3270The argument and return value are floating point numbers of the same type.
3271</p>
3272
3273<h5>Semantics:</h5>
3274
3275<p>
3276This function returns the sqrt of the specified operand if it is a positive
3277floating point number.
3278</p>
3279</div>
3280
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003281<!-- ======================================================================= -->
3282<div class="doc_subsection">
3283 <a name="int_count">Bit Counting Intrinsics</a>
3284</div>
3285
3286<div class="doc_text">
3287<p>
3288LLVM provides intrinsics for a few important bit counting operations.
3289These allow efficient code generation for some algorithms.
3290</p>
3291
3292</div>
3293
3294<!-- _______________________________________________________________________ -->
3295<div class="doc_subsubsection">
3296 <a name="int_ctpop">'<tt>llvm.ctpop</tt>' Intrinsic</a>
3297</div>
3298
3299<div class="doc_text">
3300
3301<h5>Syntax:</h5>
3302<pre>
3303 declare int %llvm.ctpop(int &lt;src&gt;)
3304
3305</pre>
3306
3307<h5>Overview:</h5>
3308
3309<p>
3310The '<tt>llvm.ctpop</tt>' intrinsic counts the number of ones in a variable.
3311</p>
3312
3313<h5>Arguments:</h5>
3314
3315<p>
Chris Lattnercfe6b372005-05-07 01:46:40 +00003316The only argument is the value to be counted. The argument may be of any
3317integer type. The return type must match the argument type.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003318</p>
3319
3320<h5>Semantics:</h5>
3321
3322<p>
3323The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable.
3324</p>
3325</div>
3326
3327<!-- _______________________________________________________________________ -->
3328<div class="doc_subsubsection">
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003329 <a name="int_ctlz">'<tt>llvm.ctlz</tt>' Intrinsic</a>
3330</div>
3331
3332<div class="doc_text">
3333
3334<h5>Syntax:</h5>
3335<pre>
3336 declare int %llvm.ctlz(int &lt;src&gt;)
3337
3338</pre>
3339
3340<h5>Overview:</h5>
3341
3342<p>
Chris Lattnercfe6b372005-05-07 01:46:40 +00003343The '<tt>llvm.ctlz</tt>' intrinsic counts the number of leading zeros in a
3344variable.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003345</p>
3346
3347<h5>Arguments:</h5>
3348
3349<p>
Chris Lattnercfe6b372005-05-07 01:46:40 +00003350The only argument is the value to be counted. The argument may be of any
3351integer type. The return type must match the argument type.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003352</p>
3353
3354<h5>Semantics:</h5>
3355
3356<p>
Chris Lattnereff29ab2005-05-15 19:39:26 +00003357The '<tt>llvm.ctlz</tt>' intrinsic counts the leading (most significant) zeros
3358in a variable. If the src == 0 then the result is the size in bits of the type
3359of src. For example, <tt>llvm.cttz(int 2) = 30</tt>.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003360</p>
3361</div>
Chris Lattner32006282004-06-11 02:28:03 +00003362
3363
Chris Lattnereff29ab2005-05-15 19:39:26 +00003364
3365<!-- _______________________________________________________________________ -->
3366<div class="doc_subsubsection">
3367 <a name="int_cttz">'<tt>llvm.cttz</tt>' Intrinsic</a>
3368</div>
3369
3370<div class="doc_text">
3371
3372<h5>Syntax:</h5>
3373<pre>
3374 declare int %llvm.cttz(int &lt;src&gt;)
3375
3376</pre>
3377
3378<h5>Overview:</h5>
3379
3380<p>
3381The '<tt>llvm.cttz</tt>' intrinsic counts the number of trailing zeros.
3382</p>
3383
3384<h5>Arguments:</h5>
3385
3386<p>
3387The only argument is the value to be counted. The argument may be of any
3388integer type. The return type must match the argument type.
3389</p>
3390
3391<h5>Semantics:</h5>
3392
3393<p>
3394The '<tt>llvm.cttz</tt>' intrinsic counts the trailing (least significant) zeros
3395in a variable. If the src == 0 then the result is the size in bits of the type
3396of src. For example, <tt>llvm.cttz(2) = 1</tt>.
3397</p>
3398</div>
3399
Chris Lattner8ff75902004-01-06 05:31:32 +00003400<!-- ======================================================================= -->
3401<div class="doc_subsection">
3402 <a name="int_debugger">Debugger Intrinsics</a>
3403</div>
3404
3405<div class="doc_text">
3406<p>
3407The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
3408are described in the <a
3409href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
3410Debugging</a> document.
3411</p>
3412</div>
3413
3414
Chris Lattner00950542001-06-06 20:29:01 +00003415<!-- *********************************************************************** -->
Chris Lattner00950542001-06-06 20:29:01 +00003416<hr>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00003417<address>
3418 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
3419 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
3420 <a href="http://validator.w3.org/check/referer"><img
3421 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
3422
3423 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
3424 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
3425 Last modified: $Date$
3426</address>
Misha Brukman9d0919f2003-11-08 01:05:38 +00003427</body>
3428</html>