blob: 72dfd88c1b6019a1073356da0322b96137768b8d [file] [log] [blame]
Misha Brukmanc501f552004-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 Brukman76307852003-11-08 01:05:38 +00003<html>
4<head>
5 <title>LLVM Assembly Language Reference Manual</title>
Reid Spencercb84e432004-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 Brukman76307852003-11-08 01:05:38 +000010 <link rel="stylesheet" href="llvm.css" type="text/css">
11</head>
Chris Lattner757528b0b2004-05-23 21:06:01 +000012
Misha Brukman76307852003-11-08 01:05:38 +000013<body>
Chris Lattner757528b0b2004-05-23 21:06:01 +000014
Chris Lattner48b383b02003-11-25 01:02:51 +000015<div class="doc_title"> LLVM Language Reference Manual </div>
Chris Lattner2f7c9632001-06-06 20:29:01 +000016<ol>
Misha Brukman76307852003-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 Lattner6af02f32004-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 Lattnerd79749a2004-12-09 16:36:40 +000023 <li><a href="#linkage">Linkage Types</a></li>
Chris Lattner0132aff2005-05-06 22:57:40 +000024 <li><a href="#callingconv">Calling Conventions</a></li>
Chris Lattner6af02f32004-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 Lattner2f7c9632001-06-06 20:29:01 +000029 <li><a href="#typesystem">Type System</a>
30 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000031 <li><a href="#t_primitive">Primitive Types</a>
32 <ol>
Misha Brukman76307852003-11-08 01:05:38 +000033 <li><a href="#t_classifications">Type Classifications</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000034 </ol>
35 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000036 <li><a href="#t_derived">Derived Types</a>
37 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000038 <li><a href="#t_array">Array Type</a></li>
Misha Brukman76307852003-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 Lattner48b383b02003-11-25 01:02:51 +000041 <li><a href="#t_struct">Structure Type</a></li>
Chris Lattnerc8cb6952004-08-12 19:12:28 +000042 <li><a href="#t_packed">Packed Type</a></li>
Chris Lattner37b6b092005-04-25 17:34:15 +000043 <li><a href="#t_opaque">Opaque Type</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000044 </ol>
45 </li>
46 </ol>
47 </li>
Chris Lattner6af02f32004-12-09 16:11:40 +000048 <li><a href="#constants">Constants</a>
Chris Lattner74d3f822004-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 Lattner48b383b02003-11-25 01:02:51 +000056 </li>
Chris Lattner2f7c9632001-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 Lattner48b383b02003-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 Brukman76307852003-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 Lattner48b383b02003-11-25 01:02:51 +000065 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
Chris Lattner08b7d5b2004-10-16 18:04:13 +000066 <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000067 </ol>
68 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000069 <li><a href="#binaryops">Binary Operations</a>
70 <ol>
Chris Lattner48b383b02003-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 Brukman76307852003-11-08 01:05:38 +000076 <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000077 </ol>
78 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000079 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
80 <ol>
Misha Brukman76307852003-11-08 01:05:38 +000081 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000082 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman76307852003-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 Lattner48b383b02003-11-25 01:02:51 +000086 </ol>
87 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000088 <li><a href="#memoryops">Memory Access Operations</a>
89 <ol>
Chris Lattner48b383b02003-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 Lattner2f7c9632001-06-06 20:29:01 +000098 <li><a href="#otherops">Other Operations</a>
99 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000100 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +0000101 <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li>
Chris Lattnerb53c28d2004-03-12 05:50:16 +0000102 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000103 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000104 <li><a href="#i_vaarg">'<tt>vaarg</tt>' Instruction</a></li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000105 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000106 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000107 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000108 </li>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +0000109 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +0000110 <ol>
Chris Lattner48b383b02003-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 Lattner757528b0b2004-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 Lattner3649c3a2004-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 Lattnerc8a2c222005-02-28 19:24:19 +0000129 <li><a href="#i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a></li>
Andrew Lenharthb4427912005-03-28 20:05:49 +0000130 <li><a href="#i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a></li>
John Criswellaa1c3c12004-04-09 16:43:20 +0000131 </ol>
132 </li>
133 <li><a href="#int_os">Operating System Intrinsics</a>
134 <ol>
Chris Lattner3b4f4372004-06-11 02:28:03 +0000135 <li><a href="#i_readport">'<tt>llvm.readport</tt>' Intrinsic</a></li>
136 <li><a href="#i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a></li>
John Criswella4501222004-04-12 15:02:16 +0000137 <li><a href="#i_readio">'<tt>llvm.readio</tt>' Intrinsic</a></li>
138 <li><a href="#i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a></li>
Chris Lattner3649c3a2004-02-14 04:08:35 +0000139 </ol>
Chris Lattnerfee11462004-02-12 17:01:32 +0000140 <li><a href="#int_libc">Standard C Library Intrinsics</a>
141 <ol>
142 <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li>
Chris Lattnerf30152e2004-02-12 18:10:10 +0000143 <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li>
Chris Lattner3649c3a2004-02-14 04:08:35 +0000144 <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li>
Alkis Evlogimenos9d740622004-06-12 19:19:14 +0000145 <li><a href="#i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a></li>
Chris Lattner8a8f2e52005-07-21 01:29:16 +0000146 <li><a href="#i_sqrt">'<tt>llvm.sqrt</tt>' Intrinsic</a></li>
147
Chris Lattnerfee11462004-02-12 17:01:32 +0000148 </ol>
149 </li>
Andrew Lenharth1d463522005-05-03 18:01:48 +0000150 <li><a href="#int_count">Bit counting Intrinsics</a>
151 <ol>
152 <li><a href="#int_ctpop">'<tt>llvm.ctpop</tt>' Intrinsic </a></li>
Andrew Lenharth1d463522005-05-03 18:01:48 +0000153 <li><a href="#int_ctlz">'<tt>llvm.ctlz</tt>' Intrinsic </a></li>
Chris Lattnerefa20fa2005-05-15 19:39:26 +0000154 <li><a href="#int_cttz">'<tt>llvm.cttz</tt>' Intrinsic </a></li>
Andrew Lenharth1d463522005-05-03 18:01:48 +0000155 </ol>
156 </li>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000157 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000158 </ol>
159 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000160</ol>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000161
162<div class="doc_author">
163 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
164 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
Misha Brukman76307852003-11-08 01:05:38 +0000165</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000166
Chris Lattner2f7c9632001-06-06 20:29:01 +0000167<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000168<div class="doc_section"> <a name="abstract">Abstract </a></div>
169<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000170
Misha Brukman76307852003-11-08 01:05:38 +0000171<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000172<p>This document is a reference manual for the LLVM assembly language.
173LLVM is an SSA based representation that provides type safety,
174low-level operations, flexibility, and the capability of representing
175'all' high-level languages cleanly. It is the common code
176representation used throughout all phases of the LLVM compilation
177strategy.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000178</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000179
Chris Lattner2f7c9632001-06-06 20:29:01 +0000180<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000181<div class="doc_section"> <a name="introduction">Introduction</a> </div>
182<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000183
Misha Brukman76307852003-11-08 01:05:38 +0000184<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000185
Chris Lattner48b383b02003-11-25 01:02:51 +0000186<p>The LLVM code representation is designed to be used in three
187different forms: as an in-memory compiler IR, as an on-disk bytecode
188representation (suitable for fast loading by a Just-In-Time compiler),
189and as a human readable assembly language representation. This allows
190LLVM to provide a powerful intermediate representation for efficient
191compiler transformations and analysis, while providing a natural means
192to debug and visualize the transformations. The three different forms
193of LLVM are all equivalent. This document describes the human readable
194representation and notation.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000195
John Criswell4a3327e2005-05-13 22:25:59 +0000196<p>The LLVM representation aims to be light-weight and low-level
Chris Lattner48b383b02003-11-25 01:02:51 +0000197while being expressive, typed, and extensible at the same time. It
198aims to be a "universal IR" of sorts, by being at a low enough level
199that high-level ideas may be cleanly mapped to it (similar to how
200microprocessors are "universal IR's", allowing many source languages to
201be mapped to them). By providing type information, LLVM can be used as
202the target of optimizations: for example, through pointer analysis, it
203can be proven that a C automatic variable is never accessed outside of
204the current function... allowing it to be promoted to a simple SSA
205value instead of a memory location.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000206
Misha Brukman76307852003-11-08 01:05:38 +0000207</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000208
Chris Lattner2f7c9632001-06-06 20:29:01 +0000209<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000210<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000211
Misha Brukman76307852003-11-08 01:05:38 +0000212<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000213
Chris Lattner48b383b02003-11-25 01:02:51 +0000214<p>It is important to note that this document describes 'well formed'
215LLVM assembly language. There is a difference between what the parser
216accepts and what is considered 'well formed'. For example, the
217following instruction is syntactically okay, but not well formed:</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000218
219<pre>
220 %x = <a href="#i_add">add</a> int 1, %x
221</pre>
222
Chris Lattner48b383b02003-11-25 01:02:51 +0000223<p>...because the definition of <tt>%x</tt> does not dominate all of
224its uses. The LLVM infrastructure provides a verification pass that may
225be used to verify that an LLVM module is well formed. This pass is
John Criswell4a3327e2005-05-13 22:25:59 +0000226automatically run by the parser after parsing input assembly and by
Chris Lattner48b383b02003-11-25 01:02:51 +0000227the optimizer before it outputs bytecode. The violations pointed out
228by the verifier pass indicate bugs in transformation passes or input to
229the parser.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000230
Chris Lattner48b383b02003-11-25 01:02:51 +0000231<!-- Describe the typesetting conventions here. --> </div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000232
Chris Lattner2f7c9632001-06-06 20:29:01 +0000233<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000234<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000235<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000236
Misha Brukman76307852003-11-08 01:05:38 +0000237<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000238
Chris Lattner48b383b02003-11-25 01:02:51 +0000239<p>LLVM uses three different forms of identifiers, for different
240purposes:</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000241
Chris Lattner2f7c9632001-06-06 20:29:01 +0000242<ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000243 <li>Named values are represented as a string of characters with a '%' prefix.
244 For example, %foo, %DivisionByZero, %a.really.long.identifier. The actual
245 regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
246 Identifiers which require other characters in their names can be surrounded
247 with quotes. In this way, anything except a <tt>"</tt> character can be used
248 in a name.</li>
249
250 <li>Unnamed values are represented as an unsigned numeric value with a '%'
251 prefix. For example, %12, %2, %44.</li>
252
Reid Spencer8f08d802004-12-09 18:02:53 +0000253 <li>Constants, which are described in a <a href="#constants">section about
254 constants</a>, below.</li>
Misha Brukman76307852003-11-08 01:05:38 +0000255</ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000256
257<p>LLVM requires that values start with a '%' sign for two reasons: Compilers
258don't need to worry about name clashes with reserved words, and the set of
259reserved words may be expanded in the future without penalty. Additionally,
260unnamed identifiers allow a compiler to quickly come up with a temporary
261variable without having to avoid symbol table conflicts.</p>
262
Chris Lattner48b383b02003-11-25 01:02:51 +0000263<p>Reserved words in LLVM are very similar to reserved words in other
264languages. There are keywords for different opcodes ('<tt><a
Chris Lattnerd79749a2004-12-09 16:36:40 +0000265href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
266href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
267href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>', etc...),
268and others. These reserved words cannot conflict with variable names, because
269none of them start with a '%' character.</p>
270
271<p>Here is an example of LLVM code to multiply the integer variable
272'<tt>%X</tt>' by 8:</p>
273
Misha Brukman76307852003-11-08 01:05:38 +0000274<p>The easy way:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000275
276<pre>
277 %result = <a href="#i_mul">mul</a> uint %X, 8
278</pre>
279
Misha Brukman76307852003-11-08 01:05:38 +0000280<p>After strength reduction:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000281
282<pre>
283 %result = <a href="#i_shl">shl</a> uint %X, ubyte 3
284</pre>
285
Misha Brukman76307852003-11-08 01:05:38 +0000286<p>And the hard way:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000287
288<pre>
289 <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
290 <a href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
291 %result = <a href="#i_add">add</a> uint %1, %1
292</pre>
293
Chris Lattner48b383b02003-11-25 01:02:51 +0000294<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
295important lexical features of LLVM:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000296
Chris Lattner2f7c9632001-06-06 20:29:01 +0000297<ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000298
299 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
300 line.</li>
301
302 <li>Unnamed temporaries are created when the result of a computation is not
303 assigned to a named value.</li>
304
Misha Brukman76307852003-11-08 01:05:38 +0000305 <li>Unnamed temporaries are numbered sequentially</li>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000306
Misha Brukman76307852003-11-08 01:05:38 +0000307</ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000308
John Criswell02fdc6f2005-05-12 16:52:32 +0000309<p>...and it also shows a convention that we follow in this document. When
Chris Lattnerd79749a2004-12-09 16:36:40 +0000310demonstrating instructions, we will follow an instruction with a comment that
311defines the type and name of value produced. Comments are shown in italic
312text.</p>
313
Misha Brukman76307852003-11-08 01:05:38 +0000314</div>
Chris Lattner6af02f32004-12-09 16:11:40 +0000315
316<!-- *********************************************************************** -->
317<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
318<!-- *********************************************************************** -->
319
320<!-- ======================================================================= -->
321<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
322</div>
323
324<div class="doc_text">
325
326<p>LLVM programs are composed of "Module"s, each of which is a
327translation unit of the input programs. Each module consists of
328functions, global variables, and symbol table entries. Modules may be
329combined together with the LLVM linker, which merges function (and
330global variable) definitions, resolves forward declarations, and merges
331symbol table entries. Here is an example of the "hello world" module:</p>
332
333<pre><i>; Declare the string constant as a global constant...</i>
334<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
335 href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00" <i>; [13 x sbyte]*</i>
336
337<i>; External declaration of the puts function</i>
338<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
339
340<i>; Definition of main function</i>
341int %main() { <i>; int()* </i>
342 <i>; Convert [13x sbyte]* to sbyte *...</i>
343 %cast210 = <a
344 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
345
346 <i>; Call puts function to write out the string to stdout...</i>
347 <a
348 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
349 <a
350 href="#i_ret">ret</a> int 0<br>}<br></pre>
351
352<p>This example is made up of a <a href="#globalvars">global variable</a>
353named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
354function, and a <a href="#functionstructure">function definition</a>
355for "<tt>main</tt>".</p>
356
Chris Lattnerd79749a2004-12-09 16:36:40 +0000357<p>In general, a module is made up of a list of global values,
358where both functions and global variables are global values. Global values are
359represented by a pointer to a memory location (in this case, a pointer to an
360array of char, and a pointer to a function), and have one of the following <a
361href="#linkage">linkage types</a>.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000362
Chris Lattnerd79749a2004-12-09 16:36:40 +0000363</div>
364
365<!-- ======================================================================= -->
366<div class="doc_subsection">
367 <a name="linkage">Linkage Types</a>
368</div>
369
370<div class="doc_text">
371
372<p>
373All Global Variables and Functions have one of the following types of linkage:
374</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000375
376<dl>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000377
Chris Lattner6af02f32004-12-09 16:11:40 +0000378 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000379
380 <dd>Global values with internal linkage are only directly accessible by
381 objects in the current module. In particular, linking code into a module with
382 an internal global value may cause the internal to be renamed as necessary to
383 avoid collisions. Because the symbol is internal to the module, all
384 references can be updated. This corresponds to the notion of the
385 '<tt>static</tt>' keyword in C, or the idea of "anonymous namespaces" in C++.
Chris Lattner6af02f32004-12-09 16:11:40 +0000386 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000387
Chris Lattner6af02f32004-12-09 16:11:40 +0000388 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000389
390 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt> linkage, with
391 the twist that linking together two modules defining the same
392 <tt>linkonce</tt> globals will cause one of the globals to be discarded. This
393 is typically used to implement inline functions. Unreferenced
394 <tt>linkonce</tt> globals are allowed to be discarded.
Chris Lattner6af02f32004-12-09 16:11:40 +0000395 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000396
Chris Lattner6af02f32004-12-09 16:11:40 +0000397 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000398
399 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage,
400 except that unreferenced <tt>weak</tt> globals may not be discarded. This is
401 used to implement constructs in C such as "<tt>int X;</tt>" at global scope.
Chris Lattner6af02f32004-12-09 16:11:40 +0000402 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000403
Chris Lattner6af02f32004-12-09 16:11:40 +0000404 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000405
406 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
407 pointer to array type. When two global variables with appending linkage are
408 linked together, the two global arrays are appended together. This is the
409 LLVM, typesafe, equivalent of having the system linker append together
410 "sections" with identical names when .o files are linked.
Chris Lattner6af02f32004-12-09 16:11:40 +0000411 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000412
Chris Lattner6af02f32004-12-09 16:11:40 +0000413 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000414
415 <dd>If none of the above identifiers are used, the global is externally
416 visible, meaning that it participates in linkage and can be used to resolve
417 external symbol references.
Chris Lattner6af02f32004-12-09 16:11:40 +0000418 </dd>
419</dl>
420
Chris Lattner6af02f32004-12-09 16:11:40 +0000421<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
422variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
423variable and was linked with this one, one of the two would be renamed,
424preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
425external (i.e., lacking any linkage declarations), they are accessible
426outside of the current module. It is illegal for a function <i>declaration</i>
427to have any linkage type other than "externally visible".</a></p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000428
Chris Lattner6af02f32004-12-09 16:11:40 +0000429</div>
430
431<!-- ======================================================================= -->
432<div class="doc_subsection">
Chris Lattner0132aff2005-05-06 22:57:40 +0000433 <a name="callingconv">Calling Conventions</a>
434</div>
435
436<div class="doc_text">
437
438<p>LLVM <a href="#functionstructure">functions</a>, <a href="#i_call">calls</a>
439and <a href="#i_invoke">invokes</a> can all have an optional calling convention
440specified for the call. The calling convention of any pair of dynamic
441caller/callee must match, or the behavior of the program is undefined. The
442following calling conventions are supported by LLVM, and more may be added in
443the future:</p>
444
445<dl>
446 <dt><b>"<tt>ccc</tt>" - The C calling convention</b>:</dt>
447
448 <dd>This calling convention (the default if no other calling convention is
449 specified) matches the target C calling conventions. This calling convention
John Criswell02fdc6f2005-05-12 16:52:32 +0000450 supports varargs function calls and tolerates some mismatch in the declared
Chris Lattner0132aff2005-05-06 22:57:40 +0000451 prototype and implemented declaration of the function (as does normal C).
452 </dd>
453
454 <dt><b>"<tt>fastcc</tt>" - The fast calling convention</b>:</dt>
455
456 <dd>This calling convention attempts to make calls as fast as possible
457 (e.g. by passing things in registers). This calling convention allows the
458 target to use whatever tricks it wants to produce fast code for the target,
Chris Lattnerc792eb32005-05-06 23:08:23 +0000459 without having to conform to an externally specified ABI. Implementations of
460 this convention should allow arbitrary tail call optimization to be supported.
461 This calling convention does not support varargs and requires the prototype of
462 all callees to exactly match the prototype of the function definition.
Chris Lattner0132aff2005-05-06 22:57:40 +0000463 </dd>
464
465 <dt><b>"<tt>coldcc</tt>" - The cold calling convention</b>:</dt>
466
467 <dd>This calling convention attempts to make code in the caller as efficient
468 as possible under the assumption that the call is not commonly executed. As
469 such, these calls often preserve all registers so that the call does not break
470 any live ranges in the caller side. This calling convention does not support
471 varargs and requires the prototype of all callees to exactly match the
472 prototype of the function definition.
473 </dd>
474
Chris Lattner573f64e2005-05-07 01:46:40 +0000475 <dt><b>"<tt>cc &lt;<em>n</em>&gt;</tt>" - Numbered convention</b>:</dt>
Chris Lattner0132aff2005-05-06 22:57:40 +0000476
477 <dd>Any calling convention may be specified by number, allowing
478 target-specific calling conventions to be used. Target specific calling
479 conventions start at 64.
480 </dd>
Chris Lattner573f64e2005-05-07 01:46:40 +0000481</dl>
Chris Lattner0132aff2005-05-06 22:57:40 +0000482
483<p>More calling conventions can be added/defined on an as-needed basis, to
484support pascal conventions or any other well-known target-independent
485convention.</p>
486
487</div>
488
489<!-- ======================================================================= -->
490<div class="doc_subsection">
Chris Lattner6af02f32004-12-09 16:11:40 +0000491 <a name="globalvars">Global Variables</a>
492</div>
493
494<div class="doc_text">
495
Chris Lattner5d5aede2005-02-12 19:30:21 +0000496<p>Global variables define regions of memory allocated at compilation time
Chris Lattner54611b42005-11-06 08:02:57 +0000497instead of run-time. Global variables may optionally be initialized, and may
498have an optional explicit alignment specified. A
John Criswell4c0cf7f2005-10-24 16:17:18 +0000499variable may be defined as a global "constant," which indicates that the
Chris Lattner5d5aede2005-02-12 19:30:21 +0000500contents of the variable will <b>never</b> be modified (enabling better
501optimization, allowing the global data to be placed in the read-only section of
502an executable, etc). Note that variables that need runtime initialization
John Criswell4c0cf7f2005-10-24 16:17:18 +0000503cannot be marked "constant" as there is a store to the variable.</p>
Chris Lattner5d5aede2005-02-12 19:30:21 +0000504
505<p>
506LLVM explicitly allows <em>declarations</em> of global variables to be marked
507constant, even if the final definition of the global is not. This capability
508can be used to enable slightly better optimization of the program, but requires
509the language definition to guarantee that optimizations based on the
510'constantness' are valid for the translation units that do not include the
511definition.
512</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000513
514<p>As SSA values, global variables define pointer values that are in
515scope (i.e. they dominate) all basic blocks in the program. Global
516variables always define a pointer to their "content" type because they
517describe a region of memory, and all memory objects in LLVM are
518accessed through pointers.</p>
519
Chris Lattner54611b42005-11-06 08:02:57 +0000520<p>An explicit alignment may be specified for a global. If not present, or if
521the alignment is set to zero, the alignment of the global is set by the target
522to whatever it feels convenient. If an explicit alignment is specified, the
523global is forced to have at least that much alignment. All alignments must be
524a power of 2.</p>
525
Chris Lattner6af02f32004-12-09 16:11:40 +0000526</div>
527
528
529<!-- ======================================================================= -->
530<div class="doc_subsection">
531 <a name="functionstructure">Functions</a>
532</div>
533
534<div class="doc_text">
535
Chris Lattner0132aff2005-05-06 22:57:40 +0000536<p>LLVM function definitions consist of an optional <a href="#linkage">linkage
537type</a>, an optional <a href="#callingconv">calling convention</a>, a return
Chris Lattner54611b42005-11-06 08:02:57 +0000538type, a function name, a (possibly empty) argument list, an optional alignment,
539an opening curly brace,
Chris Lattner0132aff2005-05-06 22:57:40 +0000540a list of basic blocks, and a closing curly brace. LLVM function declarations
541are defined with the "<tt>declare</tt>" keyword, an optional <a
Chris Lattner54611b42005-11-06 08:02:57 +0000542href="#callingconv">calling convention</a>, a return type, a function name,
543a possibly empty list of arguments, and an optional alignment.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000544
545<p>A function definition contains a list of basic blocks, forming the CFG for
546the function. Each basic block may optionally start with a label (giving the
547basic block a symbol table entry), contains a list of instructions, and ends
548with a <a href="#terminators">terminator</a> instruction (such as a branch or
549function return).</p>
550
John Criswell02fdc6f2005-05-12 16:52:32 +0000551<p>The first basic block in a program is special in two ways: it is immediately
Chris Lattner6af02f32004-12-09 16:11:40 +0000552executed on entrance to the function, and it is not allowed to have predecessor
553basic blocks (i.e. there can not be any branches to the entry block of a
554function). Because the block can have no predecessors, it also cannot have any
555<a href="#i_phi">PHI nodes</a>.</p>
556
557<p>LLVM functions are identified by their name and type signature. Hence, two
558functions with the same name but different parameter lists or return values are
Chris Lattner455fc8c2005-03-07 22:13:59 +0000559considered different functions, and LLVM will resolve references to each
Chris Lattner6af02f32004-12-09 16:11:40 +0000560appropriately.</p>
561
Chris Lattner54611b42005-11-06 08:02:57 +0000562<p>An explicit alignment may be specified for a function. If not present, or if
563the alignment is set to zero, the alignment of the function is set by the target
564to whatever it feels convenient. If an explicit alignment is specified, the
565function is forced to have at least that much alignment. All alignments must be
566a power of 2.</p>
567
Chris Lattner6af02f32004-12-09 16:11:40 +0000568</div>
569
570
571
Chris Lattner2f7c9632001-06-06 20:29:01 +0000572<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000573<div class="doc_section"> <a name="typesystem">Type System</a> </div>
574<!-- *********************************************************************** -->
Chris Lattner6af02f32004-12-09 16:11:40 +0000575
Misha Brukman76307852003-11-08 01:05:38 +0000576<div class="doc_text">
Chris Lattner6af02f32004-12-09 16:11:40 +0000577
Misha Brukman76307852003-11-08 01:05:38 +0000578<p>The LLVM type system is one of the most important features of the
Chris Lattner48b383b02003-11-25 01:02:51 +0000579intermediate representation. Being typed enables a number of
580optimizations to be performed on the IR directly, without having to do
581extra analyses on the side before the transformation. A strong type
582system makes it easier to read the generated code and enables novel
583analyses and transformations that are not feasible to perform on normal
584three address code representations.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000585
586</div>
587
Chris Lattner2f7c9632001-06-06 20:29:01 +0000588<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000589<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000590<div class="doc_text">
John Criswell417228d2004-04-09 16:48:45 +0000591<p>The primitive types are the fundamental building blocks of the LLVM
Chris Lattner455fc8c2005-03-07 22:13:59 +0000592system. The current set of primitive types is as follows:</p>
Misha Brukmanc501f552004-03-01 17:47:27 +0000593
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000594<table class="layout">
595 <tr class="layout">
596 <td class="left">
597 <table>
Chris Lattner48b383b02003-11-25 01:02:51 +0000598 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000599 <tr><th>Type</th><th>Description</th></tr>
600 <tr><td><tt>void</tt></td><td>No value</td></tr>
Misha Brukman36c6bc12005-04-22 18:02:52 +0000601 <tr><td><tt>ubyte</tt></td><td>Unsigned 8-bit value</td></tr>
602 <tr><td><tt>ushort</tt></td><td>Unsigned 16-bit value</td></tr>
603 <tr><td><tt>uint</tt></td><td>Unsigned 32-bit value</td></tr>
604 <tr><td><tt>ulong</tt></td><td>Unsigned 64-bit value</td></tr>
605 <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000606 <tr><td><tt>label</tt></td><td>Branch destination</td></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000607 </tbody>
608 </table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000609 </td>
610 <td class="right">
611 <table>
Chris Lattner48b383b02003-11-25 01:02:51 +0000612 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000613 <tr><th>Type</th><th>Description</th></tr>
614 <tr><td><tt>bool</tt></td><td>True or False value</td></tr>
Misha Brukman36c6bc12005-04-22 18:02:52 +0000615 <tr><td><tt>sbyte</tt></td><td>Signed 8-bit value</td></tr>
616 <tr><td><tt>short</tt></td><td>Signed 16-bit value</td></tr>
617 <tr><td><tt>int</tt></td><td>Signed 32-bit value</td></tr>
618 <tr><td><tt>long</tt></td><td>Signed 64-bit value</td></tr>
619 <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000620 </tbody>
621 </table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000622 </td>
623 </tr>
Misha Brukman76307852003-11-08 01:05:38 +0000624</table>
Misha Brukman76307852003-11-08 01:05:38 +0000625</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000626
Chris Lattner2f7c9632001-06-06 20:29:01 +0000627<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000628<div class="doc_subsubsection"> <a name="t_classifications">Type
629Classifications</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000630<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000631<p>These different primitive types fall into a few useful
632classifications:</p>
Misha Brukmanc501f552004-03-01 17:47:27 +0000633
634<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +0000635 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000636 <tr><th>Classification</th><th>Types</th></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000637 <tr>
638 <td><a name="t_signed">signed</a></td>
639 <td><tt>sbyte, short, int, long, float, double</tt></td>
640 </tr>
641 <tr>
642 <td><a name="t_unsigned">unsigned</a></td>
643 <td><tt>ubyte, ushort, uint, ulong</tt></td>
644 </tr>
645 <tr>
646 <td><a name="t_integer">integer</a></td>
647 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
648 </tr>
649 <tr>
650 <td><a name="t_integral">integral</a></td>
Misha Brukman20f9a622004-08-12 20:16:08 +0000651 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt>
652 </td>
Chris Lattner48b383b02003-11-25 01:02:51 +0000653 </tr>
654 <tr>
655 <td><a name="t_floating">floating point</a></td>
656 <td><tt>float, double</tt></td>
657 </tr>
658 <tr>
659 <td><a name="t_firstclass">first class</a></td>
Misha Brukman20f9a622004-08-12 20:16:08 +0000660 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long,<br>
661 float, double, <a href="#t_pointer">pointer</a>,
662 <a href="#t_packed">packed</a></tt></td>
Chris Lattner48b383b02003-11-25 01:02:51 +0000663 </tr>
664 </tbody>
Misha Brukman76307852003-11-08 01:05:38 +0000665</table>
Misha Brukmanc501f552004-03-01 17:47:27 +0000666
Chris Lattner48b383b02003-11-25 01:02:51 +0000667<p>The <a href="#t_firstclass">first class</a> types are perhaps the
668most important. Values of these types are the only ones which can be
669produced by instructions, passed as arguments, or used as operands to
670instructions. This means that all structures and arrays must be
671manipulated either by pointer or by component.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000672</div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000673
Chris Lattner2f7c9632001-06-06 20:29:01 +0000674<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000675<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000676
Misha Brukman76307852003-11-08 01:05:38 +0000677<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +0000678
Chris Lattner48b383b02003-11-25 01:02:51 +0000679<p>The real power in LLVM comes from the derived types in the system.
680This is what allows a programmer to represent arrays, functions,
681pointers, and other useful types. Note that these derived types may be
682recursive: For example, it is possible to have a two dimensional array.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000683
Misha Brukman76307852003-11-08 01:05:38 +0000684</div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000685
Chris Lattner2f7c9632001-06-06 20:29:01 +0000686<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000687<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000688
Misha Brukman76307852003-11-08 01:05:38 +0000689<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +0000690
Chris Lattner2f7c9632001-06-06 20:29:01 +0000691<h5>Overview:</h5>
Chris Lattner74d3f822004-12-09 17:30:23 +0000692
Misha Brukman76307852003-11-08 01:05:38 +0000693<p>The array type is a very simple derived type that arranges elements
Chris Lattner48b383b02003-11-25 01:02:51 +0000694sequentially in memory. The array type requires a size (number of
695elements) and an underlying data type.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000696
Chris Lattner590645f2002-04-14 06:13:44 +0000697<h5>Syntax:</h5>
Chris Lattner74d3f822004-12-09 17:30:23 +0000698
699<pre>
700 [&lt;# elements&gt; x &lt;elementtype&gt;]
701</pre>
702
John Criswell02fdc6f2005-05-12 16:52:32 +0000703<p>The number of elements is a constant integer value; elementtype may
Chris Lattner48b383b02003-11-25 01:02:51 +0000704be any type with a size.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000705
Chris Lattner590645f2002-04-14 06:13:44 +0000706<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000707<table class="layout">
708 <tr class="layout">
709 <td class="left">
710 <tt>[40 x int ]</tt><br/>
711 <tt>[41 x int ]</tt><br/>
712 <tt>[40 x uint]</tt><br/>
713 </td>
714 <td class="left">
715 Array of 40 integer values.<br/>
716 Array of 41 integer values.<br/>
717 Array of 40 unsigned integer values.<br/>
718 </td>
719 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000720</table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000721<p>Here are some examples of multidimensional arrays:</p>
722<table class="layout">
723 <tr class="layout">
724 <td class="left">
725 <tt>[3 x [4 x int]]</tt><br/>
726 <tt>[12 x [10 x float]]</tt><br/>
727 <tt>[2 x [3 x [4 x uint]]]</tt><br/>
728 </td>
729 <td class="left">
John Criswell4a3327e2005-05-13 22:25:59 +0000730 3x4 array of integer values.<br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000731 12x10 array of single precision floating point values.<br/>
732 2x3x4 array of unsigned integer values.<br/>
733 </td>
734 </tr>
735</table>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +0000736
John Criswell4c0cf7f2005-10-24 16:17:18 +0000737<p>Note that 'variable sized arrays' can be implemented in LLVM with a zero
738length array. Normally, accesses past the end of an array are undefined in
Chris Lattnerc0ad71e2005-06-24 17:22:57 +0000739LLVM (e.g. it is illegal to access the 5th element of a 3 element array).
740As a special case, however, zero length arrays are recognized to be variable
741length. This allows implementation of 'pascal style arrays' with the LLVM
742type "{ int, [0 x float]}", for example.</p>
743
Misha Brukman76307852003-11-08 01:05:38 +0000744</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000745
Chris Lattner2f7c9632001-06-06 20:29:01 +0000746<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000747<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000748<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000749<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000750<p>The function type can be thought of as a function signature. It
751consists of a return type and a list of formal parameter types.
John Criswella0d50d22003-11-25 21:45:46 +0000752Function types are usually used to build virtual function tables
Chris Lattner48b383b02003-11-25 01:02:51 +0000753(which are structures of pointers to functions), for indirect function
754calls, and when defining a function.</p>
John Criswella0d50d22003-11-25 21:45:46 +0000755<p>
756The return type of a function type cannot be an aggregate type.
757</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000758<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000759<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
John Criswell4c0cf7f2005-10-24 16:17:18 +0000760<p>...where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
Misha Brukman20f9a622004-08-12 20:16:08 +0000761specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner5ed60612003-09-03 00:41:47 +0000762which indicates that the function takes a variable number of arguments.
763Variable argument functions can access their arguments with the <a
Chris Lattner48b383b02003-11-25 01:02:51 +0000764 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000765<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000766<table class="layout">
767 <tr class="layout">
768 <td class="left">
769 <tt>int (int)</tt> <br/>
770 <tt>float (int, int *) *</tt><br/>
771 <tt>int (sbyte *, ...)</tt><br/>
772 </td>
773 <td class="left">
774 function taking an <tt>int</tt>, returning an <tt>int</tt><br/>
775 <a href="#t_pointer">Pointer</a> to a function that takes an
Misha Brukman20f9a622004-08-12 20:16:08 +0000776 <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000777 returning <tt>float</tt>.<br/>
778 A vararg function that takes at least one <a href="#t_pointer">pointer</a>
779 to <tt>sbyte</tt> (signed char in C), which returns an integer. This is
780 the signature for <tt>printf</tt> in LLVM.<br/>
781 </td>
782 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000783</table>
Misha Brukmanc501f552004-03-01 17:47:27 +0000784
Misha Brukman76307852003-11-08 01:05:38 +0000785</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000786<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000787<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000788<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000789<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000790<p>The structure type is used to represent a collection of data members
791together in memory. The packing of the field types is defined to match
792the ABI of the underlying processor. The elements of a structure may
793be any type that has a size.</p>
794<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
795and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
796field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
797instruction.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000798<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000799<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000800<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000801<table class="layout">
802 <tr class="layout">
803 <td class="left">
804 <tt>{ int, int, int }</tt><br/>
805 <tt>{ float, int (int) * }</tt><br/>
806 </td>
807 <td class="left">
808 a triple of three <tt>int</tt> values<br/>
809 A pair, where the first element is a <tt>float</tt> and the second element
810 is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a>
811 that takes an <tt>int</tt>, returning an <tt>int</tt>.<br/>
812 </td>
813 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000814</table>
Misha Brukman76307852003-11-08 01:05:38 +0000815</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000816
Chris Lattner2f7c9632001-06-06 20:29:01 +0000817<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000818<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000819<div class="doc_text">
Chris Lattner590645f2002-04-14 06:13:44 +0000820<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000821<p>As in many languages, the pointer type represents a pointer or
822reference to another object, which must live in memory.</p>
Chris Lattner590645f2002-04-14 06:13:44 +0000823<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000824<pre> &lt;type&gt; *<br></pre>
Chris Lattner590645f2002-04-14 06:13:44 +0000825<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000826<table class="layout">
827 <tr class="layout">
828 <td class="left">
829 <tt>[4x int]*</tt><br/>
830 <tt>int (int *) *</tt><br/>
831 </td>
832 <td class="left">
833 A <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of
834 four <tt>int</tt> values<br/>
835 A <a href="#t_pointer">pointer</a> to a <a
Chris Lattner16fb0032005-02-19 02:22:14 +0000836 href="#t_function">function</a> that takes an <tt>int*</tt>, returning an
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000837 <tt>int</tt>.<br/>
838 </td>
839 </tr>
Misha Brukman76307852003-11-08 01:05:38 +0000840</table>
Misha Brukman76307852003-11-08 01:05:38 +0000841</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000842
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000843<!-- _______________________________________________________________________ -->
844<div class="doc_subsubsection"> <a name="t_packed">Packed Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000845<div class="doc_text">
Chris Lattner37b6b092005-04-25 17:34:15 +0000846
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000847<h5>Overview:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +0000848
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000849<p>A packed type is a simple derived type that represents a vector
850of elements. Packed types are used when multiple primitive data
851are operated in parallel using a single instruction (SIMD).
852A packed type requires a size (number of
Chris Lattner330ce692005-11-10 01:44:22 +0000853elements) and an underlying primitive data type. Vectors must have a power
854of two length (1, 2, 4, 8, 16 ...). Packed types are
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000855considered <a href="#t_firstclass">first class</a>.</p>
Chris Lattner37b6b092005-04-25 17:34:15 +0000856
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000857<h5>Syntax:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +0000858
859<pre>
860 &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;
861</pre>
862
John Criswell4a3327e2005-05-13 22:25:59 +0000863<p>The number of elements is a constant integer value; elementtype may
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000864be any integral or floating point type.</p>
Chris Lattner37b6b092005-04-25 17:34:15 +0000865
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000866<h5>Examples:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +0000867
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000868<table class="layout">
869 <tr class="layout">
870 <td class="left">
871 <tt>&lt;4 x int&gt;</tt><br/>
872 <tt>&lt;8 x float&gt;</tt><br/>
873 <tt>&lt;2 x uint&gt;</tt><br/>
874 </td>
875 <td class="left">
876 Packed vector of 4 integer values.<br/>
877 Packed vector of 8 floating-point values.<br/>
878 Packed vector of 2 unsigned integer values.<br/>
879 </td>
880 </tr>
881</table>
Misha Brukman76307852003-11-08 01:05:38 +0000882</div>
883
Chris Lattner37b6b092005-04-25 17:34:15 +0000884<!-- _______________________________________________________________________ -->
885<div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div>
886<div class="doc_text">
887
888<h5>Overview:</h5>
889
890<p>Opaque types are used to represent unknown types in the system. This
891corresponds (for example) to the C notion of a foward declared structure type.
892In LLVM, opaque types can eventually be resolved to any type (not just a
893structure type).</p>
894
895<h5>Syntax:</h5>
896
897<pre>
898 opaque
899</pre>
900
901<h5>Examples:</h5>
902
903<table class="layout">
904 <tr class="layout">
905 <td class="left">
906 <tt>opaque</tt>
907 </td>
908 <td class="left">
909 An opaque type.<br/>
910 </td>
911 </tr>
912</table>
913</div>
914
915
Chris Lattner74d3f822004-12-09 17:30:23 +0000916<!-- *********************************************************************** -->
917<div class="doc_section"> <a name="constants">Constants</a> </div>
918<!-- *********************************************************************** -->
919
920<div class="doc_text">
921
922<p>LLVM has several different basic types of constants. This section describes
923them all and their syntax.</p>
924
925</div>
926
927<!-- ======================================================================= -->
Reid Spencer8f08d802004-12-09 18:02:53 +0000928<div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000929
930<div class="doc_text">
931
932<dl>
933 <dt><b>Boolean constants</b></dt>
934
935 <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
936 constants of the <tt><a href="#t_primitive">bool</a></tt> type.
937 </dd>
938
939 <dt><b>Integer constants</b></dt>
940
Reid Spencer8f08d802004-12-09 18:02:53 +0000941 <dd>Standard integers (such as '4') are constants of the <a
Chris Lattner74d3f822004-12-09 17:30:23 +0000942 href="#t_integer">integer</a> type. Negative numbers may be used with signed
943 integer types.
944 </dd>
945
946 <dt><b>Floating point constants</b></dt>
947
948 <dd>Floating point constants use standard decimal notation (e.g. 123.421),
949 exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
Chris Lattner74d3f822004-12-09 17:30:23 +0000950 notation (see below). Floating point constants must have a <a
951 href="#t_floating">floating point</a> type. </dd>
952
953 <dt><b>Null pointer constants</b></dt>
954
John Criswelldfe6a862004-12-10 15:51:16 +0000955 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
Chris Lattner74d3f822004-12-09 17:30:23 +0000956 and must be of <a href="#t_pointer">pointer type</a>.</dd>
957
958</dl>
959
John Criswelldfe6a862004-12-10 15:51:16 +0000960<p>The one non-intuitive notation for constants is the optional hexadecimal form
Chris Lattner74d3f822004-12-09 17:30:23 +0000961of floating point constants. For example, the form '<tt>double
9620x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
9634.5e+15</tt>'. The only time hexadecimal floating point constants are required
Reid Spencer8f08d802004-12-09 18:02:53 +0000964(and the only time that they are generated by the disassembler) is when a
965floating point constant must be emitted but it cannot be represented as a
966decimal floating point number. For example, NaN's, infinities, and other
967special values are represented in their IEEE hexadecimal format so that
968assembly and disassembly do not cause any bits to change in the constants.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000969
970</div>
971
972<!-- ======================================================================= -->
973<div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a>
974</div>
975
976<div class="doc_text">
Chris Lattner455fc8c2005-03-07 22:13:59 +0000977<p>Aggregate constants arise from aggregation of simple constants
978and smaller aggregate constants.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000979
980<dl>
981 <dt><b>Structure constants</b></dt>
982
983 <dd>Structure constants are represented with notation similar to structure
984 type definitions (a comma separated list of elements, surrounded by braces
Chris Lattner455fc8c2005-03-07 22:13:59 +0000985 (<tt>{}</tt>)). For example: "<tt>{ int 4, float 17.0, int* %G }</tt>",
986 where "<tt>%G</tt>" is declared as "<tt>%G = external global int</tt>". Structure constants
987 must have <a href="#t_struct">structure type</a>, and the number and
Chris Lattner74d3f822004-12-09 17:30:23 +0000988 types of elements must match those specified by the type.
989 </dd>
990
991 <dt><b>Array constants</b></dt>
992
993 <dd>Array constants are represented with notation similar to array type
994 definitions (a comma separated list of elements, surrounded by square brackets
John Criswelldfe6a862004-12-10 15:51:16 +0000995 (<tt>[]</tt>)). For example: "<tt>[ int 42, int 11, int 74 ]</tt>". Array
Chris Lattner74d3f822004-12-09 17:30:23 +0000996 constants must have <a href="#t_array">array type</a>, and the number and
997 types of elements must match those specified by the type.
998 </dd>
999
1000 <dt><b>Packed constants</b></dt>
1001
1002 <dd>Packed constants are represented with notation similar to packed type
1003 definitions (a comma separated list of elements, surrounded by
John Criswelldfe6a862004-12-10 15:51:16 +00001004 less-than/greater-than's (<tt>&lt;&gt;</tt>)). For example: "<tt>&lt; int 42,
Chris Lattner74d3f822004-12-09 17:30:23 +00001005 int 11, int 74, int 100 &gt;</tt>". Packed constants must have <a
1006 href="#t_packed">packed type</a>, and the number and types of elements must
1007 match those specified by the type.
1008 </dd>
1009
1010 <dt><b>Zero initialization</b></dt>
1011
1012 <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
1013 value to zero of <em>any</em> type, including scalar and aggregate types.
1014 This is often used to avoid having to print large zero initializers (e.g. for
John Criswell4c0cf7f2005-10-24 16:17:18 +00001015 large arrays) and is always exactly equivalent to using explicit zero
Chris Lattner74d3f822004-12-09 17:30:23 +00001016 initializers.
1017 </dd>
1018</dl>
1019
1020</div>
1021
1022<!-- ======================================================================= -->
1023<div class="doc_subsection">
1024 <a name="globalconstants">Global Variable and Function Addresses</a>
1025</div>
1026
1027<div class="doc_text">
1028
1029<p>The addresses of <a href="#globalvars">global variables</a> and <a
1030href="#functionstructure">functions</a> are always implicitly valid (link-time)
John Criswelldfe6a862004-12-10 15:51:16 +00001031constants. These constants are explicitly referenced when the <a
1032href="#identifiers">identifier for the global</a> is used and always have <a
Chris Lattner74d3f822004-12-09 17:30:23 +00001033href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
1034file:</p>
1035
1036<pre>
1037 %X = global int 17
1038 %Y = global int 42
1039 %Z = global [2 x int*] [ int* %X, int* %Y ]
1040</pre>
1041
1042</div>
1043
1044<!-- ======================================================================= -->
Reid Spencer641f5c92004-12-09 18:13:12 +00001045<div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001046<div class="doc_text">
Reid Spencer641f5c92004-12-09 18:13:12 +00001047 <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has
John Criswell4a3327e2005-05-13 22:25:59 +00001048 no specific value. Undefined values may be of any type and be used anywhere
Reid Spencer641f5c92004-12-09 18:13:12 +00001049 a constant is permitted.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001050
Reid Spencer641f5c92004-12-09 18:13:12 +00001051 <p>Undefined values indicate to the compiler that the program is well defined
1052 no matter what value is used, giving the compiler more freedom to optimize.
1053 </p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001054</div>
1055
1056<!-- ======================================================================= -->
1057<div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
1058</div>
1059
1060<div class="doc_text">
1061
1062<p>Constant expressions are used to allow expressions involving other constants
1063to be used as constants. Constant expressions may be of any <a
John Criswell4a3327e2005-05-13 22:25:59 +00001064href="#t_firstclass">first class</a> type and may involve any LLVM operation
Chris Lattner74d3f822004-12-09 17:30:23 +00001065that does not have side effects (e.g. load and call are not supported). The
1066following is the syntax for constant expressions:</p>
1067
1068<dl>
1069 <dt><b><tt>cast ( CST to TYPE )</tt></b></dt>
1070
1071 <dd>Cast a constant to another type.</dd>
1072
1073 <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
1074
1075 <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
1076 constants. As with the <a href="#i_getelementptr">getelementptr</a>
1077 instruction, the index list may have zero or more indexes, which are required
1078 to make sense for the type of "CSTPTR".</dd>
1079
1080 <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
1081
Reid Spencer641f5c92004-12-09 18:13:12 +00001082 <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
1083 be any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise
Chris Lattner74d3f822004-12-09 17:30:23 +00001084 binary</a> operations. The constraints on operands are the same as those for
1085 the corresponding instruction (e.g. no bitwise operations on floating point
John Criswell02fdc6f2005-05-12 16:52:32 +00001086 values are allowed).</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001087</dl>
Chris Lattner74d3f822004-12-09 17:30:23 +00001088</div>
Chris Lattnerb1652612004-03-08 16:49:10 +00001089
Chris Lattner2f7c9632001-06-06 20:29:01 +00001090<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001091<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
1092<!-- *********************************************************************** -->
Chris Lattner74d3f822004-12-09 17:30:23 +00001093
Misha Brukman76307852003-11-08 01:05:38 +00001094<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00001095
Chris Lattner48b383b02003-11-25 01:02:51 +00001096<p>The LLVM instruction set consists of several different
1097classifications of instructions: <a href="#terminators">terminator
John Criswell4a3327e2005-05-13 22:25:59 +00001098instructions</a>, <a href="#binaryops">binary instructions</a>,
1099<a href="#bitwiseops">bitwise binary instructions</a>, <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001100 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
1101instructions</a>.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001102
Misha Brukman76307852003-11-08 01:05:38 +00001103</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001104
Chris Lattner2f7c9632001-06-06 20:29:01 +00001105<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001106<div class="doc_subsection"> <a name="terminators">Terminator
1107Instructions</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001108
Misha Brukman76307852003-11-08 01:05:38 +00001109<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00001110
Chris Lattner48b383b02003-11-25 01:02:51 +00001111<p>As mentioned <a href="#functionstructure">previously</a>, every
1112basic block in a program ends with a "Terminator" instruction, which
1113indicates which block should be executed after the current block is
1114finished. These terminator instructions typically yield a '<tt>void</tt>'
1115value: they produce control flow, not values (the one exception being
1116the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
John Criswelldfe6a862004-12-10 15:51:16 +00001117<p>There are six different terminator instructions: the '<a
Chris Lattner48b383b02003-11-25 01:02:51 +00001118 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
1119instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001120the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
1121 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
1122 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001123
Misha Brukman76307852003-11-08 01:05:38 +00001124</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001125
Chris Lattner2f7c9632001-06-06 20:29:01 +00001126<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001127<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
1128Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001129<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001130<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001131<pre> ret &lt;type&gt; &lt;value&gt; <i>; Return a value from a non-void function</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001132 ret void <i>; Return from void function</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001133</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001134<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001135<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
John Criswell4a3327e2005-05-13 22:25:59 +00001136value) from a function back to the caller.</p>
John Criswell417228d2004-04-09 16:48:45 +00001137<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner48b383b02003-11-25 01:02:51 +00001138returns a value and then causes control flow, and one that just causes
1139control flow to occur.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001140<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001141<p>The '<tt>ret</tt>' instruction may return any '<a
1142 href="#t_firstclass">first class</a>' type. Notice that a function is
1143not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
1144instruction inside of the function that returns a value that does not
1145match the return type of the function.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001146<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001147<p>When the '<tt>ret</tt>' instruction is executed, control flow
1148returns back to the calling function's context. If the caller is a "<a
John Criswell40db33f2004-06-25 15:16:57 +00001149 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner48b383b02003-11-25 01:02:51 +00001150the instruction after the call. If the caller was an "<a
1151 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
John Criswell02fdc6f2005-05-12 16:52:32 +00001152at the beginning of the "normal" destination block. If the instruction
Chris Lattner48b383b02003-11-25 01:02:51 +00001153returns a value, that value shall set the call or invoke instruction's
1154return value.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001155<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001156<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001157 ret void <i>; Return from a void function</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001158</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001159</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001160<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001161<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001162<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001163<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001164<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 Lattner2f7c9632001-06-06 20:29:01 +00001165</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001166<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001167<p>The '<tt>br</tt>' instruction is used to cause control flow to
1168transfer to a different basic block in the current function. There are
1169two forms of this instruction, corresponding to a conditional branch
1170and an unconditional branch.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001171<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001172<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
1173single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
1174unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
1175value as a target.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001176<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001177<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
1178argument is evaluated. If the value is <tt>true</tt>, control flows
1179to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
1180control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001181<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001182<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
1183 href="#i_ret">ret</a> int 1<br>IfUnequal:<br> <a href="#i_ret">ret</a> int 0<br></pre>
Misha Brukman76307852003-11-08 01:05:38 +00001184</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001185<!-- _______________________________________________________________________ -->
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001186<div class="doc_subsubsection">
1187 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
1188</div>
1189
Misha Brukman76307852003-11-08 01:05:38 +00001190<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001191<h5>Syntax:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001192
1193<pre>
1194 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
1195</pre>
1196
Chris Lattner2f7c9632001-06-06 20:29:01 +00001197<h5>Overview:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001198
1199<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
1200several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman76307852003-11-08 01:05:38 +00001201instruction, allowing a branch to occur to one of many possible
1202destinations.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001203
1204
Chris Lattner2f7c9632001-06-06 20:29:01 +00001205<h5>Arguments:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001206
1207<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
1208comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
1209an array of pairs of comparison value constants and '<tt>label</tt>'s. The
1210table is not allowed to contain duplicate constant entries.</p>
1211
Chris Lattner2f7c9632001-06-06 20:29:01 +00001212<h5>Semantics:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001213
Chris Lattner48b383b02003-11-25 01:02:51 +00001214<p>The <tt>switch</tt> instruction specifies a table of values and
1215destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswellbcbb18c2004-06-25 16:05:06 +00001216table is searched for the given value. If the value is found, control flow is
1217transfered to the corresponding destination; otherwise, control flow is
1218transfered to the default destination.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001219
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001220<h5>Implementation:</h5>
1221
1222<p>Depending on properties of the target machine and the particular
1223<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswellbcbb18c2004-06-25 16:05:06 +00001224ways. For example, it could be generated as a series of chained conditional
1225branches or with a lookup table.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001226
1227<h5>Example:</h5>
1228
1229<pre>
1230 <i>; Emulate a conditional br instruction</i>
1231 %Val = <a href="#i_cast">cast</a> bool %value to int
1232 switch int %Val, label %truedest [int 0, label %falsedest ]
1233
1234 <i>; Emulate an unconditional br instruction</i>
1235 switch uint 0, label %dest [ ]
1236
1237 <i>; Implement a jump table:</i>
1238 switch uint %val, label %otherwise [ uint 0, label %onzero
1239 uint 1, label %onone
1240 uint 2, label %ontwo ]
Chris Lattner2f7c9632001-06-06 20:29:01 +00001241</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001242</div>
Chris Lattner0132aff2005-05-06 22:57:40 +00001243
Chris Lattner2f7c9632001-06-06 20:29:01 +00001244<!-- _______________________________________________________________________ -->
Chris Lattner0132aff2005-05-06 22:57:40 +00001245<div class="doc_subsubsection">
1246 <a name="i_invoke">'<tt>invoke</tt>' Instruction</a>
1247</div>
1248
Misha Brukman76307852003-11-08 01:05:38 +00001249<div class="doc_text">
Chris Lattner0132aff2005-05-06 22:57:40 +00001250
Chris Lattner2f7c9632001-06-06 20:29:01 +00001251<h5>Syntax:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001252
1253<pre>
1254 &lt;result&gt; = invoke [<a href="#callingconv">cconv</a>] &lt;ptr to function ty&gt; %&lt;function ptr val&gt;(&lt;function args&gt;)
1255 to label &lt;normal label&gt; except label &lt;exception label&gt;
1256</pre>
1257
Chris Lattnera8292f32002-05-06 22:08:29 +00001258<h5>Overview:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001259
1260<p>The '<tt>invoke</tt>' instruction causes control to transfer to a specified
1261function, with the possibility of control flow transfer to either the
John Criswell02fdc6f2005-05-12 16:52:32 +00001262'<tt>normal</tt>' label or the
1263'<tt>exception</tt>' label. If the callee function returns with the
Chris Lattner0132aff2005-05-06 22:57:40 +00001264"<tt><a href="#i_ret">ret</a></tt>" instruction, control flow will return to the
1265"normal" label. If the callee (or any indirect callees) returns with the "<a
John Criswell02fdc6f2005-05-12 16:52:32 +00001266href="#i_unwind"><tt>unwind</tt></a>" instruction, control is interrupted and
1267continued at the dynamically nearest "exception" label.</p>
Chris Lattner0132aff2005-05-06 22:57:40 +00001268
Chris Lattner2f7c9632001-06-06 20:29:01 +00001269<h5>Arguments:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001270
Misha Brukman76307852003-11-08 01:05:38 +00001271<p>This instruction requires several arguments:</p>
Chris Lattner0132aff2005-05-06 22:57:40 +00001272
Chris Lattner2f7c9632001-06-06 20:29:01 +00001273<ol>
Chris Lattner0132aff2005-05-06 22:57:40 +00001274 <li>
John Criswell4a3327e2005-05-13 22:25:59 +00001275 The optional "cconv" marker indicates which <a href="callingconv">calling
Chris Lattner0132aff2005-05-06 22:57:40 +00001276 convention</a> the call should use. If none is specified, the call defaults
1277 to using C calling conventions.
1278 </li>
1279 <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to
1280 function value being invoked. In most cases, this is a direct function
1281 invocation, but indirect <tt>invoke</tt>s are just as possible, branching off
1282 an arbitrary pointer to function value.
1283 </li>
1284
1285 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a
1286 function to be invoked. </li>
1287
1288 <li>'<tt>function args</tt>': argument list whose types match the function
1289 signature argument types. If the function signature indicates the function
1290 accepts a variable number of arguments, the extra arguments can be
1291 specified. </li>
1292
1293 <li>'<tt>normal label</tt>': the label reached when the called function
1294 executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
1295
1296 <li>'<tt>exception label</tt>': the label reached when a callee returns with
1297 the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
1298
Chris Lattner2f7c9632001-06-06 20:29:01 +00001299</ol>
Chris Lattner0132aff2005-05-06 22:57:40 +00001300
Chris Lattner2f7c9632001-06-06 20:29:01 +00001301<h5>Semantics:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001302
Misha Brukman76307852003-11-08 01:05:38 +00001303<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner0132aff2005-05-06 22:57:40 +00001304href="#i_call">call</a></tt>' instruction in most regards. The primary
1305difference is that it establishes an association with a label, which is used by
1306the runtime library to unwind the stack.</p>
1307
1308<p>This instruction is used in languages with destructors to ensure that proper
1309cleanup is performed in the case of either a <tt>longjmp</tt> or a thrown
1310exception. Additionally, this is important for implementation of
1311'<tt>catch</tt>' clauses in high-level languages that support them.</p>
1312
Chris Lattner2f7c9632001-06-06 20:29:01 +00001313<h5>Example:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001314<pre>
1315 %retval = invoke int %Test(int 15) to label %Continue
1316 except label %TestCleanup <i>; {int}:retval set</i>
1317 %retval = invoke <a href="#callingconv">coldcc</a> int %Test(int 15) to label %Continue
1318 except label %TestCleanup <i>; {int}:retval set</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001319</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001320</div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001321
1322
Chris Lattner5ed60612003-09-03 00:41:47 +00001323<!-- _______________________________________________________________________ -->
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001324
Chris Lattner48b383b02003-11-25 01:02:51 +00001325<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
1326Instruction</a> </div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001327
Misha Brukman76307852003-11-08 01:05:38 +00001328<div class="doc_text">
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001329
Chris Lattner5ed60612003-09-03 00:41:47 +00001330<h5>Syntax:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001331<pre>
1332 unwind
1333</pre>
1334
Chris Lattner5ed60612003-09-03 00:41:47 +00001335<h5>Overview:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001336
1337<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
1338at the first callee in the dynamic call stack which used an <a
1339href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
1340primarily used to implement exception handling.</p>
1341
Chris Lattner5ed60612003-09-03 00:41:47 +00001342<h5>Semantics:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001343
1344<p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to
1345immediately halt. The dynamic call stack is then searched for the first <a
1346href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
1347execution continues at the "exceptional" destination block specified by the
1348<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
1349dynamic call chain, undefined behavior results.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001350</div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001351
1352<!-- _______________________________________________________________________ -->
1353
1354<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
1355Instruction</a> </div>
1356
1357<div class="doc_text">
1358
1359<h5>Syntax:</h5>
1360<pre>
1361 unreachable
1362</pre>
1363
1364<h5>Overview:</h5>
1365
1366<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
1367instruction is used to inform the optimizer that a particular portion of the
1368code is not reachable. This can be used to indicate that the code after a
1369no-return function cannot be reached, and other facts.</p>
1370
1371<h5>Semantics:</h5>
1372
1373<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
1374</div>
1375
1376
1377
Chris Lattner2f7c9632001-06-06 20:29:01 +00001378<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001379<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001380<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +00001381<p>Binary operators are used to do most of the computation in a
1382program. They require two operands, execute an operation on them, and
John Criswelldfe6a862004-12-10 15:51:16 +00001383produce a single value. The operands might represent
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001384multiple data, as is the case with the <a href="#t_packed">packed</a> data type.
1385The result value of a binary operator is not
Chris Lattner48b383b02003-11-25 01:02:51 +00001386necessarily the same type as its operands.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001387<p>There are several different binary operators:</p>
Misha Brukman76307852003-11-08 01:05:38 +00001388</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001389<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001390<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
1391Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001392<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001393<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001394<pre> &lt;result&gt; = add &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001395</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001396<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001397<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001398<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001399<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001400 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
1401 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1402Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001403<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001404<p>The value produced is the integer or floating point sum of the two
1405operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001406<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001407<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001408</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001409</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001410<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001411<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
1412Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001413<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001414<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001415<pre> &lt;result&gt; = sub &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001416</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001417<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001418<p>The '<tt>sub</tt>' instruction returns the difference of its two
1419operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001420<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
1421instruction present in most other intermediate representations.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001422<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001423<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001424 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001425values.
1426This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1427Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001428<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001429<p>The value produced is the integer or floating point difference of
1430the two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001431<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001432<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001433 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
1434</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001435</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001436<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001437<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
1438Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001439<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001440<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001441<pre> &lt;result&gt; = mul &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001442</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001443<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001444<p>The '<tt>mul</tt>' instruction returns the product of its two
1445operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001446<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001447<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001448 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001449values.
1450This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1451Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001452<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001453<p>The value produced is the integer or floating point product of the
Misha Brukman76307852003-11-08 01:05:38 +00001454two operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001455<p>There is no signed vs unsigned multiplication. The appropriate
1456action is taken based on the type of the operand.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001457<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001458<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001459</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001460</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001461<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001462<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
1463Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001464<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001465<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001466<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1467</pre>
1468<h5>Overview:</h5>
1469<p>The '<tt>div</tt>' instruction returns the quotient of its two
1470operands.</p>
1471<h5>Arguments:</h5>
1472<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
1473 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001474values.
1475This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1476Both arguments must have identical types.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001477<h5>Semantics:</h5>
1478<p>The value produced is the integer or floating point quotient of the
1479two operands.</p>
1480<h5>Example:</h5>
1481<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
1482</pre>
1483</div>
1484<!-- _______________________________________________________________________ -->
1485<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
1486Instruction</a> </div>
1487<div class="doc_text">
1488<h5>Syntax:</h5>
1489<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1490</pre>
1491<h5>Overview:</h5>
1492<p>The '<tt>rem</tt>' instruction returns the remainder from the
1493division of its two operands.</p>
1494<h5>Arguments:</h5>
1495<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1496 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001497values.
1498This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1499Both arguments must have identical types.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001500<h5>Semantics:</h5>
1501<p>This returns the <i>remainder</i> of a division (where the result
1502has the same sign as the divisor), not the <i>modulus</i> (where the
1503result has the same sign as the dividend) of a value. For more
John Criswell4c0cf7f2005-10-24 16:17:18 +00001504information about the difference, see <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001505 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1506Math Forum</a>.</p>
1507<h5>Example:</h5>
1508<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1509</pre>
1510</div>
1511<!-- _______________________________________________________________________ -->
1512<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1513Instructions</a> </div>
1514<div class="doc_text">
1515<h5>Syntax:</h5>
1516<pre> &lt;result&gt; = seteq &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001517 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1518 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1519 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1520 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1521 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1522</pre>
Chris Lattner48b383b02003-11-25 01:02:51 +00001523<h5>Overview:</h5>
1524<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1525value based on a comparison of their two operands.</p>
1526<h5>Arguments:</h5>
1527<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1528be of <a href="#t_firstclass">first class</a> type (it is not possible
1529to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1530or '<tt>void</tt>' values, etc...). Both arguments must have identical
1531types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001532<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001533<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1534value if both operands are equal.<br>
1535The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1536value if both operands are unequal.<br>
1537The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1538value if the first operand is less than the second operand.<br>
1539The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1540value if the first operand is greater than the second operand.<br>
1541The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1542value if the first operand is less than or equal to the second operand.<br>
1543The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1544value if the first operand is greater than or equal to the second
1545operand.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001546<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001547<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001548 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
1549 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1550 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1551 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1552 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1553</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001554</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001555<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001556<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1557Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001558<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +00001559<p>Bitwise binary operators are used to do various forms of
1560bit-twiddling in a program. They are generally very efficient
John Criswelldfe6a862004-12-10 15:51:16 +00001561instructions and can commonly be strength reduced from other
Chris Lattner48b383b02003-11-25 01:02:51 +00001562instructions. They require two operands, execute an operation on them,
1563and produce a single value. The resulting value of the bitwise binary
1564operators is always the same type as its first operand.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001565</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001566<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001567<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1568Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001569<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001570<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001571<pre> &lt;result&gt; = and &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001572</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001573<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001574<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1575its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001576<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001577<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001578 href="#t_integral">integral</a> values. Both arguments must have
1579identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001580<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001581<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001582<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00001583<div style="align: center">
Misha Brukman76307852003-11-08 01:05:38 +00001584<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +00001585 <tbody>
1586 <tr>
1587 <td>In0</td>
1588 <td>In1</td>
1589 <td>Out</td>
1590 </tr>
1591 <tr>
1592 <td>0</td>
1593 <td>0</td>
1594 <td>0</td>
1595 </tr>
1596 <tr>
1597 <td>0</td>
1598 <td>1</td>
1599 <td>0</td>
1600 </tr>
1601 <tr>
1602 <td>1</td>
1603 <td>0</td>
1604 <td>0</td>
1605 </tr>
1606 <tr>
1607 <td>1</td>
1608 <td>1</td>
1609 <td>1</td>
1610 </tr>
1611 </tbody>
1612</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001613</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001614<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001615<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001616 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1617 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1618</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001619</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001620<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001621<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001622<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001623<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001624<pre> &lt;result&gt; = or &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001625</pre>
Chris Lattner48b383b02003-11-25 01:02:51 +00001626<h5>Overview:</h5>
1627<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1628or of its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001629<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001630<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001631 href="#t_integral">integral</a> values. Both arguments must have
1632identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001633<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001634<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001635<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00001636<div style="align: center">
Chris Lattner48b383b02003-11-25 01:02:51 +00001637<table border="1" cellspacing="0" cellpadding="4">
1638 <tbody>
1639 <tr>
1640 <td>In0</td>
1641 <td>In1</td>
1642 <td>Out</td>
1643 </tr>
1644 <tr>
1645 <td>0</td>
1646 <td>0</td>
1647 <td>0</td>
1648 </tr>
1649 <tr>
1650 <td>0</td>
1651 <td>1</td>
1652 <td>1</td>
1653 </tr>
1654 <tr>
1655 <td>1</td>
1656 <td>0</td>
1657 <td>1</td>
1658 </tr>
1659 <tr>
1660 <td>1</td>
1661 <td>1</td>
1662 <td>1</td>
1663 </tr>
1664 </tbody>
1665</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001666</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001667<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001668<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001669 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1670 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1671</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001672</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001673<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001674<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1675Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001676<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001677<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001678<pre> &lt;result&gt; = xor &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001679</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001680<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001681<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1682or of its two operands. The <tt>xor</tt> is used to implement the
1683"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001684<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001685<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001686 href="#t_integral">integral</a> values. Both arguments must have
1687identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001688<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001689<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001690<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00001691<div style="align: center">
Chris Lattner48b383b02003-11-25 01:02:51 +00001692<table border="1" cellspacing="0" cellpadding="4">
1693 <tbody>
1694 <tr>
1695 <td>In0</td>
1696 <td>In1</td>
1697 <td>Out</td>
1698 </tr>
1699 <tr>
1700 <td>0</td>
1701 <td>0</td>
1702 <td>0</td>
1703 </tr>
1704 <tr>
1705 <td>0</td>
1706 <td>1</td>
1707 <td>1</td>
1708 </tr>
1709 <tr>
1710 <td>1</td>
1711 <td>0</td>
1712 <td>1</td>
1713 </tr>
1714 <tr>
1715 <td>1</td>
1716 <td>1</td>
1717 <td>0</td>
1718 </tr>
1719 </tbody>
1720</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001721</div>
Chris Lattner48b383b02003-11-25 01:02:51 +00001722<p> </p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001723<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001724<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001725 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1726 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner5ed60612003-09-03 00:41:47 +00001727 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001728</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001729</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001730<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001731<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1732Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001733<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001734<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001735<pre> &lt;result&gt; = shl &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001736</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001737<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001738<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1739the left a specified number of bits.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001740<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001741<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001742 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1743type.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001744<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001745<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001746<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001747<pre> &lt;result&gt; = shl int 4, ubyte %var <i>; yields {int}:result = 4 &lt;&lt; %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001748 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1749 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1750</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001751</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001752<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001753<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1754Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001755<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001756<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001757<pre> &lt;result&gt; = shr &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001758</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001759<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001760<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1761the right a specified number of bits.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001762<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001763<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001764 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1765type.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001766<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001767<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1768most significant bit is duplicated in the newly free'd bit positions.
1769If the first argument is unsigned, zero bits shall fill the empty
1770positions.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001771<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001772<pre> &lt;result&gt; = shr int 4, ubyte %var <i>; yields {int}:result = 4 &gt;&gt; %var</i>
Chris Lattner33426d92003-06-18 21:30:51 +00001773 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001774 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner33426d92003-06-18 21:30:51 +00001775 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1776 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001777</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001778</div>
Chris Lattner54611b42005-11-06 08:02:57 +00001779
Chris Lattner2f7c9632001-06-06 20:29:01 +00001780<!-- ======================================================================= -->
Chris Lattner54611b42005-11-06 08:02:57 +00001781<div class="doc_subsection">
1782 <a name="memoryops">Memory Access Operations</a>
1783</div>
1784
Misha Brukman76307852003-11-08 01:05:38 +00001785<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00001786
Chris Lattner48b383b02003-11-25 01:02:51 +00001787<p>A key design point of an SSA-based representation is how it
1788represents memory. In LLVM, no memory locations are in SSA form, which
1789makes things very simple. This section describes how to read, write,
John Criswelldfe6a862004-12-10 15:51:16 +00001790allocate, and free memory in LLVM.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001791
Misha Brukman76307852003-11-08 01:05:38 +00001792</div>
Chris Lattner54611b42005-11-06 08:02:57 +00001793
Chris Lattner2f7c9632001-06-06 20:29:01 +00001794<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00001795<div class="doc_subsubsection">
1796 <a name="i_malloc">'<tt>malloc</tt>' Instruction</a>
1797</div>
1798
Misha Brukman76307852003-11-08 01:05:38 +00001799<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00001800
Chris Lattner2f7c9632001-06-06 20:29:01 +00001801<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001802
1803<pre>
1804 &lt;result&gt; = malloc &lt;type&gt;[, uint &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001805</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00001806
Chris Lattner2f7c9632001-06-06 20:29:01 +00001807<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001808
Chris Lattner48b383b02003-11-25 01:02:51 +00001809<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1810heap and returns a pointer to it.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001811
Chris Lattner2f7c9632001-06-06 20:29:01 +00001812<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001813
1814<p>The '<tt>malloc</tt>' instruction allocates
1815<tt>sizeof(&lt;type&gt;)*NumElements</tt>
John Criswella92e5862004-02-24 16:13:56 +00001816bytes of memory from the operating system and returns a pointer of the
Chris Lattner54611b42005-11-06 08:02:57 +00001817appropriate type to the program. If "NumElements" is specified, it is the
1818number of elements allocated. If an alignment is specified, the value result
1819of the allocation is guaranteed to be aligned to at least that boundary. If
1820not specified, or if zero, the target can choose to align the allocation on any
1821convenient boundary.</p>
1822
Misha Brukman76307852003-11-08 01:05:38 +00001823<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001824
Chris Lattner2f7c9632001-06-06 20:29:01 +00001825<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001826
Chris Lattner48b383b02003-11-25 01:02:51 +00001827<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1828a pointer is returned.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001829
Chris Lattner54611b42005-11-06 08:02:57 +00001830<h5>Example:</h5>
1831
1832<pre>
1833 %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
1834
1835 %size = <a href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001836 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1837 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner54611b42005-11-06 08:02:57 +00001838 %array3 = malloc int, uint 4, align 1024 <i>; yields {int*}:array3</i>
1839 %array4 = malloc int, align 1024 <i>; yields {int*}:array4</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001840</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001841</div>
Chris Lattner54611b42005-11-06 08:02:57 +00001842
Chris Lattner2f7c9632001-06-06 20:29:01 +00001843<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00001844<div class="doc_subsubsection">
1845 <a name="i_free">'<tt>free</tt>' Instruction</a>
1846</div>
1847
Misha Brukman76307852003-11-08 01:05:38 +00001848<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00001849
Chris Lattner2f7c9632001-06-06 20:29:01 +00001850<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001851
1852<pre>
1853 free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001854</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00001855
Chris Lattner2f7c9632001-06-06 20:29:01 +00001856<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001857
Chris Lattner48b383b02003-11-25 01:02:51 +00001858<p>The '<tt>free</tt>' instruction returns memory back to the unused
John Criswell4a3327e2005-05-13 22:25:59 +00001859memory heap to be reallocated in the future.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001860
Chris Lattner2f7c9632001-06-06 20:29:01 +00001861<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001862
Chris Lattner48b383b02003-11-25 01:02:51 +00001863<p>'<tt>value</tt>' shall be a pointer value that points to a value
1864that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1865instruction.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001866
Chris Lattner2f7c9632001-06-06 20:29:01 +00001867<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001868
John Criswelldfe6a862004-12-10 15:51:16 +00001869<p>Access to the memory pointed to by the pointer is no longer defined
Chris Lattner48b383b02003-11-25 01:02:51 +00001870after this instruction executes.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001871
Chris Lattner2f7c9632001-06-06 20:29:01 +00001872<h5>Example:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001873
1874<pre>
1875 %array = <a href="#i_malloc">malloc</a> [4 x ubyte] <i>; yields {[4 x ubyte]*}:array</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001876 free [4 x ubyte]* %array
1877</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001878</div>
Chris Lattner54611b42005-11-06 08:02:57 +00001879
Chris Lattner2f7c9632001-06-06 20:29:01 +00001880<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00001881<div class="doc_subsubsection">
1882 <a name="i_alloca">'<tt>alloca</tt>' Instruction</a>
1883</div>
1884
Misha Brukman76307852003-11-08 01:05:38 +00001885<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00001886
Chris Lattner2f7c9632001-06-06 20:29:01 +00001887<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001888
1889<pre>
1890 &lt;result&gt; = alloca &lt;type&gt;[, uint &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001891</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00001892
Chris Lattner2f7c9632001-06-06 20:29:01 +00001893<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001894
Chris Lattner48b383b02003-11-25 01:02:51 +00001895<p>The '<tt>alloca</tt>' instruction allocates memory on the current
1896stack frame of the procedure that is live until the current function
1897returns to its caller.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001898
Chris Lattner2f7c9632001-06-06 20:29:01 +00001899<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001900
John Criswelldfe6a862004-12-10 15:51:16 +00001901<p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00001902bytes of memory on the runtime stack, returning a pointer of the
Chris Lattner54611b42005-11-06 08:02:57 +00001903appropriate type to the program. If "NumElements" is specified, it is the
1904number of elements allocated. If an alignment is specified, the value result
1905of the allocation is guaranteed to be aligned to at least that boundary. If
1906not specified, or if zero, the target can choose to align the allocation on any
1907convenient boundary.</p>
1908
Misha Brukman76307852003-11-08 01:05:38 +00001909<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001910
Chris Lattner2f7c9632001-06-06 20:29:01 +00001911<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001912
John Criswell4a3327e2005-05-13 22:25:59 +00001913<p>Memory is allocated; a pointer is returned. '<tt>alloca</tt>'d
Chris Lattner48b383b02003-11-25 01:02:51 +00001914memory is automatically released when the function returns. The '<tt>alloca</tt>'
1915instruction is commonly used to represent automatic variables that must
1916have an address available. When the function returns (either with the <tt><a
John Criswellc932bef2005-05-12 16:55:34 +00001917 href="#i_ret">ret</a></tt> or <tt><a href="#i_unwind">unwind</a></tt>
Misha Brukman76307852003-11-08 01:05:38 +00001918instructions), the memory is reclaimed.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001919
Chris Lattner2f7c9632001-06-06 20:29:01 +00001920<h5>Example:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001921
1922<pre>
1923 %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001924 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner54611b42005-11-06 08:02:57 +00001925 %ptr = alloca int, uint 4, align 1024 <i>; yields {int*}:ptr</i>
1926 %ptr = alloca int, align 1024 <i>; yields {int*}:ptr</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001927</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001928</div>
Chris Lattner54611b42005-11-06 08:02:57 +00001929
Chris Lattner2f7c9632001-06-06 20:29:01 +00001930<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001931<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1932Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001933<div class="doc_text">
Chris Lattner095735d2002-05-06 03:03:22 +00001934<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001935<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 Lattner095735d2002-05-06 03:03:22 +00001936<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001937<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00001938<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001939<p>The argument to the '<tt>load</tt>' instruction specifies the memory
John Criswell4c0cf7f2005-10-24 16:17:18 +00001940address from which to load. The pointer must point to a <a
Chris Lattner10ee9652004-06-03 22:57:15 +00001941 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
John Criswell4c0cf7f2005-10-24 16:17:18 +00001942marked as <tt>volatile</tt>, then the optimizer is not allowed to modify
Chris Lattner48b383b02003-11-25 01:02:51 +00001943the number or order of execution of this <tt>load</tt> with other
1944volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1945instructions. </p>
Chris Lattner095735d2002-05-06 03:03:22 +00001946<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001947<p>The location of memory pointed to is loaded.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00001948<h5>Examples:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001949<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1950 <a
1951 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner095735d2002-05-06 03:03:22 +00001952 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1953</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001954</div>
Chris Lattner095735d2002-05-06 03:03:22 +00001955<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001956<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1957Instruction</a> </div>
Chris Lattner095735d2002-05-06 03:03:22 +00001958<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001959<pre> store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt; <i>; yields {void}</i>
Chris Lattner12d456c2003-09-08 18:27:49 +00001960 volatile store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt; <i>; yields {void}</i>
Chris Lattner095735d2002-05-06 03:03:22 +00001961</pre>
Chris Lattner095735d2002-05-06 03:03:22 +00001962<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001963<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00001964<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001965<p>There are two arguments to the '<tt>store</tt>' instruction: a value
John Criswell4c0cf7f2005-10-24 16:17:18 +00001966to store and an address in which to store it. The type of the '<tt>&lt;pointer&gt;</tt>'
Chris Lattner48b383b02003-11-25 01:02:51 +00001967operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
John Criswell4a3327e2005-05-13 22:25:59 +00001968operand. If the <tt>store</tt> is marked as <tt>volatile</tt>, then the
Chris Lattner48b383b02003-11-25 01:02:51 +00001969optimizer is not allowed to modify the number or order of execution of
1970this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1971 href="#i_store">store</a></tt> instructions.</p>
1972<h5>Semantics:</h5>
1973<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
1974at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00001975<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001976<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1977 <a
1978 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner095735d2002-05-06 03:03:22 +00001979 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1980</pre>
Chris Lattner095735d2002-05-06 03:03:22 +00001981<!-- _______________________________________________________________________ -->
Chris Lattner33fd7022004-04-05 01:30:49 +00001982<div class="doc_subsubsection">
1983 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
1984</div>
1985
Misha Brukman76307852003-11-08 01:05:38 +00001986<div class="doc_text">
Chris Lattner590645f2002-04-14 06:13:44 +00001987<h5>Syntax:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00001988<pre>
1989 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
1990</pre>
1991
Chris Lattner590645f2002-04-14 06:13:44 +00001992<h5>Overview:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00001993
1994<p>
1995The '<tt>getelementptr</tt>' instruction is used to get the address of a
1996subelement of an aggregate data structure.</p>
1997
Chris Lattner590645f2002-04-14 06:13:44 +00001998<h5>Arguments:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00001999
2000<p>This instruction takes a list of integer constants that indicate what
2001elements of the aggregate object to index to. The actual types of the arguments
2002provided depend on the type of the first pointer argument. The
2003'<tt>getelementptr</tt>' instruction is used to index down through the type
John Criswell88190562005-05-16 16:17:45 +00002004levels of a structure or to a specific index in an array. When indexing into a
2005structure, only <tt>uint</tt>
John Criswell4a3327e2005-05-13 22:25:59 +00002006integer constants are allowed. When indexing into an array or pointer,
Chris Lattner33fd7022004-04-05 01:30:49 +00002007<tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
2008
Chris Lattner48b383b02003-11-25 01:02:51 +00002009<p>For example, let's consider a C code fragment and how it gets
2010compiled to LLVM:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002011
2012<pre>
2013 struct RT {
2014 char A;
2015 int B[10][20];
2016 char C;
2017 };
2018 struct ST {
2019 int X;
2020 double Y;
2021 struct RT Z;
2022 };
2023
2024 int *foo(struct ST *s) {
2025 return &amp;s[1].Z.B[5][13];
2026 }
2027</pre>
2028
Misha Brukman76307852003-11-08 01:05:38 +00002029<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002030
2031<pre>
2032 %RT = type { sbyte, [10 x [20 x int]], sbyte }
2033 %ST = type { int, double, %RT }
2034
Brian Gaeke317ef962004-07-02 21:08:14 +00002035 implementation
2036
2037 int* %foo(%ST* %s) {
2038 entry:
2039 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13
Chris Lattner33fd7022004-04-05 01:30:49 +00002040 ret int* %reg
2041 }
2042</pre>
2043
Chris Lattner590645f2002-04-14 06:13:44 +00002044<h5>Semantics:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00002045
2046<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
John Criswell4a3327e2005-05-13 22:25:59 +00002047on the pointer type that is being indexed into. <a href="#t_pointer">Pointer</a>
Chris Lattner10ee9652004-06-03 22:57:15 +00002048and <a href="#t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
2049<tt>ulong</tt>, or <tt>long</tt> values, and <a href="#t_struct">structure</a>
Chris Lattner33fd7022004-04-05 01:30:49 +00002050types require <tt>uint</tt> <b>constants</b>.</p>
2051
Misha Brukman76307852003-11-08 01:05:38 +00002052<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattner33fd7022004-04-05 01:30:49 +00002053type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
2054}</tt>' type, a structure. The second index indexes into the third element of
2055the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
2056sbyte }</tt>' type, another structure. The third index indexes into the second
2057element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
2058array. The two dimensions of the array are subscripted into, yielding an
John Criswell88190562005-05-16 16:17:45 +00002059'<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction returns a pointer
Chris Lattner33fd7022004-04-05 01:30:49 +00002060to this element, thus computing a value of '<tt>int*</tt>' type.</p>
2061
Chris Lattner48b383b02003-11-25 01:02:51 +00002062<p>Note that it is perfectly legal to index partially through a
2063structure, returning a pointer to an inner element. Because of this,
2064the LLVM code for the given testcase is equivalent to:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002065
2066<pre>
Chris Lattner455fc8c2005-03-07 22:13:59 +00002067 int* %foo(%ST* %s) {
Chris Lattner33fd7022004-04-05 01:30:49 +00002068 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
2069 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
2070 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
2071 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
2072 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
2073 ret int* %t5
2074 }
Chris Lattnera8292f32002-05-06 22:08:29 +00002075</pre>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00002076
2077<p>Note that it is undefined to access an array out of bounds: array and
2078pointer indexes must always be within the defined bounds of the array type.
2079The one exception for this rules is zero length arrays. These arrays are
2080defined to be accessible as variable length arrays, which requires access
2081beyond the zero'th element.</p>
2082
Chris Lattner590645f2002-04-14 06:13:44 +00002083<h5>Example:</h5>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00002084
Chris Lattner33fd7022004-04-05 01:30:49 +00002085<pre>
2086 <i>; yields [12 x ubyte]*:aptr</i>
2087 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
2088</pre>
2089
2090</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002091<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002092<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002093<div class="doc_text">
John Criswell417228d2004-04-09 16:48:45 +00002094<p>The instructions in this category are the "miscellaneous"
Chris Lattner48b383b02003-11-25 01:02:51 +00002095instructions, which defy better classification.</p>
Misha Brukman76307852003-11-08 01:05:38 +00002096</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002097<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002098<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
2099Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002100<div class="doc_text">
Chris Lattner70de6632001-07-09 00:26:23 +00002101<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002102<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner70de6632001-07-09 00:26:23 +00002103<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002104<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
2105the SSA graph representing the function.</p>
Chris Lattner70de6632001-07-09 00:26:23 +00002106<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002107<p>The type of the incoming values are specified with the first type
2108field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
2109as arguments, with one pair for each predecessor basic block of the
2110current block. Only values of <a href="#t_firstclass">first class</a>
2111type may be used as the value arguments to the PHI node. Only labels
2112may be used as the label arguments.</p>
2113<p>There must be no non-phi instructions between the start of a basic
2114block and the PHI instructions: i.e. PHI instructions must be first in
2115a basic block.</p>
Chris Lattner70de6632001-07-09 00:26:23 +00002116<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002117<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
2118value specified by the parameter, depending on which basic block we
2119came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattnera8292f32002-05-06 22:08:29 +00002120<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002121<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 Brukman76307852003-11-08 01:05:38 +00002122</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002123
Chris Lattnera8292f32002-05-06 22:08:29 +00002124<!-- _______________________________________________________________________ -->
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002125<div class="doc_subsubsection">
2126 <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
2127</div>
2128
Misha Brukman76307852003-11-08 01:05:38 +00002129<div class="doc_text">
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002130
Chris Lattnera8292f32002-05-06 22:08:29 +00002131<h5>Syntax:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002132
2133<pre>
2134 &lt;result&gt; = cast &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Chris Lattnera8292f32002-05-06 22:08:29 +00002135</pre>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002136
Chris Lattnera8292f32002-05-06 22:08:29 +00002137<h5>Overview:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002138
2139<p>
2140The '<tt>cast</tt>' instruction is used as the primitive means to convert
2141integers to floating point, change data type sizes, and break type safety (by
2142casting pointers).
2143</p>
2144
2145
Chris Lattnera8292f32002-05-06 22:08:29 +00002146<h5>Arguments:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002147
2148<p>
2149The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
2150class value, and a type to cast it to, which must also be a <a
2151href="#t_firstclass">first class</a> type.
2152</p>
2153
Chris Lattnera8292f32002-05-06 22:08:29 +00002154<h5>Semantics:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002155
2156<p>
2157This instruction follows the C rules for explicit casts when determining how the
2158data being cast must change to fit in its new container.
2159</p>
2160
2161<p>
2162When casting to bool, any value that would be considered true in the context of
2163a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
2164all else are '<tt>false</tt>'.
2165</p>
2166
2167<p>
2168When extending an integral value from a type of one signness to another (for
2169example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
2170<b>source</b> value is signed, and zero-extended if the source value is
2171unsigned. <tt>bool</tt> values are always zero extended into either zero or
2172one.
2173</p>
2174
Chris Lattner70de6632001-07-09 00:26:23 +00002175<h5>Example:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002176
2177<pre>
2178 %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattnerd8f8ede2002-06-25 18:03:17 +00002179 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner70de6632001-07-09 00:26:23 +00002180</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002181</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002182
2183<!-- _______________________________________________________________________ -->
2184<div class="doc_subsubsection">
2185 <a name="i_select">'<tt>select</tt>' Instruction</a>
2186</div>
2187
2188<div class="doc_text">
2189
2190<h5>Syntax:</h5>
2191
2192<pre>
2193 &lt;result&gt; = select bool &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
2194</pre>
2195
2196<h5>Overview:</h5>
2197
2198<p>
2199The '<tt>select</tt>' instruction is used to choose one value based on a
2200condition, without branching.
2201</p>
2202
2203
2204<h5>Arguments:</h5>
2205
2206<p>
2207The '<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.
2208</p>
2209
2210<h5>Semantics:</h5>
2211
2212<p>
2213If the boolean condition evaluates to true, the instruction returns the first
John Criswell88190562005-05-16 16:17:45 +00002214value argument; otherwise, it returns the second value argument.
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002215</p>
2216
2217<h5>Example:</h5>
2218
2219<pre>
2220 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
2221</pre>
2222</div>
2223
2224
2225
2226
2227
Chris Lattner70de6632001-07-09 00:26:23 +00002228<!-- _______________________________________________________________________ -->
Chris Lattnere23c1392005-05-06 05:47:36 +00002229<div class="doc_subsubsection">
2230 <a name="i_call">'<tt>call</tt>' Instruction</a>
2231</div>
2232
Misha Brukman76307852003-11-08 01:05:38 +00002233<div class="doc_text">
Chris Lattnere23c1392005-05-06 05:47:36 +00002234
Chris Lattner2f7c9632001-06-06 20:29:01 +00002235<h5>Syntax:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00002236<pre>
Chris Lattner0132aff2005-05-06 22:57:40 +00002237 &lt;result&gt; = [tail] call [<a href="#callingconv">cconv</a>] &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)
Chris Lattnere23c1392005-05-06 05:47:36 +00002238</pre>
2239
Chris Lattner2f7c9632001-06-06 20:29:01 +00002240<h5>Overview:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00002241
Misha Brukman76307852003-11-08 01:05:38 +00002242<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00002243
Chris Lattner2f7c9632001-06-06 20:29:01 +00002244<h5>Arguments:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00002245
Misha Brukman76307852003-11-08 01:05:38 +00002246<p>This instruction requires several arguments:</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00002247
Chris Lattnera8292f32002-05-06 22:08:29 +00002248<ol>
Chris Lattner48b383b02003-11-25 01:02:51 +00002249 <li>
Chris Lattner0132aff2005-05-06 22:57:40 +00002250 <p>The optional "tail" marker indicates whether the callee function accesses
2251 any allocas or varargs in the caller. If the "tail" marker is present, the
Chris Lattnere23c1392005-05-06 05:47:36 +00002252 function call is eligible for tail call optimization. Note that calls may
2253 be marked "tail" even if they do not occur before a <a
2254 href="#i_ret"><tt>ret</tt></a> instruction.
Chris Lattner48b383b02003-11-25 01:02:51 +00002255 </li>
2256 <li>
Chris Lattner0132aff2005-05-06 22:57:40 +00002257 <p>The optional "cconv" marker indicates which <a href="callingconv">calling
2258 convention</a> the call should use. If none is specified, the call defaults
2259 to using C calling conventions.
2260 </li>
2261 <li>
Chris Lattnere23c1392005-05-06 05:47:36 +00002262 <p>'<tt>ty</tt>': shall be the signature of the pointer to function value
2263 being invoked. The argument types must match the types implied by this
John Criswell88190562005-05-16 16:17:45 +00002264 signature. This type can be omitted if the function is not varargs and
2265 if the function type does not return a pointer to a function.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00002266 </li>
2267 <li>
2268 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to
2269 be invoked. In most cases, this is a direct function invocation, but
2270 indirect <tt>call</tt>s are just as possible, calling an arbitrary pointer
John Criswell88190562005-05-16 16:17:45 +00002271 to function value.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002272 </li>
2273 <li>
2274 <p>'<tt>function args</tt>': argument list whose types match the
Reid Spencerd845d162005-05-01 22:22:57 +00002275 function signature argument types. All arguments must be of
2276 <a href="#t_firstclass">first class</a> type. If the function signature
2277 indicates the function accepts a variable number of arguments, the extra
2278 arguments can be specified.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002279 </li>
Chris Lattnera8292f32002-05-06 22:08:29 +00002280</ol>
Chris Lattnere23c1392005-05-06 05:47:36 +00002281
Chris Lattner2f7c9632001-06-06 20:29:01 +00002282<h5>Semantics:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00002283
Chris Lattner48b383b02003-11-25 01:02:51 +00002284<p>The '<tt>call</tt>' instruction is used to cause control flow to
2285transfer to a specified function, with its incoming arguments bound to
2286the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
2287instruction in the called function, control flow continues with the
2288instruction after the function call, and the return value of the
2289function is bound to the result argument. This is a simpler case of
2290the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00002291
Chris Lattner2f7c9632001-06-06 20:29:01 +00002292<h5>Example:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00002293
2294<pre>
2295 %retval = call int %test(int %argc)
2296 call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42);
2297 %X = tail call int %foo()
Chris Lattner0132aff2005-05-06 22:57:40 +00002298 %Y = tail call <a href="#callingconv">fastcc</a> int %foo()
Chris Lattnere23c1392005-05-06 05:47:36 +00002299</pre>
2300
Misha Brukman76307852003-11-08 01:05:38 +00002301</div>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002302
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002303<!-- _______________________________________________________________________ -->
Chris Lattner6a4a0492004-09-27 21:51:25 +00002304<div class="doc_subsubsection">
Chris Lattner6a4a0492004-09-27 21:51:25 +00002305 <a name="i_vaarg">'<tt>vaarg</tt>' Instruction</a>
2306</div>
2307
Misha Brukman76307852003-11-08 01:05:38 +00002308<div class="doc_text">
Chris Lattner6a4a0492004-09-27 21:51:25 +00002309
Chris Lattner26ca62e2003-10-18 05:51:36 +00002310<h5>Syntax:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002311
2312<pre>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002313 &lt;resultval&gt; = va_arg &lt;va_list*&gt; &lt;arglist&gt;, &lt;argty&gt;
Chris Lattner6a4a0492004-09-27 21:51:25 +00002314</pre>
2315
Chris Lattner26ca62e2003-10-18 05:51:36 +00002316<h5>Overview:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002317
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002318<p>The '<tt>va_arg</tt>' instruction is used to access arguments passed through
Chris Lattner6a4a0492004-09-27 21:51:25 +00002319the "variable argument" area of a function call. It is used to implement the
2320<tt>va_arg</tt> macro in C.</p>
2321
Chris Lattner26ca62e2003-10-18 05:51:36 +00002322<h5>Arguments:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002323
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002324<p>This instruction takes a <tt>va_list*</tt> value and the type of
2325the argument. It returns a value of the specified argument type and
Jeff Cohendc6bfea2005-11-11 02:15:27 +00002326increments the <tt>va_list</tt> to point to the next argument. Again, the
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002327actual type of <tt>va_list</tt> is target specific.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002328
Chris Lattner26ca62e2003-10-18 05:51:36 +00002329<h5>Semantics:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002330
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002331<p>The '<tt>va_arg</tt>' instruction loads an argument of the specified
2332type from the specified <tt>va_list</tt> and causes the
2333<tt>va_list</tt> to point to the next argument. For more information,
2334see the variable argument handling <a href="#int_varargs">Intrinsic
2335Functions</a>.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002336
2337<p>It is legal for this instruction to be called in a function which does not
2338take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman76307852003-11-08 01:05:38 +00002339function.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002340
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002341<p><tt>va_arg</tt> is an LLVM instruction instead of an <a
John Criswell88190562005-05-16 16:17:45 +00002342href="#intrinsics">intrinsic function</a> because it takes a type as an
Chris Lattner6a4a0492004-09-27 21:51:25 +00002343argument.</p>
2344
Chris Lattner26ca62e2003-10-18 05:51:36 +00002345<h5>Example:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002346
2347<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
2348
Misha Brukman76307852003-11-08 01:05:38 +00002349</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002350
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002351<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002352<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
2353<!-- *********************************************************************** -->
Chris Lattner941515c2004-01-06 05:31:32 +00002354
Misha Brukman76307852003-11-08 01:05:38 +00002355<div class="doc_text">
Chris Lattnerfee11462004-02-12 17:01:32 +00002356
2357<p>LLVM supports the notion of an "intrinsic function". These functions have
John Criswell88190562005-05-16 16:17:45 +00002358well known names and semantics and are required to follow certain
Chris Lattnerfee11462004-02-12 17:01:32 +00002359restrictions. Overall, these instructions represent an extension mechanism for
2360the LLVM language that does not require changing all of the transformations in
2361LLVM to add to the language (or the bytecode reader/writer, the parser,
2362etc...).</p>
2363
John Criswell88190562005-05-16 16:17:45 +00002364<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix. This
2365prefix is reserved in LLVM for intrinsic names; thus, functions may not be named
Chris Lattnerfee11462004-02-12 17:01:32 +00002366this. Intrinsic functions must always be external functions: you cannot define
2367the body of intrinsic functions. Intrinsic functions may only be used in call
2368or invoke instructions: it is illegal to take the address of an intrinsic
2369function. Additionally, because intrinsic functions are part of the LLVM
2370language, it is required that they all be documented here if any are added.</p>
2371
2372
John Criswell88190562005-05-16 16:17:45 +00002373<p>To learn how to add an intrinsic function, please see the <a
Chris Lattner90391c12005-05-11 03:35:57 +00002374href="ExtendingLLVM.html">Extending LLVM Guide</a>.
Chris Lattnerfee11462004-02-12 17:01:32 +00002375</p>
2376
Misha Brukman76307852003-11-08 01:05:38 +00002377</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002378
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002379<!-- ======================================================================= -->
Chris Lattner941515c2004-01-06 05:31:32 +00002380<div class="doc_subsection">
2381 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
2382</div>
2383
Misha Brukman76307852003-11-08 01:05:38 +00002384<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +00002385
Misha Brukman76307852003-11-08 01:05:38 +00002386<p>Variable argument support is defined in LLVM with the <a
Chris Lattner48b383b02003-11-25 01:02:51 +00002387 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
2388intrinsic functions. These functions are related to the similarly
2389named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002390
Chris Lattner48b383b02003-11-25 01:02:51 +00002391<p>All of these functions operate on arguments that use a
2392target-specific value type "<tt>va_list</tt>". The LLVM assembly
2393language reference manual does not define what this type is, so all
2394transformations should be prepared to handle intrinsics with any type
2395used.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002396
Misha Brukman76307852003-11-08 01:05:38 +00002397<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner48b383b02003-11-25 01:02:51 +00002398instruction and the variable argument handling intrinsic functions are
2399used.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002400
Chris Lattnerfee11462004-02-12 17:01:32 +00002401<pre>
2402int %test(int %X, ...) {
2403 ; Initialize variable argument processing
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002404 %ap = alloca sbyte*
2405 call void %<a href="#i_va_start">llvm.va_start</a>(sbyte** %ap)
Chris Lattnerfee11462004-02-12 17:01:32 +00002406
2407 ; Read a single integer argument
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002408 %tmp = va_arg sbyte** %ap, int
Chris Lattnerfee11462004-02-12 17:01:32 +00002409
2410 ; Demonstrate usage of llvm.va_copy and llvm.va_end
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002411 %aq = alloca sbyte*
Andrew Lenharth5305ea52005-06-22 20:38:11 +00002412 call void %<a href="#i_va_copy">llvm.va_copy</a>(sbyte** %aq, sbyte** %ap)
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002413 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte** %aq)
Chris Lattnerfee11462004-02-12 17:01:32 +00002414
2415 ; Stop processing of arguments.
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002416 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte** %ap)
Chris Lattnerfee11462004-02-12 17:01:32 +00002417 ret int %tmp
2418}
2419</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002420</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002421
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002422<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00002423<div class="doc_subsubsection">
2424 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
2425</div>
2426
2427
Misha Brukman76307852003-11-08 01:05:38 +00002428<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002429<h5>Syntax:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002430<pre> declare void %llvm.va_start(&lt;va_list&gt;* &lt;arglist&gt;)<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002431<h5>Overview:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002432<P>The '<tt>llvm.va_start</tt>' intrinsic initializes
2433<tt>*&lt;arglist&gt;</tt> for subsequent use by <tt><a
2434href="#i_va_arg">va_arg</a></tt>.</p>
2435
2436<h5>Arguments:</h5>
2437
2438<P>The argument is a pointer to a <tt>va_list</tt> element to initialize.</p>
2439
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002440<h5>Semantics:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002441
2442<P>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
2443macro available in C. In a target-dependent way, it initializes the
2444<tt>va_list</tt> element the argument points to, so that the next call to
2445<tt>va_arg</tt> will produce the first variable argument passed to the function.
2446Unlike the C <tt>va_start</tt> macro, this intrinsic does not need to know the
2447last argument of the function, the compiler can figure that out.</p>
2448
Misha Brukman76307852003-11-08 01:05:38 +00002449</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002450
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002451<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00002452<div class="doc_subsubsection">
2453 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
2454</div>
2455
Misha Brukman76307852003-11-08 01:05:38 +00002456<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002457<h5>Syntax:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002458<pre> declare void %llvm.va_end(&lt;va_list*&gt; &lt;arglist&gt;)<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002459<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002460<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
2461which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
2462or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002463<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002464<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002465<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002466<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00002467macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
2468Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
2469 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
2470with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman76307852003-11-08 01:05:38 +00002471</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002472
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002473<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00002474<div class="doc_subsubsection">
2475 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
2476</div>
2477
Misha Brukman76307852003-11-08 01:05:38 +00002478<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +00002479
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002480<h5>Syntax:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002481
2482<pre>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002483 declare void %llvm.va_copy(&lt;va_list&gt;* &lt;destarglist&gt;,
Andrew Lenharth5305ea52005-06-22 20:38:11 +00002484 &lt;va_list&gt;* &lt;srcarglist&gt;)
Chris Lattner757528b0b2004-05-23 21:06:01 +00002485</pre>
2486
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002487<h5>Overview:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002488
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002489<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position from
2490the source argument list to the destination argument list.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002491
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002492<h5>Arguments:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002493
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002494<p>The first argument is a pointer to a <tt>va_list</tt> element to initialize.
Andrew Lenharth5305ea52005-06-22 20:38:11 +00002495The second argument is a pointer to a <tt>va_list</tt> element to copy from.</p>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002496
Chris Lattner757528b0b2004-05-23 21:06:01 +00002497
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002498<h5>Semantics:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002499
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002500<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt> macro
2501available in C. In a target-dependent way, it copies the source
2502<tt>va_list</tt> element into the destination list. This intrinsic is necessary
2503because the <tt><a href="i_va_begin">llvm.va_begin</a></tt> intrinsic may be
Chris Lattner757528b0b2004-05-23 21:06:01 +00002504arbitrarily complex and require memory allocation, for example.</p>
2505
Misha Brukman76307852003-11-08 01:05:38 +00002506</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002507
Chris Lattnerfee11462004-02-12 17:01:32 +00002508<!-- ======================================================================= -->
2509<div class="doc_subsection">
Chris Lattner757528b0b2004-05-23 21:06:01 +00002510 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
2511</div>
2512
2513<div class="doc_text">
2514
2515<p>
2516LLVM support for <a href="GarbageCollection.html">Accurate Garbage
2517Collection</a> requires the implementation and generation of these intrinsics.
2518These intrinsics allow identification of <a href="#i_gcroot">GC roots on the
2519stack</a>, as well as garbage collector implementations that require <a
2520href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers.
2521Front-ends for type-safe garbage collected languages should generate these
2522intrinsics to make use of the LLVM garbage collectors. For more details, see <a
2523href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
2524</p>
2525</div>
2526
2527<!-- _______________________________________________________________________ -->
2528<div class="doc_subsubsection">
2529 <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
2530</div>
2531
2532<div class="doc_text">
2533
2534<h5>Syntax:</h5>
2535
2536<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002537 declare void %llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
Chris Lattner757528b0b2004-05-23 21:06:01 +00002538</pre>
2539
2540<h5>Overview:</h5>
2541
John Criswelldfe6a862004-12-10 15:51:16 +00002542<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
Chris Lattner757528b0b2004-05-23 21:06:01 +00002543the code generator, and allows some metadata to be associated with it.</p>
2544
2545<h5>Arguments:</h5>
2546
2547<p>The first argument specifies the address of a stack object that contains the
2548root pointer. The second pointer (which must be either a constant or a global
2549value address) contains the meta-data to be associated with the root.</p>
2550
2551<h5>Semantics:</h5>
2552
2553<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
2554location. At compile-time, the code generator generates information to allow
2555the runtime to find the pointer at GC safe points.
2556</p>
2557
2558</div>
2559
2560
2561<!-- _______________________________________________________________________ -->
2562<div class="doc_subsubsection">
2563 <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
2564</div>
2565
2566<div class="doc_text">
2567
2568<h5>Syntax:</h5>
2569
2570<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002571 declare sbyte* %llvm.gcread(sbyte** %Ptr)
Chris Lattner757528b0b2004-05-23 21:06:01 +00002572</pre>
2573
2574<h5>Overview:</h5>
2575
2576<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
2577locations, allowing garbage collector implementations that require read
2578barriers.</p>
2579
2580<h5>Arguments:</h5>
2581
2582<p>The argument is the address to read from, which should be an address
2583allocated from the garbage collector.</p>
2584
2585<h5>Semantics:</h5>
2586
2587<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
2588instruction, but may be replaced with substantially more complex code by the
2589garbage collector runtime, as needed.</p>
2590
2591</div>
2592
2593
2594<!-- _______________________________________________________________________ -->
2595<div class="doc_subsubsection">
2596 <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
2597</div>
2598
2599<div class="doc_text">
2600
2601<h5>Syntax:</h5>
2602
2603<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002604 declare void %llvm.gcwrite(sbyte* %P1, sbyte** %P2)
Chris Lattner757528b0b2004-05-23 21:06:01 +00002605</pre>
2606
2607<h5>Overview:</h5>
2608
2609<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
2610locations, allowing garbage collector implementations that require write
2611barriers (such as generational or reference counting collectors).</p>
2612
2613<h5>Arguments:</h5>
2614
2615<p>The first argument is the reference to store, and the second is the heap
2616location to store to.</p>
2617
2618<h5>Semantics:</h5>
2619
2620<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
2621instruction, but may be replaced with substantially more complex code by the
2622garbage collector runtime, as needed.</p>
2623
2624</div>
2625
2626
2627
2628<!-- ======================================================================= -->
2629<div class="doc_subsection">
Chris Lattner3649c3a2004-02-14 04:08:35 +00002630 <a name="int_codegen">Code Generator Intrinsics</a>
2631</div>
2632
2633<div class="doc_text">
2634<p>
2635These intrinsics are provided by LLVM to expose special features that may only
2636be implemented with code generator support.
2637</p>
2638
2639</div>
2640
2641<!-- _______________________________________________________________________ -->
2642<div class="doc_subsubsection">
2643 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
2644</div>
2645
2646<div class="doc_text">
2647
2648<h5>Syntax:</h5>
2649<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002650 declare void* %llvm.returnaddress(uint &lt;level&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00002651</pre>
2652
2653<h5>Overview:</h5>
2654
2655<p>
2656The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
2657indicating the return address of the current function or one of its callers.
2658</p>
2659
2660<h5>Arguments:</h5>
2661
2662<p>
2663The argument to this intrinsic indicates which function to return the address
2664for. Zero indicates the calling function, one indicates its caller, etc. The
2665argument is <b>required</b> to be a constant integer value.
2666</p>
2667
2668<h5>Semantics:</h5>
2669
2670<p>
2671The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
2672the return address of the specified call frame, or zero if it cannot be
2673identified. The value returned by this intrinsic is likely to be incorrect or 0
2674for arguments other than zero, so it should only be used for debugging purposes.
2675</p>
2676
2677<p>
2678Note that calling this intrinsic does not prevent function inlining or other
Chris Lattner2e6eb5f2005-03-07 20:30:51 +00002679aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner3649c3a2004-02-14 04:08:35 +00002680source-language caller.
2681</p>
2682</div>
2683
2684
2685<!-- _______________________________________________________________________ -->
2686<div class="doc_subsubsection">
2687 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
2688</div>
2689
2690<div class="doc_text">
2691
2692<h5>Syntax:</h5>
2693<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002694 declare void* %llvm.frameaddress(uint &lt;level&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00002695</pre>
2696
2697<h5>Overview:</h5>
2698
2699<p>
2700The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
2701pointer value for the specified stack frame.
2702</p>
2703
2704<h5>Arguments:</h5>
2705
2706<p>
2707The argument to this intrinsic indicates which function to return the frame
2708pointer for. Zero indicates the calling function, one indicates its caller,
2709etc. The argument is <b>required</b> to be a constant integer value.
2710</p>
2711
2712<h5>Semantics:</h5>
2713
2714<p>
2715The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
2716the frame address of the specified call frame, or zero if it cannot be
2717identified. The value returned by this intrinsic is likely to be incorrect or 0
2718for arguments other than zero, so it should only be used for debugging purposes.
2719</p>
2720
2721<p>
2722Note that calling this intrinsic does not prevent function inlining or other
Chris Lattner2e6eb5f2005-03-07 20:30:51 +00002723aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner3649c3a2004-02-14 04:08:35 +00002724source-language caller.
2725</p>
2726</div>
2727
Chris Lattnerc8a2c222005-02-28 19:24:19 +00002728<!-- _______________________________________________________________________ -->
2729<div class="doc_subsubsection">
2730 <a name="i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a>
2731</div>
2732
2733<div class="doc_text">
2734
2735<h5>Syntax:</h5>
2736<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002737 declare void %llvm.prefetch(sbyte * &lt;address&gt;,
2738 uint &lt;rw&gt;, uint &lt;locality&gt;)
Chris Lattnerc8a2c222005-02-28 19:24:19 +00002739</pre>
2740
2741<h5>Overview:</h5>
2742
2743
2744<p>
2745The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to insert
John Criswell88190562005-05-16 16:17:45 +00002746a prefetch instruction if supported; otherwise, it is a noop. Prefetches have
2747no
2748effect on the behavior of the program but can change its performance
Chris Lattnerff851072005-02-28 19:47:14 +00002749characteristics.
Chris Lattnerc8a2c222005-02-28 19:24:19 +00002750</p>
2751
2752<h5>Arguments:</h5>
2753
2754<p>
2755<tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier
2756determining if the fetch should be for a read (0) or write (1), and
2757<tt>locality</tt> is a temporal locality specifier ranging from (0) - no
Chris Lattnerd3e641c2005-03-07 20:31:38 +00002758locality, to (3) - extremely local keep in cache. The <tt>rw</tt> and
Chris Lattnerc8a2c222005-02-28 19:24:19 +00002759<tt>locality</tt> arguments must be constant integers.
2760</p>
2761
2762<h5>Semantics:</h5>
2763
2764<p>
2765This intrinsic does not modify the behavior of the program. In particular,
2766prefetches cannot trap and do not produce a value. On targets that support this
2767intrinsic, the prefetch can provide hints to the processor cache for better
2768performance.
2769</p>
2770
2771</div>
2772
Andrew Lenharthb4427912005-03-28 20:05:49 +00002773<!-- _______________________________________________________________________ -->
2774<div class="doc_subsubsection">
2775 <a name="i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a>
2776</div>
2777
2778<div class="doc_text">
2779
2780<h5>Syntax:</h5>
2781<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002782 declare void %llvm.pcmarker( uint &lt;id&gt; )
Andrew Lenharthb4427912005-03-28 20:05:49 +00002783</pre>
2784
2785<h5>Overview:</h5>
2786
2787
2788<p>
John Criswell88190562005-05-16 16:17:45 +00002789The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a Program Counter
2790(PC) in a region of
Andrew Lenharthb4427912005-03-28 20:05:49 +00002791code to simulators and other tools. The method is target specific, but it is
2792expected that the marker will use exported symbols to transmit the PC of the marker.
Jeff Cohendc6bfea2005-11-11 02:15:27 +00002793The marker makes no guarantees that it will remain with any specific instruction
Andrew Lenharthb4427912005-03-28 20:05:49 +00002794after optimizations. It is possible that the presense of a marker will inhibit
2795optimizations. The intended use is to be inserted after optmizations to allow
John Criswell88190562005-05-16 16:17:45 +00002796correlations of simulation runs.
Andrew Lenharthb4427912005-03-28 20:05:49 +00002797</p>
2798
2799<h5>Arguments:</h5>
2800
2801<p>
2802<tt>id</tt> is a numerical id identifying the marker.
2803</p>
2804
2805<h5>Semantics:</h5>
2806
2807<p>
2808This intrinsic does not modify the behavior of the program. Backends that do not
2809support this intrinisic may ignore it.
2810</p>
2811
2812</div>
2813
Chris Lattnerc8a2c222005-02-28 19:24:19 +00002814
John Criswellaa1c3c12004-04-09 16:43:20 +00002815<!-- ======================================================================= -->
2816<div class="doc_subsection">
2817 <a name="int_os">Operating System Intrinsics</a>
2818</div>
2819
2820<div class="doc_text">
2821<p>
2822These intrinsics are provided by LLVM to support the implementation of
2823operating system level code.
2824</p>
2825
2826</div>
John Criswella4501222004-04-12 15:02:16 +00002827
John Criswell508b93c2004-04-09 15:23:37 +00002828<!-- _______________________________________________________________________ -->
2829<div class="doc_subsubsection">
2830 <a name="i_readport">'<tt>llvm.readport</tt>' Intrinsic</a>
2831</div>
2832
2833<div class="doc_text">
2834
2835<h5>Syntax:</h5>
2836<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002837 declare &lt;integer type&gt; %llvm.readport (&lt;integer type&gt; &lt;address&gt;)
John Criswell508b93c2004-04-09 15:23:37 +00002838</pre>
2839
2840<h5>Overview:</h5>
2841
2842<p>
John Criswellaa1c3c12004-04-09 16:43:20 +00002843The '<tt>llvm.readport</tt>' intrinsic reads data from the specified hardware
2844I/O port.
John Criswell508b93c2004-04-09 15:23:37 +00002845</p>
2846
2847<h5>Arguments:</h5>
2848
2849<p>
John Criswellaa1c3c12004-04-09 16:43:20 +00002850The argument to this intrinsic indicates the hardware I/O address from which
2851to read the data. The address is in the hardware I/O address namespace (as
2852opposed to being a memory location for memory mapped I/O).
John Criswell508b93c2004-04-09 15:23:37 +00002853</p>
2854
2855<h5>Semantics:</h5>
2856
2857<p>
John Criswellaa1c3c12004-04-09 16:43:20 +00002858The '<tt>llvm.readport</tt>' intrinsic reads data from the hardware I/O port
2859specified by <i>address</i> and returns the value. The address and return
2860value must be integers, but the size is dependent upon the platform upon which
2861the program is code generated. For example, on x86, the address must be an
Misha Brukman36c6bc12005-04-22 18:02:52 +00002862unsigned 16-bit value, and the return value must be 8, 16, or 32 bits.
John Criswell508b93c2004-04-09 15:23:37 +00002863</p>
2864
2865</div>
2866
2867<!-- _______________________________________________________________________ -->
2868<div class="doc_subsubsection">
2869 <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a>
2870</div>
2871
2872<div class="doc_text">
2873
2874<h5>Syntax:</h5>
2875<pre>
Chris Lattner74d3f822004-12-09 17:30:23 +00002876 call void (&lt;integer type&gt;, &lt;integer type&gt;)*
2877 %llvm.writeport (&lt;integer type&gt; &lt;value&gt;,
2878 &lt;integer type&gt; &lt;address&gt;)
John Criswell508b93c2004-04-09 15:23:37 +00002879</pre>
2880
2881<h5>Overview:</h5>
2882
2883<p>
John Criswellaa1c3c12004-04-09 16:43:20 +00002884The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified hardware
2885I/O port.
John Criswell508b93c2004-04-09 15:23:37 +00002886</p>
2887
2888<h5>Arguments:</h5>
2889
2890<p>
John Criswell7a576472004-04-12 16:33:19 +00002891The first argument is the value to write to the I/O port.
John Criswell508b93c2004-04-09 15:23:37 +00002892</p>
2893
2894<p>
John Criswell7a576472004-04-12 16:33:19 +00002895The second argument indicates the hardware I/O address to which data should be
2896written. The address is in the hardware I/O address namespace (as opposed to
2897being a memory location for memory mapped I/O).
John Criswell508b93c2004-04-09 15:23:37 +00002898</p>
2899
2900<h5>Semantics:</h5>
2901
2902<p>
2903The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port
2904specified by <i>address</i>. The address and value must be integers, but the
2905size is dependent upon the platform upon which the program is code generated.
Misha Brukman36c6bc12005-04-22 18:02:52 +00002906For example, on x86, the address must be an unsigned 16-bit value, and the
John Criswellaa1c3c12004-04-09 16:43:20 +00002907value written must be 8, 16, or 32 bits in length.
John Criswell508b93c2004-04-09 15:23:37 +00002908</p>
2909
2910</div>
Chris Lattner3649c3a2004-02-14 04:08:35 +00002911
John Criswella4501222004-04-12 15:02:16 +00002912<!-- _______________________________________________________________________ -->
2913<div class="doc_subsubsection">
2914 <a name="i_readio">'<tt>llvm.readio</tt>' Intrinsic</a>
2915</div>
2916
2917<div class="doc_text">
2918
2919<h5>Syntax:</h5>
2920<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002921 declare &lt;result&gt; %llvm.readio (&lt;ty&gt; * &lt;pointer&gt;)
John Criswella4501222004-04-12 15:02:16 +00002922</pre>
2923
2924<h5>Overview:</h5>
2925
2926<p>
2927The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
2928address.
2929</p>
2930
2931<h5>Arguments:</h5>
2932
2933<p>
John Criswell7a576472004-04-12 16:33:19 +00002934The argument to this intrinsic is a pointer indicating the memory address from
2935which to read the data. The data must be a
2936<a href="#t_firstclass">first class</a> type.
John Criswella4501222004-04-12 15:02:16 +00002937</p>
2938
2939<h5>Semantics:</h5>
2940
2941<p>
2942The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
John Criswell7a576472004-04-12 16:33:19 +00002943location specified by <i>pointer</i> and returns the value. The argument must
2944be a pointer, and the return value must be a
2945<a href="#t_firstclass">first class</a> type. However, certain architectures
Misha Brukman36c6bc12005-04-22 18:02:52 +00002946may not support I/O on all first class types. For example, 32-bit processors
John Criswell7a576472004-04-12 16:33:19 +00002947may only support I/O on data types that are 32 bits or less.
John Criswella4501222004-04-12 15:02:16 +00002948</p>
2949
2950<p>
John Criswell7a576472004-04-12 16:33:19 +00002951This intrinsic enforces an in-order memory model for llvm.readio and
2952llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2953scheduled processors may execute loads and stores out of order, re-ordering at
2954run time accesses to memory mapped I/O registers. Using these intrinsics
2955ensures that accesses to memory mapped I/O registers occur in program order.
John Criswella4501222004-04-12 15:02:16 +00002956</p>
2957
2958</div>
2959
2960<!-- _______________________________________________________________________ -->
2961<div class="doc_subsubsection">
2962 <a name="i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a>
2963</div>
2964
2965<div class="doc_text">
2966
2967<h5>Syntax:</h5>
2968<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002969 declare void %llvm.writeio (&lt;ty1&gt; &lt;value&gt;, &lt;ty2&gt; * &lt;pointer&gt;)
John Criswella4501222004-04-12 15:02:16 +00002970</pre>
2971
2972<h5>Overview:</h5>
2973
2974<p>
2975The '<tt>llvm.writeio</tt>' intrinsic writes data to the specified memory
2976mapped I/O address.
2977</p>
2978
2979<h5>Arguments:</h5>
2980
2981<p>
John Criswell7a576472004-04-12 16:33:19 +00002982The first argument is the value to write to the memory mapped I/O location.
2983The second argument is a pointer indicating the memory address to which the
2984data should be written.
John Criswella4501222004-04-12 15:02:16 +00002985</p>
2986
2987<h5>Semantics:</h5>
2988
2989<p>
2990The '<tt>llvm.writeio</tt>' intrinsic writes <i>value</i> to the memory mapped
John Criswell7a576472004-04-12 16:33:19 +00002991I/O address specified by <i>pointer</i>. The value must be a
2992<a href="#t_firstclass">first class</a> type. However, certain architectures
Misha Brukman36c6bc12005-04-22 18:02:52 +00002993may not support I/O on all first class types. For example, 32-bit processors
John Criswell7a576472004-04-12 16:33:19 +00002994may only support I/O on data types that are 32 bits or less.
John Criswella4501222004-04-12 15:02:16 +00002995</p>
2996
2997<p>
John Criswell7a576472004-04-12 16:33:19 +00002998This intrinsic enforces an in-order memory model for llvm.readio and
2999llvm.writeio calls on machines that use dynamic scheduling. Dynamically
3000scheduled processors may execute loads and stores out of order, re-ordering at
3001run time accesses to memory mapped I/O registers. Using these intrinsics
3002ensures that accesses to memory mapped I/O registers occur in program order.
John Criswella4501222004-04-12 15:02:16 +00003003</p>
3004
3005</div>
3006
Chris Lattner3649c3a2004-02-14 04:08:35 +00003007<!-- ======================================================================= -->
3008<div class="doc_subsection">
Chris Lattnerfee11462004-02-12 17:01:32 +00003009 <a name="int_libc">Standard C Library Intrinsics</a>
3010</div>
3011
3012<div class="doc_text">
3013<p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00003014LLVM provides intrinsics for a few important standard C library functions.
3015These intrinsics allow source-language front-ends to pass information about the
3016alignment of the pointer arguments to the code generator, providing opportunity
3017for more efficient code generation.
Chris Lattnerfee11462004-02-12 17:01:32 +00003018</p>
3019
3020</div>
3021
3022<!-- _______________________________________________________________________ -->
3023<div class="doc_subsubsection">
3024 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
3025</div>
3026
3027<div class="doc_text">
3028
3029<h5>Syntax:</h5>
3030<pre>
Reid Spencercf669d82005-04-26 20:41:16 +00003031 declare void %llvm.memcpy(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
3032 uint &lt;len&gt;, uint &lt;align&gt;)
Chris Lattnerfee11462004-02-12 17:01:32 +00003033</pre>
3034
3035<h5>Overview:</h5>
3036
3037<p>
3038The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
3039location to the destination location.
3040</p>
3041
3042<p>
3043Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
3044does not return a value, and takes an extra alignment argument.
3045</p>
3046
3047<h5>Arguments:</h5>
3048
3049<p>
3050The first argument is a pointer to the destination, the second is a pointer to
3051the source. The third argument is an (arbitrarily sized) integer argument
3052specifying the number of bytes to copy, and the fourth argument is the alignment
3053of the source and destination locations.
3054</p>
3055
Chris Lattner4c67c482004-02-12 21:18:15 +00003056<p>
3057If the call to this intrinisic has an alignment value that is not 0 or 1, then
3058the caller guarantees that the size of the copy is a multiple of the alignment
3059and that both the source and destination pointers are aligned to that boundary.
3060</p>
3061
Chris Lattnerfee11462004-02-12 17:01:32 +00003062<h5>Semantics:</h5>
3063
3064<p>
3065The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
3066location to the destination location, which are not allowed to overlap. It
3067copies "len" bytes of memory over. If the argument is known to be aligned to
3068some boundary, this can be specified as the fourth argument, otherwise it should
3069be set to 0 or 1.
3070</p>
3071</div>
3072
3073
Chris Lattnerf30152e2004-02-12 18:10:10 +00003074<!-- _______________________________________________________________________ -->
3075<div class="doc_subsubsection">
3076 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
3077</div>
3078
3079<div class="doc_text">
3080
3081<h5>Syntax:</h5>
3082<pre>
Reid Spencercf669d82005-04-26 20:41:16 +00003083 declare void %llvm.memmove(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
3084 uint &lt;len&gt;, uint &lt;align&gt;)
Chris Lattnerf30152e2004-02-12 18:10:10 +00003085</pre>
3086
3087<h5>Overview:</h5>
3088
3089<p>
3090The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
3091location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>'
3092intrinsic but allows the two memory locations to overlap.
3093</p>
3094
3095<p>
3096Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
3097does not return a value, and takes an extra alignment argument.
3098</p>
3099
3100<h5>Arguments:</h5>
3101
3102<p>
3103The first argument is a pointer to the destination, the second is a pointer to
3104the source. The third argument is an (arbitrarily sized) integer argument
3105specifying the number of bytes to copy, and the fourth argument is the alignment
3106of the source and destination locations.
3107</p>
3108
Chris Lattner4c67c482004-02-12 21:18:15 +00003109<p>
3110If the call to this intrinisic has an alignment value that is not 0 or 1, then
3111the caller guarantees that the size of the copy is a multiple of the alignment
3112and that both the source and destination pointers are aligned to that boundary.
3113</p>
3114
Chris Lattnerf30152e2004-02-12 18:10:10 +00003115<h5>Semantics:</h5>
3116
3117<p>
3118The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
3119location to the destination location, which may overlap. It
3120copies "len" bytes of memory over. If the argument is known to be aligned to
3121some boundary, this can be specified as the fourth argument, otherwise it should
3122be set to 0 or 1.
3123</p>
3124</div>
3125
Chris Lattner941515c2004-01-06 05:31:32 +00003126
Chris Lattner3649c3a2004-02-14 04:08:35 +00003127<!-- _______________________________________________________________________ -->
3128<div class="doc_subsubsection">
3129 <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a>
3130</div>
3131
3132<div class="doc_text">
3133
3134<h5>Syntax:</h5>
3135<pre>
Reid Spencercf669d82005-04-26 20:41:16 +00003136 declare void %llvm.memset(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
3137 uint &lt;len&gt;, uint &lt;align&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00003138</pre>
3139
3140<h5>Overview:</h5>
3141
3142<p>
3143The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular
3144byte value.
3145</p>
3146
3147<p>
3148Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
3149does not return a value, and takes an extra alignment argument.
3150</p>
3151
3152<h5>Arguments:</h5>
3153
3154<p>
3155The first argument is a pointer to the destination to fill, the second is the
3156byte value to fill it with, the third argument is an (arbitrarily sized) integer
3157argument specifying the number of bytes to fill, and the fourth argument is the
3158known alignment of destination location.
3159</p>
3160
3161<p>
3162If the call to this intrinisic has an alignment value that is not 0 or 1, then
3163the caller guarantees that the size of the copy is a multiple of the alignment
3164and that the destination pointer is aligned to that boundary.
3165</p>
3166
3167<h5>Semantics:</h5>
3168
3169<p>
3170The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the
3171destination location. If the argument is known to be aligned to some boundary,
3172this can be specified as the fourth argument, otherwise it should be set to 0 or
31731.
3174</p>
3175</div>
3176
3177
Chris Lattner3b4f4372004-06-11 02:28:03 +00003178<!-- _______________________________________________________________________ -->
3179<div class="doc_subsubsection">
Alkis Evlogimenos0fa39232004-06-13 01:16:15 +00003180 <a name="i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a>
3181</div>
3182
3183<div class="doc_text">
3184
3185<h5>Syntax:</h5>
3186<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00003187 declare bool %llvm.isunordered(&lt;float or double&gt; Val1, &lt;float or double&gt; Val2)
Alkis Evlogimenos0fa39232004-06-13 01:16:15 +00003188</pre>
3189
3190<h5>Overview:</h5>
3191
3192<p>
3193The '<tt>llvm.isunordered</tt>' intrinsic returns true if either or both of the
3194specified floating point values is a NAN.
3195</p>
3196
3197<h5>Arguments:</h5>
3198
3199<p>
3200The arguments are floating point numbers of the same type.
3201</p>
3202
3203<h5>Semantics:</h5>
3204
3205<p>
3206If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise
3207false.
3208</p>
3209</div>
3210
3211
Chris Lattner8a8f2e52005-07-21 01:29:16 +00003212<!-- _______________________________________________________________________ -->
3213<div class="doc_subsubsection">
3214 <a name="i_sqrt">'<tt>llvm.sqrt</tt>' Intrinsic</a>
3215</div>
3216
3217<div class="doc_text">
3218
3219<h5>Syntax:</h5>
3220<pre>
3221 declare &lt;float or double&gt; %llvm.sqrt(&lt;float or double&gt; Val)
3222</pre>
3223
3224<h5>Overview:</h5>
3225
3226<p>
3227The '<tt>llvm.sqrt</tt>' intrinsic returns the sqrt of the specified operand,
3228returning the same value as the libm '<tt>sqrt</tt>' function would. Unlike
3229<tt>sqrt</tt> in libm, however, <tt>llvm.sqrt</tt> has undefined behavior for
3230negative numbers (which allows for better optimization).
3231</p>
3232
3233<h5>Arguments:</h5>
3234
3235<p>
3236The argument and return value are floating point numbers of the same type.
3237</p>
3238
3239<h5>Semantics:</h5>
3240
3241<p>
3242This function returns the sqrt of the specified operand if it is a positive
3243floating point number.
3244</p>
3245</div>
3246
Andrew Lenharth1d463522005-05-03 18:01:48 +00003247<!-- ======================================================================= -->
3248<div class="doc_subsection">
3249 <a name="int_count">Bit Counting Intrinsics</a>
3250</div>
3251
3252<div class="doc_text">
3253<p>
3254LLVM provides intrinsics for a few important bit counting operations.
3255These allow efficient code generation for some algorithms.
3256</p>
3257
3258</div>
3259
3260<!-- _______________________________________________________________________ -->
3261<div class="doc_subsubsection">
3262 <a name="int_ctpop">'<tt>llvm.ctpop</tt>' Intrinsic</a>
3263</div>
3264
3265<div class="doc_text">
3266
3267<h5>Syntax:</h5>
3268<pre>
3269 declare int %llvm.ctpop(int &lt;src&gt;)
3270
3271</pre>
3272
3273<h5>Overview:</h5>
3274
3275<p>
3276The '<tt>llvm.ctpop</tt>' intrinsic counts the number of ones in a variable.
3277</p>
3278
3279<h5>Arguments:</h5>
3280
3281<p>
Chris Lattner573f64e2005-05-07 01:46:40 +00003282The only argument is the value to be counted. The argument may be of any
3283integer type. The return type must match the argument type.
Andrew Lenharth1d463522005-05-03 18:01:48 +00003284</p>
3285
3286<h5>Semantics:</h5>
3287
3288<p>
3289The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable.
3290</p>
3291</div>
3292
3293<!-- _______________________________________________________________________ -->
3294<div class="doc_subsubsection">
Andrew Lenharth1d463522005-05-03 18:01:48 +00003295 <a name="int_ctlz">'<tt>llvm.ctlz</tt>' Intrinsic</a>
3296</div>
3297
3298<div class="doc_text">
3299
3300<h5>Syntax:</h5>
3301<pre>
3302 declare int %llvm.ctlz(int &lt;src&gt;)
3303
3304</pre>
3305
3306<h5>Overview:</h5>
3307
3308<p>
Chris Lattner573f64e2005-05-07 01:46:40 +00003309The '<tt>llvm.ctlz</tt>' intrinsic counts the number of leading zeros in a
3310variable.
Andrew Lenharth1d463522005-05-03 18:01:48 +00003311</p>
3312
3313<h5>Arguments:</h5>
3314
3315<p>
Chris Lattner573f64e2005-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 Lenharth1d463522005-05-03 18:01:48 +00003318</p>
3319
3320<h5>Semantics:</h5>
3321
3322<p>
Chris Lattnerefa20fa2005-05-15 19:39:26 +00003323The '<tt>llvm.ctlz</tt>' intrinsic counts the leading (most significant) zeros
3324in a variable. If the src == 0 then the result is the size in bits of the type
3325of src. For example, <tt>llvm.cttz(int 2) = 30</tt>.
Andrew Lenharth1d463522005-05-03 18:01:48 +00003326</p>
3327</div>
Chris Lattner3b4f4372004-06-11 02:28:03 +00003328
3329
Chris Lattnerefa20fa2005-05-15 19:39:26 +00003330
3331<!-- _______________________________________________________________________ -->
3332<div class="doc_subsubsection">
3333 <a name="int_cttz">'<tt>llvm.cttz</tt>' Intrinsic</a>
3334</div>
3335
3336<div class="doc_text">
3337
3338<h5>Syntax:</h5>
3339<pre>
3340 declare int %llvm.cttz(int &lt;src&gt;)
3341
3342</pre>
3343
3344<h5>Overview:</h5>
3345
3346<p>
3347The '<tt>llvm.cttz</tt>' intrinsic counts the number of trailing zeros.
3348</p>
3349
3350<h5>Arguments:</h5>
3351
3352<p>
3353The only argument is the value to be counted. The argument may be of any
3354integer type. The return type must match the argument type.
3355</p>
3356
3357<h5>Semantics:</h5>
3358
3359<p>
3360The '<tt>llvm.cttz</tt>' intrinsic counts the trailing (least significant) zeros
3361in a variable. If the src == 0 then the result is the size in bits of the type
3362of src. For example, <tt>llvm.cttz(2) = 1</tt>.
3363</p>
3364</div>
3365
Chris Lattner941515c2004-01-06 05:31:32 +00003366<!-- ======================================================================= -->
3367<div class="doc_subsection">
3368 <a name="int_debugger">Debugger Intrinsics</a>
3369</div>
3370
3371<div class="doc_text">
3372<p>
3373The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
3374are described in the <a
3375href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
3376Debugging</a> document.
3377</p>
3378</div>
3379
3380
Chris Lattner2f7c9632001-06-06 20:29:01 +00003381<!-- *********************************************************************** -->
Chris Lattner2f7c9632001-06-06 20:29:01 +00003382<hr>
Misha Brukmanc501f552004-03-01 17:47:27 +00003383<address>
3384 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
3385 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
3386 <a href="http://validator.w3.org/check/referer"><img
3387 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
3388
3389 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
3390 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
3391 Last modified: $Date$
3392</address>
Misha Brukman76307852003-11-08 01:05:38 +00003393</body>
3394</html>