blob: 70071e05f756dcdc6838371d06c3d1812bd81866 [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>
Andrew Lenharth01aa5632005-11-11 16:47:30 +0000131 <li><a href="#i_readcyclecounter"><tt>llvm.readcyclecounter</tt>' Intrinsic</a></li>
John Criswellaa1c3c12004-04-09 16:43:20 +0000132 </ol>
133 </li>
134 <li><a href="#int_os">Operating System Intrinsics</a>
135 <ol>
Chris Lattner3b4f4372004-06-11 02:28:03 +0000136 <li><a href="#i_readport">'<tt>llvm.readport</tt>' Intrinsic</a></li>
137 <li><a href="#i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a></li>
John Criswella4501222004-04-12 15:02:16 +0000138 <li><a href="#i_readio">'<tt>llvm.readio</tt>' Intrinsic</a></li>
139 <li><a href="#i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a></li>
Chris Lattner3649c3a2004-02-14 04:08:35 +0000140 </ol>
Chris Lattnerfee11462004-02-12 17:01:32 +0000141 <li><a href="#int_libc">Standard C Library Intrinsics</a>
142 <ol>
143 <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li>
Chris Lattnerf30152e2004-02-12 18:10:10 +0000144 <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li>
Chris Lattner3649c3a2004-02-14 04:08:35 +0000145 <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li>
Alkis Evlogimenos9d740622004-06-12 19:19:14 +0000146 <li><a href="#i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a></li>
Chris Lattner8a8f2e52005-07-21 01:29:16 +0000147 <li><a href="#i_sqrt">'<tt>llvm.sqrt</tt>' Intrinsic</a></li>
148
Chris Lattnerfee11462004-02-12 17:01:32 +0000149 </ol>
150 </li>
Andrew Lenharth1d463522005-05-03 18:01:48 +0000151 <li><a href="#int_count">Bit counting Intrinsics</a>
152 <ol>
153 <li><a href="#int_ctpop">'<tt>llvm.ctpop</tt>' Intrinsic </a></li>
Andrew Lenharth1d463522005-05-03 18:01:48 +0000154 <li><a href="#int_ctlz">'<tt>llvm.ctlz</tt>' Intrinsic </a></li>
Chris Lattnerefa20fa2005-05-15 19:39:26 +0000155 <li><a href="#int_cttz">'<tt>llvm.cttz</tt>' Intrinsic </a></li>
Andrew Lenharth1d463522005-05-03 18:01:48 +0000156 </ol>
157 </li>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000158 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000159 </ol>
160 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000161</ol>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000162
163<div class="doc_author">
164 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
165 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
Misha Brukman76307852003-11-08 01:05:38 +0000166</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000167
Chris Lattner2f7c9632001-06-06 20:29:01 +0000168<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000169<div class="doc_section"> <a name="abstract">Abstract </a></div>
170<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000171
Misha Brukman76307852003-11-08 01:05:38 +0000172<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000173<p>This document is a reference manual for the LLVM assembly language.
174LLVM is an SSA based representation that provides type safety,
175low-level operations, flexibility, and the capability of representing
176'all' high-level languages cleanly. It is the common code
177representation used throughout all phases of the LLVM compilation
178strategy.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000179</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000180
Chris Lattner2f7c9632001-06-06 20:29:01 +0000181<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000182<div class="doc_section"> <a name="introduction">Introduction</a> </div>
183<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000184
Misha Brukman76307852003-11-08 01:05:38 +0000185<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000186
Chris Lattner48b383b02003-11-25 01:02:51 +0000187<p>The LLVM code representation is designed to be used in three
188different forms: as an in-memory compiler IR, as an on-disk bytecode
189representation (suitable for fast loading by a Just-In-Time compiler),
190and as a human readable assembly language representation. This allows
191LLVM to provide a powerful intermediate representation for efficient
192compiler transformations and analysis, while providing a natural means
193to debug and visualize the transformations. The three different forms
194of LLVM are all equivalent. This document describes the human readable
195representation and notation.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000196
John Criswell4a3327e2005-05-13 22:25:59 +0000197<p>The LLVM representation aims to be light-weight and low-level
Chris Lattner48b383b02003-11-25 01:02:51 +0000198while being expressive, typed, and extensible at the same time. It
199aims to be a "universal IR" of sorts, by being at a low enough level
200that high-level ideas may be cleanly mapped to it (similar to how
201microprocessors are "universal IR's", allowing many source languages to
202be mapped to them). By providing type information, LLVM can be used as
203the target of optimizations: for example, through pointer analysis, it
204can be proven that a C automatic variable is never accessed outside of
205the current function... allowing it to be promoted to a simple SSA
206value instead of a memory location.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000207
Misha Brukman76307852003-11-08 01:05:38 +0000208</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000209
Chris Lattner2f7c9632001-06-06 20:29:01 +0000210<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000211<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000212
Misha Brukman76307852003-11-08 01:05:38 +0000213<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000214
Chris Lattner48b383b02003-11-25 01:02:51 +0000215<p>It is important to note that this document describes 'well formed'
216LLVM assembly language. There is a difference between what the parser
217accepts and what is considered 'well formed'. For example, the
218following instruction is syntactically okay, but not well formed:</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000219
220<pre>
221 %x = <a href="#i_add">add</a> int 1, %x
222</pre>
223
Chris Lattner48b383b02003-11-25 01:02:51 +0000224<p>...because the definition of <tt>%x</tt> does not dominate all of
225its uses. The LLVM infrastructure provides a verification pass that may
226be used to verify that an LLVM module is well formed. This pass is
John Criswell4a3327e2005-05-13 22:25:59 +0000227automatically run by the parser after parsing input assembly and by
Chris Lattner48b383b02003-11-25 01:02:51 +0000228the optimizer before it outputs bytecode. The violations pointed out
229by the verifier pass indicate bugs in transformation passes or input to
230the parser.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000231
Chris Lattner48b383b02003-11-25 01:02:51 +0000232<!-- Describe the typesetting conventions here. --> </div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000233
Chris Lattner2f7c9632001-06-06 20:29:01 +0000234<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000235<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000236<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000237
Misha Brukman76307852003-11-08 01:05:38 +0000238<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000239
Chris Lattner48b383b02003-11-25 01:02:51 +0000240<p>LLVM uses three different forms of identifiers, for different
241purposes:</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000242
Chris Lattner2f7c9632001-06-06 20:29:01 +0000243<ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000244 <li>Named values are represented as a string of characters with a '%' prefix.
245 For example, %foo, %DivisionByZero, %a.really.long.identifier. The actual
246 regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
247 Identifiers which require other characters in their names can be surrounded
248 with quotes. In this way, anything except a <tt>"</tt> character can be used
249 in a name.</li>
250
251 <li>Unnamed values are represented as an unsigned numeric value with a '%'
252 prefix. For example, %12, %2, %44.</li>
253
Reid Spencer8f08d802004-12-09 18:02:53 +0000254 <li>Constants, which are described in a <a href="#constants">section about
255 constants</a>, below.</li>
Misha Brukman76307852003-11-08 01:05:38 +0000256</ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000257
258<p>LLVM requires that values start with a '%' sign for two reasons: Compilers
259don't need to worry about name clashes with reserved words, and the set of
260reserved words may be expanded in the future without penalty. Additionally,
261unnamed identifiers allow a compiler to quickly come up with a temporary
262variable without having to avoid symbol table conflicts.</p>
263
Chris Lattner48b383b02003-11-25 01:02:51 +0000264<p>Reserved words in LLVM are very similar to reserved words in other
265languages. There are keywords for different opcodes ('<tt><a
Chris Lattnerd79749a2004-12-09 16:36:40 +0000266href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
267href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
268href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>', etc...),
269and others. These reserved words cannot conflict with variable names, because
270none of them start with a '%' character.</p>
271
272<p>Here is an example of LLVM code to multiply the integer variable
273'<tt>%X</tt>' by 8:</p>
274
Misha Brukman76307852003-11-08 01:05:38 +0000275<p>The easy way:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000276
277<pre>
278 %result = <a href="#i_mul">mul</a> uint %X, 8
279</pre>
280
Misha Brukman76307852003-11-08 01:05:38 +0000281<p>After strength reduction:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000282
283<pre>
284 %result = <a href="#i_shl">shl</a> uint %X, ubyte 3
285</pre>
286
Misha Brukman76307852003-11-08 01:05:38 +0000287<p>And the hard way:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000288
289<pre>
290 <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
291 <a href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
292 %result = <a href="#i_add">add</a> uint %1, %1
293</pre>
294
Chris Lattner48b383b02003-11-25 01:02:51 +0000295<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
296important lexical features of LLVM:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000297
Chris Lattner2f7c9632001-06-06 20:29:01 +0000298<ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000299
300 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
301 line.</li>
302
303 <li>Unnamed temporaries are created when the result of a computation is not
304 assigned to a named value.</li>
305
Misha Brukman76307852003-11-08 01:05:38 +0000306 <li>Unnamed temporaries are numbered sequentially</li>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000307
Misha Brukman76307852003-11-08 01:05:38 +0000308</ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000309
John Criswell02fdc6f2005-05-12 16:52:32 +0000310<p>...and it also shows a convention that we follow in this document. When
Chris Lattnerd79749a2004-12-09 16:36:40 +0000311demonstrating instructions, we will follow an instruction with a comment that
312defines the type and name of value produced. Comments are shown in italic
313text.</p>
314
Misha Brukman76307852003-11-08 01:05:38 +0000315</div>
Chris Lattner6af02f32004-12-09 16:11:40 +0000316
317<!-- *********************************************************************** -->
318<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
319<!-- *********************************************************************** -->
320
321<!-- ======================================================================= -->
322<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
323</div>
324
325<div class="doc_text">
326
327<p>LLVM programs are composed of "Module"s, each of which is a
328translation unit of the input programs. Each module consists of
329functions, global variables, and symbol table entries. Modules may be
330combined together with the LLVM linker, which merges function (and
331global variable) definitions, resolves forward declarations, and merges
332symbol table entries. Here is an example of the "hello world" module:</p>
333
334<pre><i>; Declare the string constant as a global constant...</i>
335<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
336 href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00" <i>; [13 x sbyte]*</i>
337
338<i>; External declaration of the puts function</i>
339<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
340
341<i>; Definition of main function</i>
342int %main() { <i>; int()* </i>
343 <i>; Convert [13x sbyte]* to sbyte *...</i>
344 %cast210 = <a
345 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
346
347 <i>; Call puts function to write out the string to stdout...</i>
348 <a
349 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
350 <a
351 href="#i_ret">ret</a> int 0<br>}<br></pre>
352
353<p>This example is made up of a <a href="#globalvars">global variable</a>
354named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
355function, and a <a href="#functionstructure">function definition</a>
356for "<tt>main</tt>".</p>
357
Chris Lattnerd79749a2004-12-09 16:36:40 +0000358<p>In general, a module is made up of a list of global values,
359where both functions and global variables are global values. Global values are
360represented by a pointer to a memory location (in this case, a pointer to an
361array of char, and a pointer to a function), and have one of the following <a
362href="#linkage">linkage types</a>.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000363
Chris Lattnerd79749a2004-12-09 16:36:40 +0000364</div>
365
366<!-- ======================================================================= -->
367<div class="doc_subsection">
368 <a name="linkage">Linkage Types</a>
369</div>
370
371<div class="doc_text">
372
373<p>
374All Global Variables and Functions have one of the following types of linkage:
375</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000376
377<dl>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000378
Chris Lattner6af02f32004-12-09 16:11:40 +0000379 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000380
381 <dd>Global values with internal linkage are only directly accessible by
382 objects in the current module. In particular, linking code into a module with
383 an internal global value may cause the internal to be renamed as necessary to
384 avoid collisions. Because the symbol is internal to the module, all
385 references can be updated. This corresponds to the notion of the
386 '<tt>static</tt>' keyword in C, or the idea of "anonymous namespaces" in C++.
Chris Lattner6af02f32004-12-09 16:11:40 +0000387 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000388
Chris Lattner6af02f32004-12-09 16:11:40 +0000389 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000390
391 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt> linkage, with
392 the twist that linking together two modules defining the same
393 <tt>linkonce</tt> globals will cause one of the globals to be discarded. This
394 is typically used to implement inline functions. Unreferenced
395 <tt>linkonce</tt> globals are allowed to be discarded.
Chris Lattner6af02f32004-12-09 16:11:40 +0000396 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000397
Chris Lattner6af02f32004-12-09 16:11:40 +0000398 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000399
400 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage,
401 except that unreferenced <tt>weak</tt> globals may not be discarded. This is
402 used to implement constructs in C such as "<tt>int X;</tt>" at global scope.
Chris Lattner6af02f32004-12-09 16:11:40 +0000403 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000404
Chris Lattner6af02f32004-12-09 16:11:40 +0000405 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000406
407 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
408 pointer to array type. When two global variables with appending linkage are
409 linked together, the two global arrays are appended together. This is the
410 LLVM, typesafe, equivalent of having the system linker append together
411 "sections" with identical names when .o files are linked.
Chris Lattner6af02f32004-12-09 16:11:40 +0000412 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000413
Chris Lattner6af02f32004-12-09 16:11:40 +0000414 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000415
416 <dd>If none of the above identifiers are used, the global is externally
417 visible, meaning that it participates in linkage and can be used to resolve
418 external symbol references.
Chris Lattner6af02f32004-12-09 16:11:40 +0000419 </dd>
420</dl>
421
Chris Lattner6af02f32004-12-09 16:11:40 +0000422<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
423variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
424variable and was linked with this one, one of the two would be renamed,
425preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
426external (i.e., lacking any linkage declarations), they are accessible
427outside of the current module. It is illegal for a function <i>declaration</i>
428to have any linkage type other than "externally visible".</a></p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000429
Chris Lattner6af02f32004-12-09 16:11:40 +0000430</div>
431
432<!-- ======================================================================= -->
433<div class="doc_subsection">
Chris Lattner0132aff2005-05-06 22:57:40 +0000434 <a name="callingconv">Calling Conventions</a>
435</div>
436
437<div class="doc_text">
438
439<p>LLVM <a href="#functionstructure">functions</a>, <a href="#i_call">calls</a>
440and <a href="#i_invoke">invokes</a> can all have an optional calling convention
441specified for the call. The calling convention of any pair of dynamic
442caller/callee must match, or the behavior of the program is undefined. The
443following calling conventions are supported by LLVM, and more may be added in
444the future:</p>
445
446<dl>
447 <dt><b>"<tt>ccc</tt>" - The C calling convention</b>:</dt>
448
449 <dd>This calling convention (the default if no other calling convention is
450 specified) matches the target C calling conventions. This calling convention
John Criswell02fdc6f2005-05-12 16:52:32 +0000451 supports varargs function calls and tolerates some mismatch in the declared
Chris Lattner0132aff2005-05-06 22:57:40 +0000452 prototype and implemented declaration of the function (as does normal C).
453 </dd>
454
455 <dt><b>"<tt>fastcc</tt>" - The fast calling convention</b>:</dt>
456
457 <dd>This calling convention attempts to make calls as fast as possible
458 (e.g. by passing things in registers). This calling convention allows the
459 target to use whatever tricks it wants to produce fast code for the target,
Chris Lattnerc792eb32005-05-06 23:08:23 +0000460 without having to conform to an externally specified ABI. Implementations of
461 this convention should allow arbitrary tail call optimization to be supported.
462 This calling convention does not support varargs and requires the prototype of
463 all callees to exactly match the prototype of the function definition.
Chris Lattner0132aff2005-05-06 22:57:40 +0000464 </dd>
465
466 <dt><b>"<tt>coldcc</tt>" - The cold calling convention</b>:</dt>
467
468 <dd>This calling convention attempts to make code in the caller as efficient
469 as possible under the assumption that the call is not commonly executed. As
470 such, these calls often preserve all registers so that the call does not break
471 any live ranges in the caller side. This calling convention does not support
472 varargs and requires the prototype of all callees to exactly match the
473 prototype of the function definition.
474 </dd>
475
Chris Lattner573f64e2005-05-07 01:46:40 +0000476 <dt><b>"<tt>cc &lt;<em>n</em>&gt;</tt>" - Numbered convention</b>:</dt>
Chris Lattner0132aff2005-05-06 22:57:40 +0000477
478 <dd>Any calling convention may be specified by number, allowing
479 target-specific calling conventions to be used. Target specific calling
480 conventions start at 64.
481 </dd>
Chris Lattner573f64e2005-05-07 01:46:40 +0000482</dl>
Chris Lattner0132aff2005-05-06 22:57:40 +0000483
484<p>More calling conventions can be added/defined on an as-needed basis, to
485support pascal conventions or any other well-known target-independent
486convention.</p>
487
488</div>
489
490<!-- ======================================================================= -->
491<div class="doc_subsection">
Chris Lattner6af02f32004-12-09 16:11:40 +0000492 <a name="globalvars">Global Variables</a>
493</div>
494
495<div class="doc_text">
496
Chris Lattner5d5aede2005-02-12 19:30:21 +0000497<p>Global variables define regions of memory allocated at compilation time
Chris Lattner662c8722005-11-12 00:45:07 +0000498instead of run-time. Global variables may optionally be initialized, may have
499an explicit section to be placed in, and may
Chris Lattner54611b42005-11-06 08:02:57 +0000500have an optional explicit alignment specified. A
John Criswell4c0cf7f2005-10-24 16:17:18 +0000501variable may be defined as a global "constant," which indicates that the
Chris Lattner5d5aede2005-02-12 19:30:21 +0000502contents of the variable will <b>never</b> be modified (enabling better
503optimization, allowing the global data to be placed in the read-only section of
504an executable, etc). Note that variables that need runtime initialization
John Criswell4c0cf7f2005-10-24 16:17:18 +0000505cannot be marked "constant" as there is a store to the variable.</p>
Chris Lattner5d5aede2005-02-12 19:30:21 +0000506
507<p>
508LLVM explicitly allows <em>declarations</em> of global variables to be marked
509constant, even if the final definition of the global is not. This capability
510can be used to enable slightly better optimization of the program, but requires
511the language definition to guarantee that optimizations based on the
512'constantness' are valid for the translation units that do not include the
513definition.
514</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000515
516<p>As SSA values, global variables define pointer values that are in
517scope (i.e. they dominate) all basic blocks in the program. Global
518variables always define a pointer to their "content" type because they
519describe a region of memory, and all memory objects in LLVM are
520accessed through pointers.</p>
521
Chris Lattner662c8722005-11-12 00:45:07 +0000522<p>LLVM allows an explicit section to be specified for globals. If the target
523supports it, it will emit globals to the section specified.</p>
524
Chris Lattner54611b42005-11-06 08:02:57 +0000525<p>An explicit alignment may be specified for a global. If not present, or if
526the alignment is set to zero, the alignment of the global is set by the target
527to whatever it feels convenient. If an explicit alignment is specified, the
528global is forced to have at least that much alignment. All alignments must be
529a power of 2.</p>
530
Chris Lattner6af02f32004-12-09 16:11:40 +0000531</div>
532
533
534<!-- ======================================================================= -->
535<div class="doc_subsection">
536 <a name="functionstructure">Functions</a>
537</div>
538
539<div class="doc_text">
540
Chris Lattner0132aff2005-05-06 22:57:40 +0000541<p>LLVM function definitions consist of an optional <a href="#linkage">linkage
542type</a>, an optional <a href="#callingconv">calling convention</a>, a return
Chris Lattner662c8722005-11-12 00:45:07 +0000543type, a function name, a (possibly empty) argument list, an optional section,
544an optional alignment, an opening curly brace,
Chris Lattner0132aff2005-05-06 22:57:40 +0000545a list of basic blocks, and a closing curly brace. LLVM function declarations
546are defined with the "<tt>declare</tt>" keyword, an optional <a
Chris Lattner54611b42005-11-06 08:02:57 +0000547href="#callingconv">calling convention</a>, a return type, a function name,
548a possibly empty list of arguments, and an optional alignment.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000549
550<p>A function definition contains a list of basic blocks, forming the CFG for
551the function. Each basic block may optionally start with a label (giving the
552basic block a symbol table entry), contains a list of instructions, and ends
553with a <a href="#terminators">terminator</a> instruction (such as a branch or
554function return).</p>
555
John Criswell02fdc6f2005-05-12 16:52:32 +0000556<p>The first basic block in a program is special in two ways: it is immediately
Chris Lattner6af02f32004-12-09 16:11:40 +0000557executed on entrance to the function, and it is not allowed to have predecessor
558basic blocks (i.e. there can not be any branches to the entry block of a
559function). Because the block can have no predecessors, it also cannot have any
560<a href="#i_phi">PHI nodes</a>.</p>
561
562<p>LLVM functions are identified by their name and type signature. Hence, two
563functions with the same name but different parameter lists or return values are
Chris Lattner455fc8c2005-03-07 22:13:59 +0000564considered different functions, and LLVM will resolve references to each
Chris Lattner6af02f32004-12-09 16:11:40 +0000565appropriately.</p>
566
Chris Lattner662c8722005-11-12 00:45:07 +0000567<p>LLVM allows an explicit section to be specified for functions. If the target
568supports it, it will emit functions to the section specified.</p>
569
Chris Lattner54611b42005-11-06 08:02:57 +0000570<p>An explicit alignment may be specified for a function. If not present, or if
571the alignment is set to zero, the alignment of the function is set by the target
572to whatever it feels convenient. If an explicit alignment is specified, the
573function is forced to have at least that much alignment. All alignments must be
574a power of 2.</p>
575
Chris Lattner6af02f32004-12-09 16:11:40 +0000576</div>
577
578
579
Chris Lattner2f7c9632001-06-06 20:29:01 +0000580<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000581<div class="doc_section"> <a name="typesystem">Type System</a> </div>
582<!-- *********************************************************************** -->
Chris Lattner6af02f32004-12-09 16:11:40 +0000583
Misha Brukman76307852003-11-08 01:05:38 +0000584<div class="doc_text">
Chris Lattner6af02f32004-12-09 16:11:40 +0000585
Misha Brukman76307852003-11-08 01:05:38 +0000586<p>The LLVM type system is one of the most important features of the
Chris Lattner48b383b02003-11-25 01:02:51 +0000587intermediate representation. Being typed enables a number of
588optimizations to be performed on the IR directly, without having to do
589extra analyses on the side before the transformation. A strong type
590system makes it easier to read the generated code and enables novel
591analyses and transformations that are not feasible to perform on normal
592three address code representations.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000593
594</div>
595
Chris Lattner2f7c9632001-06-06 20:29:01 +0000596<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000597<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000598<div class="doc_text">
John Criswell417228d2004-04-09 16:48:45 +0000599<p>The primitive types are the fundamental building blocks of the LLVM
Chris Lattner455fc8c2005-03-07 22:13:59 +0000600system. The current set of primitive types is as follows:</p>
Misha Brukmanc501f552004-03-01 17:47:27 +0000601
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000602<table class="layout">
603 <tr class="layout">
604 <td class="left">
605 <table>
Chris Lattner48b383b02003-11-25 01:02:51 +0000606 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000607 <tr><th>Type</th><th>Description</th></tr>
608 <tr><td><tt>void</tt></td><td>No value</td></tr>
Misha Brukman36c6bc12005-04-22 18:02:52 +0000609 <tr><td><tt>ubyte</tt></td><td>Unsigned 8-bit value</td></tr>
610 <tr><td><tt>ushort</tt></td><td>Unsigned 16-bit value</td></tr>
611 <tr><td><tt>uint</tt></td><td>Unsigned 32-bit value</td></tr>
612 <tr><td><tt>ulong</tt></td><td>Unsigned 64-bit value</td></tr>
613 <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000614 <tr><td><tt>label</tt></td><td>Branch destination</td></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000615 </tbody>
616 </table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000617 </td>
618 <td class="right">
619 <table>
Chris Lattner48b383b02003-11-25 01:02:51 +0000620 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000621 <tr><th>Type</th><th>Description</th></tr>
622 <tr><td><tt>bool</tt></td><td>True or False value</td></tr>
Misha Brukman36c6bc12005-04-22 18:02:52 +0000623 <tr><td><tt>sbyte</tt></td><td>Signed 8-bit value</td></tr>
624 <tr><td><tt>short</tt></td><td>Signed 16-bit value</td></tr>
625 <tr><td><tt>int</tt></td><td>Signed 32-bit value</td></tr>
626 <tr><td><tt>long</tt></td><td>Signed 64-bit value</td></tr>
627 <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000628 </tbody>
629 </table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000630 </td>
631 </tr>
Misha Brukman76307852003-11-08 01:05:38 +0000632</table>
Misha Brukman76307852003-11-08 01:05:38 +0000633</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000634
Chris Lattner2f7c9632001-06-06 20:29:01 +0000635<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000636<div class="doc_subsubsection"> <a name="t_classifications">Type
637Classifications</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000638<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000639<p>These different primitive types fall into a few useful
640classifications:</p>
Misha Brukmanc501f552004-03-01 17:47:27 +0000641
642<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +0000643 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000644 <tr><th>Classification</th><th>Types</th></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000645 <tr>
646 <td><a name="t_signed">signed</a></td>
647 <td><tt>sbyte, short, int, long, float, double</tt></td>
648 </tr>
649 <tr>
650 <td><a name="t_unsigned">unsigned</a></td>
651 <td><tt>ubyte, ushort, uint, ulong</tt></td>
652 </tr>
653 <tr>
654 <td><a name="t_integer">integer</a></td>
655 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
656 </tr>
657 <tr>
658 <td><a name="t_integral">integral</a></td>
Misha Brukman20f9a622004-08-12 20:16:08 +0000659 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt>
660 </td>
Chris Lattner48b383b02003-11-25 01:02:51 +0000661 </tr>
662 <tr>
663 <td><a name="t_floating">floating point</a></td>
664 <td><tt>float, double</tt></td>
665 </tr>
666 <tr>
667 <td><a name="t_firstclass">first class</a></td>
Misha Brukman20f9a622004-08-12 20:16:08 +0000668 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long,<br>
669 float, double, <a href="#t_pointer">pointer</a>,
670 <a href="#t_packed">packed</a></tt></td>
Chris Lattner48b383b02003-11-25 01:02:51 +0000671 </tr>
672 </tbody>
Misha Brukman76307852003-11-08 01:05:38 +0000673</table>
Misha Brukmanc501f552004-03-01 17:47:27 +0000674
Chris Lattner48b383b02003-11-25 01:02:51 +0000675<p>The <a href="#t_firstclass">first class</a> types are perhaps the
676most important. Values of these types are the only ones which can be
677produced by instructions, passed as arguments, or used as operands to
678instructions. This means that all structures and arrays must be
679manipulated either by pointer or by component.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000680</div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000681
Chris Lattner2f7c9632001-06-06 20:29:01 +0000682<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000683<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000684
Misha Brukman76307852003-11-08 01:05:38 +0000685<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +0000686
Chris Lattner48b383b02003-11-25 01:02:51 +0000687<p>The real power in LLVM comes from the derived types in the system.
688This is what allows a programmer to represent arrays, functions,
689pointers, and other useful types. Note that these derived types may be
690recursive: For example, it is possible to have a two dimensional array.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000691
Misha Brukman76307852003-11-08 01:05:38 +0000692</div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000693
Chris Lattner2f7c9632001-06-06 20:29:01 +0000694<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000695<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000696
Misha Brukman76307852003-11-08 01:05:38 +0000697<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +0000698
Chris Lattner2f7c9632001-06-06 20:29:01 +0000699<h5>Overview:</h5>
Chris Lattner74d3f822004-12-09 17:30:23 +0000700
Misha Brukman76307852003-11-08 01:05:38 +0000701<p>The array type is a very simple derived type that arranges elements
Chris Lattner48b383b02003-11-25 01:02:51 +0000702sequentially in memory. The array type requires a size (number of
703elements) and an underlying data type.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000704
Chris Lattner590645f2002-04-14 06:13:44 +0000705<h5>Syntax:</h5>
Chris Lattner74d3f822004-12-09 17:30:23 +0000706
707<pre>
708 [&lt;# elements&gt; x &lt;elementtype&gt;]
709</pre>
710
John Criswell02fdc6f2005-05-12 16:52:32 +0000711<p>The number of elements is a constant integer value; elementtype may
Chris Lattner48b383b02003-11-25 01:02:51 +0000712be any type with a size.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000713
Chris Lattner590645f2002-04-14 06:13:44 +0000714<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000715<table class="layout">
716 <tr class="layout">
717 <td class="left">
718 <tt>[40 x int ]</tt><br/>
719 <tt>[41 x int ]</tt><br/>
720 <tt>[40 x uint]</tt><br/>
721 </td>
722 <td class="left">
723 Array of 40 integer values.<br/>
724 Array of 41 integer values.<br/>
725 Array of 40 unsigned integer values.<br/>
726 </td>
727 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000728</table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000729<p>Here are some examples of multidimensional arrays:</p>
730<table class="layout">
731 <tr class="layout">
732 <td class="left">
733 <tt>[3 x [4 x int]]</tt><br/>
734 <tt>[12 x [10 x float]]</tt><br/>
735 <tt>[2 x [3 x [4 x uint]]]</tt><br/>
736 </td>
737 <td class="left">
John Criswell4a3327e2005-05-13 22:25:59 +0000738 3x4 array of integer values.<br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000739 12x10 array of single precision floating point values.<br/>
740 2x3x4 array of unsigned integer values.<br/>
741 </td>
742 </tr>
743</table>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +0000744
John Criswell4c0cf7f2005-10-24 16:17:18 +0000745<p>Note that 'variable sized arrays' can be implemented in LLVM with a zero
746length array. Normally, accesses past the end of an array are undefined in
Chris Lattnerc0ad71e2005-06-24 17:22:57 +0000747LLVM (e.g. it is illegal to access the 5th element of a 3 element array).
748As a special case, however, zero length arrays are recognized to be variable
749length. This allows implementation of 'pascal style arrays' with the LLVM
750type "{ int, [0 x float]}", for example.</p>
751
Misha Brukman76307852003-11-08 01:05:38 +0000752</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000753
Chris Lattner2f7c9632001-06-06 20:29:01 +0000754<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000755<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000756<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000757<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000758<p>The function type can be thought of as a function signature. It
759consists of a return type and a list of formal parameter types.
John Criswella0d50d22003-11-25 21:45:46 +0000760Function types are usually used to build virtual function tables
Chris Lattner48b383b02003-11-25 01:02:51 +0000761(which are structures of pointers to functions), for indirect function
762calls, and when defining a function.</p>
John Criswella0d50d22003-11-25 21:45:46 +0000763<p>
764The return type of a function type cannot be an aggregate type.
765</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000766<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000767<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
John Criswell4c0cf7f2005-10-24 16:17:18 +0000768<p>...where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
Misha Brukman20f9a622004-08-12 20:16:08 +0000769specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner5ed60612003-09-03 00:41:47 +0000770which indicates that the function takes a variable number of arguments.
771Variable argument functions can access their arguments with the <a
Chris Lattner48b383b02003-11-25 01:02:51 +0000772 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000773<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000774<table class="layout">
775 <tr class="layout">
776 <td class="left">
777 <tt>int (int)</tt> <br/>
778 <tt>float (int, int *) *</tt><br/>
779 <tt>int (sbyte *, ...)</tt><br/>
780 </td>
781 <td class="left">
782 function taking an <tt>int</tt>, returning an <tt>int</tt><br/>
783 <a href="#t_pointer">Pointer</a> to a function that takes an
Misha Brukman20f9a622004-08-12 20:16:08 +0000784 <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000785 returning <tt>float</tt>.<br/>
786 A vararg function that takes at least one <a href="#t_pointer">pointer</a>
787 to <tt>sbyte</tt> (signed char in C), which returns an integer. This is
788 the signature for <tt>printf</tt> in LLVM.<br/>
789 </td>
790 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000791</table>
Misha Brukmanc501f552004-03-01 17:47:27 +0000792
Misha Brukman76307852003-11-08 01:05:38 +0000793</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000794<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000795<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000796<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000797<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000798<p>The structure type is used to represent a collection of data members
799together in memory. The packing of the field types is defined to match
800the ABI of the underlying processor. The elements of a structure may
801be any type that has a size.</p>
802<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
803and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
804field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
805instruction.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000806<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000807<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000808<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000809<table class="layout">
810 <tr class="layout">
811 <td class="left">
812 <tt>{ int, int, int }</tt><br/>
813 <tt>{ float, int (int) * }</tt><br/>
814 </td>
815 <td class="left">
816 a triple of three <tt>int</tt> values<br/>
817 A pair, where the first element is a <tt>float</tt> and the second element
818 is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a>
819 that takes an <tt>int</tt>, returning an <tt>int</tt>.<br/>
820 </td>
821 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000822</table>
Misha Brukman76307852003-11-08 01:05:38 +0000823</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000824
Chris Lattner2f7c9632001-06-06 20:29:01 +0000825<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000826<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000827<div class="doc_text">
Chris Lattner590645f2002-04-14 06:13:44 +0000828<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000829<p>As in many languages, the pointer type represents a pointer or
830reference to another object, which must live in memory.</p>
Chris Lattner590645f2002-04-14 06:13:44 +0000831<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000832<pre> &lt;type&gt; *<br></pre>
Chris Lattner590645f2002-04-14 06:13:44 +0000833<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000834<table class="layout">
835 <tr class="layout">
836 <td class="left">
837 <tt>[4x int]*</tt><br/>
838 <tt>int (int *) *</tt><br/>
839 </td>
840 <td class="left">
841 A <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of
842 four <tt>int</tt> values<br/>
843 A <a href="#t_pointer">pointer</a> to a <a
Chris Lattner16fb0032005-02-19 02:22:14 +0000844 href="#t_function">function</a> that takes an <tt>int*</tt>, returning an
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000845 <tt>int</tt>.<br/>
846 </td>
847 </tr>
Misha Brukman76307852003-11-08 01:05:38 +0000848</table>
Misha Brukman76307852003-11-08 01:05:38 +0000849</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000850
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000851<!-- _______________________________________________________________________ -->
852<div class="doc_subsubsection"> <a name="t_packed">Packed Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000853<div class="doc_text">
Chris Lattner37b6b092005-04-25 17:34:15 +0000854
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000855<h5>Overview:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +0000856
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000857<p>A packed type is a simple derived type that represents a vector
858of elements. Packed types are used when multiple primitive data
859are operated in parallel using a single instruction (SIMD).
860A packed type requires a size (number of
Chris Lattner330ce692005-11-10 01:44:22 +0000861elements) and an underlying primitive data type. Vectors must have a power
862of two length (1, 2, 4, 8, 16 ...). Packed types are
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000863considered <a href="#t_firstclass">first class</a>.</p>
Chris Lattner37b6b092005-04-25 17:34:15 +0000864
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000865<h5>Syntax:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +0000866
867<pre>
868 &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;
869</pre>
870
John Criswell4a3327e2005-05-13 22:25:59 +0000871<p>The number of elements is a constant integer value; elementtype may
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000872be any integral or floating point type.</p>
Chris Lattner37b6b092005-04-25 17:34:15 +0000873
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000874<h5>Examples:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +0000875
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000876<table class="layout">
877 <tr class="layout">
878 <td class="left">
879 <tt>&lt;4 x int&gt;</tt><br/>
880 <tt>&lt;8 x float&gt;</tt><br/>
881 <tt>&lt;2 x uint&gt;</tt><br/>
882 </td>
883 <td class="left">
884 Packed vector of 4 integer values.<br/>
885 Packed vector of 8 floating-point values.<br/>
886 Packed vector of 2 unsigned integer values.<br/>
887 </td>
888 </tr>
889</table>
Misha Brukman76307852003-11-08 01:05:38 +0000890</div>
891
Chris Lattner37b6b092005-04-25 17:34:15 +0000892<!-- _______________________________________________________________________ -->
893<div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div>
894<div class="doc_text">
895
896<h5>Overview:</h5>
897
898<p>Opaque types are used to represent unknown types in the system. This
899corresponds (for example) to the C notion of a foward declared structure type.
900In LLVM, opaque types can eventually be resolved to any type (not just a
901structure type).</p>
902
903<h5>Syntax:</h5>
904
905<pre>
906 opaque
907</pre>
908
909<h5>Examples:</h5>
910
911<table class="layout">
912 <tr class="layout">
913 <td class="left">
914 <tt>opaque</tt>
915 </td>
916 <td class="left">
917 An opaque type.<br/>
918 </td>
919 </tr>
920</table>
921</div>
922
923
Chris Lattner74d3f822004-12-09 17:30:23 +0000924<!-- *********************************************************************** -->
925<div class="doc_section"> <a name="constants">Constants</a> </div>
926<!-- *********************************************************************** -->
927
928<div class="doc_text">
929
930<p>LLVM has several different basic types of constants. This section describes
931them all and their syntax.</p>
932
933</div>
934
935<!-- ======================================================================= -->
Reid Spencer8f08d802004-12-09 18:02:53 +0000936<div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000937
938<div class="doc_text">
939
940<dl>
941 <dt><b>Boolean constants</b></dt>
942
943 <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
944 constants of the <tt><a href="#t_primitive">bool</a></tt> type.
945 </dd>
946
947 <dt><b>Integer constants</b></dt>
948
Reid Spencer8f08d802004-12-09 18:02:53 +0000949 <dd>Standard integers (such as '4') are constants of the <a
Chris Lattner74d3f822004-12-09 17:30:23 +0000950 href="#t_integer">integer</a> type. Negative numbers may be used with signed
951 integer types.
952 </dd>
953
954 <dt><b>Floating point constants</b></dt>
955
956 <dd>Floating point constants use standard decimal notation (e.g. 123.421),
957 exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
Chris Lattner74d3f822004-12-09 17:30:23 +0000958 notation (see below). Floating point constants must have a <a
959 href="#t_floating">floating point</a> type. </dd>
960
961 <dt><b>Null pointer constants</b></dt>
962
John Criswelldfe6a862004-12-10 15:51:16 +0000963 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
Chris Lattner74d3f822004-12-09 17:30:23 +0000964 and must be of <a href="#t_pointer">pointer type</a>.</dd>
965
966</dl>
967
John Criswelldfe6a862004-12-10 15:51:16 +0000968<p>The one non-intuitive notation for constants is the optional hexadecimal form
Chris Lattner74d3f822004-12-09 17:30:23 +0000969of floating point constants. For example, the form '<tt>double
9700x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
9714.5e+15</tt>'. The only time hexadecimal floating point constants are required
Reid Spencer8f08d802004-12-09 18:02:53 +0000972(and the only time that they are generated by the disassembler) is when a
973floating point constant must be emitted but it cannot be represented as a
974decimal floating point number. For example, NaN's, infinities, and other
975special values are represented in their IEEE hexadecimal format so that
976assembly and disassembly do not cause any bits to change in the constants.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000977
978</div>
979
980<!-- ======================================================================= -->
981<div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a>
982</div>
983
984<div class="doc_text">
Chris Lattner455fc8c2005-03-07 22:13:59 +0000985<p>Aggregate constants arise from aggregation of simple constants
986and smaller aggregate constants.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000987
988<dl>
989 <dt><b>Structure constants</b></dt>
990
991 <dd>Structure constants are represented with notation similar to structure
992 type definitions (a comma separated list of elements, surrounded by braces
Chris Lattner455fc8c2005-03-07 22:13:59 +0000993 (<tt>{}</tt>)). For example: "<tt>{ int 4, float 17.0, int* %G }</tt>",
994 where "<tt>%G</tt>" is declared as "<tt>%G = external global int</tt>". Structure constants
995 must have <a href="#t_struct">structure type</a>, and the number and
Chris Lattner74d3f822004-12-09 17:30:23 +0000996 types of elements must match those specified by the type.
997 </dd>
998
999 <dt><b>Array constants</b></dt>
1000
1001 <dd>Array constants are represented with notation similar to array type
1002 definitions (a comma separated list of elements, surrounded by square brackets
John Criswelldfe6a862004-12-10 15:51:16 +00001003 (<tt>[]</tt>)). For example: "<tt>[ int 42, int 11, int 74 ]</tt>". Array
Chris Lattner74d3f822004-12-09 17:30:23 +00001004 constants must have <a href="#t_array">array type</a>, and the number and
1005 types of elements must match those specified by the type.
1006 </dd>
1007
1008 <dt><b>Packed constants</b></dt>
1009
1010 <dd>Packed constants are represented with notation similar to packed type
1011 definitions (a comma separated list of elements, surrounded by
John Criswelldfe6a862004-12-10 15:51:16 +00001012 less-than/greater-than's (<tt>&lt;&gt;</tt>)). For example: "<tt>&lt; int 42,
Chris Lattner74d3f822004-12-09 17:30:23 +00001013 int 11, int 74, int 100 &gt;</tt>". Packed constants must have <a
1014 href="#t_packed">packed type</a>, and the number and types of elements must
1015 match those specified by the type.
1016 </dd>
1017
1018 <dt><b>Zero initialization</b></dt>
1019
1020 <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
1021 value to zero of <em>any</em> type, including scalar and aggregate types.
1022 This is often used to avoid having to print large zero initializers (e.g. for
John Criswell4c0cf7f2005-10-24 16:17:18 +00001023 large arrays) and is always exactly equivalent to using explicit zero
Chris Lattner74d3f822004-12-09 17:30:23 +00001024 initializers.
1025 </dd>
1026</dl>
1027
1028</div>
1029
1030<!-- ======================================================================= -->
1031<div class="doc_subsection">
1032 <a name="globalconstants">Global Variable and Function Addresses</a>
1033</div>
1034
1035<div class="doc_text">
1036
1037<p>The addresses of <a href="#globalvars">global variables</a> and <a
1038href="#functionstructure">functions</a> are always implicitly valid (link-time)
John Criswelldfe6a862004-12-10 15:51:16 +00001039constants. These constants are explicitly referenced when the <a
1040href="#identifiers">identifier for the global</a> is used and always have <a
Chris Lattner74d3f822004-12-09 17:30:23 +00001041href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
1042file:</p>
1043
1044<pre>
1045 %X = global int 17
1046 %Y = global int 42
1047 %Z = global [2 x int*] [ int* %X, int* %Y ]
1048</pre>
1049
1050</div>
1051
1052<!-- ======================================================================= -->
Reid Spencer641f5c92004-12-09 18:13:12 +00001053<div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001054<div class="doc_text">
Reid Spencer641f5c92004-12-09 18:13:12 +00001055 <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has
John Criswell4a3327e2005-05-13 22:25:59 +00001056 no specific value. Undefined values may be of any type and be used anywhere
Reid Spencer641f5c92004-12-09 18:13:12 +00001057 a constant is permitted.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001058
Reid Spencer641f5c92004-12-09 18:13:12 +00001059 <p>Undefined values indicate to the compiler that the program is well defined
1060 no matter what value is used, giving the compiler more freedom to optimize.
1061 </p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001062</div>
1063
1064<!-- ======================================================================= -->
1065<div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
1066</div>
1067
1068<div class="doc_text">
1069
1070<p>Constant expressions are used to allow expressions involving other constants
1071to be used as constants. Constant expressions may be of any <a
John Criswell4a3327e2005-05-13 22:25:59 +00001072href="#t_firstclass">first class</a> type and may involve any LLVM operation
Chris Lattner74d3f822004-12-09 17:30:23 +00001073that does not have side effects (e.g. load and call are not supported). The
1074following is the syntax for constant expressions:</p>
1075
1076<dl>
1077 <dt><b><tt>cast ( CST to TYPE )</tt></b></dt>
1078
1079 <dd>Cast a constant to another type.</dd>
1080
1081 <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
1082
1083 <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
1084 constants. As with the <a href="#i_getelementptr">getelementptr</a>
1085 instruction, the index list may have zero or more indexes, which are required
1086 to make sense for the type of "CSTPTR".</dd>
1087
1088 <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
1089
Reid Spencer641f5c92004-12-09 18:13:12 +00001090 <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
1091 be any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise
Chris Lattner74d3f822004-12-09 17:30:23 +00001092 binary</a> operations. The constraints on operands are the same as those for
1093 the corresponding instruction (e.g. no bitwise operations on floating point
John Criswell02fdc6f2005-05-12 16:52:32 +00001094 values are allowed).</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001095</dl>
Chris Lattner74d3f822004-12-09 17:30:23 +00001096</div>
Chris Lattnerb1652612004-03-08 16:49:10 +00001097
Chris Lattner2f7c9632001-06-06 20:29:01 +00001098<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001099<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
1100<!-- *********************************************************************** -->
Chris Lattner74d3f822004-12-09 17:30:23 +00001101
Misha Brukman76307852003-11-08 01:05:38 +00001102<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00001103
Chris Lattner48b383b02003-11-25 01:02:51 +00001104<p>The LLVM instruction set consists of several different
1105classifications of instructions: <a href="#terminators">terminator
John Criswell4a3327e2005-05-13 22:25:59 +00001106instructions</a>, <a href="#binaryops">binary instructions</a>,
1107<a href="#bitwiseops">bitwise binary instructions</a>, <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001108 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
1109instructions</a>.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001110
Misha Brukman76307852003-11-08 01:05:38 +00001111</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001112
Chris Lattner2f7c9632001-06-06 20:29:01 +00001113<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001114<div class="doc_subsection"> <a name="terminators">Terminator
1115Instructions</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001116
Misha Brukman76307852003-11-08 01:05:38 +00001117<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00001118
Chris Lattner48b383b02003-11-25 01:02:51 +00001119<p>As mentioned <a href="#functionstructure">previously</a>, every
1120basic block in a program ends with a "Terminator" instruction, which
1121indicates which block should be executed after the current block is
1122finished. These terminator instructions typically yield a '<tt>void</tt>'
1123value: they produce control flow, not values (the one exception being
1124the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
John Criswelldfe6a862004-12-10 15:51:16 +00001125<p>There are six different terminator instructions: the '<a
Chris Lattner48b383b02003-11-25 01:02:51 +00001126 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
1127instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001128the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
1129 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
1130 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001131
Misha Brukman76307852003-11-08 01:05:38 +00001132</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001133
Chris Lattner2f7c9632001-06-06 20:29:01 +00001134<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001135<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
1136Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001137<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001138<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001139<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 +00001140 ret void <i>; Return from void function</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001141</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001142<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001143<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
John Criswell4a3327e2005-05-13 22:25:59 +00001144value) from a function back to the caller.</p>
John Criswell417228d2004-04-09 16:48:45 +00001145<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner48b383b02003-11-25 01:02:51 +00001146returns a value and then causes control flow, and one that just causes
1147control flow to occur.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001148<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001149<p>The '<tt>ret</tt>' instruction may return any '<a
1150 href="#t_firstclass">first class</a>' type. Notice that a function is
1151not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
1152instruction inside of the function that returns a value that does not
1153match the return type of the function.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001154<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001155<p>When the '<tt>ret</tt>' instruction is executed, control flow
1156returns back to the calling function's context. If the caller is a "<a
John Criswell40db33f2004-06-25 15:16:57 +00001157 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner48b383b02003-11-25 01:02:51 +00001158the instruction after the call. If the caller was an "<a
1159 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
John Criswell02fdc6f2005-05-12 16:52:32 +00001160at the beginning of the "normal" destination block. If the instruction
Chris Lattner48b383b02003-11-25 01:02:51 +00001161returns a value, that value shall set the call or invoke instruction's
1162return value.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001163<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001164<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001165 ret void <i>; Return from a void function</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001166</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001167</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001168<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001169<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001170<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001171<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001172<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 +00001173</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001174<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001175<p>The '<tt>br</tt>' instruction is used to cause control flow to
1176transfer to a different basic block in the current function. There are
1177two forms of this instruction, corresponding to a conditional branch
1178and an unconditional branch.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001179<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001180<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
1181single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
1182unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
1183value as a target.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001184<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001185<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
1186argument is evaluated. If the value is <tt>true</tt>, control flows
1187to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
1188control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001189<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001190<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
1191 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 +00001192</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001193<!-- _______________________________________________________________________ -->
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001194<div class="doc_subsubsection">
1195 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
1196</div>
1197
Misha Brukman76307852003-11-08 01:05:38 +00001198<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001199<h5>Syntax:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001200
1201<pre>
1202 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
1203</pre>
1204
Chris Lattner2f7c9632001-06-06 20:29:01 +00001205<h5>Overview:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001206
1207<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
1208several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman76307852003-11-08 01:05:38 +00001209instruction, allowing a branch to occur to one of many possible
1210destinations.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001211
1212
Chris Lattner2f7c9632001-06-06 20:29:01 +00001213<h5>Arguments:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001214
1215<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
1216comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
1217an array of pairs of comparison value constants and '<tt>label</tt>'s. The
1218table is not allowed to contain duplicate constant entries.</p>
1219
Chris Lattner2f7c9632001-06-06 20:29:01 +00001220<h5>Semantics:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001221
Chris Lattner48b383b02003-11-25 01:02:51 +00001222<p>The <tt>switch</tt> instruction specifies a table of values and
1223destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswellbcbb18c2004-06-25 16:05:06 +00001224table is searched for the given value. If the value is found, control flow is
1225transfered to the corresponding destination; otherwise, control flow is
1226transfered to the default destination.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001227
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001228<h5>Implementation:</h5>
1229
1230<p>Depending on properties of the target machine and the particular
1231<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswellbcbb18c2004-06-25 16:05:06 +00001232ways. For example, it could be generated as a series of chained conditional
1233branches or with a lookup table.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001234
1235<h5>Example:</h5>
1236
1237<pre>
1238 <i>; Emulate a conditional br instruction</i>
1239 %Val = <a href="#i_cast">cast</a> bool %value to int
1240 switch int %Val, label %truedest [int 0, label %falsedest ]
1241
1242 <i>; Emulate an unconditional br instruction</i>
1243 switch uint 0, label %dest [ ]
1244
1245 <i>; Implement a jump table:</i>
1246 switch uint %val, label %otherwise [ uint 0, label %onzero
1247 uint 1, label %onone
1248 uint 2, label %ontwo ]
Chris Lattner2f7c9632001-06-06 20:29:01 +00001249</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001250</div>
Chris Lattner0132aff2005-05-06 22:57:40 +00001251
Chris Lattner2f7c9632001-06-06 20:29:01 +00001252<!-- _______________________________________________________________________ -->
Chris Lattner0132aff2005-05-06 22:57:40 +00001253<div class="doc_subsubsection">
1254 <a name="i_invoke">'<tt>invoke</tt>' Instruction</a>
1255</div>
1256
Misha Brukman76307852003-11-08 01:05:38 +00001257<div class="doc_text">
Chris Lattner0132aff2005-05-06 22:57:40 +00001258
Chris Lattner2f7c9632001-06-06 20:29:01 +00001259<h5>Syntax:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001260
1261<pre>
1262 &lt;result&gt; = invoke [<a href="#callingconv">cconv</a>] &lt;ptr to function ty&gt; %&lt;function ptr val&gt;(&lt;function args&gt;)
1263 to label &lt;normal label&gt; except label &lt;exception label&gt;
1264</pre>
1265
Chris Lattnera8292f32002-05-06 22:08:29 +00001266<h5>Overview:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001267
1268<p>The '<tt>invoke</tt>' instruction causes control to transfer to a specified
1269function, with the possibility of control flow transfer to either the
John Criswell02fdc6f2005-05-12 16:52:32 +00001270'<tt>normal</tt>' label or the
1271'<tt>exception</tt>' label. If the callee function returns with the
Chris Lattner0132aff2005-05-06 22:57:40 +00001272"<tt><a href="#i_ret">ret</a></tt>" instruction, control flow will return to the
1273"normal" label. If the callee (or any indirect callees) returns with the "<a
John Criswell02fdc6f2005-05-12 16:52:32 +00001274href="#i_unwind"><tt>unwind</tt></a>" instruction, control is interrupted and
1275continued at the dynamically nearest "exception" label.</p>
Chris Lattner0132aff2005-05-06 22:57:40 +00001276
Chris Lattner2f7c9632001-06-06 20:29:01 +00001277<h5>Arguments:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001278
Misha Brukman76307852003-11-08 01:05:38 +00001279<p>This instruction requires several arguments:</p>
Chris Lattner0132aff2005-05-06 22:57:40 +00001280
Chris Lattner2f7c9632001-06-06 20:29:01 +00001281<ol>
Chris Lattner0132aff2005-05-06 22:57:40 +00001282 <li>
John Criswell4a3327e2005-05-13 22:25:59 +00001283 The optional "cconv" marker indicates which <a href="callingconv">calling
Chris Lattner0132aff2005-05-06 22:57:40 +00001284 convention</a> the call should use. If none is specified, the call defaults
1285 to using C calling conventions.
1286 </li>
1287 <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to
1288 function value being invoked. In most cases, this is a direct function
1289 invocation, but indirect <tt>invoke</tt>s are just as possible, branching off
1290 an arbitrary pointer to function value.
1291 </li>
1292
1293 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a
1294 function to be invoked. </li>
1295
1296 <li>'<tt>function args</tt>': argument list whose types match the function
1297 signature argument types. If the function signature indicates the function
1298 accepts a variable number of arguments, the extra arguments can be
1299 specified. </li>
1300
1301 <li>'<tt>normal label</tt>': the label reached when the called function
1302 executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
1303
1304 <li>'<tt>exception label</tt>': the label reached when a callee returns with
1305 the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
1306
Chris Lattner2f7c9632001-06-06 20:29:01 +00001307</ol>
Chris Lattner0132aff2005-05-06 22:57:40 +00001308
Chris Lattner2f7c9632001-06-06 20:29:01 +00001309<h5>Semantics:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001310
Misha Brukman76307852003-11-08 01:05:38 +00001311<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner0132aff2005-05-06 22:57:40 +00001312href="#i_call">call</a></tt>' instruction in most regards. The primary
1313difference is that it establishes an association with a label, which is used by
1314the runtime library to unwind the stack.</p>
1315
1316<p>This instruction is used in languages with destructors to ensure that proper
1317cleanup is performed in the case of either a <tt>longjmp</tt> or a thrown
1318exception. Additionally, this is important for implementation of
1319'<tt>catch</tt>' clauses in high-level languages that support them.</p>
1320
Chris Lattner2f7c9632001-06-06 20:29:01 +00001321<h5>Example:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001322<pre>
1323 %retval = invoke int %Test(int 15) to label %Continue
1324 except label %TestCleanup <i>; {int}:retval set</i>
1325 %retval = invoke <a href="#callingconv">coldcc</a> int %Test(int 15) to label %Continue
1326 except label %TestCleanup <i>; {int}:retval set</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001327</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001328</div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001329
1330
Chris Lattner5ed60612003-09-03 00:41:47 +00001331<!-- _______________________________________________________________________ -->
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001332
Chris Lattner48b383b02003-11-25 01:02:51 +00001333<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
1334Instruction</a> </div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001335
Misha Brukman76307852003-11-08 01:05:38 +00001336<div class="doc_text">
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001337
Chris Lattner5ed60612003-09-03 00:41:47 +00001338<h5>Syntax:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001339<pre>
1340 unwind
1341</pre>
1342
Chris Lattner5ed60612003-09-03 00:41:47 +00001343<h5>Overview:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001344
1345<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
1346at the first callee in the dynamic call stack which used an <a
1347href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
1348primarily used to implement exception handling.</p>
1349
Chris Lattner5ed60612003-09-03 00:41:47 +00001350<h5>Semantics:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001351
1352<p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to
1353immediately halt. The dynamic call stack is then searched for the first <a
1354href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
1355execution continues at the "exceptional" destination block specified by the
1356<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
1357dynamic call chain, undefined behavior results.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001358</div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001359
1360<!-- _______________________________________________________________________ -->
1361
1362<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
1363Instruction</a> </div>
1364
1365<div class="doc_text">
1366
1367<h5>Syntax:</h5>
1368<pre>
1369 unreachable
1370</pre>
1371
1372<h5>Overview:</h5>
1373
1374<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
1375instruction is used to inform the optimizer that a particular portion of the
1376code is not reachable. This can be used to indicate that the code after a
1377no-return function cannot be reached, and other facts.</p>
1378
1379<h5>Semantics:</h5>
1380
1381<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
1382</div>
1383
1384
1385
Chris Lattner2f7c9632001-06-06 20:29:01 +00001386<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001387<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001388<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +00001389<p>Binary operators are used to do most of the computation in a
1390program. They require two operands, execute an operation on them, and
John Criswelldfe6a862004-12-10 15:51:16 +00001391produce a single value. The operands might represent
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001392multiple data, as is the case with the <a href="#t_packed">packed</a> data type.
1393The result value of a binary operator is not
Chris Lattner48b383b02003-11-25 01:02:51 +00001394necessarily the same type as its operands.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001395<p>There are several different binary operators:</p>
Misha Brukman76307852003-11-08 01:05:38 +00001396</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001397<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001398<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
1399Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001400<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001401<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001402<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 +00001403</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001404<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001405<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001406<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001407<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001408 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
1409 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1410Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001411<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001412<p>The value produced is the integer or floating point sum of the two
1413operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001414<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001415<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001416</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001417</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001418<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001419<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
1420Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001421<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001422<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001423<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 +00001424</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001425<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001426<p>The '<tt>sub</tt>' instruction returns the difference of its two
1427operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001428<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
1429instruction present in most other intermediate representations.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001430<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001431<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001432 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001433values.
1434This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1435Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001436<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001437<p>The value produced is the integer or floating point difference of
1438the two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001439<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001440<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001441 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
1442</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001443</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001444<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001445<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
1446Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001447<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001448<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001449<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 +00001450</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001451<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001452<p>The '<tt>mul</tt>' instruction returns the product of its two
1453operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001454<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001455<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001456 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001457values.
1458This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1459Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001460<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001461<p>The value produced is the integer or floating point product of the
Misha Brukman76307852003-11-08 01:05:38 +00001462two operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001463<p>There is no signed vs unsigned multiplication. The appropriate
1464action is taken based on the type of the operand.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001465<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001466<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001467</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001468</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001469<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001470<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
1471Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001472<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001473<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001474<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1475</pre>
1476<h5>Overview:</h5>
1477<p>The '<tt>div</tt>' instruction returns the quotient of its two
1478operands.</p>
1479<h5>Arguments:</h5>
1480<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
1481 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001482values.
1483This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1484Both arguments must have identical types.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001485<h5>Semantics:</h5>
1486<p>The value produced is the integer or floating point quotient of the
1487two operands.</p>
1488<h5>Example:</h5>
1489<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
1490</pre>
1491</div>
1492<!-- _______________________________________________________________________ -->
1493<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
1494Instruction</a> </div>
1495<div class="doc_text">
1496<h5>Syntax:</h5>
1497<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1498</pre>
1499<h5>Overview:</h5>
1500<p>The '<tt>rem</tt>' instruction returns the remainder from the
1501division of its two operands.</p>
1502<h5>Arguments:</h5>
1503<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1504 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001505values.
1506This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1507Both arguments must have identical types.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001508<h5>Semantics:</h5>
1509<p>This returns the <i>remainder</i> of a division (where the result
1510has the same sign as the divisor), not the <i>modulus</i> (where the
1511result has the same sign as the dividend) of a value. For more
John Criswell4c0cf7f2005-10-24 16:17:18 +00001512information about the difference, see <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001513 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1514Math Forum</a>.</p>
1515<h5>Example:</h5>
1516<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1517</pre>
1518</div>
1519<!-- _______________________________________________________________________ -->
1520<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1521Instructions</a> </div>
1522<div class="doc_text">
1523<h5>Syntax:</h5>
1524<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 +00001525 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1526 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1527 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1528 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1529 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1530</pre>
Chris Lattner48b383b02003-11-25 01:02:51 +00001531<h5>Overview:</h5>
1532<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1533value based on a comparison of their two operands.</p>
1534<h5>Arguments:</h5>
1535<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1536be of <a href="#t_firstclass">first class</a> type (it is not possible
1537to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1538or '<tt>void</tt>' values, etc...). Both arguments must have identical
1539types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001540<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001541<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1542value if both operands are equal.<br>
1543The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1544value if both operands are unequal.<br>
1545The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1546value if the first operand is less than the second operand.<br>
1547The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1548value if the first operand is greater than the second operand.<br>
1549The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1550value if the first operand is less than or equal to the second operand.<br>
1551The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1552value if the first operand is greater than or equal to the second
1553operand.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001554<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001555<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001556 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
1557 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1558 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1559 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1560 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1561</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001562</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001563<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001564<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1565Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001566<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +00001567<p>Bitwise binary operators are used to do various forms of
1568bit-twiddling in a program. They are generally very efficient
John Criswelldfe6a862004-12-10 15:51:16 +00001569instructions and can commonly be strength reduced from other
Chris Lattner48b383b02003-11-25 01:02:51 +00001570instructions. They require two operands, execute an operation on them,
1571and produce a single value. The resulting value of the bitwise binary
1572operators is always the same type as its first operand.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001573</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001574<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001575<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1576Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001577<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001578<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001579<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 +00001580</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001581<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001582<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1583its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001584<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001585<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001586 href="#t_integral">integral</a> values. Both arguments must have
1587identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001588<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001589<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001590<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00001591<div style="align: center">
Misha Brukman76307852003-11-08 01:05:38 +00001592<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +00001593 <tbody>
1594 <tr>
1595 <td>In0</td>
1596 <td>In1</td>
1597 <td>Out</td>
1598 </tr>
1599 <tr>
1600 <td>0</td>
1601 <td>0</td>
1602 <td>0</td>
1603 </tr>
1604 <tr>
1605 <td>0</td>
1606 <td>1</td>
1607 <td>0</td>
1608 </tr>
1609 <tr>
1610 <td>1</td>
1611 <td>0</td>
1612 <td>0</td>
1613 </tr>
1614 <tr>
1615 <td>1</td>
1616 <td>1</td>
1617 <td>1</td>
1618 </tr>
1619 </tbody>
1620</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001621</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001622<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001623<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001624 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1625 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1626</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001627</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001628<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001629<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001630<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001631<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001632<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 +00001633</pre>
Chris Lattner48b383b02003-11-25 01:02:51 +00001634<h5>Overview:</h5>
1635<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1636or of its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001637<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001638<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001639 href="#t_integral">integral</a> values. Both arguments must have
1640identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001641<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001642<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001643<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00001644<div style="align: center">
Chris Lattner48b383b02003-11-25 01:02:51 +00001645<table border="1" cellspacing="0" cellpadding="4">
1646 <tbody>
1647 <tr>
1648 <td>In0</td>
1649 <td>In1</td>
1650 <td>Out</td>
1651 </tr>
1652 <tr>
1653 <td>0</td>
1654 <td>0</td>
1655 <td>0</td>
1656 </tr>
1657 <tr>
1658 <td>0</td>
1659 <td>1</td>
1660 <td>1</td>
1661 </tr>
1662 <tr>
1663 <td>1</td>
1664 <td>0</td>
1665 <td>1</td>
1666 </tr>
1667 <tr>
1668 <td>1</td>
1669 <td>1</td>
1670 <td>1</td>
1671 </tr>
1672 </tbody>
1673</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001674</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001675<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001676<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001677 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1678 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1679</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001680</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001681<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001682<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1683Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001684<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001685<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001686<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 +00001687</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001688<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001689<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1690or of its two operands. The <tt>xor</tt> is used to implement the
1691"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001692<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001693<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001694 href="#t_integral">integral</a> values. Both arguments must have
1695identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001696<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001697<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001698<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00001699<div style="align: center">
Chris Lattner48b383b02003-11-25 01:02:51 +00001700<table border="1" cellspacing="0" cellpadding="4">
1701 <tbody>
1702 <tr>
1703 <td>In0</td>
1704 <td>In1</td>
1705 <td>Out</td>
1706 </tr>
1707 <tr>
1708 <td>0</td>
1709 <td>0</td>
1710 <td>0</td>
1711 </tr>
1712 <tr>
1713 <td>0</td>
1714 <td>1</td>
1715 <td>1</td>
1716 </tr>
1717 <tr>
1718 <td>1</td>
1719 <td>0</td>
1720 <td>1</td>
1721 </tr>
1722 <tr>
1723 <td>1</td>
1724 <td>1</td>
1725 <td>0</td>
1726 </tr>
1727 </tbody>
1728</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001729</div>
Chris Lattner48b383b02003-11-25 01:02:51 +00001730<p> </p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001731<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001732<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001733 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1734 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner5ed60612003-09-03 00:41:47 +00001735 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001736</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001737</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001738<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001739<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1740Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001741<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001742<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001743<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 +00001744</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001745<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001746<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1747the left a specified number of bits.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001748<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001749<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001750 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1751type.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001752<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001753<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001754<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001755<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 +00001756 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1757 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1758</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001759</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001760<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001761<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1762Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001763<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001764<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001765<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 +00001766</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001767<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001768<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1769the right a specified number of bits.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001770<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001771<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001772 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1773type.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001774<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001775<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1776most significant bit is duplicated in the newly free'd bit positions.
1777If the first argument is unsigned, zero bits shall fill the empty
1778positions.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001779<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001780<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 +00001781 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001782 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner33426d92003-06-18 21:30:51 +00001783 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1784 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001785</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001786</div>
Chris Lattner54611b42005-11-06 08:02:57 +00001787
Chris Lattner2f7c9632001-06-06 20:29:01 +00001788<!-- ======================================================================= -->
Chris Lattner54611b42005-11-06 08:02:57 +00001789<div class="doc_subsection">
1790 <a name="memoryops">Memory Access Operations</a>
1791</div>
1792
Misha Brukman76307852003-11-08 01:05:38 +00001793<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00001794
Chris Lattner48b383b02003-11-25 01:02:51 +00001795<p>A key design point of an SSA-based representation is how it
1796represents memory. In LLVM, no memory locations are in SSA form, which
1797makes things very simple. This section describes how to read, write,
John Criswelldfe6a862004-12-10 15:51:16 +00001798allocate, and free memory in LLVM.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001799
Misha Brukman76307852003-11-08 01:05:38 +00001800</div>
Chris Lattner54611b42005-11-06 08:02:57 +00001801
Chris Lattner2f7c9632001-06-06 20:29:01 +00001802<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00001803<div class="doc_subsubsection">
1804 <a name="i_malloc">'<tt>malloc</tt>' Instruction</a>
1805</div>
1806
Misha Brukman76307852003-11-08 01:05:38 +00001807<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00001808
Chris Lattner2f7c9632001-06-06 20:29:01 +00001809<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001810
1811<pre>
1812 &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 +00001813</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00001814
Chris Lattner2f7c9632001-06-06 20:29:01 +00001815<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001816
Chris Lattner48b383b02003-11-25 01:02:51 +00001817<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1818heap and returns a pointer to it.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001819
Chris Lattner2f7c9632001-06-06 20:29:01 +00001820<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001821
1822<p>The '<tt>malloc</tt>' instruction allocates
1823<tt>sizeof(&lt;type&gt;)*NumElements</tt>
John Criswella92e5862004-02-24 16:13:56 +00001824bytes of memory from the operating system and returns a pointer of the
Chris Lattner54611b42005-11-06 08:02:57 +00001825appropriate type to the program. If "NumElements" is specified, it is the
1826number of elements allocated. If an alignment is specified, the value result
1827of the allocation is guaranteed to be aligned to at least that boundary. If
1828not specified, or if zero, the target can choose to align the allocation on any
1829convenient boundary.</p>
1830
Misha Brukman76307852003-11-08 01:05:38 +00001831<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001832
Chris Lattner2f7c9632001-06-06 20:29:01 +00001833<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001834
Chris Lattner48b383b02003-11-25 01:02:51 +00001835<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1836a pointer is returned.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001837
Chris Lattner54611b42005-11-06 08:02:57 +00001838<h5>Example:</h5>
1839
1840<pre>
1841 %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
1842
1843 %size = <a href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001844 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1845 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner54611b42005-11-06 08:02:57 +00001846 %array3 = malloc int, uint 4, align 1024 <i>; yields {int*}:array3</i>
1847 %array4 = malloc int, align 1024 <i>; yields {int*}:array4</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001848</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001849</div>
Chris Lattner54611b42005-11-06 08:02:57 +00001850
Chris Lattner2f7c9632001-06-06 20:29:01 +00001851<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00001852<div class="doc_subsubsection">
1853 <a name="i_free">'<tt>free</tt>' Instruction</a>
1854</div>
1855
Misha Brukman76307852003-11-08 01:05:38 +00001856<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00001857
Chris Lattner2f7c9632001-06-06 20:29:01 +00001858<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001859
1860<pre>
1861 free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001862</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00001863
Chris Lattner2f7c9632001-06-06 20:29:01 +00001864<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001865
Chris Lattner48b383b02003-11-25 01:02:51 +00001866<p>The '<tt>free</tt>' instruction returns memory back to the unused
John Criswell4a3327e2005-05-13 22:25:59 +00001867memory heap to be reallocated in the future.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001868
Chris Lattner2f7c9632001-06-06 20:29:01 +00001869<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001870
Chris Lattner48b383b02003-11-25 01:02:51 +00001871<p>'<tt>value</tt>' shall be a pointer value that points to a value
1872that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1873instruction.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001874
Chris Lattner2f7c9632001-06-06 20:29:01 +00001875<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001876
John Criswelldfe6a862004-12-10 15:51:16 +00001877<p>Access to the memory pointed to by the pointer is no longer defined
Chris Lattner48b383b02003-11-25 01:02:51 +00001878after this instruction executes.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001879
Chris Lattner2f7c9632001-06-06 20:29:01 +00001880<h5>Example:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001881
1882<pre>
1883 %array = <a href="#i_malloc">malloc</a> [4 x ubyte] <i>; yields {[4 x ubyte]*}:array</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001884 free [4 x ubyte]* %array
1885</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001886</div>
Chris Lattner54611b42005-11-06 08:02:57 +00001887
Chris Lattner2f7c9632001-06-06 20:29:01 +00001888<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00001889<div class="doc_subsubsection">
1890 <a name="i_alloca">'<tt>alloca</tt>' Instruction</a>
1891</div>
1892
Misha Brukman76307852003-11-08 01:05:38 +00001893<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00001894
Chris Lattner2f7c9632001-06-06 20:29:01 +00001895<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001896
1897<pre>
1898 &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 +00001899</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00001900
Chris Lattner2f7c9632001-06-06 20:29:01 +00001901<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001902
Chris Lattner48b383b02003-11-25 01:02:51 +00001903<p>The '<tt>alloca</tt>' instruction allocates memory on the current
1904stack frame of the procedure that is live until the current function
1905returns to its caller.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001906
Chris Lattner2f7c9632001-06-06 20:29:01 +00001907<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001908
John Criswelldfe6a862004-12-10 15:51:16 +00001909<p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00001910bytes of memory on the runtime stack, returning a pointer of the
Chris Lattner54611b42005-11-06 08:02:57 +00001911appropriate type to the program. If "NumElements" is specified, it is the
1912number of elements allocated. If an alignment is specified, the value result
1913of the allocation is guaranteed to be aligned to at least that boundary. If
1914not specified, or if zero, the target can choose to align the allocation on any
1915convenient boundary.</p>
1916
Misha Brukman76307852003-11-08 01:05:38 +00001917<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001918
Chris Lattner2f7c9632001-06-06 20:29:01 +00001919<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001920
John Criswell4a3327e2005-05-13 22:25:59 +00001921<p>Memory is allocated; a pointer is returned. '<tt>alloca</tt>'d
Chris Lattner48b383b02003-11-25 01:02:51 +00001922memory is automatically released when the function returns. The '<tt>alloca</tt>'
1923instruction is commonly used to represent automatic variables that must
1924have an address available. When the function returns (either with the <tt><a
John Criswellc932bef2005-05-12 16:55:34 +00001925 href="#i_ret">ret</a></tt> or <tt><a href="#i_unwind">unwind</a></tt>
Misha Brukman76307852003-11-08 01:05:38 +00001926instructions), the memory is reclaimed.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001927
Chris Lattner2f7c9632001-06-06 20:29:01 +00001928<h5>Example:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001929
1930<pre>
1931 %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001932 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner54611b42005-11-06 08:02:57 +00001933 %ptr = alloca int, uint 4, align 1024 <i>; yields {int*}:ptr</i>
1934 %ptr = alloca int, align 1024 <i>; yields {int*}:ptr</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001935</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001936</div>
Chris Lattner54611b42005-11-06 08:02:57 +00001937
Chris Lattner2f7c9632001-06-06 20:29:01 +00001938<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001939<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1940Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001941<div class="doc_text">
Chris Lattner095735d2002-05-06 03:03:22 +00001942<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001943<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 +00001944<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001945<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00001946<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001947<p>The argument to the '<tt>load</tt>' instruction specifies the memory
John Criswell4c0cf7f2005-10-24 16:17:18 +00001948address from which to load. The pointer must point to a <a
Chris Lattner10ee9652004-06-03 22:57:15 +00001949 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
John Criswell4c0cf7f2005-10-24 16:17:18 +00001950marked as <tt>volatile</tt>, then the optimizer is not allowed to modify
Chris Lattner48b383b02003-11-25 01:02:51 +00001951the number or order of execution of this <tt>load</tt> with other
1952volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1953instructions. </p>
Chris Lattner095735d2002-05-06 03:03:22 +00001954<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001955<p>The location of memory pointed to is loaded.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00001956<h5>Examples:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001957<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1958 <a
1959 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner095735d2002-05-06 03:03:22 +00001960 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1961</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001962</div>
Chris Lattner095735d2002-05-06 03:03:22 +00001963<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001964<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1965Instruction</a> </div>
Chris Lattner095735d2002-05-06 03:03:22 +00001966<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001967<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 +00001968 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 +00001969</pre>
Chris Lattner095735d2002-05-06 03:03:22 +00001970<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001971<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00001972<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001973<p>There are two arguments to the '<tt>store</tt>' instruction: a value
John Criswell4c0cf7f2005-10-24 16:17:18 +00001974to 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 +00001975operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
John Criswell4a3327e2005-05-13 22:25:59 +00001976operand. If the <tt>store</tt> is marked as <tt>volatile</tt>, then the
Chris Lattner48b383b02003-11-25 01:02:51 +00001977optimizer is not allowed to modify the number or order of execution of
1978this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1979 href="#i_store">store</a></tt> instructions.</p>
1980<h5>Semantics:</h5>
1981<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
1982at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00001983<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001984<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1985 <a
1986 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner095735d2002-05-06 03:03:22 +00001987 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1988</pre>
Chris Lattner095735d2002-05-06 03:03:22 +00001989<!-- _______________________________________________________________________ -->
Chris Lattner33fd7022004-04-05 01:30:49 +00001990<div class="doc_subsubsection">
1991 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
1992</div>
1993
Misha Brukman76307852003-11-08 01:05:38 +00001994<div class="doc_text">
Chris Lattner590645f2002-04-14 06:13:44 +00001995<h5>Syntax:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00001996<pre>
1997 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
1998</pre>
1999
Chris Lattner590645f2002-04-14 06:13:44 +00002000<h5>Overview:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00002001
2002<p>
2003The '<tt>getelementptr</tt>' instruction is used to get the address of a
2004subelement of an aggregate data structure.</p>
2005
Chris Lattner590645f2002-04-14 06:13:44 +00002006<h5>Arguments:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00002007
2008<p>This instruction takes a list of integer constants that indicate what
2009elements of the aggregate object to index to. The actual types of the arguments
2010provided depend on the type of the first pointer argument. The
2011'<tt>getelementptr</tt>' instruction is used to index down through the type
John Criswell88190562005-05-16 16:17:45 +00002012levels of a structure or to a specific index in an array. When indexing into a
2013structure, only <tt>uint</tt>
John Criswell4a3327e2005-05-13 22:25:59 +00002014integer constants are allowed. When indexing into an array or pointer,
Chris Lattner33fd7022004-04-05 01:30:49 +00002015<tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
2016
Chris Lattner48b383b02003-11-25 01:02:51 +00002017<p>For example, let's consider a C code fragment and how it gets
2018compiled to LLVM:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002019
2020<pre>
2021 struct RT {
2022 char A;
2023 int B[10][20];
2024 char C;
2025 };
2026 struct ST {
2027 int X;
2028 double Y;
2029 struct RT Z;
2030 };
2031
2032 int *foo(struct ST *s) {
2033 return &amp;s[1].Z.B[5][13];
2034 }
2035</pre>
2036
Misha Brukman76307852003-11-08 01:05:38 +00002037<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002038
2039<pre>
2040 %RT = type { sbyte, [10 x [20 x int]], sbyte }
2041 %ST = type { int, double, %RT }
2042
Brian Gaeke317ef962004-07-02 21:08:14 +00002043 implementation
2044
2045 int* %foo(%ST* %s) {
2046 entry:
2047 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13
Chris Lattner33fd7022004-04-05 01:30:49 +00002048 ret int* %reg
2049 }
2050</pre>
2051
Chris Lattner590645f2002-04-14 06:13:44 +00002052<h5>Semantics:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00002053
2054<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
John Criswell4a3327e2005-05-13 22:25:59 +00002055on the pointer type that is being indexed into. <a href="#t_pointer">Pointer</a>
Chris Lattner10ee9652004-06-03 22:57:15 +00002056and <a href="#t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
2057<tt>ulong</tt>, or <tt>long</tt> values, and <a href="#t_struct">structure</a>
Chris Lattner33fd7022004-04-05 01:30:49 +00002058types require <tt>uint</tt> <b>constants</b>.</p>
2059
Misha Brukman76307852003-11-08 01:05:38 +00002060<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattner33fd7022004-04-05 01:30:49 +00002061type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
2062}</tt>' type, a structure. The second index indexes into the third element of
2063the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
2064sbyte }</tt>' type, another structure. The third index indexes into the second
2065element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
2066array. The two dimensions of the array are subscripted into, yielding an
John Criswell88190562005-05-16 16:17:45 +00002067'<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction returns a pointer
Chris Lattner33fd7022004-04-05 01:30:49 +00002068to this element, thus computing a value of '<tt>int*</tt>' type.</p>
2069
Chris Lattner48b383b02003-11-25 01:02:51 +00002070<p>Note that it is perfectly legal to index partially through a
2071structure, returning a pointer to an inner element. Because of this,
2072the LLVM code for the given testcase is equivalent to:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002073
2074<pre>
Chris Lattner455fc8c2005-03-07 22:13:59 +00002075 int* %foo(%ST* %s) {
Chris Lattner33fd7022004-04-05 01:30:49 +00002076 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
2077 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
2078 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
2079 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
2080 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
2081 ret int* %t5
2082 }
Chris Lattnera8292f32002-05-06 22:08:29 +00002083</pre>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00002084
2085<p>Note that it is undefined to access an array out of bounds: array and
2086pointer indexes must always be within the defined bounds of the array type.
2087The one exception for this rules is zero length arrays. These arrays are
2088defined to be accessible as variable length arrays, which requires access
2089beyond the zero'th element.</p>
2090
Chris Lattner590645f2002-04-14 06:13:44 +00002091<h5>Example:</h5>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00002092
Chris Lattner33fd7022004-04-05 01:30:49 +00002093<pre>
2094 <i>; yields [12 x ubyte]*:aptr</i>
2095 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
2096</pre>
2097
2098</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002099<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002100<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002101<div class="doc_text">
John Criswell417228d2004-04-09 16:48:45 +00002102<p>The instructions in this category are the "miscellaneous"
Chris Lattner48b383b02003-11-25 01:02:51 +00002103instructions, which defy better classification.</p>
Misha Brukman76307852003-11-08 01:05:38 +00002104</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002105<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002106<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
2107Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002108<div class="doc_text">
Chris Lattner70de6632001-07-09 00:26:23 +00002109<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002110<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner70de6632001-07-09 00:26:23 +00002111<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002112<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
2113the SSA graph representing the function.</p>
Chris Lattner70de6632001-07-09 00:26:23 +00002114<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002115<p>The type of the incoming values are specified with the first type
2116field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
2117as arguments, with one pair for each predecessor basic block of the
2118current block. Only values of <a href="#t_firstclass">first class</a>
2119type may be used as the value arguments to the PHI node. Only labels
2120may be used as the label arguments.</p>
2121<p>There must be no non-phi instructions between the start of a basic
2122block and the PHI instructions: i.e. PHI instructions must be first in
2123a basic block.</p>
Chris Lattner70de6632001-07-09 00:26:23 +00002124<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002125<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
2126value specified by the parameter, depending on which basic block we
2127came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattnera8292f32002-05-06 22:08:29 +00002128<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002129<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 +00002130</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002131
Chris Lattnera8292f32002-05-06 22:08:29 +00002132<!-- _______________________________________________________________________ -->
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002133<div class="doc_subsubsection">
2134 <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
2135</div>
2136
Misha Brukman76307852003-11-08 01:05:38 +00002137<div class="doc_text">
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002138
Chris Lattnera8292f32002-05-06 22:08:29 +00002139<h5>Syntax:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002140
2141<pre>
2142 &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 +00002143</pre>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002144
Chris Lattnera8292f32002-05-06 22:08:29 +00002145<h5>Overview:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002146
2147<p>
2148The '<tt>cast</tt>' instruction is used as the primitive means to convert
2149integers to floating point, change data type sizes, and break type safety (by
2150casting pointers).
2151</p>
2152
2153
Chris Lattnera8292f32002-05-06 22:08:29 +00002154<h5>Arguments:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002155
2156<p>
2157The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
2158class value, and a type to cast it to, which must also be a <a
2159href="#t_firstclass">first class</a> type.
2160</p>
2161
Chris Lattnera8292f32002-05-06 22:08:29 +00002162<h5>Semantics:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002163
2164<p>
2165This instruction follows the C rules for explicit casts when determining how the
2166data being cast must change to fit in its new container.
2167</p>
2168
2169<p>
2170When casting to bool, any value that would be considered true in the context of
2171a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
2172all else are '<tt>false</tt>'.
2173</p>
2174
2175<p>
2176When extending an integral value from a type of one signness to another (for
2177example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
2178<b>source</b> value is signed, and zero-extended if the source value is
2179unsigned. <tt>bool</tt> values are always zero extended into either zero or
2180one.
2181</p>
2182
Chris Lattner70de6632001-07-09 00:26:23 +00002183<h5>Example:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002184
2185<pre>
2186 %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattnerd8f8ede2002-06-25 18:03:17 +00002187 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner70de6632001-07-09 00:26:23 +00002188</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002189</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002190
2191<!-- _______________________________________________________________________ -->
2192<div class="doc_subsubsection">
2193 <a name="i_select">'<tt>select</tt>' Instruction</a>
2194</div>
2195
2196<div class="doc_text">
2197
2198<h5>Syntax:</h5>
2199
2200<pre>
2201 &lt;result&gt; = select bool &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
2202</pre>
2203
2204<h5>Overview:</h5>
2205
2206<p>
2207The '<tt>select</tt>' instruction is used to choose one value based on a
2208condition, without branching.
2209</p>
2210
2211
2212<h5>Arguments:</h5>
2213
2214<p>
2215The '<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.
2216</p>
2217
2218<h5>Semantics:</h5>
2219
2220<p>
2221If the boolean condition evaluates to true, the instruction returns the first
John Criswell88190562005-05-16 16:17:45 +00002222value argument; otherwise, it returns the second value argument.
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002223</p>
2224
2225<h5>Example:</h5>
2226
2227<pre>
2228 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
2229</pre>
2230</div>
2231
2232
2233
2234
2235
Chris Lattner70de6632001-07-09 00:26:23 +00002236<!-- _______________________________________________________________________ -->
Chris Lattnere23c1392005-05-06 05:47:36 +00002237<div class="doc_subsubsection">
2238 <a name="i_call">'<tt>call</tt>' Instruction</a>
2239</div>
2240
Misha Brukman76307852003-11-08 01:05:38 +00002241<div class="doc_text">
Chris Lattnere23c1392005-05-06 05:47:36 +00002242
Chris Lattner2f7c9632001-06-06 20:29:01 +00002243<h5>Syntax:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00002244<pre>
Chris Lattner0132aff2005-05-06 22:57:40 +00002245 &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 +00002246</pre>
2247
Chris Lattner2f7c9632001-06-06 20:29:01 +00002248<h5>Overview:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00002249
Misha Brukman76307852003-11-08 01:05:38 +00002250<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00002251
Chris Lattner2f7c9632001-06-06 20:29:01 +00002252<h5>Arguments:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00002253
Misha Brukman76307852003-11-08 01:05:38 +00002254<p>This instruction requires several arguments:</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00002255
Chris Lattnera8292f32002-05-06 22:08:29 +00002256<ol>
Chris Lattner48b383b02003-11-25 01:02:51 +00002257 <li>
Chris Lattner0132aff2005-05-06 22:57:40 +00002258 <p>The optional "tail" marker indicates whether the callee function accesses
2259 any allocas or varargs in the caller. If the "tail" marker is present, the
Chris Lattnere23c1392005-05-06 05:47:36 +00002260 function call is eligible for tail call optimization. Note that calls may
2261 be marked "tail" even if they do not occur before a <a
2262 href="#i_ret"><tt>ret</tt></a> instruction.
Chris Lattner48b383b02003-11-25 01:02:51 +00002263 </li>
2264 <li>
Chris Lattner0132aff2005-05-06 22:57:40 +00002265 <p>The optional "cconv" marker indicates which <a href="callingconv">calling
2266 convention</a> the call should use. If none is specified, the call defaults
2267 to using C calling conventions.
2268 </li>
2269 <li>
Chris Lattnere23c1392005-05-06 05:47:36 +00002270 <p>'<tt>ty</tt>': shall be the signature of the pointer to function value
2271 being invoked. The argument types must match the types implied by this
John Criswell88190562005-05-16 16:17:45 +00002272 signature. This type can be omitted if the function is not varargs and
2273 if the function type does not return a pointer to a function.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00002274 </li>
2275 <li>
2276 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to
2277 be invoked. In most cases, this is a direct function invocation, but
2278 indirect <tt>call</tt>s are just as possible, calling an arbitrary pointer
John Criswell88190562005-05-16 16:17:45 +00002279 to function value.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002280 </li>
2281 <li>
2282 <p>'<tt>function args</tt>': argument list whose types match the
Reid Spencerd845d162005-05-01 22:22:57 +00002283 function signature argument types. All arguments must be of
2284 <a href="#t_firstclass">first class</a> type. If the function signature
2285 indicates the function accepts a variable number of arguments, the extra
2286 arguments can be specified.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002287 </li>
Chris Lattnera8292f32002-05-06 22:08:29 +00002288</ol>
Chris Lattnere23c1392005-05-06 05:47:36 +00002289
Chris Lattner2f7c9632001-06-06 20:29:01 +00002290<h5>Semantics:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00002291
Chris Lattner48b383b02003-11-25 01:02:51 +00002292<p>The '<tt>call</tt>' instruction is used to cause control flow to
2293transfer to a specified function, with its incoming arguments bound to
2294the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
2295instruction in the called function, control flow continues with the
2296instruction after the function call, and the return value of the
2297function is bound to the result argument. This is a simpler case of
2298the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00002299
Chris Lattner2f7c9632001-06-06 20:29:01 +00002300<h5>Example:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00002301
2302<pre>
2303 %retval = call int %test(int %argc)
2304 call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42);
2305 %X = tail call int %foo()
Chris Lattner0132aff2005-05-06 22:57:40 +00002306 %Y = tail call <a href="#callingconv">fastcc</a> int %foo()
Chris Lattnere23c1392005-05-06 05:47:36 +00002307</pre>
2308
Misha Brukman76307852003-11-08 01:05:38 +00002309</div>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002310
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002311<!-- _______________________________________________________________________ -->
Chris Lattner6a4a0492004-09-27 21:51:25 +00002312<div class="doc_subsubsection">
Chris Lattner6a4a0492004-09-27 21:51:25 +00002313 <a name="i_vaarg">'<tt>vaarg</tt>' Instruction</a>
2314</div>
2315
Misha Brukman76307852003-11-08 01:05:38 +00002316<div class="doc_text">
Chris Lattner6a4a0492004-09-27 21:51:25 +00002317
Chris Lattner26ca62e2003-10-18 05:51:36 +00002318<h5>Syntax:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002319
2320<pre>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002321 &lt;resultval&gt; = va_arg &lt;va_list*&gt; &lt;arglist&gt;, &lt;argty&gt;
Chris Lattner6a4a0492004-09-27 21:51:25 +00002322</pre>
2323
Chris Lattner26ca62e2003-10-18 05:51:36 +00002324<h5>Overview:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002325
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002326<p>The '<tt>va_arg</tt>' instruction is used to access arguments passed through
Chris Lattner6a4a0492004-09-27 21:51:25 +00002327the "variable argument" area of a function call. It is used to implement the
2328<tt>va_arg</tt> macro in C.</p>
2329
Chris Lattner26ca62e2003-10-18 05:51:36 +00002330<h5>Arguments:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002331
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002332<p>This instruction takes a <tt>va_list*</tt> value and the type of
2333the argument. It returns a value of the specified argument type and
Jeff Cohendc6bfea2005-11-11 02:15:27 +00002334increments the <tt>va_list</tt> to point to the next argument. Again, the
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002335actual type of <tt>va_list</tt> is target specific.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002336
Chris Lattner26ca62e2003-10-18 05:51:36 +00002337<h5>Semantics:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002338
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002339<p>The '<tt>va_arg</tt>' instruction loads an argument of the specified
2340type from the specified <tt>va_list</tt> and causes the
2341<tt>va_list</tt> to point to the next argument. For more information,
2342see the variable argument handling <a href="#int_varargs">Intrinsic
2343Functions</a>.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002344
2345<p>It is legal for this instruction to be called in a function which does not
2346take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman76307852003-11-08 01:05:38 +00002347function.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002348
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002349<p><tt>va_arg</tt> is an LLVM instruction instead of an <a
John Criswell88190562005-05-16 16:17:45 +00002350href="#intrinsics">intrinsic function</a> because it takes a type as an
Chris Lattner6a4a0492004-09-27 21:51:25 +00002351argument.</p>
2352
Chris Lattner26ca62e2003-10-18 05:51:36 +00002353<h5>Example:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002354
2355<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
2356
Misha Brukman76307852003-11-08 01:05:38 +00002357</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002358
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002359<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002360<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
2361<!-- *********************************************************************** -->
Chris Lattner941515c2004-01-06 05:31:32 +00002362
Misha Brukman76307852003-11-08 01:05:38 +00002363<div class="doc_text">
Chris Lattnerfee11462004-02-12 17:01:32 +00002364
2365<p>LLVM supports the notion of an "intrinsic function". These functions have
John Criswell88190562005-05-16 16:17:45 +00002366well known names and semantics and are required to follow certain
Chris Lattnerfee11462004-02-12 17:01:32 +00002367restrictions. Overall, these instructions represent an extension mechanism for
2368the LLVM language that does not require changing all of the transformations in
2369LLVM to add to the language (or the bytecode reader/writer, the parser,
2370etc...).</p>
2371
John Criswell88190562005-05-16 16:17:45 +00002372<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix. This
2373prefix is reserved in LLVM for intrinsic names; thus, functions may not be named
Chris Lattnerfee11462004-02-12 17:01:32 +00002374this. Intrinsic functions must always be external functions: you cannot define
2375the body of intrinsic functions. Intrinsic functions may only be used in call
2376or invoke instructions: it is illegal to take the address of an intrinsic
2377function. Additionally, because intrinsic functions are part of the LLVM
2378language, it is required that they all be documented here if any are added.</p>
2379
2380
John Criswell88190562005-05-16 16:17:45 +00002381<p>To learn how to add an intrinsic function, please see the <a
Chris Lattner90391c12005-05-11 03:35:57 +00002382href="ExtendingLLVM.html">Extending LLVM Guide</a>.
Chris Lattnerfee11462004-02-12 17:01:32 +00002383</p>
2384
Misha Brukman76307852003-11-08 01:05:38 +00002385</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002386
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002387<!-- ======================================================================= -->
Chris Lattner941515c2004-01-06 05:31:32 +00002388<div class="doc_subsection">
2389 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
2390</div>
2391
Misha Brukman76307852003-11-08 01:05:38 +00002392<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +00002393
Misha Brukman76307852003-11-08 01:05:38 +00002394<p>Variable argument support is defined in LLVM with the <a
Chris Lattner48b383b02003-11-25 01:02:51 +00002395 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
2396intrinsic functions. These functions are related to the similarly
2397named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002398
Chris Lattner48b383b02003-11-25 01:02:51 +00002399<p>All of these functions operate on arguments that use a
2400target-specific value type "<tt>va_list</tt>". The LLVM assembly
2401language reference manual does not define what this type is, so all
2402transformations should be prepared to handle intrinsics with any type
2403used.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002404
Misha Brukman76307852003-11-08 01:05:38 +00002405<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner48b383b02003-11-25 01:02:51 +00002406instruction and the variable argument handling intrinsic functions are
2407used.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002408
Chris Lattnerfee11462004-02-12 17:01:32 +00002409<pre>
2410int %test(int %X, ...) {
2411 ; Initialize variable argument processing
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002412 %ap = alloca sbyte*
2413 call void %<a href="#i_va_start">llvm.va_start</a>(sbyte** %ap)
Chris Lattnerfee11462004-02-12 17:01:32 +00002414
2415 ; Read a single integer argument
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002416 %tmp = va_arg sbyte** %ap, int
Chris Lattnerfee11462004-02-12 17:01:32 +00002417
2418 ; Demonstrate usage of llvm.va_copy and llvm.va_end
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002419 %aq = alloca sbyte*
Andrew Lenharth5305ea52005-06-22 20:38:11 +00002420 call void %<a href="#i_va_copy">llvm.va_copy</a>(sbyte** %aq, sbyte** %ap)
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002421 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte** %aq)
Chris Lattnerfee11462004-02-12 17:01:32 +00002422
2423 ; Stop processing of arguments.
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002424 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte** %ap)
Chris Lattnerfee11462004-02-12 17:01:32 +00002425 ret int %tmp
2426}
2427</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002428</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002429
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002430<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00002431<div class="doc_subsubsection">
2432 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
2433</div>
2434
2435
Misha Brukman76307852003-11-08 01:05:38 +00002436<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002437<h5>Syntax:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002438<pre> declare void %llvm.va_start(&lt;va_list&gt;* &lt;arglist&gt;)<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002439<h5>Overview:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002440<P>The '<tt>llvm.va_start</tt>' intrinsic initializes
2441<tt>*&lt;arglist&gt;</tt> for subsequent use by <tt><a
2442href="#i_va_arg">va_arg</a></tt>.</p>
2443
2444<h5>Arguments:</h5>
2445
2446<P>The argument is a pointer to a <tt>va_list</tt> element to initialize.</p>
2447
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002448<h5>Semantics:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002449
2450<P>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
2451macro available in C. In a target-dependent way, it initializes the
2452<tt>va_list</tt> element the argument points to, so that the next call to
2453<tt>va_arg</tt> will produce the first variable argument passed to the function.
2454Unlike the C <tt>va_start</tt> macro, this intrinsic does not need to know the
2455last argument of the function, the compiler can figure that out.</p>
2456
Misha Brukman76307852003-11-08 01:05:38 +00002457</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002458
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002459<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00002460<div class="doc_subsubsection">
2461 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
2462</div>
2463
Misha Brukman76307852003-11-08 01:05:38 +00002464<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002465<h5>Syntax:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002466<pre> declare void %llvm.va_end(&lt;va_list*&gt; &lt;arglist&gt;)<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002467<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002468<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
2469which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
2470or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002471<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002472<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002473<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002474<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00002475macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
2476Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
2477 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
2478with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman76307852003-11-08 01:05:38 +00002479</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002480
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002481<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00002482<div class="doc_subsubsection">
2483 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
2484</div>
2485
Misha Brukman76307852003-11-08 01:05:38 +00002486<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +00002487
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002488<h5>Syntax:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002489
2490<pre>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002491 declare void %llvm.va_copy(&lt;va_list&gt;* &lt;destarglist&gt;,
Andrew Lenharth5305ea52005-06-22 20:38:11 +00002492 &lt;va_list&gt;* &lt;srcarglist&gt;)
Chris Lattner757528b0b2004-05-23 21:06:01 +00002493</pre>
2494
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002495<h5>Overview:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002496
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002497<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position from
2498the source argument list to the destination argument list.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002499
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002500<h5>Arguments:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002501
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002502<p>The first argument is a pointer to a <tt>va_list</tt> element to initialize.
Andrew Lenharth5305ea52005-06-22 20:38:11 +00002503The second argument is a pointer to a <tt>va_list</tt> element to copy from.</p>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002504
Chris Lattner757528b0b2004-05-23 21:06:01 +00002505
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002506<h5>Semantics:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002507
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002508<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt> macro
2509available in C. In a target-dependent way, it copies the source
2510<tt>va_list</tt> element into the destination list. This intrinsic is necessary
2511because the <tt><a href="i_va_begin">llvm.va_begin</a></tt> intrinsic may be
Chris Lattner757528b0b2004-05-23 21:06:01 +00002512arbitrarily complex and require memory allocation, for example.</p>
2513
Misha Brukman76307852003-11-08 01:05:38 +00002514</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002515
Chris Lattnerfee11462004-02-12 17:01:32 +00002516<!-- ======================================================================= -->
2517<div class="doc_subsection">
Chris Lattner757528b0b2004-05-23 21:06:01 +00002518 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
2519</div>
2520
2521<div class="doc_text">
2522
2523<p>
2524LLVM support for <a href="GarbageCollection.html">Accurate Garbage
2525Collection</a> requires the implementation and generation of these intrinsics.
2526These intrinsics allow identification of <a href="#i_gcroot">GC roots on the
2527stack</a>, as well as garbage collector implementations that require <a
2528href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers.
2529Front-ends for type-safe garbage collected languages should generate these
2530intrinsics to make use of the LLVM garbage collectors. For more details, see <a
2531href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
2532</p>
2533</div>
2534
2535<!-- _______________________________________________________________________ -->
2536<div class="doc_subsubsection">
2537 <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
2538</div>
2539
2540<div class="doc_text">
2541
2542<h5>Syntax:</h5>
2543
2544<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002545 declare void %llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
Chris Lattner757528b0b2004-05-23 21:06:01 +00002546</pre>
2547
2548<h5>Overview:</h5>
2549
John Criswelldfe6a862004-12-10 15:51:16 +00002550<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
Chris Lattner757528b0b2004-05-23 21:06:01 +00002551the code generator, and allows some metadata to be associated with it.</p>
2552
2553<h5>Arguments:</h5>
2554
2555<p>The first argument specifies the address of a stack object that contains the
2556root pointer. The second pointer (which must be either a constant or a global
2557value address) contains the meta-data to be associated with the root.</p>
2558
2559<h5>Semantics:</h5>
2560
2561<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
2562location. At compile-time, the code generator generates information to allow
2563the runtime to find the pointer at GC safe points.
2564</p>
2565
2566</div>
2567
2568
2569<!-- _______________________________________________________________________ -->
2570<div class="doc_subsubsection">
2571 <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
2572</div>
2573
2574<div class="doc_text">
2575
2576<h5>Syntax:</h5>
2577
2578<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002579 declare sbyte* %llvm.gcread(sbyte** %Ptr)
Chris Lattner757528b0b2004-05-23 21:06:01 +00002580</pre>
2581
2582<h5>Overview:</h5>
2583
2584<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
2585locations, allowing garbage collector implementations that require read
2586barriers.</p>
2587
2588<h5>Arguments:</h5>
2589
2590<p>The argument is the address to read from, which should be an address
2591allocated from the garbage collector.</p>
2592
2593<h5>Semantics:</h5>
2594
2595<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
2596instruction, but may be replaced with substantially more complex code by the
2597garbage collector runtime, as needed.</p>
2598
2599</div>
2600
2601
2602<!-- _______________________________________________________________________ -->
2603<div class="doc_subsubsection">
2604 <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
2605</div>
2606
2607<div class="doc_text">
2608
2609<h5>Syntax:</h5>
2610
2611<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002612 declare void %llvm.gcwrite(sbyte* %P1, sbyte** %P2)
Chris Lattner757528b0b2004-05-23 21:06:01 +00002613</pre>
2614
2615<h5>Overview:</h5>
2616
2617<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
2618locations, allowing garbage collector implementations that require write
2619barriers (such as generational or reference counting collectors).</p>
2620
2621<h5>Arguments:</h5>
2622
2623<p>The first argument is the reference to store, and the second is the heap
2624location to store to.</p>
2625
2626<h5>Semantics:</h5>
2627
2628<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
2629instruction, but may be replaced with substantially more complex code by the
2630garbage collector runtime, as needed.</p>
2631
2632</div>
2633
2634
2635
2636<!-- ======================================================================= -->
2637<div class="doc_subsection">
Chris Lattner3649c3a2004-02-14 04:08:35 +00002638 <a name="int_codegen">Code Generator Intrinsics</a>
2639</div>
2640
2641<div class="doc_text">
2642<p>
2643These intrinsics are provided by LLVM to expose special features that may only
2644be implemented with code generator support.
2645</p>
2646
2647</div>
2648
2649<!-- _______________________________________________________________________ -->
2650<div class="doc_subsubsection">
2651 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
2652</div>
2653
2654<div class="doc_text">
2655
2656<h5>Syntax:</h5>
2657<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002658 declare void* %llvm.returnaddress(uint &lt;level&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00002659</pre>
2660
2661<h5>Overview:</h5>
2662
2663<p>
2664The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
2665indicating the return address of the current function or one of its callers.
2666</p>
2667
2668<h5>Arguments:</h5>
2669
2670<p>
2671The argument to this intrinsic indicates which function to return the address
2672for. Zero indicates the calling function, one indicates its caller, etc. The
2673argument is <b>required</b> to be a constant integer value.
2674</p>
2675
2676<h5>Semantics:</h5>
2677
2678<p>
2679The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
2680the return address of the specified call frame, or zero if it cannot be
2681identified. The value returned by this intrinsic is likely to be incorrect or 0
2682for arguments other than zero, so it should only be used for debugging purposes.
2683</p>
2684
2685<p>
2686Note that calling this intrinsic does not prevent function inlining or other
Chris Lattner2e6eb5f2005-03-07 20:30:51 +00002687aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner3649c3a2004-02-14 04:08:35 +00002688source-language caller.
2689</p>
2690</div>
2691
2692
2693<!-- _______________________________________________________________________ -->
2694<div class="doc_subsubsection">
2695 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
2696</div>
2697
2698<div class="doc_text">
2699
2700<h5>Syntax:</h5>
2701<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002702 declare void* %llvm.frameaddress(uint &lt;level&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00002703</pre>
2704
2705<h5>Overview:</h5>
2706
2707<p>
2708The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
2709pointer value for the specified stack frame.
2710</p>
2711
2712<h5>Arguments:</h5>
2713
2714<p>
2715The argument to this intrinsic indicates which function to return the frame
2716pointer for. Zero indicates the calling function, one indicates its caller,
2717etc. The argument is <b>required</b> to be a constant integer value.
2718</p>
2719
2720<h5>Semantics:</h5>
2721
2722<p>
2723The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
2724the frame address of the specified call frame, or zero if it cannot be
2725identified. The value returned by this intrinsic is likely to be incorrect or 0
2726for arguments other than zero, so it should only be used for debugging purposes.
2727</p>
2728
2729<p>
2730Note that calling this intrinsic does not prevent function inlining or other
Chris Lattner2e6eb5f2005-03-07 20:30:51 +00002731aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner3649c3a2004-02-14 04:08:35 +00002732source-language caller.
2733</p>
2734</div>
2735
Chris Lattnerc8a2c222005-02-28 19:24:19 +00002736<!-- _______________________________________________________________________ -->
2737<div class="doc_subsubsection">
2738 <a name="i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a>
2739</div>
2740
2741<div class="doc_text">
2742
2743<h5>Syntax:</h5>
2744<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002745 declare void %llvm.prefetch(sbyte * &lt;address&gt;,
2746 uint &lt;rw&gt;, uint &lt;locality&gt;)
Chris Lattnerc8a2c222005-02-28 19:24:19 +00002747</pre>
2748
2749<h5>Overview:</h5>
2750
2751
2752<p>
2753The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to insert
John Criswell88190562005-05-16 16:17:45 +00002754a prefetch instruction if supported; otherwise, it is a noop. Prefetches have
2755no
2756effect on the behavior of the program but can change its performance
Chris Lattnerff851072005-02-28 19:47:14 +00002757characteristics.
Chris Lattnerc8a2c222005-02-28 19:24:19 +00002758</p>
2759
2760<h5>Arguments:</h5>
2761
2762<p>
2763<tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier
2764determining if the fetch should be for a read (0) or write (1), and
2765<tt>locality</tt> is a temporal locality specifier ranging from (0) - no
Chris Lattnerd3e641c2005-03-07 20:31:38 +00002766locality, to (3) - extremely local keep in cache. The <tt>rw</tt> and
Chris Lattnerc8a2c222005-02-28 19:24:19 +00002767<tt>locality</tt> arguments must be constant integers.
2768</p>
2769
2770<h5>Semantics:</h5>
2771
2772<p>
2773This intrinsic does not modify the behavior of the program. In particular,
2774prefetches cannot trap and do not produce a value. On targets that support this
2775intrinsic, the prefetch can provide hints to the processor cache for better
2776performance.
2777</p>
2778
2779</div>
2780
Andrew Lenharthb4427912005-03-28 20:05:49 +00002781<!-- _______________________________________________________________________ -->
2782<div class="doc_subsubsection">
2783 <a name="i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a>
2784</div>
2785
2786<div class="doc_text">
2787
2788<h5>Syntax:</h5>
2789<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002790 declare void %llvm.pcmarker( uint &lt;id&gt; )
Andrew Lenharthb4427912005-03-28 20:05:49 +00002791</pre>
2792
2793<h5>Overview:</h5>
2794
2795
2796<p>
John Criswell88190562005-05-16 16:17:45 +00002797The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a Program Counter
2798(PC) in a region of
Andrew Lenharthb4427912005-03-28 20:05:49 +00002799code to simulators and other tools. The method is target specific, but it is
2800expected that the marker will use exported symbols to transmit the PC of the marker.
Jeff Cohendc6bfea2005-11-11 02:15:27 +00002801The marker makes no guarantees that it will remain with any specific instruction
Andrew Lenharthb4427912005-03-28 20:05:49 +00002802after optimizations. It is possible that the presense of a marker will inhibit
2803optimizations. The intended use is to be inserted after optmizations to allow
John Criswell88190562005-05-16 16:17:45 +00002804correlations of simulation runs.
Andrew Lenharthb4427912005-03-28 20:05:49 +00002805</p>
2806
2807<h5>Arguments:</h5>
2808
2809<p>
2810<tt>id</tt> is a numerical id identifying the marker.
2811</p>
2812
2813<h5>Semantics:</h5>
2814
2815<p>
2816This intrinsic does not modify the behavior of the program. Backends that do not
2817support this intrinisic may ignore it.
2818</p>
2819
2820</div>
2821
Andrew Lenharth01aa5632005-11-11 16:47:30 +00002822<!-- _______________________________________________________________________ -->
2823<div class="doc_subsubsection">
2824 <a name="i_readcyclecounter">'<tt>llvm.readcyclecounter</tt>' Intrinsic</a>
2825</div>
2826
2827<div class="doc_text">
2828
2829<h5>Syntax:</h5>
2830<pre>
2831 declare ulong %llvm.readcyclecounter( )
2832</pre>
2833
2834<h5>Overview:</h5>
2835
2836
2837<p>
2838The '<tt>llvm.readcyclecounter</tt>' intrinsic provides access to the cycle
2839counter register (or similar low latency, high accuracy clocks) on those targets
2840that support it. On X86, it should map to RDTSC. On Alpha, it should map to RPCC.
2841As the backing counters overflow quickly (on the order of 9 seconds on alpha), this
2842should only be used for small timings.
2843</p>
2844
2845<h5>Semantics:</h5>
2846
2847<p>
2848When directly supported, reading the cycle counter should not modify any memory.
2849Implementations are allowed to either return a application specific value or a
2850system wide value. On backends without support, this is lowered to a constant 0.
2851</p>
2852
2853</div>
2854
Chris Lattnerc8a2c222005-02-28 19:24:19 +00002855
John Criswellaa1c3c12004-04-09 16:43:20 +00002856<!-- ======================================================================= -->
2857<div class="doc_subsection">
2858 <a name="int_os">Operating System Intrinsics</a>
2859</div>
2860
2861<div class="doc_text">
2862<p>
2863These intrinsics are provided by LLVM to support the implementation of
2864operating system level code.
2865</p>
2866
2867</div>
John Criswella4501222004-04-12 15:02:16 +00002868
John Criswell508b93c2004-04-09 15:23:37 +00002869<!-- _______________________________________________________________________ -->
2870<div class="doc_subsubsection">
2871 <a name="i_readport">'<tt>llvm.readport</tt>' Intrinsic</a>
2872</div>
2873
2874<div class="doc_text">
2875
2876<h5>Syntax:</h5>
2877<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002878 declare &lt;integer type&gt; %llvm.readport (&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.readport</tt>' intrinsic reads data from the specified hardware
2885I/O port.
John Criswell508b93c2004-04-09 15:23:37 +00002886</p>
2887
2888<h5>Arguments:</h5>
2889
2890<p>
John Criswellaa1c3c12004-04-09 16:43:20 +00002891The argument to this intrinsic indicates the hardware I/O address from which
2892to read the data. The address is in the hardware I/O address namespace (as
2893opposed to being a memory location for memory mapped I/O).
John Criswell508b93c2004-04-09 15:23:37 +00002894</p>
2895
2896<h5>Semantics:</h5>
2897
2898<p>
John Criswellaa1c3c12004-04-09 16:43:20 +00002899The '<tt>llvm.readport</tt>' intrinsic reads data from the hardware I/O port
2900specified by <i>address</i> and returns the value. The address and return
2901value must be integers, but the size is dependent upon the platform upon which
2902the program is code generated. For example, on x86, the address must be an
Misha Brukman36c6bc12005-04-22 18:02:52 +00002903unsigned 16-bit value, and the return value must be 8, 16, or 32 bits.
John Criswell508b93c2004-04-09 15:23:37 +00002904</p>
2905
2906</div>
2907
2908<!-- _______________________________________________________________________ -->
2909<div class="doc_subsubsection">
2910 <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a>
2911</div>
2912
2913<div class="doc_text">
2914
2915<h5>Syntax:</h5>
2916<pre>
Chris Lattner74d3f822004-12-09 17:30:23 +00002917 call void (&lt;integer type&gt;, &lt;integer type&gt;)*
2918 %llvm.writeport (&lt;integer type&gt; &lt;value&gt;,
2919 &lt;integer type&gt; &lt;address&gt;)
John Criswell508b93c2004-04-09 15:23:37 +00002920</pre>
2921
2922<h5>Overview:</h5>
2923
2924<p>
John Criswellaa1c3c12004-04-09 16:43:20 +00002925The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified hardware
2926I/O port.
John Criswell508b93c2004-04-09 15:23:37 +00002927</p>
2928
2929<h5>Arguments:</h5>
2930
2931<p>
John Criswell7a576472004-04-12 16:33:19 +00002932The first argument is the value to write to the I/O port.
John Criswell508b93c2004-04-09 15:23:37 +00002933</p>
2934
2935<p>
John Criswell7a576472004-04-12 16:33:19 +00002936The second argument indicates the hardware I/O address to which data should be
2937written. The address is in the hardware I/O address namespace (as opposed to
2938being a memory location for memory mapped I/O).
John Criswell508b93c2004-04-09 15:23:37 +00002939</p>
2940
2941<h5>Semantics:</h5>
2942
2943<p>
2944The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port
2945specified by <i>address</i>. The address and value must be integers, but the
2946size is dependent upon the platform upon which the program is code generated.
Misha Brukman36c6bc12005-04-22 18:02:52 +00002947For example, on x86, the address must be an unsigned 16-bit value, and the
John Criswellaa1c3c12004-04-09 16:43:20 +00002948value written must be 8, 16, or 32 bits in length.
John Criswell508b93c2004-04-09 15:23:37 +00002949</p>
2950
2951</div>
Chris Lattner3649c3a2004-02-14 04:08:35 +00002952
John Criswella4501222004-04-12 15:02:16 +00002953<!-- _______________________________________________________________________ -->
2954<div class="doc_subsubsection">
2955 <a name="i_readio">'<tt>llvm.readio</tt>' Intrinsic</a>
2956</div>
2957
2958<div class="doc_text">
2959
2960<h5>Syntax:</h5>
2961<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002962 declare &lt;result&gt; %llvm.readio (&lt;ty&gt; * &lt;pointer&gt;)
John Criswella4501222004-04-12 15:02:16 +00002963</pre>
2964
2965<h5>Overview:</h5>
2966
2967<p>
2968The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
2969address.
2970</p>
2971
2972<h5>Arguments:</h5>
2973
2974<p>
John Criswell7a576472004-04-12 16:33:19 +00002975The argument to this intrinsic is a pointer indicating the memory address from
2976which to read the data. The data must be a
2977<a href="#t_firstclass">first class</a> type.
John Criswella4501222004-04-12 15:02:16 +00002978</p>
2979
2980<h5>Semantics:</h5>
2981
2982<p>
2983The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
John Criswell7a576472004-04-12 16:33:19 +00002984location specified by <i>pointer</i> and returns the value. The argument must
2985be a pointer, and the return value must be a
2986<a href="#t_firstclass">first class</a> type. However, certain architectures
Misha Brukman36c6bc12005-04-22 18:02:52 +00002987may not support I/O on all first class types. For example, 32-bit processors
John Criswell7a576472004-04-12 16:33:19 +00002988may only support I/O on data types that are 32 bits or less.
John Criswella4501222004-04-12 15:02:16 +00002989</p>
2990
2991<p>
John Criswell7a576472004-04-12 16:33:19 +00002992This intrinsic enforces an in-order memory model for llvm.readio and
2993llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2994scheduled processors may execute loads and stores out of order, re-ordering at
2995run time accesses to memory mapped I/O registers. Using these intrinsics
2996ensures that accesses to memory mapped I/O registers occur in program order.
John Criswella4501222004-04-12 15:02:16 +00002997</p>
2998
2999</div>
3000
3001<!-- _______________________________________________________________________ -->
3002<div class="doc_subsubsection">
3003 <a name="i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a>
3004</div>
3005
3006<div class="doc_text">
3007
3008<h5>Syntax:</h5>
3009<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00003010 declare void %llvm.writeio (&lt;ty1&gt; &lt;value&gt;, &lt;ty2&gt; * &lt;pointer&gt;)
John Criswella4501222004-04-12 15:02:16 +00003011</pre>
3012
3013<h5>Overview:</h5>
3014
3015<p>
3016The '<tt>llvm.writeio</tt>' intrinsic writes data to the specified memory
3017mapped I/O address.
3018</p>
3019
3020<h5>Arguments:</h5>
3021
3022<p>
John Criswell7a576472004-04-12 16:33:19 +00003023The first argument is the value to write to the memory mapped I/O location.
3024The second argument is a pointer indicating the memory address to which the
3025data should be written.
John Criswella4501222004-04-12 15:02:16 +00003026</p>
3027
3028<h5>Semantics:</h5>
3029
3030<p>
3031The '<tt>llvm.writeio</tt>' intrinsic writes <i>value</i> to the memory mapped
John Criswell7a576472004-04-12 16:33:19 +00003032I/O address specified by <i>pointer</i>. The value must be a
3033<a href="#t_firstclass">first class</a> type. However, certain architectures
Misha Brukman36c6bc12005-04-22 18:02:52 +00003034may not support I/O on all first class types. For example, 32-bit processors
John Criswell7a576472004-04-12 16:33:19 +00003035may only support I/O on data types that are 32 bits or less.
John Criswella4501222004-04-12 15:02:16 +00003036</p>
3037
3038<p>
John Criswell7a576472004-04-12 16:33:19 +00003039This intrinsic enforces an in-order memory model for llvm.readio and
3040llvm.writeio calls on machines that use dynamic scheduling. Dynamically
3041scheduled processors may execute loads and stores out of order, re-ordering at
3042run time accesses to memory mapped I/O registers. Using these intrinsics
3043ensures that accesses to memory mapped I/O registers occur in program order.
John Criswella4501222004-04-12 15:02:16 +00003044</p>
3045
3046</div>
3047
Chris Lattner3649c3a2004-02-14 04:08:35 +00003048<!-- ======================================================================= -->
3049<div class="doc_subsection">
Chris Lattnerfee11462004-02-12 17:01:32 +00003050 <a name="int_libc">Standard C Library Intrinsics</a>
3051</div>
3052
3053<div class="doc_text">
3054<p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00003055LLVM provides intrinsics for a few important standard C library functions.
3056These intrinsics allow source-language front-ends to pass information about the
3057alignment of the pointer arguments to the code generator, providing opportunity
3058for more efficient code generation.
Chris Lattnerfee11462004-02-12 17:01:32 +00003059</p>
3060
3061</div>
3062
3063<!-- _______________________________________________________________________ -->
3064<div class="doc_subsubsection">
3065 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
3066</div>
3067
3068<div class="doc_text">
3069
3070<h5>Syntax:</h5>
3071<pre>
Reid Spencercf669d82005-04-26 20:41:16 +00003072 declare void %llvm.memcpy(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
3073 uint &lt;len&gt;, uint &lt;align&gt;)
Chris Lattnerfee11462004-02-12 17:01:32 +00003074</pre>
3075
3076<h5>Overview:</h5>
3077
3078<p>
3079The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
3080location to the destination location.
3081</p>
3082
3083<p>
3084Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
3085does not return a value, and takes an extra alignment argument.
3086</p>
3087
3088<h5>Arguments:</h5>
3089
3090<p>
3091The first argument is a pointer to the destination, the second is a pointer to
3092the source. The third argument is an (arbitrarily sized) integer argument
3093specifying the number of bytes to copy, and the fourth argument is the alignment
3094of the source and destination locations.
3095</p>
3096
Chris Lattner4c67c482004-02-12 21:18:15 +00003097<p>
3098If the call to this intrinisic has an alignment value that is not 0 or 1, then
3099the caller guarantees that the size of the copy is a multiple of the alignment
3100and that both the source and destination pointers are aligned to that boundary.
3101</p>
3102
Chris Lattnerfee11462004-02-12 17:01:32 +00003103<h5>Semantics:</h5>
3104
3105<p>
3106The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
3107location to the destination location, which are not allowed to overlap. It
3108copies "len" bytes of memory over. If the argument is known to be aligned to
3109some boundary, this can be specified as the fourth argument, otherwise it should
3110be set to 0 or 1.
3111</p>
3112</div>
3113
3114
Chris Lattnerf30152e2004-02-12 18:10:10 +00003115<!-- _______________________________________________________________________ -->
3116<div class="doc_subsubsection">
3117 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
3118</div>
3119
3120<div class="doc_text">
3121
3122<h5>Syntax:</h5>
3123<pre>
Reid Spencercf669d82005-04-26 20:41:16 +00003124 declare void %llvm.memmove(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
3125 uint &lt;len&gt;, uint &lt;align&gt;)
Chris Lattnerf30152e2004-02-12 18:10:10 +00003126</pre>
3127
3128<h5>Overview:</h5>
3129
3130<p>
3131The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
3132location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>'
3133intrinsic but allows the two memory locations to overlap.
3134</p>
3135
3136<p>
3137Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
3138does not return a value, and takes an extra alignment argument.
3139</p>
3140
3141<h5>Arguments:</h5>
3142
3143<p>
3144The first argument is a pointer to the destination, the second is a pointer to
3145the source. The third argument is an (arbitrarily sized) integer argument
3146specifying the number of bytes to copy, and the fourth argument is the alignment
3147of the source and destination locations.
3148</p>
3149
Chris Lattner4c67c482004-02-12 21:18:15 +00003150<p>
3151If the call to this intrinisic has an alignment value that is not 0 or 1, then
3152the caller guarantees that the size of the copy is a multiple of the alignment
3153and that both the source and destination pointers are aligned to that boundary.
3154</p>
3155
Chris Lattnerf30152e2004-02-12 18:10:10 +00003156<h5>Semantics:</h5>
3157
3158<p>
3159The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
3160location to the destination location, which may overlap. It
3161copies "len" bytes of memory over. If the argument is known to be aligned to
3162some boundary, this can be specified as the fourth argument, otherwise it should
3163be set to 0 or 1.
3164</p>
3165</div>
3166
Chris Lattner941515c2004-01-06 05:31:32 +00003167
Chris Lattner3649c3a2004-02-14 04:08:35 +00003168<!-- _______________________________________________________________________ -->
3169<div class="doc_subsubsection">
3170 <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a>
3171</div>
3172
3173<div class="doc_text">
3174
3175<h5>Syntax:</h5>
3176<pre>
Reid Spencercf669d82005-04-26 20:41:16 +00003177 declare void %llvm.memset(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
3178 uint &lt;len&gt;, uint &lt;align&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00003179</pre>
3180
3181<h5>Overview:</h5>
3182
3183<p>
3184The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular
3185byte value.
3186</p>
3187
3188<p>
3189Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
3190does not return a value, and takes an extra alignment argument.
3191</p>
3192
3193<h5>Arguments:</h5>
3194
3195<p>
3196The first argument is a pointer to the destination to fill, the second is the
3197byte value to fill it with, the third argument is an (arbitrarily sized) integer
3198argument specifying the number of bytes to fill, and the fourth argument is the
3199known alignment of destination location.
3200</p>
3201
3202<p>
3203If the call to this intrinisic has an alignment value that is not 0 or 1, then
3204the caller guarantees that the size of the copy is a multiple of the alignment
3205and that the destination pointer is aligned to that boundary.
3206</p>
3207
3208<h5>Semantics:</h5>
3209
3210<p>
3211The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the
3212destination location. If the argument is known to be aligned to some boundary,
3213this can be specified as the fourth argument, otherwise it should be set to 0 or
32141.
3215</p>
3216</div>
3217
3218
Chris Lattner3b4f4372004-06-11 02:28:03 +00003219<!-- _______________________________________________________________________ -->
3220<div class="doc_subsubsection">
Alkis Evlogimenos0fa39232004-06-13 01:16:15 +00003221 <a name="i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a>
3222</div>
3223
3224<div class="doc_text">
3225
3226<h5>Syntax:</h5>
3227<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00003228 declare bool %llvm.isunordered(&lt;float or double&gt; Val1, &lt;float or double&gt; Val2)
Alkis Evlogimenos0fa39232004-06-13 01:16:15 +00003229</pre>
3230
3231<h5>Overview:</h5>
3232
3233<p>
3234The '<tt>llvm.isunordered</tt>' intrinsic returns true if either or both of the
3235specified floating point values is a NAN.
3236</p>
3237
3238<h5>Arguments:</h5>
3239
3240<p>
3241The arguments are floating point numbers of the same type.
3242</p>
3243
3244<h5>Semantics:</h5>
3245
3246<p>
3247If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise
3248false.
3249</p>
3250</div>
3251
3252
Chris Lattner8a8f2e52005-07-21 01:29:16 +00003253<!-- _______________________________________________________________________ -->
3254<div class="doc_subsubsection">
3255 <a name="i_sqrt">'<tt>llvm.sqrt</tt>' Intrinsic</a>
3256</div>
3257
3258<div class="doc_text">
3259
3260<h5>Syntax:</h5>
3261<pre>
3262 declare &lt;float or double&gt; %llvm.sqrt(&lt;float or double&gt; Val)
3263</pre>
3264
3265<h5>Overview:</h5>
3266
3267<p>
3268The '<tt>llvm.sqrt</tt>' intrinsic returns the sqrt of the specified operand,
3269returning the same value as the libm '<tt>sqrt</tt>' function would. Unlike
3270<tt>sqrt</tt> in libm, however, <tt>llvm.sqrt</tt> has undefined behavior for
3271negative numbers (which allows for better optimization).
3272</p>
3273
3274<h5>Arguments:</h5>
3275
3276<p>
3277The argument and return value are floating point numbers of the same type.
3278</p>
3279
3280<h5>Semantics:</h5>
3281
3282<p>
3283This function returns the sqrt of the specified operand if it is a positive
3284floating point number.
3285</p>
3286</div>
3287
Andrew Lenharth1d463522005-05-03 18:01:48 +00003288<!-- ======================================================================= -->
3289<div class="doc_subsection">
3290 <a name="int_count">Bit Counting Intrinsics</a>
3291</div>
3292
3293<div class="doc_text">
3294<p>
3295LLVM provides intrinsics for a few important bit counting operations.
3296These allow efficient code generation for some algorithms.
3297</p>
3298
3299</div>
3300
3301<!-- _______________________________________________________________________ -->
3302<div class="doc_subsubsection">
3303 <a name="int_ctpop">'<tt>llvm.ctpop</tt>' Intrinsic</a>
3304</div>
3305
3306<div class="doc_text">
3307
3308<h5>Syntax:</h5>
3309<pre>
3310 declare int %llvm.ctpop(int &lt;src&gt;)
3311
3312</pre>
3313
3314<h5>Overview:</h5>
3315
3316<p>
3317The '<tt>llvm.ctpop</tt>' intrinsic counts the number of ones in a variable.
3318</p>
3319
3320<h5>Arguments:</h5>
3321
3322<p>
Chris Lattner573f64e2005-05-07 01:46:40 +00003323The only argument is the value to be counted. The argument may be of any
3324integer type. The return type must match the argument type.
Andrew Lenharth1d463522005-05-03 18:01:48 +00003325</p>
3326
3327<h5>Semantics:</h5>
3328
3329<p>
3330The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable.
3331</p>
3332</div>
3333
3334<!-- _______________________________________________________________________ -->
3335<div class="doc_subsubsection">
Andrew Lenharth1d463522005-05-03 18:01:48 +00003336 <a name="int_ctlz">'<tt>llvm.ctlz</tt>' Intrinsic</a>
3337</div>
3338
3339<div class="doc_text">
3340
3341<h5>Syntax:</h5>
3342<pre>
3343 declare int %llvm.ctlz(int &lt;src&gt;)
3344
3345</pre>
3346
3347<h5>Overview:</h5>
3348
3349<p>
Chris Lattner573f64e2005-05-07 01:46:40 +00003350The '<tt>llvm.ctlz</tt>' intrinsic counts the number of leading zeros in a
3351variable.
Andrew Lenharth1d463522005-05-03 18:01:48 +00003352</p>
3353
3354<h5>Arguments:</h5>
3355
3356<p>
Chris Lattner573f64e2005-05-07 01:46:40 +00003357The only argument is the value to be counted. The argument may be of any
3358integer type. The return type must match the argument type.
Andrew Lenharth1d463522005-05-03 18:01:48 +00003359</p>
3360
3361<h5>Semantics:</h5>
3362
3363<p>
Chris Lattnerefa20fa2005-05-15 19:39:26 +00003364The '<tt>llvm.ctlz</tt>' intrinsic counts the leading (most significant) zeros
3365in a variable. If the src == 0 then the result is the size in bits of the type
3366of src. For example, <tt>llvm.cttz(int 2) = 30</tt>.
Andrew Lenharth1d463522005-05-03 18:01:48 +00003367</p>
3368</div>
Chris Lattner3b4f4372004-06-11 02:28:03 +00003369
3370
Chris Lattnerefa20fa2005-05-15 19:39:26 +00003371
3372<!-- _______________________________________________________________________ -->
3373<div class="doc_subsubsection">
3374 <a name="int_cttz">'<tt>llvm.cttz</tt>' Intrinsic</a>
3375</div>
3376
3377<div class="doc_text">
3378
3379<h5>Syntax:</h5>
3380<pre>
3381 declare int %llvm.cttz(int &lt;src&gt;)
3382
3383</pre>
3384
3385<h5>Overview:</h5>
3386
3387<p>
3388The '<tt>llvm.cttz</tt>' intrinsic counts the number of trailing zeros.
3389</p>
3390
3391<h5>Arguments:</h5>
3392
3393<p>
3394The only argument is the value to be counted. The argument may be of any
3395integer type. The return type must match the argument type.
3396</p>
3397
3398<h5>Semantics:</h5>
3399
3400<p>
3401The '<tt>llvm.cttz</tt>' intrinsic counts the trailing (least significant) zeros
3402in a variable. If the src == 0 then the result is the size in bits of the type
3403of src. For example, <tt>llvm.cttz(2) = 1</tt>.
3404</p>
3405</div>
3406
Chris Lattner941515c2004-01-06 05:31:32 +00003407<!-- ======================================================================= -->
3408<div class="doc_subsection">
3409 <a name="int_debugger">Debugger Intrinsics</a>
3410</div>
3411
3412<div class="doc_text">
3413<p>
3414The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
3415are described in the <a
3416href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
3417Debugging</a> document.
3418</p>
3419</div>
3420
3421
Chris Lattner2f7c9632001-06-06 20:29:01 +00003422<!-- *********************************************************************** -->
Chris Lattner2f7c9632001-06-06 20:29:01 +00003423<hr>
Misha Brukmanc501f552004-03-01 17:47:27 +00003424<address>
3425 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
3426 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
3427 <a href="http://validator.w3.org/check/referer"><img
3428 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
3429
3430 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
3431 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
3432 Last modified: $Date$
3433</address>
Misha Brukman76307852003-11-08 01:05:38 +00003434</body>
3435</html>