blob: 9b801cffc3ac6aa9150f82771cf8873445f13248 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3<html>
4<head>
5 <title>LLVM Assembly Language Reference Manual</title>
6 <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.">
10 <link rel="stylesheet" href="llvm.css" type="text/css">
11</head>
12
13<body>
14
15<div class="doc_title"> LLVM Language Reference Manual </div>
16<ol>
17 <li><a href="#abstract">Abstract</a></li>
18 <li><a href="#introduction">Introduction</a></li>
19 <li><a href="#identifiers">Identifiers</a></li>
20 <li><a href="#highlevel">High Level Structure</a>
21 <ol>
22 <li><a href="#modulestructure">Module Structure</a></li>
Bill Wendling41a07852009-07-20 01:03:30 +000023 <li><a href="#linkage">Linkage Types</a>
24 <ol>
25 <li><a href="#linkage_private">private</a></li>
26 <li><a href="#linkage_linker_private">linker_private</a></li>
27 <li><a href="#linkage_internal">internal</a></li>
28 <li><a href="#linkage_available_externally">available_externally</a></li>
29 <li><a href="#linkage_linkonce">linkonce</a></li>
30 <li><a href="#linkage_common">common</a></li>
31 <li><a href="#linkage_weak">weak</a></li>
32 <li><a href="#linkage_appending">appending</a></li>
33 <li><a href="#linkage_externweak">extern_weak</a></li>
34 <li><a href="#linkage_linkonce">linkonce_odr</a></li>
35 <li><a href="#linkage_weak">weak_odr</a></li>
36 <li><a href="#linkage_external">externally visible</a></li>
37 <li><a href="#linkage_dllimport">dllimport</a></li>
38 <li><a href="#linkage_dllexport">dllexport</a></li>
39 </ol>
40 </li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +000041 <li><a href="#callingconv">Calling Conventions</a></li>
Chris Lattner5b6dc6e2009-01-11 20:53:49 +000042 <li><a href="#namedtypes">Named Types</a></li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +000043 <li><a href="#globalvars">Global Variables</a></li>
44 <li><a href="#functionstructure">Functions</a></li>
Dan Gohman2672f3e2008-10-14 16:51:45 +000045 <li><a href="#aliasstructure">Aliases</a></li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +000046 <li><a href="#paramattrs">Parameter Attributes</a></li>
Devang Patel008cd3e2008-09-26 23:51:19 +000047 <li><a href="#fnattrs">Function Attributes</a></li>
Gordon Henriksen13fe5e32007-12-10 03:18:06 +000048 <li><a href="#gc">Garbage Collector Names</a></li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +000049 <li><a href="#moduleasm">Module-Level Inline Assembly</a></li>
50 <li><a href="#datalayout">Data Layout</a></li>
51 </ol>
52 </li>
53 <li><a href="#typesystem">Type System</a>
54 <ol>
Chris Lattner488772f2008-01-04 04:32:38 +000055 <li><a href="#t_classifications">Type Classifications</a></li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +000056 <li><a href="#t_primitive">Primitive Types</a>
57 <ol>
Chris Lattner488772f2008-01-04 04:32:38 +000058 <li><a href="#t_floating">Floating Point Types</a></li>
59 <li><a href="#t_void">Void Type</a></li>
60 <li><a href="#t_label">Label Type</a></li>
Nick Lewycky29aaef82009-05-30 05:06:04 +000061 <li><a href="#t_metadata">Metadata Type</a></li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +000062 </ol>
63 </li>
64 <li><a href="#t_derived">Derived Types</a>
65 <ol>
Chris Lattner251ab812007-12-18 06:18:21 +000066 <li><a href="#t_integer">Integer Type</a></li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +000067 <li><a href="#t_array">Array Type</a></li>
68 <li><a href="#t_function">Function Type</a></li>
69 <li><a href="#t_pointer">Pointer Type</a></li>
70 <li><a href="#t_struct">Structure Type</a></li>
71 <li><a href="#t_pstruct">Packed Structure Type</a></li>
72 <li><a href="#t_vector">Vector Type</a></li>
73 <li><a href="#t_opaque">Opaque Type</a></li>
74 </ol>
75 </li>
Chris Lattner515195a2009-02-02 07:32:36 +000076 <li><a href="#t_uprefs">Type Up-references</a></li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +000077 </ol>
78 </li>
79 <li><a href="#constants">Constants</a>
80 <ol>
Dan Gohman2672f3e2008-10-14 16:51:45 +000081 <li><a href="#simpleconstants">Simple Constants</a></li>
Chris Lattner97063852009-02-28 18:32:25 +000082 <li><a href="#complexconstants">Complex Constants</a></li>
Dan Gohman2672f3e2008-10-14 16:51:45 +000083 <li><a href="#globalconstants">Global Variable and Function Addresses</a></li>
84 <li><a href="#undefvalues">Undefined Values</a></li>
85 <li><a href="#constantexprs">Constant Expressions</a></li>
Nick Lewycky4dcf8102009-04-04 07:22:01 +000086 <li><a href="#metadata">Embedded Metadata</a></li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +000087 </ol>
88 </li>
89 <li><a href="#othervalues">Other Values</a>
90 <ol>
Dan Gohman2672f3e2008-10-14 16:51:45 +000091 <li><a href="#inlineasm">Inline Assembler Expressions</a></li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +000092 </ol>
93 </li>
94 <li><a href="#instref">Instruction Reference</a>
95 <ol>
96 <li><a href="#terminators">Terminator Instructions</a>
97 <ol>
98 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
99 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
100 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
101 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
102 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
103 <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
104 </ol>
105 </li>
106 <li><a href="#binaryops">Binary Operations</a>
107 <ol>
108 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
Dan Gohman7ce405e2009-06-04 22:49:04 +0000109 <li><a href="#i_fadd">'<tt>fadd</tt>' Instruction</a></li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000110 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
Dan Gohman7ce405e2009-06-04 22:49:04 +0000111 <li><a href="#i_fsub">'<tt>fsub</tt>' Instruction</a></li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000112 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
Dan Gohman7ce405e2009-06-04 22:49:04 +0000113 <li><a href="#i_fmul">'<tt>fmul</tt>' Instruction</a></li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000114 <li><a href="#i_udiv">'<tt>udiv</tt>' Instruction</a></li>
115 <li><a href="#i_sdiv">'<tt>sdiv</tt>' Instruction</a></li>
116 <li><a href="#i_fdiv">'<tt>fdiv</tt>' Instruction</a></li>
117 <li><a href="#i_urem">'<tt>urem</tt>' Instruction</a></li>
118 <li><a href="#i_srem">'<tt>srem</tt>' Instruction</a></li>
119 <li><a href="#i_frem">'<tt>frem</tt>' Instruction</a></li>
120 </ol>
121 </li>
122 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
123 <ol>
124 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
125 <li><a href="#i_lshr">'<tt>lshr</tt>' Instruction</a></li>
126 <li><a href="#i_ashr">'<tt>ashr</tt>' Instruction</a></li>
127 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
128 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
129 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
130 </ol>
131 </li>
132 <li><a href="#vectorops">Vector Operations</a>
133 <ol>
134 <li><a href="#i_extractelement">'<tt>extractelement</tt>' Instruction</a></li>
135 <li><a href="#i_insertelement">'<tt>insertelement</tt>' Instruction</a></li>
136 <li><a href="#i_shufflevector">'<tt>shufflevector</tt>' Instruction</a></li>
137 </ol>
138 </li>
Dan Gohman74d6faf2008-05-12 23:51:09 +0000139 <li><a href="#aggregateops">Aggregate Operations</a>
140 <ol>
141 <li><a href="#i_extractvalue">'<tt>extractvalue</tt>' Instruction</a></li>
142 <li><a href="#i_insertvalue">'<tt>insertvalue</tt>' Instruction</a></li>
143 </ol>
144 </li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000145 <li><a href="#memoryops">Memory Access and Addressing Operations</a>
146 <ol>
147 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
148 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
149 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
150 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
151 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
152 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
153 </ol>
154 </li>
155 <li><a href="#convertops">Conversion Operations</a>
156 <ol>
157 <li><a href="#i_trunc">'<tt>trunc .. to</tt>' Instruction</a></li>
158 <li><a href="#i_zext">'<tt>zext .. to</tt>' Instruction</a></li>
159 <li><a href="#i_sext">'<tt>sext .. to</tt>' Instruction</a></li>
160 <li><a href="#i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a></li>
161 <li><a href="#i_fpext">'<tt>fpext .. to</tt>' Instruction</a></li>
162 <li><a href="#i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a></li>
163 <li><a href="#i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a></li>
164 <li><a href="#i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a></li>
165 <li><a href="#i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a></li>
166 <li><a href="#i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a></li>
167 <li><a href="#i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a></li>
168 <li><a href="#i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a></li>
169 </ol>
Dan Gohman2672f3e2008-10-14 16:51:45 +0000170 </li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000171 <li><a href="#otherops">Other Operations</a>
172 <ol>
173 <li><a href="#i_icmp">'<tt>icmp</tt>' Instruction</a></li>
174 <li><a href="#i_fcmp">'<tt>fcmp</tt>' Instruction</a></li>
175 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
176 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
177 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
178 <li><a href="#i_va_arg">'<tt>va_arg</tt>' Instruction</a></li>
179 </ol>
180 </li>
181 </ol>
182 </li>
183 <li><a href="#intrinsics">Intrinsic Functions</a>
184 <ol>
185 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
186 <ol>
187 <li><a href="#int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
188 <li><a href="#int_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
189 <li><a href="#int_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
190 </ol>
191 </li>
192 <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
193 <ol>
194 <li><a href="#int_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li>
195 <li><a href="#int_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li>
196 <li><a href="#int_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li>
197 </ol>
198 </li>
199 <li><a href="#int_codegen">Code Generator Intrinsics</a>
200 <ol>
201 <li><a href="#int_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
202 <li><a href="#int_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
203 <li><a href="#int_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a></li>
204 <li><a href="#int_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a></li>
205 <li><a href="#int_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a></li>
206 <li><a href="#int_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a></li>
207 <li><a href="#int_readcyclecounter"><tt>llvm.readcyclecounter</tt>' Intrinsic</a></li>
208 </ol>
209 </li>
210 <li><a href="#int_libc">Standard C Library Intrinsics</a>
211 <ol>
212 <li><a href="#int_memcpy">'<tt>llvm.memcpy.*</tt>' Intrinsic</a></li>
213 <li><a href="#int_memmove">'<tt>llvm.memmove.*</tt>' Intrinsic</a></li>
214 <li><a href="#int_memset">'<tt>llvm.memset.*</tt>' Intrinsic</a></li>
215 <li><a href="#int_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a></li>
216 <li><a href="#int_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a></li>
Dan Gohman361079c2007-10-15 20:30:11 +0000217 <li><a href="#int_sin">'<tt>llvm.sin.*</tt>' Intrinsic</a></li>
218 <li><a href="#int_cos">'<tt>llvm.cos.*</tt>' Intrinsic</a></li>
219 <li><a href="#int_pow">'<tt>llvm.pow.*</tt>' Intrinsic</a></li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000220 </ol>
221 </li>
222 <li><a href="#int_manip">Bit Manipulation Intrinsics</a>
223 <ol>
224 <li><a href="#int_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a></li>
225 <li><a href="#int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic </a></li>
226 <li><a href="#int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic </a></li>
227 <li><a href="#int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic </a></li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000228 </ol>
229 </li>
Bill Wendling3f8cebe2009-02-08 01:40:31 +0000230 <li><a href="#int_overflow">Arithmetic with Overflow Intrinsics</a>
231 <ol>
Bill Wendling3e1258b2009-02-08 04:04:40 +0000232 <li><a href="#int_sadd_overflow">'<tt>llvm.sadd.with.overflow.*</tt> Intrinsics</a></li>
233 <li><a href="#int_uadd_overflow">'<tt>llvm.uadd.with.overflow.*</tt> Intrinsics</a></li>
234 <li><a href="#int_ssub_overflow">'<tt>llvm.ssub.with.overflow.*</tt> Intrinsics</a></li>
235 <li><a href="#int_usub_overflow">'<tt>llvm.usub.with.overflow.*</tt> Intrinsics</a></li>
236 <li><a href="#int_smul_overflow">'<tt>llvm.smul.with.overflow.*</tt> Intrinsics</a></li>
Bill Wendlingbda98b62009-02-08 23:00:09 +0000237 <li><a href="#int_umul_overflow">'<tt>llvm.umul.with.overflow.*</tt> Intrinsics</a></li>
Bill Wendling3f8cebe2009-02-08 01:40:31 +0000238 </ol>
239 </li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000240 <li><a href="#int_debugger">Debugger intrinsics</a></li>
241 <li><a href="#int_eh">Exception Handling intrinsics</a></li>
Duncan Sands7407a9f2007-09-11 14:10:23 +0000242 <li><a href="#int_trampoline">Trampoline Intrinsic</a>
Duncan Sands38947cd2007-07-27 12:58:54 +0000243 <ol>
244 <li><a href="#int_it">'<tt>llvm.init.trampoline</tt>' Intrinsic</a></li>
Duncan Sands38947cd2007-07-27 12:58:54 +0000245 </ol>
246 </li>
Bill Wendling9127adb2008-11-18 22:10:53 +0000247 <li><a href="#int_atomics">Atomic intrinsics</a>
248 <ol>
249 <li><a href="#int_memory_barrier"><tt>llvm.memory_barrier</tt></a></li>
250 <li><a href="#int_atomic_cmp_swap"><tt>llvm.atomic.cmp.swap</tt></a></li>
251 <li><a href="#int_atomic_swap"><tt>llvm.atomic.swap</tt></a></li>
252 <li><a href="#int_atomic_load_add"><tt>llvm.atomic.load.add</tt></a></li>
253 <li><a href="#int_atomic_load_sub"><tt>llvm.atomic.load.sub</tt></a></li>
254 <li><a href="#int_atomic_load_and"><tt>llvm.atomic.load.and</tt></a></li>
255 <li><a href="#int_atomic_load_nand"><tt>llvm.atomic.load.nand</tt></a></li>
256 <li><a href="#int_atomic_load_or"><tt>llvm.atomic.load.or</tt></a></li>
257 <li><a href="#int_atomic_load_xor"><tt>llvm.atomic.load.xor</tt></a></li>
258 <li><a href="#int_atomic_load_max"><tt>llvm.atomic.load.max</tt></a></li>
259 <li><a href="#int_atomic_load_min"><tt>llvm.atomic.load.min</tt></a></li>
260 <li><a href="#int_atomic_load_umax"><tt>llvm.atomic.load.umax</tt></a></li>
261 <li><a href="#int_atomic_load_umin"><tt>llvm.atomic.load.umin</tt></a></li>
262 </ol>
263 </li>
Reid Spencerb043f672007-07-20 19:59:11 +0000264 <li><a href="#int_general">General intrinsics</a>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000265 <ol>
Reid Spencerb043f672007-07-20 19:59:11 +0000266 <li><a href="#int_var_annotation">
Bill Wendlinge4164592008-11-19 05:56:17 +0000267 '<tt>llvm.var.annotation</tt>' Intrinsic</a></li>
Tanya Lattnerb306a9e2007-09-21 22:59:12 +0000268 <li><a href="#int_annotation">
Bill Wendlinge4164592008-11-19 05:56:17 +0000269 '<tt>llvm.annotation.*</tt>' Intrinsic</a></li>
Anton Korobeynikove6e764f2008-01-15 22:31:34 +0000270 <li><a href="#int_trap">
Bill Wendlinge4164592008-11-19 05:56:17 +0000271 '<tt>llvm.trap</tt>' Intrinsic</a></li>
272 <li><a href="#int_stackprotector">
273 '<tt>llvm.stackprotector</tt>' Intrinsic</a></li>
Tanya Lattnerb306a9e2007-09-21 22:59:12 +0000274 </ol>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000275 </li>
276 </ol>
277 </li>
278</ol>
279
280<div class="doc_author">
281 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
282 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
283</div>
284
285<!-- *********************************************************************** -->
286<div class="doc_section"> <a name="abstract">Abstract </a></div>
287<!-- *********************************************************************** -->
288
289<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +0000290
291<p>This document is a reference manual for the LLVM assembly language. LLVM is
292 a Static Single Assignment (SSA) based representation that provides type
293 safety, low-level operations, flexibility, and the capability of representing
294 'all' high-level languages cleanly. It is the common code representation
295 used throughout all phases of the LLVM compilation strategy.</p>
296
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000297</div>
298
299<!-- *********************************************************************** -->
300<div class="doc_section"> <a name="introduction">Introduction</a> </div>
301<!-- *********************************************************************** -->
302
303<div class="doc_text">
304
Bill Wendlingf85859d2009-07-20 02:29:24 +0000305<p>The LLVM code representation is designed to be used in three different forms:
306 as an in-memory compiler IR, as an on-disk bitcode representation (suitable
307 for fast loading by a Just-In-Time compiler), and as a human readable
308 assembly language representation. This allows LLVM to provide a powerful
309 intermediate representation for efficient compiler transformations and
310 analysis, while providing a natural means to debug and visualize the
311 transformations. The three different forms of LLVM are all equivalent. This
312 document describes the human readable representation and notation.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000313
Bill Wendlingf85859d2009-07-20 02:29:24 +0000314<p>The LLVM representation aims to be light-weight and low-level while being
315 expressive, typed, and extensible at the same time. It aims to be a
316 "universal IR" of sorts, by being at a low enough level that high-level ideas
317 may be cleanly mapped to it (similar to how microprocessors are "universal
318 IR's", allowing many source languages to be mapped to them). By providing
319 type information, LLVM can be used as the target of optimizations: for
320 example, through pointer analysis, it can be proven that a C automatic
321 variable is never accessed outside of the current function... allowing it to
322 be promoted to a simple SSA value instead of a memory location.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000323
324</div>
325
326<!-- _______________________________________________________________________ -->
327<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
328
329<div class="doc_text">
330
Bill Wendlingf85859d2009-07-20 02:29:24 +0000331<p>It is important to note that this document describes 'well formed' LLVM
332 assembly language. There is a difference between what the parser accepts and
333 what is considered 'well formed'. For example, the following instruction is
334 syntactically okay, but not well formed:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000335
336<div class="doc_code">
337<pre>
338%x = <a href="#i_add">add</a> i32 1, %x
339</pre>
340</div>
341
Bill Wendlingf85859d2009-07-20 02:29:24 +0000342<p>...because the definition of <tt>%x</tt> does not dominate all of its
343 uses. The LLVM infrastructure provides a verification pass that may be used
344 to verify that an LLVM module is well formed. This pass is automatically run
345 by the parser after parsing input assembly and by the optimizer before it
346 outputs bitcode. The violations pointed out by the verifier pass indicate
347 bugs in transformation passes or input to the parser.</p>
348
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000349</div>
350
Chris Lattnera83fdc02007-10-03 17:34:29 +0000351<!-- Describe the typesetting conventions here. -->
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000352
353<!-- *********************************************************************** -->
354<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
355<!-- *********************************************************************** -->
356
357<div class="doc_text">
358
Bill Wendlingf85859d2009-07-20 02:29:24 +0000359<p>LLVM identifiers come in two basic types: global and local. Global
360 identifiers (functions, global variables) begin with the <tt>'@'</tt>
361 character. Local identifiers (register names, types) begin with
362 the <tt>'%'</tt> character. Additionally, there are three different formats
363 for identifiers, for different purposes:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000364
365<ol>
Reid Spencerc8245b02007-08-07 14:34:28 +0000366 <li>Named values are represented as a string of characters with their prefix.
Bill Wendlingf85859d2009-07-20 02:29:24 +0000367 For example, <tt>%foo</tt>, <tt>@DivisionByZero</tt>,
368 <tt>%a.really.long.identifier</tt>. The actual regular expression used is
369 '<tt>[%@][a-zA-Z$._][a-zA-Z$._0-9]*</tt>'. Identifiers which require
370 other characters in their names can be surrounded with quotes. Special
371 characters may be escaped using <tt>"\xx"</tt> where <tt>xx</tt> is the
372 ASCII code for the character in hexadecimal. In this way, any character
373 can be used in a name value, even quotes themselves.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000374
Reid Spencerc8245b02007-08-07 14:34:28 +0000375 <li>Unnamed values are represented as an unsigned numeric value with their
Bill Wendlingf85859d2009-07-20 02:29:24 +0000376 prefix. For example, <tt>%12</tt>, <tt>@2</tt>, <tt>%44</tt>.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000377
378 <li>Constants, which are described in a <a href="#constants">section about
Bill Wendlingf85859d2009-07-20 02:29:24 +0000379 constants</a>, below.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000380</ol>
381
Reid Spencerc8245b02007-08-07 14:34:28 +0000382<p>LLVM requires that values start with a prefix for two reasons: Compilers
Bill Wendlingf85859d2009-07-20 02:29:24 +0000383 don't need to worry about name clashes with reserved words, and the set of
384 reserved words may be expanded in the future without penalty. Additionally,
385 unnamed identifiers allow a compiler to quickly come up with a temporary
386 variable without having to avoid symbol table conflicts.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000387
388<p>Reserved words in LLVM are very similar to reserved words in other
Bill Wendlingf85859d2009-07-20 02:29:24 +0000389 languages. There are keywords for different opcodes
390 ('<tt><a href="#i_add">add</a></tt>',
391 '<tt><a href="#i_bitcast">bitcast</a></tt>',
392 '<tt><a href="#i_ret">ret</a></tt>', etc...), for primitive type names
393 ('<tt><a href="#t_void">void</a></tt>',
394 '<tt><a href="#t_primitive">i32</a></tt>', etc...), and others. These
395 reserved words cannot conflict with variable names, because none of them
396 start with a prefix character (<tt>'%'</tt> or <tt>'@'</tt>).</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000397
398<p>Here is an example of LLVM code to multiply the integer variable
Bill Wendlingf85859d2009-07-20 02:29:24 +0000399 '<tt>%X</tt>' by 8:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000400
401<p>The easy way:</p>
402
403<div class="doc_code">
404<pre>
405%result = <a href="#i_mul">mul</a> i32 %X, 8
406</pre>
407</div>
408
409<p>After strength reduction:</p>
410
411<div class="doc_code">
412<pre>
413%result = <a href="#i_shl">shl</a> i32 %X, i8 3
414</pre>
415</div>
416
417<p>And the hard way:</p>
418
419<div class="doc_code">
420<pre>
421<a href="#i_add">add</a> i32 %X, %X <i>; yields {i32}:%0</i>
422<a href="#i_add">add</a> i32 %0, %0 <i>; yields {i32}:%1</i>
423%result = <a href="#i_add">add</a> i32 %1, %1
424</pre>
425</div>
426
Bill Wendlingf85859d2009-07-20 02:29:24 +0000427<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several important
428 lexical features of LLVM:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000429
430<ol>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000431 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
Bill Wendlingf85859d2009-07-20 02:29:24 +0000432 line.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000433
434 <li>Unnamed temporaries are created when the result of a computation is not
Bill Wendlingf85859d2009-07-20 02:29:24 +0000435 assigned to a named value.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000436
437 <li>Unnamed temporaries are numbered sequentially</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000438</ol>
439
440<p>...and it also shows a convention that we follow in this document. When
Bill Wendlingf85859d2009-07-20 02:29:24 +0000441 demonstrating instructions, we will follow an instruction with a comment that
442 defines the type and name of value produced. Comments are shown in italic
443 text.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000444
445</div>
446
447<!-- *********************************************************************** -->
448<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
449<!-- *********************************************************************** -->
450
451<!-- ======================================================================= -->
452<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
453</div>
454
455<div class="doc_text">
456
Bill Wendlingf85859d2009-07-20 02:29:24 +0000457<p>LLVM programs are composed of "Module"s, each of which is a translation unit
458 of the input programs. Each module consists of functions, global variables,
459 and symbol table entries. Modules may be combined together with the LLVM
460 linker, which merges function (and global variable) definitions, resolves
461 forward declarations, and merges symbol table entries. Here is an example of
462 the "hello world" module:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000463
464<div class="doc_code">
465<pre><i>; Declare the string constant as a global constant...</i>
466<a href="#identifiers">@.LC0</a> = <a href="#linkage_internal">internal</a> <a
467 href="#globalvars">constant</a> <a href="#t_array">[13 x i8]</a> c"hello world\0A\00" <i>; [13 x i8]*</i>
468
469<i>; External declaration of the puts function</i>
Bill Wendlingf85859d2009-07-20 02:29:24 +0000470<a href="#functionstructure">declare</a> i32 @puts(i8 *) <i>; i32(i8 *)* </i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000471
472<i>; Definition of main function</i>
Bill Wendlingf85859d2009-07-20 02:29:24 +0000473define i32 @main() { <i>; i32()* </i>
Dan Gohman01852382009-01-04 23:44:43 +0000474 <i>; Convert [13 x i8]* to i8 *...</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000475 %cast210 = <a
Bill Wendlingf85859d2009-07-20 02:29:24 +0000476 href="#i_getelementptr">getelementptr</a> [13 x i8]* @.LC0, i64 0, i64 0 <i>; i8 *</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000477
478 <i>; Call puts function to write out the string to stdout...</i>
479 <a
Bill Wendlingf85859d2009-07-20 02:29:24 +0000480 href="#i_call">call</a> i32 @puts(i8 * %cast210) <i>; i32</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000481 <a
482 href="#i_ret">ret</a> i32 0<br>}<br>
483</pre>
484</div>
485
Bill Wendlingf85859d2009-07-20 02:29:24 +0000486<p>This example is made up of a <a href="#globalvars">global variable</a> named
487 "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>" function, and
488 a <a href="#functionstructure">function definition</a> for
489 "<tt>main</tt>".</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000490
Bill Wendlingf85859d2009-07-20 02:29:24 +0000491<p>In general, a module is made up of a list of global values, where both
492 functions and global variables are global values. Global values are
493 represented by a pointer to a memory location (in this case, a pointer to an
494 array of char, and a pointer to a function), and have one of the
495 following <a href="#linkage">linkage types</a>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000496
497</div>
498
499<!-- ======================================================================= -->
500<div class="doc_subsection">
501 <a name="linkage">Linkage Types</a>
502</div>
503
504<div class="doc_text">
505
Bill Wendlingf85859d2009-07-20 02:29:24 +0000506<p>All Global Variables and Functions have one of the following types of
507 linkage:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000508
509<dl>
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000510 <dt><tt><b><a name="linkage_private">private</a></b></tt>: </dt>
511
Bill Wendlingf85859d2009-07-20 02:29:24 +0000512 <dd>Global values with private linkage are only directly accessible by objects
513 in the current module. In particular, linking code into a module with an
514 private global value may cause the private to be renamed as necessary to
515 avoid collisions. Because the symbol is private to the module, all
516 references can be updated. This doesn't show up in any symbol table in the
517 object file.</dd>
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000518
Bill Wendling41a07852009-07-20 01:03:30 +0000519 <dt><tt><b><a name="linkage_linker_private">linker_private</a></b></tt>: </dt>
520
521 <dd>Similar to private, but the symbol is passed through the assembler and
522 removed by the linker after evaluation.</dd>
523
Dale Johannesen96e7e092008-05-23 23:13:41 +0000524 <dt><tt><b><a name="linkage_internal">internal</a></b></tt>: </dt>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000525
Bill Wendlingf85859d2009-07-20 02:29:24 +0000526 <dd>Similar to private, but the value shows as a local symbol
527 (<tt>STB_LOCAL</tt> in the case of ELF) in the object file. This
528 corresponds to the notion of the '<tt>static</tt>' keyword in C.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000529
Bill Wendlingf85859d2009-07-20 02:29:24 +0000530 <dt><tt><b><a name="linkage_available_externally">available_externally</a></b></tt>: </dt>
Chris Lattner68433442009-04-13 05:44:34 +0000531
532 <dd>Globals with "<tt>available_externally</tt>" linkage are never emitted
Bill Wendlingf85859d2009-07-20 02:29:24 +0000533 into the object file corresponding to the LLVM module. They exist to
534 allow inlining and other optimizations to take place given knowledge of
535 the definition of the global, which is known to be somewhere outside the
536 module. Globals with <tt>available_externally</tt> linkage are allowed to
537 be discarded at will, and are otherwise the same as <tt>linkonce_odr</tt>.
538 This linkage type is only allowed on definitions, not declarations.</dd>
Chris Lattner68433442009-04-13 05:44:34 +0000539
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000540 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
541
542 <dd>Globals with "<tt>linkonce</tt>" linkage are merged with other globals of
Bill Wendlingf85859d2009-07-20 02:29:24 +0000543 the same name when linkage occurs. This is typically used to implement
544 inline functions, templates, or other code which must be generated in each
545 translation unit that uses it. Unreferenced <tt>linkonce</tt> globals are
546 allowed to be discarded.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000547
Dale Johannesen96e7e092008-05-23 23:13:41 +0000548 <dt><tt><b><a name="linkage_common">common</a></b></tt>: </dt>
549
Bill Wendlingf85859d2009-07-20 02:29:24 +0000550 <dd>"<tt>common</tt>" linkage is exactly the same as <tt>linkonce</tt>
551 linkage, except that unreferenced <tt>common</tt> globals may not be
552 discarded. This is used for globals that may be emitted in multiple
553 translation units, but that are not guaranteed to be emitted into every
554 translation unit that uses them. One example of this is tentative
555 definitions in C, such as "<tt>int X;</tt>" at global scope.</dd>
Dale Johannesen96e7e092008-05-23 23:13:41 +0000556
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000557 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
558
Dale Johannesen96e7e092008-05-23 23:13:41 +0000559 <dd>"<tt>weak</tt>" linkage is the same as <tt>common</tt> linkage, except
Bill Wendlingf85859d2009-07-20 02:29:24 +0000560 that some targets may choose to emit different assembly sequences for them
561 for target-dependent reasons. This is used for globals that are declared
562 "weak" in C source code.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000563
564 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
565
566 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
Bill Wendlingf85859d2009-07-20 02:29:24 +0000567 pointer to array type. When two global variables with appending linkage
568 are linked together, the two global arrays are appended together. This is
569 the LLVM, typesafe, equivalent of having the system linker append together
570 "sections" with identical names when .o files are linked.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000571
572 <dt><tt><b><a name="linkage_externweak">extern_weak</a></b></tt>: </dt>
Duncan Sands19d161f2009-03-07 15:45:40 +0000573
Bill Wendlingf85859d2009-07-20 02:29:24 +0000574 <dd>The semantics of this linkage follow the ELF object file model: the symbol
575 is weak until linked, if not linked, the symbol becomes null instead of
576 being an undefined reference.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000577
Duncan Sands19d161f2009-03-07 15:45:40 +0000578 <dt><tt><b><a name="linkage_linkonce">linkonce_odr</a></b></tt>: </dt>
Duncan Sands19d161f2009-03-07 15:45:40 +0000579 <dt><tt><b><a name="linkage_weak">weak_odr</a></b></tt>: </dt>
Bill Wendlingf85859d2009-07-20 02:29:24 +0000580
581 <dd>Some languages allow differing globals to be merged, such as two functions
582 with different semantics. Other languages, such as <tt>C++</tt>, ensure
583 that only equivalent globals are ever merged (the "one definition rule" -
584 "ODR"). Such languages can use the <tt>linkonce_odr</tt>
585 and <tt>weak_odr</tt> linkage types to indicate that the global will only
586 be merged with equivalent globals. These linkage types are otherwise the
587 same as their non-<tt>odr</tt> versions.</dd>
Duncan Sands19d161f2009-03-07 15:45:40 +0000588
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000589 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
590
591 <dd>If none of the above identifiers are used, the global is externally
Bill Wendlingf85859d2009-07-20 02:29:24 +0000592 visible, meaning that it participates in linkage and can be used to
593 resolve external symbol references.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000594</dl>
595
Bill Wendlingf85859d2009-07-20 02:29:24 +0000596<p>The next two types of linkage are targeted for Microsoft Windows platform
597 only. They are designed to support importing (exporting) symbols from (to)
598 DLLs (Dynamic Link Libraries).</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000599
Bill Wendlingf85859d2009-07-20 02:29:24 +0000600<dl>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000601 <dt><tt><b><a name="linkage_dllimport">dllimport</a></b></tt>: </dt>
602
603 <dd>"<tt>dllimport</tt>" linkage causes the compiler to reference a function
Bill Wendlingf85859d2009-07-20 02:29:24 +0000604 or variable via a global pointer to a pointer that is set up by the DLL
605 exporting the symbol. On Microsoft Windows targets, the pointer name is
606 formed by combining <code>__imp_</code> and the function or variable
607 name.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000608
609 <dt><tt><b><a name="linkage_dllexport">dllexport</a></b></tt>: </dt>
610
611 <dd>"<tt>dllexport</tt>" linkage causes the compiler to provide a global
Bill Wendlingf85859d2009-07-20 02:29:24 +0000612 pointer to a pointer in a DLL, so that it can be referenced with the
613 <tt>dllimport</tt> attribute. On Microsoft Windows targets, the pointer
614 name is formed by combining <code>__imp_</code> and the function or
615 variable name.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000616</dl>
617
Bill Wendlingf85859d2009-07-20 02:29:24 +0000618<p>For example, since the "<tt>.LC0</tt>" variable is defined to be internal, if
619 another module defined a "<tt>.LC0</tt>" variable and was linked with this
620 one, one of the two would be renamed, preventing a collision. Since
621 "<tt>main</tt>" and "<tt>puts</tt>" are external (i.e., lacking any linkage
622 declarations), they are accessible outside of the current module.</p>
623
624<p>It is illegal for a function <i>declaration</i> to have any linkage type
625 other than "externally visible", <tt>dllimport</tt>
626 or <tt>extern_weak</tt>.</p>
627
Duncan Sands19d161f2009-03-07 15:45:40 +0000628<p>Aliases can have only <tt>external</tt>, <tt>internal</tt>, <tt>weak</tt>
Bill Wendlingf85859d2009-07-20 02:29:24 +0000629 or <tt>weak_odr</tt> linkages.</p>
630
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000631</div>
632
633<!-- ======================================================================= -->
634<div class="doc_subsection">
635 <a name="callingconv">Calling Conventions</a>
636</div>
637
638<div class="doc_text">
639
640<p>LLVM <a href="#functionstructure">functions</a>, <a href="#i_call">calls</a>
Bill Wendlingf85859d2009-07-20 02:29:24 +0000641 and <a href="#i_invoke">invokes</a> can all have an optional calling
642 convention specified for the call. The calling convention of any pair of
643 dynamic caller/callee must match, or the behavior of the program is
644 undefined. The following calling conventions are supported by LLVM, and more
645 may be added in the future:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000646
647<dl>
648 <dt><b>"<tt>ccc</tt>" - The C calling convention</b>:</dt>
649
650 <dd>This calling convention (the default if no other calling convention is
Bill Wendlingf85859d2009-07-20 02:29:24 +0000651 specified) matches the target C calling conventions. This calling
652 convention supports varargs function calls and tolerates some mismatch in
653 the declared prototype and implemented declaration of the function (as
654 does normal C).</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000655
656 <dt><b>"<tt>fastcc</tt>" - The fast calling convention</b>:</dt>
657
658 <dd>This calling convention attempts to make calls as fast as possible
Bill Wendlingf85859d2009-07-20 02:29:24 +0000659 (e.g. by passing things in registers). This calling convention allows the
660 target to use whatever tricks it wants to produce fast code for the
661 target, without having to conform to an externally specified ABI
662 (Application Binary Interface). Implementations of this convention should
663 allow arbitrary <a href="CodeGenerator.html#tailcallopt">tail call
664 optimization</a> to be supported. This calling convention does not
665 support varargs and requires the prototype of all callees to exactly match
666 the prototype of the function definition.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000667
668 <dt><b>"<tt>coldcc</tt>" - The cold calling convention</b>:</dt>
669
670 <dd>This calling convention attempts to make code in the caller as efficient
Bill Wendlingf85859d2009-07-20 02:29:24 +0000671 as possible under the assumption that the call is not commonly executed.
672 As such, these calls often preserve all registers so that the call does
673 not break any live ranges in the caller side. This calling convention
674 does not support varargs and requires the prototype of all callees to
675 exactly match the prototype of the function definition.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000676
677 <dt><b>"<tt>cc &lt;<em>n</em>&gt;</tt>" - Numbered convention</b>:</dt>
678
679 <dd>Any calling convention may be specified by number, allowing
Bill Wendlingf85859d2009-07-20 02:29:24 +0000680 target-specific calling conventions to be used. Target specific calling
681 conventions start at 64.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000682</dl>
683
684<p>More calling conventions can be added/defined on an as-needed basis, to
Bill Wendlingf85859d2009-07-20 02:29:24 +0000685 support Pascal conventions or any other well-known target-independent
686 convention.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000687
688</div>
689
690<!-- ======================================================================= -->
691<div class="doc_subsection">
692 <a name="visibility">Visibility Styles</a>
693</div>
694
695<div class="doc_text">
696
Bill Wendlingf85859d2009-07-20 02:29:24 +0000697<p>All Global Variables and Functions have one of the following visibility
698 styles:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000699
700<dl>
701 <dt><b>"<tt>default</tt>" - Default style</b>:</dt>
702
Chris Lattner96451482008-08-05 18:29:16 +0000703 <dd>On targets that use the ELF object file format, default visibility means
Bill Wendlingf85859d2009-07-20 02:29:24 +0000704 that the declaration is visible to other modules and, in shared libraries,
705 means that the declared entity may be overridden. On Darwin, default
706 visibility means that the declaration is visible to other modules. Default
707 visibility corresponds to "external linkage" in the language.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000708
709 <dt><b>"<tt>hidden</tt>" - Hidden style</b>:</dt>
710
711 <dd>Two declarations of an object with hidden visibility refer to the same
Bill Wendlingf85859d2009-07-20 02:29:24 +0000712 object if they are in the same shared object. Usually, hidden visibility
713 indicates that the symbol will not be placed into the dynamic symbol
714 table, so no other module (executable or shared library) can reference it
715 directly.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000716
717 <dt><b>"<tt>protected</tt>" - Protected style</b>:</dt>
718
719 <dd>On ELF, protected visibility indicates that the symbol will be placed in
Bill Wendlingf85859d2009-07-20 02:29:24 +0000720 the dynamic symbol table, but that references within the defining module
721 will bind to the local symbol. That is, the symbol cannot be overridden by
722 another module.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000723</dl>
724
725</div>
726
727<!-- ======================================================================= -->
728<div class="doc_subsection">
Chris Lattner5b6dc6e2009-01-11 20:53:49 +0000729 <a name="namedtypes">Named Types</a>
730</div>
731
732<div class="doc_text">
733
734<p>LLVM IR allows you to specify name aliases for certain types. This can make
Bill Wendlingf85859d2009-07-20 02:29:24 +0000735 it easier to read the IR and make the IR more condensed (particularly when
736 recursive types are involved). An example of a name specification is:</p>
Chris Lattner5b6dc6e2009-01-11 20:53:49 +0000737
738<div class="doc_code">
739<pre>
740%mytype = type { %mytype*, i32 }
741</pre>
742</div>
743
Bill Wendlingf85859d2009-07-20 02:29:24 +0000744<p>You may give a name to any <a href="#typesystem">type</a> except
745 "<a href="t_void">void</a>". Type name aliases may be used anywhere a type
746 is expected with the syntax "%mytype".</p>
Chris Lattner5b6dc6e2009-01-11 20:53:49 +0000747
748<p>Note that type names are aliases for the structural type that they indicate,
Bill Wendlingf85859d2009-07-20 02:29:24 +0000749 and that you can therefore specify multiple names for the same type. This
750 often leads to confusing behavior when dumping out a .ll file. Since LLVM IR
751 uses structural typing, the name is not part of the type. When printing out
752 LLVM IR, the printer will pick <em>one name</em> to render all types of a
753 particular shape. This means that if you have code where two different
754 source types end up having the same LLVM type, that the dumper will sometimes
755 print the "wrong" or unexpected type. This is an important design point and
756 isn't going to change.</p>
Chris Lattner5b6dc6e2009-01-11 20:53:49 +0000757
758</div>
759
Chris Lattner5b6dc6e2009-01-11 20:53:49 +0000760<!-- ======================================================================= -->
761<div class="doc_subsection">
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000762 <a name="globalvars">Global Variables</a>
763</div>
764
765<div class="doc_text">
766
767<p>Global variables define regions of memory allocated at compilation time
Bill Wendlingf85859d2009-07-20 02:29:24 +0000768 instead of run-time. Global variables may optionally be initialized, may
769 have an explicit section to be placed in, and may have an optional explicit
770 alignment specified. A variable may be defined as "thread_local", which
771 means that it will not be shared by threads (each thread will have a
772 separated copy of the variable). A variable may be defined as a global
773 "constant," which indicates that the contents of the variable
774 will <b>never</b> be modified (enabling better optimization, allowing the
775 global data to be placed in the read-only section of an executable, etc).
776 Note that variables that need runtime initialization cannot be marked
777 "constant" as there is a store to the variable.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000778
Bill Wendlingf85859d2009-07-20 02:29:24 +0000779<p>LLVM explicitly allows <em>declarations</em> of global variables to be marked
780 constant, even if the final definition of the global is not. This capability
781 can be used to enable slightly better optimization of the program, but
782 requires the language definition to guarantee that optimizations based on the
783 'constantness' are valid for the translation units that do not include the
784 definition.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000785
Bill Wendlingf85859d2009-07-20 02:29:24 +0000786<p>As SSA values, global variables define pointer values that are in scope
787 (i.e. they dominate) all basic blocks in the program. Global variables
788 always define a pointer to their "content" type because they describe a
789 region of memory, and all memory objects in LLVM are accessed through
790 pointers.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000791
Bill Wendlingf85859d2009-07-20 02:29:24 +0000792<p>A global variable may be declared to reside in a target-specific numbered
793 address space. For targets that support them, address spaces may affect how
794 optimizations are performed and/or what target instructions are used to
795 access the variable. The default address space is zero. The address space
796 qualifier must precede any other attributes.</p>
Christopher Lambdd0049d2007-12-11 09:31:00 +0000797
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000798<p>LLVM allows an explicit section to be specified for globals. If the target
Bill Wendlingf85859d2009-07-20 02:29:24 +0000799 supports it, it will emit globals to the section specified.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000800
801<p>An explicit alignment may be specified for a global. If not present, or if
Bill Wendlingf85859d2009-07-20 02:29:24 +0000802 the alignment is set to zero, the alignment of the global is set by the
803 target to whatever it feels convenient. If an explicit alignment is
804 specified, the global is forced to have at least that much alignment. All
805 alignments must be a power of 2.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000806
Bill Wendlingf85859d2009-07-20 02:29:24 +0000807<p>For example, the following defines a global in a numbered address space with
808 an initializer, section, and alignment:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000809
810<div class="doc_code">
811<pre>
Dan Gohman21ef02c2009-01-11 00:40:00 +0000812@G = addrspace(5) constant float 1.0, section "foo", align 4
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000813</pre>
814</div>
815
816</div>
817
818
819<!-- ======================================================================= -->
820<div class="doc_subsection">
821 <a name="functionstructure">Functions</a>
822</div>
823
824<div class="doc_text">
825
Bill Wendlingf85859d2009-07-20 02:29:24 +0000826<p>LLVM function definitions consist of the "<tt>define</tt>" keyord, an
827 optional <a href="#linkage">linkage type</a>, an optional
828 <a href="#visibility">visibility style</a>, an optional
829 <a href="#callingconv">calling convention</a>, a return type, an optional
830 <a href="#paramattrs">parameter attribute</a> for the return type, a function
831 name, a (possibly empty) argument list (each with optional
832 <a href="#paramattrs">parameter attributes</a>), optional
833 <a href="#fnattrs">function attributes</a>, an optional section, an optional
834 alignment, an optional <a href="#gc">garbage collector name</a>, an opening
835 curly brace, a list of basic blocks, and a closing curly brace.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000836
Bill Wendlingf85859d2009-07-20 02:29:24 +0000837<p>LLVM function declarations consist of the "<tt>declare</tt>" keyword, an
838 optional <a href="#linkage">linkage type</a>, an optional
839 <a href="#visibility">visibility style</a>, an optional
840 <a href="#callingconv">calling convention</a>, a return type, an optional
841 <a href="#paramattrs">parameter attribute</a> for the return type, a function
842 name, a possibly empty list of arguments, an optional alignment, and an
843 optional <a href="#gc">garbage collector name</a>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000844
Chris Lattner96451482008-08-05 18:29:16 +0000845<p>A function definition contains a list of basic blocks, forming the CFG
Bill Wendlingf85859d2009-07-20 02:29:24 +0000846 (Control Flow Graph) for the function. Each basic block may optionally start
847 with a label (giving the basic block a symbol table entry), contains a list
848 of instructions, and ends with a <a href="#terminators">terminator</a>
849 instruction (such as a branch or function return).</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000850
851<p>The first basic block in a function is special in two ways: it is immediately
Bill Wendlingf85859d2009-07-20 02:29:24 +0000852 executed on entrance to the function, and it is not allowed to have
853 predecessor basic blocks (i.e. there can not be any branches to the entry
854 block of a function). Because the block can have no predecessors, it also
855 cannot have any <a href="#i_phi">PHI nodes</a>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000856
857<p>LLVM allows an explicit section to be specified for functions. If the target
Bill Wendlingf85859d2009-07-20 02:29:24 +0000858 supports it, it will emit functions to the section specified.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000859
860<p>An explicit alignment may be specified for a function. If not present, or if
Bill Wendlingf85859d2009-07-20 02:29:24 +0000861 the alignment is set to zero, the alignment of the function is set by the
862 target to whatever it feels convenient. If an explicit alignment is
863 specified, the function is forced to have at least that much alignment. All
864 alignments must be a power of 2.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000865
Devang Pateld0bfcc72008-10-07 17:48:33 +0000866 <h5>Syntax:</h5>
867
868<div class="doc_code">
Bill Wendlingf85859d2009-07-20 02:29:24 +0000869<pre>
Chris Lattner1e5c5cd02008-10-13 16:55:18 +0000870define [<a href="#linkage">linkage</a>] [<a href="#visibility">visibility</a>]
Bill Wendlingf85859d2009-07-20 02:29:24 +0000871 [<a href="#callingconv">cconv</a>] [<a href="#paramattrs">ret attrs</a>]
872 &lt;ResultType&gt; @&lt;FunctionName&gt; ([argument list])
873 [<a href="#fnattrs">fn Attrs</a>] [section "name"] [align N]
874 [<a href="#gc">gc</a>] { ... }
875</pre>
Devang Pateld0bfcc72008-10-07 17:48:33 +0000876</div>
877
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000878</div>
879
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000880<!-- ======================================================================= -->
881<div class="doc_subsection">
882 <a name="aliasstructure">Aliases</a>
883</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +0000884
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000885<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +0000886
887<p>Aliases act as "second name" for the aliasee value (which can be either
888 function, global variable, another alias or bitcast of global value). Aliases
889 may have an optional <a href="#linkage">linkage type</a>, and an
890 optional <a href="#visibility">visibility style</a>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000891
892 <h5>Syntax:</h5>
893
894<div class="doc_code">
895<pre>
Duncan Sandsd7bfabf2008-09-12 20:48:21 +0000896@&lt;Name&gt; = alias [Linkage] [Visibility] &lt;AliaseeTy&gt; @&lt;Aliasee&gt;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000897</pre>
898</div>
899
900</div>
901
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000902<!-- ======================================================================= -->
903<div class="doc_subsection"><a name="paramattrs">Parameter Attributes</a></div>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000904
Bill Wendlingf85859d2009-07-20 02:29:24 +0000905<div class="doc_text">
906
907<p>The return type and each parameter of a function type may have a set of
908 <i>parameter attributes</i> associated with them. Parameter attributes are
909 used to communicate additional information about the result or parameters of
910 a function. Parameter attributes are considered to be part of the function,
911 not of the function type, so functions with different parameter attributes
912 can have the same function type.</p>
913
914<p>Parameter attributes are simple keywords that follow the type specified. If
915 multiple parameter attributes are needed, they are space separated. For
916 example:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000917
918<div class="doc_code">
919<pre>
Nick Lewycky3022a742009-02-15 23:06:14 +0000920declare i32 @printf(i8* noalias nocapture, ...)
Chris Lattnerf33b8452008-10-04 18:33:34 +0000921declare i32 @atoi(i8 zeroext)
922declare signext i8 @returns_signed_char()
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000923</pre>
924</div>
925
Bill Wendlingf85859d2009-07-20 02:29:24 +0000926<p>Note that any attributes for the function result (<tt>nounwind</tt>,
927 <tt>readonly</tt>) come immediately after the argument list.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000928
Bill Wendlingf85859d2009-07-20 02:29:24 +0000929<p>Currently, only the following parameter attributes are defined:</p>
Chris Lattner275e6be2008-01-11 06:20:47 +0000930
Bill Wendlingf85859d2009-07-20 02:29:24 +0000931<dl>
932 <dt><tt>zeroext</tt></dt>
Chris Lattner275e6be2008-01-11 06:20:47 +0000933
Bill Wendlingf85859d2009-07-20 02:29:24 +0000934 <dd>This indicates to the code generator that the parameter or return value
935 should be zero-extended to a 32-bit value by the caller (for a parameter)
936 or the callee (for a return value).</dd>
Chris Lattner275e6be2008-01-11 06:20:47 +0000937
Bill Wendlingf85859d2009-07-20 02:29:24 +0000938 <dt><tt>signext</tt></dt>
Chris Lattner275e6be2008-01-11 06:20:47 +0000939
Bill Wendlingf85859d2009-07-20 02:29:24 +0000940 <dd>This indicates to the code generator that the parameter or return value
941 should be sign-extended to a 32-bit value by the caller (for a parameter)
942 or the callee (for a return value).</dd>
Chris Lattner275e6be2008-01-11 06:20:47 +0000943
Bill Wendlingf85859d2009-07-20 02:29:24 +0000944 <dt><tt>inreg</tt></dt>
Nick Lewycky40fb6f22008-12-19 06:39:12 +0000945
Bill Wendlingf85859d2009-07-20 02:29:24 +0000946 <dd>This indicates that this parameter or return value should be treated in a
947 special target-dependent fashion during while emitting code for a function
948 call or return (usually, by putting it in a register as opposed to memory,
949 though some targets use it to distinguish between two different kinds of
950 registers). Use of this attribute is target-specific.</dd>
Chris Lattner275e6be2008-01-11 06:20:47 +0000951
Bill Wendlingf85859d2009-07-20 02:29:24 +0000952 <dt><tt><a name="byval">byval</a></tt></dt>
953
954 <dd>This indicates that the pointer parameter should really be passed by value
955 to the function. The attribute implies that a hidden copy of the pointee
956 is made between the caller and the callee, so the callee is unable to
957 modify the value in the callee. This attribute is only valid on LLVM
958 pointer arguments. It is generally used to pass structs and arrays by
959 value, but is also valid on pointers to scalars. The copy is considered
960 to belong to the caller not the callee (for example,
961 <tt><a href="#readonly">readonly</a></tt> functions should not write to
962 <tt>byval</tt> parameters). This is not a valid attribute for return
963 values. The byval attribute also supports specifying an alignment with
964 the align attribute. This has a target-specific effect on the code
965 generator that usually indicates a desired alignment for the synthesized
966 stack slot.</dd>
967
968 <dt><tt>sret</tt></dt>
969
970 <dd>This indicates that the pointer parameter specifies the address of a
971 structure that is the return value of the function in the source program.
972 This pointer must be guaranteed by the caller to be valid: loads and
973 stores to the structure may be assumed by the callee to not to trap. This
974 may only be applied to the first parameter. This is not a valid attribute
975 for return values. </dd>
976
977 <dt><tt>noalias</tt></dt>
978
979 <dd>This indicates that the pointer does not alias any global or any other
980 parameter. The caller is responsible for ensuring that this is the
981 case. On a function return value, <tt>noalias</tt> additionally indicates
982 that the pointer does not alias any other pointers visible to the
983 caller. For further details, please see the discussion of the NoAlias
984 response in
985 <a href="http://llvm.org/docs/AliasAnalysis.html#MustMayNo">alias
986 analysis</a>.</dd>
987
988 <dt><tt>nocapture</tt></dt>
989
990 <dd>This indicates that the callee does not make any copies of the pointer
991 that outlive the callee itself. This is not a valid attribute for return
992 values.</dd>
993
994 <dt><tt>nest</tt></dt>
995
996 <dd>This indicates that the pointer parameter can be excised using the
997 <a href="#int_trampoline">trampoline intrinsics</a>. This is not a valid
998 attribute for return values.</dd>
999</dl>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001000
1001</div>
1002
1003<!-- ======================================================================= -->
1004<div class="doc_subsection">
Gordon Henriksen13fe5e32007-12-10 03:18:06 +00001005 <a name="gc">Garbage Collector Names</a>
1006</div>
1007
1008<div class="doc_text">
Gordon Henriksen13fe5e32007-12-10 03:18:06 +00001009
Bill Wendlingf85859d2009-07-20 02:29:24 +00001010<p>Each function may specify a garbage collector name, which is simply a
1011 string:</p>
1012
1013<div class="doc_code">
1014<pre>
1015define void @f() gc "name" { ...
1016</pre>
1017</div>
Gordon Henriksen13fe5e32007-12-10 03:18:06 +00001018
1019<p>The compiler declares the supported values of <i>name</i>. Specifying a
Bill Wendlingf85859d2009-07-20 02:29:24 +00001020 collector which will cause the compiler to alter its output in order to
1021 support the named garbage collection algorithm.</p>
1022
Gordon Henriksen13fe5e32007-12-10 03:18:06 +00001023</div>
1024
1025<!-- ======================================================================= -->
1026<div class="doc_subsection">
Devang Patel008cd3e2008-09-26 23:51:19 +00001027 <a name="fnattrs">Function Attributes</a>
Devang Pateld468f1c2008-09-04 23:05:13 +00001028</div>
1029
1030<div class="doc_text">
Devang Patel008cd3e2008-09-26 23:51:19 +00001031
Bill Wendlingf85859d2009-07-20 02:29:24 +00001032<p>Function attributes are set to communicate additional information about a
1033 function. Function attributes are considered to be part of the function, not
1034 of the function type, so functions with different parameter attributes can
1035 have the same function type.</p>
Devang Patel008cd3e2008-09-26 23:51:19 +00001036
Bill Wendlingf85859d2009-07-20 02:29:24 +00001037<p>Function attributes are simple keywords that follow the type specified. If
1038 multiple attributes are needed, they are space separated. For example:</p>
Devang Pateld468f1c2008-09-04 23:05:13 +00001039
1040<div class="doc_code">
Bill Wendling74d3eac2008-09-07 10:26:33 +00001041<pre>
Devang Patel008cd3e2008-09-26 23:51:19 +00001042define void @f() noinline { ... }
1043define void @f() alwaysinline { ... }
1044define void @f() alwaysinline optsize { ... }
1045define void @f() optsize
Bill Wendling74d3eac2008-09-07 10:26:33 +00001046</pre>
Devang Pateld468f1c2008-09-04 23:05:13 +00001047</div>
1048
Bill Wendling74d3eac2008-09-07 10:26:33 +00001049<dl>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001050 <dt><tt>alwaysinline</tt></dt>
Bill Wendling74d3eac2008-09-07 10:26:33 +00001051
Bill Wendlingf85859d2009-07-20 02:29:24 +00001052 <dd>This attribute indicates that the inliner should attempt to inline this
1053 function into callers whenever possible, ignoring any active inlining size
1054 threshold for this caller.</dd>
Bill Wendling74d3eac2008-09-07 10:26:33 +00001055
Bill Wendlingf85859d2009-07-20 02:29:24 +00001056 <dt><tt>noinline</tt></dt>
Bill Wendling74d3eac2008-09-07 10:26:33 +00001057
Bill Wendlingf85859d2009-07-20 02:29:24 +00001058 <dd>This attribute indicates that the inliner should never inline this
1059 function in any situation. This attribute may not be used together with
1060 the <tt>alwaysinline</tt> attribute.</dd>
Devang Patel008cd3e2008-09-26 23:51:19 +00001061
Bill Wendlingf85859d2009-07-20 02:29:24 +00001062 <dt><tt>optsize</tt></dt>
Chris Lattner82d70f92008-10-04 18:23:17 +00001063
Bill Wendlingf85859d2009-07-20 02:29:24 +00001064 <dd>This attribute suggests that optimization passes and code generator passes
1065 make choices that keep the code size of this function low, and otherwise
1066 do optimizations specifically to reduce code size.</dd>
Devang Patel008cd3e2008-09-26 23:51:19 +00001067
Bill Wendlingf85859d2009-07-20 02:29:24 +00001068 <dt><tt>noreturn</tt></dt>
Bill Wendlingdfaabba2008-11-13 01:02:51 +00001069
Bill Wendlingf85859d2009-07-20 02:29:24 +00001070 <dd>This function attribute indicates that the function never returns
1071 normally. This produces undefined behavior at runtime if the function
1072 ever does dynamically return.</dd>
Bill Wendlingdfaabba2008-11-13 01:02:51 +00001073
Bill Wendlingf85859d2009-07-20 02:29:24 +00001074 <dt><tt>nounwind</tt></dt>
Bill Wendlingbe9ec3f2008-11-26 19:07:40 +00001075
Bill Wendlingf85859d2009-07-20 02:29:24 +00001076 <dd>This function attribute indicates that the function never returns with an
1077 unwind or exceptional control flow. If the function does unwind, its
1078 runtime behavior is undefined.</dd>
Bill Wendlingbe9ec3f2008-11-26 19:07:40 +00001079
Bill Wendlingf85859d2009-07-20 02:29:24 +00001080 <dt><tt>readnone</tt></dt>
Devang Patela2f9f412009-06-12 19:45:19 +00001081
Bill Wendlingf85859d2009-07-20 02:29:24 +00001082 <dd>This attribute indicates that the function computes its result (or decides
1083 to unwind an exception) based strictly on its arguments, without
1084 dereferencing any pointer arguments or otherwise accessing any mutable
1085 state (e.g. memory, control registers, etc) visible to caller functions.
1086 It does not write through any pointer arguments
1087 (including <tt><a href="#byval">byval</a></tt> arguments) and never
1088 changes any state visible to callers. This means that it cannot unwind
1089 exceptions by calling the <tt>C++</tt> exception throwing methods, but
1090 could use the <tt>unwind</tt> instruction.</dd>
Devang Patela2f9f412009-06-12 19:45:19 +00001091
Bill Wendlingf85859d2009-07-20 02:29:24 +00001092 <dt><tt><a name="readonly">readonly</a></tt></dt>
Devang Patela2f9f412009-06-12 19:45:19 +00001093
Bill Wendlingf85859d2009-07-20 02:29:24 +00001094 <dd>This attribute indicates that the function does not write through any
1095 pointer arguments (including <tt><a href="#byval">byval</a></tt>
1096 arguments) or otherwise modify any state (e.g. memory, control registers,
1097 etc) visible to caller functions. It may dereference pointer arguments
1098 and read state that may be set in the caller. A readonly function always
1099 returns the same value (or unwinds an exception identically) when called
1100 with the same set of arguments and global state. It cannot unwind an
1101 exception by calling the <tt>C++</tt> exception throwing methods, but may
1102 use the <tt>unwind</tt> instruction.</dd>
Anton Korobeynikovedd7d112009-07-17 18:07:26 +00001103
Bill Wendlingf85859d2009-07-20 02:29:24 +00001104 <dt><tt><a name="ssp">ssp</a></tt></dt>
1105
1106 <dd>This attribute indicates that the function should emit a stack smashing
1107 protector. It is in the form of a "canary"&mdash;a random value placed on
1108 the stack before the local variables that's checked upon return from the
1109 function to see if it has been overwritten. A heuristic is used to
1110 determine if a function needs stack protectors or not.<br>
1111<br>
1112 If a function that has an <tt>ssp</tt> attribute is inlined into a
1113 function that doesn't have an <tt>ssp</tt> attribute, then the resulting
1114 function will have an <tt>ssp</tt> attribute.</dd>
1115
1116 <dt><tt>sspreq</tt></dt>
1117
1118 <dd>This attribute indicates that the function should <em>always</em> emit a
1119 stack smashing protector. This overrides
1120 the <tt><a href="#ssp">ssp</a></tt> function attribute.
1121
1122 If a function that has an <tt>sspreq</tt> attribute is inlined into a
1123 function that doesn't have an <tt>sspreq</tt> attribute or which has
1124 an <tt>ssp</tt> attribute, then the resulting function will have
1125 an <tt>sspreq</tt> attribute.</dd>
1126
1127 <dt><tt>noredzone</tt></dt>
1128
1129 <dd>This attribute indicates that the code generator should not use a red
1130 zone, even if the target-specific ABI normally permits it.</dd>
1131
1132 <dt><tt>noimplicitfloat</tt></dt>
1133
1134 <dd>This attributes disables implicit floating point instructions.</dd>
1135
1136 <dt><tt>naked</tt></dt>
1137
1138 <dd>This attribute disables prologue / epilogue emission for the function.
1139 This can have very system-specific consequences.</dd>
Bill Wendling74d3eac2008-09-07 10:26:33 +00001140</dl>
1141
Devang Pateld468f1c2008-09-04 23:05:13 +00001142</div>
1143
1144<!-- ======================================================================= -->
1145<div class="doc_subsection">
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001146 <a name="moduleasm">Module-Level Inline Assembly</a>
1147</div>
1148
1149<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00001150
1151<p>Modules may contain "module-level inline asm" blocks, which corresponds to
1152 the GCC "file scope inline asm" blocks. These blocks are internally
1153 concatenated by LLVM and treated as a single unit, but may be separated in
1154 the <tt>.ll</tt> file if desired. The syntax is very simple:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001155
1156<div class="doc_code">
1157<pre>
1158module asm "inline asm code goes here"
1159module asm "more can go here"
1160</pre>
1161</div>
1162
1163<p>The strings can contain any character by escaping non-printable characters.
1164 The escape sequence used is simply "\xx" where "xx" is the two digit hex code
Bill Wendlingf85859d2009-07-20 02:29:24 +00001165 for the number.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001166
Bill Wendlingf85859d2009-07-20 02:29:24 +00001167<p>The inline asm code is simply printed to the machine code .s file when
1168 assembly code is generated.</p>
1169
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001170</div>
1171
1172<!-- ======================================================================= -->
1173<div class="doc_subsection">
1174 <a name="datalayout">Data Layout</a>
1175</div>
1176
1177<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00001178
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001179<p>A module may specify a target specific data layout string that specifies how
Bill Wendlingf85859d2009-07-20 02:29:24 +00001180 data is to be laid out in memory. The syntax for the data layout is
1181 simply:</p>
1182
1183<div class="doc_code">
1184<pre>
1185target datalayout = "<i>layout specification</i>"
1186</pre>
1187</div>
1188
1189<p>The <i>layout specification</i> consists of a list of specifications
1190 separated by the minus sign character ('-'). Each specification starts with
1191 a letter and may include other information after the letter to define some
1192 aspect of the data layout. The specifications accepted are as follows:</p>
1193
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001194<dl>
1195 <dt><tt>E</tt></dt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001196
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001197 <dd>Specifies that the target lays out data in big-endian form. That is, the
Bill Wendlingf85859d2009-07-20 02:29:24 +00001198 bits with the most significance have the lowest address location.</dd>
1199
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001200 <dt><tt>e</tt></dt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001201
Chris Lattner96451482008-08-05 18:29:16 +00001202 <dd>Specifies that the target lays out data in little-endian form. That is,
Bill Wendlingf85859d2009-07-20 02:29:24 +00001203 the bits with the least significance have the lowest address
1204 location.</dd>
1205
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001206 <dt><tt>p:<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001207
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001208 <dd>This specifies the <i>size</i> of a pointer and its <i>abi</i> and
Bill Wendlingf85859d2009-07-20 02:29:24 +00001209 <i>preferred</i> alignments. All sizes are in bits. Specifying
1210 the <i>pref</i> alignment is optional. If omitted, the
1211 preceding <tt>:</tt> should be omitted too.</dd>
1212
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001213 <dt><tt>i<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001214
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001215 <dd>This specifies the alignment for an integer type of a given bit
Bill Wendlingf85859d2009-07-20 02:29:24 +00001216 <i>size</i>. The value of <i>size</i> must be in the range [1,2^23).</dd>
1217
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001218 <dt><tt>v<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001219
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001220 <dd>This specifies the alignment for a vector type of a given bit
Bill Wendlingf85859d2009-07-20 02:29:24 +00001221 <i>size</i>.</dd>
1222
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001223 <dt><tt>f<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001224
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001225 <dd>This specifies the alignment for a floating point type of a given bit
Bill Wendlingf85859d2009-07-20 02:29:24 +00001226 <i>size</i>. The value of <i>size</i> must be either 32 (float) or 64
1227 (double).</dd>
1228
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001229 <dt><tt>a<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001230
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001231 <dd>This specifies the alignment for an aggregate type of a given bit
Bill Wendlingf85859d2009-07-20 02:29:24 +00001232 <i>size</i>.</dd>
1233
Daniel Dunbard88a97b2009-06-08 22:17:53 +00001234 <dt><tt>s<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001235
Daniel Dunbard88a97b2009-06-08 22:17:53 +00001236 <dd>This specifies the alignment for a stack object of a given bit
Bill Wendlingf85859d2009-07-20 02:29:24 +00001237 <i>size</i>.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001238</dl>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001239
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001240<p>When constructing the data layout for a given target, LLVM starts with a
Bill Wendlingf85859d2009-07-20 02:29:24 +00001241 default set of specifications which are then (possibly) overriden by the
1242 specifications in the <tt>datalayout</tt> keyword. The default specifications
1243 are given in this list:</p>
1244
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001245<ul>
1246 <li><tt>E</tt> - big endian</li>
1247 <li><tt>p:32:64:64</tt> - 32-bit pointers with 64-bit alignment</li>
1248 <li><tt>i1:8:8</tt> - i1 is 8-bit (byte) aligned</li>
1249 <li><tt>i8:8:8</tt> - i8 is 8-bit (byte) aligned</li>
1250 <li><tt>i16:16:16</tt> - i16 is 16-bit aligned</li>
1251 <li><tt>i32:32:32</tt> - i32 is 32-bit aligned</li>
Chris Lattner96451482008-08-05 18:29:16 +00001252 <li><tt>i64:32:64</tt> - i64 has ABI alignment of 32-bits but preferred
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001253 alignment of 64-bits</li>
1254 <li><tt>f32:32:32</tt> - float is 32-bit aligned</li>
1255 <li><tt>f64:64:64</tt> - double is 64-bit aligned</li>
1256 <li><tt>v64:64:64</tt> - 64-bit vector is 64-bit aligned</li>
1257 <li><tt>v128:128:128</tt> - 128-bit vector is 128-bit aligned</li>
1258 <li><tt>a0:0:1</tt> - aggregates are 8-bit aligned</li>
Daniel Dunbard88a97b2009-06-08 22:17:53 +00001259 <li><tt>s0:64:64</tt> - stack objects are 64-bit aligned</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001260</ul>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001261
1262<p>When LLVM is determining the alignment for a given type, it uses the
1263 following rules:</p>
1264
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001265<ol>
1266 <li>If the type sought is an exact match for one of the specifications, that
Bill Wendlingf85859d2009-07-20 02:29:24 +00001267 specification is used.</li>
1268
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001269 <li>If no match is found, and the type sought is an integer type, then the
Bill Wendlingf85859d2009-07-20 02:29:24 +00001270 smallest integer type that is larger than the bitwidth of the sought type
1271 is used. If none of the specifications are larger than the bitwidth then
1272 the the largest integer type is used. For example, given the default
1273 specifications above, the i7 type will use the alignment of i8 (next
1274 largest) while both i65 and i256 will use the alignment of i64 (largest
1275 specified).</li>
1276
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001277 <li>If no match is found, and the type sought is a vector type, then the
Bill Wendlingf85859d2009-07-20 02:29:24 +00001278 largest vector type that is smaller than the sought vector type will be
1279 used as a fall back. This happens because &lt;128 x double&gt; can be
1280 implemented in terms of 64 &lt;2 x double&gt;, for example.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001281</ol>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001282
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001283</div>
1284
1285<!-- *********************************************************************** -->
1286<div class="doc_section"> <a name="typesystem">Type System</a> </div>
1287<!-- *********************************************************************** -->
1288
1289<div class="doc_text">
1290
1291<p>The LLVM type system is one of the most important features of the
Bill Wendlingf85859d2009-07-20 02:29:24 +00001292 intermediate representation. Being typed enables a number of optimizations
1293 to be performed on the intermediate representation directly, without having
1294 to do extra analyses on the side before the transformation. A strong type
1295 system makes it easier to read the generated code and enables novel analyses
1296 and transformations that are not feasible to perform on normal three address
1297 code representations.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001298
1299</div>
1300
1301<!-- ======================================================================= -->
Chris Lattner488772f2008-01-04 04:32:38 +00001302<div class="doc_subsection"> <a name="t_classifications">Type
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001303Classifications</a> </div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001304
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001305<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00001306
1307<p>The types fall into a few useful classifications:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001308
1309<table border="1" cellspacing="0" cellpadding="4">
1310 <tbody>
1311 <tr><th>Classification</th><th>Types</th></tr>
1312 <tr>
Chris Lattner488772f2008-01-04 04:32:38 +00001313 <td><a href="#t_integer">integer</a></td>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001314 <td><tt>i1, i2, i3, ... i8, ... i16, ... i32, ... i64, ... </tt></td>
1315 </tr>
1316 <tr>
Chris Lattner488772f2008-01-04 04:32:38 +00001317 <td><a href="#t_floating">floating point</a></td>
1318 <td><tt>float, double, x86_fp80, fp128, ppc_fp128</tt></td>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001319 </tr>
1320 <tr>
1321 <td><a name="t_firstclass">first class</a></td>
Chris Lattner488772f2008-01-04 04:32:38 +00001322 <td><a href="#t_integer">integer</a>,
1323 <a href="#t_floating">floating point</a>,
1324 <a href="#t_pointer">pointer</a>,
Dan Gohmanf6237db2008-06-18 18:42:13 +00001325 <a href="#t_vector">vector</a>,
Dan Gohman74d6faf2008-05-12 23:51:09 +00001326 <a href="#t_struct">structure</a>,
1327 <a href="#t_array">array</a>,
Nick Lewycky29aaef82009-05-30 05:06:04 +00001328 <a href="#t_label">label</a>,
1329 <a href="#t_metadata">metadata</a>.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001330 </td>
1331 </tr>
Chris Lattner488772f2008-01-04 04:32:38 +00001332 <tr>
1333 <td><a href="#t_primitive">primitive</a></td>
1334 <td><a href="#t_label">label</a>,
1335 <a href="#t_void">void</a>,
Nick Lewycky29aaef82009-05-30 05:06:04 +00001336 <a href="#t_floating">floating point</a>,
1337 <a href="#t_metadata">metadata</a>.</td>
Chris Lattner488772f2008-01-04 04:32:38 +00001338 </tr>
1339 <tr>
1340 <td><a href="#t_derived">derived</a></td>
1341 <td><a href="#t_integer">integer</a>,
1342 <a href="#t_array">array</a>,
1343 <a href="#t_function">function</a>,
1344 <a href="#t_pointer">pointer</a>,
1345 <a href="#t_struct">structure</a>,
1346 <a href="#t_pstruct">packed structure</a>,
1347 <a href="#t_vector">vector</a>,
1348 <a href="#t_opaque">opaque</a>.
Dan Gohman032ba852008-10-14 16:32:04 +00001349 </td>
Chris Lattner488772f2008-01-04 04:32:38 +00001350 </tr>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001351 </tbody>
1352</table>
1353
Bill Wendlingf85859d2009-07-20 02:29:24 +00001354<p>The <a href="#t_firstclass">first class</a> types are perhaps the most
1355 important. Values of these types are the only ones which can be produced by
1356 instructions, passed as arguments, or used as operands to instructions.</p>
1357
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001358</div>
1359
1360<!-- ======================================================================= -->
Chris Lattner488772f2008-01-04 04:32:38 +00001361<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Chris Lattner86437612008-01-04 04:34:14 +00001362
Chris Lattner488772f2008-01-04 04:32:38 +00001363<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00001364
Chris Lattner488772f2008-01-04 04:32:38 +00001365<p>The primitive types are the fundamental building blocks of the LLVM
Bill Wendlingf85859d2009-07-20 02:29:24 +00001366 system.</p>
Chris Lattner488772f2008-01-04 04:32:38 +00001367
Chris Lattner86437612008-01-04 04:34:14 +00001368</div>
1369
Chris Lattner488772f2008-01-04 04:32:38 +00001370<!-- _______________________________________________________________________ -->
1371<div class="doc_subsubsection"> <a name="t_floating">Floating Point Types</a> </div>
1372
1373<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00001374
1375<table>
1376 <tbody>
1377 <tr><th>Type</th><th>Description</th></tr>
1378 <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr>
1379 <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr>
1380 <tr><td><tt>fp128</tt></td><td>128-bit floating point value (112-bit mantissa)</td></tr>
1381 <tr><td><tt>x86_fp80</tt></td><td>80-bit floating point value (X87)</td></tr>
1382 <tr><td><tt>ppc_fp128</tt></td><td>128-bit floating point value (two 64-bits)</td></tr>
1383 </tbody>
1384</table>
1385
Chris Lattner488772f2008-01-04 04:32:38 +00001386</div>
1387
1388<!-- _______________________________________________________________________ -->
1389<div class="doc_subsubsection"> <a name="t_void">Void Type</a> </div>
1390
1391<div class="doc_text">
1392<h5>Overview:</h5>
1393<p>The void type does not represent any value and has no size.</p>
1394
1395<h5>Syntax:</h5>
1396
1397<pre>
1398 void
1399</pre>
1400</div>
1401
1402<!-- _______________________________________________________________________ -->
1403<div class="doc_subsubsection"> <a name="t_label">Label Type</a> </div>
1404
1405<div class="doc_text">
1406<h5>Overview:</h5>
1407<p>The label type represents code labels.</p>
1408
1409<h5>Syntax:</h5>
1410
1411<pre>
1412 label
1413</pre>
1414</div>
1415
Nick Lewycky29aaef82009-05-30 05:06:04 +00001416<!-- _______________________________________________________________________ -->
1417<div class="doc_subsubsection"> <a name="t_metadata">Metadata Type</a> </div>
1418
1419<div class="doc_text">
1420<h5>Overview:</h5>
1421<p>The metadata type represents embedded metadata. The only derived type that
Bill Wendlingf85859d2009-07-20 02:29:24 +00001422 may contain metadata is <tt>metadata*</tt> or a function type that returns or
1423 takes metadata typed parameters, but not pointer to metadata types.</p>
Nick Lewycky29aaef82009-05-30 05:06:04 +00001424
1425<h5>Syntax:</h5>
1426
1427<pre>
1428 metadata
1429</pre>
1430</div>
1431
Chris Lattner488772f2008-01-04 04:32:38 +00001432
1433<!-- ======================================================================= -->
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001434<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
1435
1436<div class="doc_text">
1437
Bill Wendlingf85859d2009-07-20 02:29:24 +00001438<p>The real power in LLVM comes from the derived types in the system. This is
1439 what allows a programmer to represent arrays, functions, pointers, and other
1440 useful types. Note that these derived types may be recursive: For example,
1441 it is possible to have a two dimensional array.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001442
1443</div>
1444
1445<!-- _______________________________________________________________________ -->
1446<div class="doc_subsubsection"> <a name="t_integer">Integer Type</a> </div>
1447
1448<div class="doc_text">
1449
1450<h5>Overview:</h5>
1451<p>The integer type is a very simple derived type that simply specifies an
Bill Wendlingf85859d2009-07-20 02:29:24 +00001452 arbitrary bit width for the integer type desired. Any bit width from 1 bit to
1453 2^23-1 (about 8 million) can be specified.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001454
1455<h5>Syntax:</h5>
1456
1457<pre>
1458 iN
1459</pre>
1460
1461<p>The number of bits the integer will occupy is specified by the <tt>N</tt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001462 value.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001463
1464<h5>Examples:</h5>
1465<table class="layout">
Nick Lewycky39382d62009-05-24 02:46:06 +00001466 <tr class="layout">
1467 <td class="left"><tt>i1</tt></td>
1468 <td class="left">a single-bit integer.</td>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001469 </tr>
Nick Lewycky39382d62009-05-24 02:46:06 +00001470 <tr class="layout">
1471 <td class="left"><tt>i32</tt></td>
1472 <td class="left">a 32-bit integer.</td>
1473 </tr>
1474 <tr class="layout">
1475 <td class="left"><tt>i1942652</tt></td>
1476 <td class="left">a really big integer of over 1 million bits.</td>
1477 </tr>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001478</table>
djge93155c2009-01-24 15:58:40 +00001479
Bill Wendlingf85859d2009-07-20 02:29:24 +00001480<p>Note that the code generator does not yet support large integer types to be
1481 used as function return types. The specific limit on how large a return type
1482 the code generator can currently handle is target-dependent; currently it's
1483 often 64 bits for 32-bit targets and 128 bits for 64-bit targets.</p>
djge93155c2009-01-24 15:58:40 +00001484
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001485</div>
1486
1487<!-- _______________________________________________________________________ -->
1488<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
1489
1490<div class="doc_text">
1491
1492<h5>Overview:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001493<p>The array type is a very simple derived type that arranges elements
Bill Wendlingf85859d2009-07-20 02:29:24 +00001494 sequentially in memory. The array type requires a size (number of elements)
1495 and an underlying data type.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001496
1497<h5>Syntax:</h5>
1498
1499<pre>
1500 [&lt;# elements&gt; x &lt;elementtype&gt;]
1501</pre>
1502
Bill Wendlingf85859d2009-07-20 02:29:24 +00001503<p>The number of elements is a constant integer value; <tt>elementtype</tt> may
1504 be any type with a size.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001505
1506<h5>Examples:</h5>
1507<table class="layout">
1508 <tr class="layout">
Chris Lattner7311d222007-12-19 05:04:11 +00001509 <td class="left"><tt>[40 x i32]</tt></td>
1510 <td class="left">Array of 40 32-bit integer values.</td>
1511 </tr>
1512 <tr class="layout">
1513 <td class="left"><tt>[41 x i32]</tt></td>
1514 <td class="left">Array of 41 32-bit integer values.</td>
1515 </tr>
1516 <tr class="layout">
1517 <td class="left"><tt>[4 x i8]</tt></td>
1518 <td class="left">Array of 4 8-bit integer values.</td>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001519 </tr>
1520</table>
1521<p>Here are some examples of multidimensional arrays:</p>
1522<table class="layout">
1523 <tr class="layout">
Chris Lattner7311d222007-12-19 05:04:11 +00001524 <td class="left"><tt>[3 x [4 x i32]]</tt></td>
1525 <td class="left">3x4 array of 32-bit integer values.</td>
1526 </tr>
1527 <tr class="layout">
1528 <td class="left"><tt>[12 x [10 x float]]</tt></td>
1529 <td class="left">12x10 array of single precision floating point values.</td>
1530 </tr>
1531 <tr class="layout">
1532 <td class="left"><tt>[2 x [3 x [4 x i16]]]</tt></td>
1533 <td class="left">2x3x4 array of 16-bit integer values.</td>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001534 </tr>
1535</table>
1536
Bill Wendlingf85859d2009-07-20 02:29:24 +00001537<p>Note that 'variable sized arrays' can be implemented in LLVM with a zero
1538 length array. Normally, accesses past the end of an array are undefined in
1539 LLVM (e.g. it is illegal to access the 5th element of a 3 element array). As
1540 a special case, however, zero length arrays are recognized to be variable
1541 length. This allows implementation of 'pascal style arrays' with the LLVM
1542 type "<tt>{ i32, [0 x float]}</tt>", for example.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001543
Bill Wendlingf85859d2009-07-20 02:29:24 +00001544<p>Note that the code generator does not yet support large aggregate types to be
1545 used as function return types. The specific limit on how large an aggregate
1546 return type the code generator can currently handle is target-dependent, and
1547 also dependent on the aggregate element types.</p>
djge93155c2009-01-24 15:58:40 +00001548
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001549</div>
1550
1551<!-- _______________________________________________________________________ -->
1552<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001553
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001554<div class="doc_text">
Chris Lattner43030e72008-04-23 04:59:35 +00001555
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001556<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001557<p>The function type can be thought of as a function signature. It consists of
1558 a return type and a list of formal parameter types. The return type of a
1559 function type is a scalar type, a void type, or a struct type. If the return
1560 type is a struct type then all struct elements must be of first class types,
1561 and the struct must have at least one element.</p>
Devang Patela3cc5372008-03-10 20:49:15 +00001562
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001563<h5>Syntax:</h5>
Chris Lattner43030e72008-04-23 04:59:35 +00001564
1565<pre>
1566 &lt;returntype list&gt; (&lt;parameter list&gt;)
1567</pre>
1568
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001569<p>...where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
Bill Wendlingf85859d2009-07-20 02:29:24 +00001570 specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
1571 which indicates that the function takes a variable number of arguments.
1572 Variable argument functions can access their arguments with
1573 the <a href="#int_varargs">variable argument handling intrinsic</a>
1574 functions. '<tt>&lt;returntype list&gt;</tt>' is a comma-separated list of
1575 <a href="#t_firstclass">first class</a> type specifiers.</p>
Chris Lattner43030e72008-04-23 04:59:35 +00001576
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001577<h5>Examples:</h5>
1578<table class="layout">
1579 <tr class="layout">
1580 <td class="left"><tt>i32 (i32)</tt></td>
1581 <td class="left">function taking an <tt>i32</tt>, returning an <tt>i32</tt>
1582 </td>
1583 </tr><tr class="layout">
Reid Spencerf234bed2007-07-19 23:13:04 +00001584 <td class="left"><tt>float&nbsp;(i16&nbsp;signext,&nbsp;i32&nbsp;*)&nbsp;*
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001585 </tt></td>
1586 <td class="left"><a href="#t_pointer">Pointer</a> to a function that takes
1587 an <tt>i16</tt> that should be sign extended and a
1588 <a href="#t_pointer">pointer</a> to <tt>i32</tt>, returning
1589 <tt>float</tt>.
1590 </td>
1591 </tr><tr class="layout">
1592 <td class="left"><tt>i32 (i8*, ...)</tt></td>
1593 <td class="left">A vararg function that takes at least one
1594 <a href="#t_pointer">pointer</a> to <tt>i8 </tt> (char in C),
1595 which returns an integer. This is the signature for <tt>printf</tt> in
1596 LLVM.
1597 </td>
Devang Pateld4ba41d2008-03-24 05:35:41 +00001598 </tr><tr class="layout">
1599 <td class="left"><tt>{i32, i32} (i32)</tt></td>
Misha Brukmanafc88b02008-11-27 06:41:20 +00001600 <td class="left">A function taking an <tt>i32</tt>, returning two
1601 <tt>i32</tt> values as an aggregate of type <tt>{ i32, i32 }</tt>
Devang Pateld4ba41d2008-03-24 05:35:41 +00001602 </td>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001603 </tr>
1604</table>
1605
1606</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001607
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001608<!-- _______________________________________________________________________ -->
1609<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001610
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001611<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00001612
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001613<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001614<p>The structure type is used to represent a collection of data members together
1615 in memory. The packing of the field types is defined to match the ABI of the
1616 underlying processor. The elements of a structure may be any type that has a
1617 size.</p>
1618
1619<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt> and
1620 '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a field with
1621 the '<tt><a href="#i_getelementptr">getelementptr</a></tt>' instruction.</p>
1622
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001623<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001624
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001625<pre> { &lt;type list&gt; }<br></pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001626
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001627<h5>Examples:</h5>
1628<table class="layout">
1629 <tr class="layout">
1630 <td class="left"><tt>{ i32, i32, i32 }</tt></td>
1631 <td class="left">A triple of three <tt>i32</tt> values</td>
1632 </tr><tr class="layout">
1633 <td class="left"><tt>{&nbsp;float,&nbsp;i32&nbsp;(i32)&nbsp;*&nbsp;}</tt></td>
1634 <td class="left">A pair, where the first element is a <tt>float</tt> and the
1635 second element is a <a href="#t_pointer">pointer</a> to a
1636 <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning
1637 an <tt>i32</tt>.</td>
1638 </tr>
1639</table>
djge93155c2009-01-24 15:58:40 +00001640
Bill Wendlingf85859d2009-07-20 02:29:24 +00001641<p>Note that the code generator does not yet support large aggregate types to be
1642 used as function return types. The specific limit on how large an aggregate
1643 return type the code generator can currently handle is target-dependent, and
1644 also dependent on the aggregate element types.</p>
djge93155c2009-01-24 15:58:40 +00001645
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001646</div>
1647
1648<!-- _______________________________________________________________________ -->
1649<div class="doc_subsubsection"> <a name="t_pstruct">Packed Structure Type</a>
1650</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001651
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001652<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00001653
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001654<h5>Overview:</h5>
1655<p>The packed structure type is used to represent a collection of data members
Bill Wendlingf85859d2009-07-20 02:29:24 +00001656 together in memory. There is no padding between fields. Further, the
1657 alignment of a packed structure is 1 byte. The elements of a packed
1658 structure may be any type that has a size.</p>
1659
1660<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt> and
1661 '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a field with
1662 the '<tt><a href="#i_getelementptr">getelementptr</a></tt>' instruction.</p>
1663
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001664<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001665
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001666<pre> &lt; { &lt;type list&gt; } &gt; <br></pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001667
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001668<h5>Examples:</h5>
1669<table class="layout">
1670 <tr class="layout">
1671 <td class="left"><tt>&lt; { i32, i32, i32 } &gt;</tt></td>
1672 <td class="left">A triple of three <tt>i32</tt> values</td>
1673 </tr><tr class="layout">
Bill Wendling74d3eac2008-09-07 10:26:33 +00001674 <td class="left">
1675<tt>&lt;&nbsp;{&nbsp;float,&nbsp;i32&nbsp;(i32)*&nbsp;}&nbsp;&gt;</tt></td>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001676 <td class="left">A pair, where the first element is a <tt>float</tt> and the
1677 second element is a <a href="#t_pointer">pointer</a> to a
1678 <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning
1679 an <tt>i32</tt>.</td>
1680 </tr>
1681</table>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001682
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001683</div>
1684
1685<!-- _______________________________________________________________________ -->
1686<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Chris Lattner96edbd32009-02-08 19:53:29 +00001687
Bill Wendlingf85859d2009-07-20 02:29:24 +00001688<div class="doc_text">
1689
1690<h5>Overview:</h5>
1691<p>As in many languages, the pointer type represents a pointer or reference to
1692 another object, which must live in memory. Pointer types may have an optional
1693 address space attribute defining the target-specific numbered address space
1694 where the pointed-to object resides. The default address space is zero.</p>
1695
1696<p>Note that LLVM does not permit pointers to void (<tt>void*</tt>) nor does it
1697 permit pointers to labels (<tt>label*</tt>). Use <tt>i8*</tt> instead.</p>
Chris Lattner96edbd32009-02-08 19:53:29 +00001698
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001699<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001700
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001701<pre> &lt;type&gt; *<br></pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001702
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001703<h5>Examples:</h5>
1704<table class="layout">
1705 <tr class="layout">
Dan Gohman01852382009-01-04 23:44:43 +00001706 <td class="left"><tt>[4 x i32]*</tt></td>
Chris Lattner7311d222007-12-19 05:04:11 +00001707 <td class="left">A <a href="#t_pointer">pointer</a> to <a
1708 href="#t_array">array</a> of four <tt>i32</tt> values.</td>
1709 </tr>
1710 <tr class="layout">
1711 <td class="left"><tt>i32 (i32 *) *</tt></td>
1712 <td class="left"> A <a href="#t_pointer">pointer</a> to a <a
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001713 href="#t_function">function</a> that takes an <tt>i32*</tt>, returning an
Chris Lattner7311d222007-12-19 05:04:11 +00001714 <tt>i32</tt>.</td>
1715 </tr>
1716 <tr class="layout">
1717 <td class="left"><tt>i32 addrspace(5)*</tt></td>
1718 <td class="left">A <a href="#t_pointer">pointer</a> to an <tt>i32</tt> value
1719 that resides in address space #5.</td>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001720 </tr>
1721</table>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001722
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001723</div>
1724
1725<!-- _______________________________________________________________________ -->
1726<div class="doc_subsubsection"> <a name="t_vector">Vector Type</a> </div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001727
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001728<div class="doc_text">
1729
1730<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001731<p>A vector type is a simple derived type that represents a vector of elements.
1732 Vector types are used when multiple primitive data are operated in parallel
1733 using a single instruction (SIMD). A vector type requires a size (number of
1734 elements) and an underlying primitive data type. Vectors must have a power
1735 of two length (1, 2, 4, 8, 16 ...). Vector types are considered
1736 <a href="#t_firstclass">first class</a>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001737
1738<h5>Syntax:</h5>
1739
1740<pre>
1741 &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;
1742</pre>
1743
Bill Wendlingf85859d2009-07-20 02:29:24 +00001744<p>The number of elements is a constant integer value; elementtype may be any
1745 integer or floating point type.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001746
1747<h5>Examples:</h5>
1748
1749<table class="layout">
1750 <tr class="layout">
Chris Lattner7311d222007-12-19 05:04:11 +00001751 <td class="left"><tt>&lt;4 x i32&gt;</tt></td>
1752 <td class="left">Vector of 4 32-bit integer values.</td>
1753 </tr>
1754 <tr class="layout">
1755 <td class="left"><tt>&lt;8 x float&gt;</tt></td>
1756 <td class="left">Vector of 8 32-bit floating-point values.</td>
1757 </tr>
1758 <tr class="layout">
1759 <td class="left"><tt>&lt;2 x i64&gt;</tt></td>
1760 <td class="left">Vector of 2 64-bit integer values.</td>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001761 </tr>
1762</table>
djge93155c2009-01-24 15:58:40 +00001763
Bill Wendlingf85859d2009-07-20 02:29:24 +00001764<p>Note that the code generator does not yet support large vector types to be
1765 used as function return types. The specific limit on how large a vector
1766 return type codegen can currently handle is target-dependent; currently it's
1767 often a few times longer than a hardware vector register.</p>
djge93155c2009-01-24 15:58:40 +00001768
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001769</div>
1770
1771<!-- _______________________________________________________________________ -->
1772<div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div>
1773<div class="doc_text">
1774
1775<h5>Overview:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001776<p>Opaque types are used to represent unknown types in the system. This
Bill Wendlingf85859d2009-07-20 02:29:24 +00001777 corresponds (for example) to the C notion of a forward declared structure
1778 type. In LLVM, opaque types can eventually be resolved to any type (not just
1779 a structure type).</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001780
1781<h5>Syntax:</h5>
1782
1783<pre>
1784 opaque
1785</pre>
1786
1787<h5>Examples:</h5>
1788
1789<table class="layout">
1790 <tr class="layout">
Chris Lattner7311d222007-12-19 05:04:11 +00001791 <td class="left"><tt>opaque</tt></td>
1792 <td class="left">An opaque type.</td>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001793 </tr>
1794</table>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001795
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001796</div>
1797
Chris Lattner515195a2009-02-02 07:32:36 +00001798<!-- ======================================================================= -->
1799<div class="doc_subsection">
1800 <a name="t_uprefs">Type Up-references</a>
1801</div>
1802
1803<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00001804
Chris Lattner515195a2009-02-02 07:32:36 +00001805<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001806<p>An "up reference" allows you to refer to a lexically enclosing type without
1807 requiring it to have a name. For instance, a structure declaration may
1808 contain a pointer to any of the types it is lexically a member of. Example
1809 of up references (with their equivalent as named type declarations)
1810 include:</p>
Chris Lattner515195a2009-02-02 07:32:36 +00001811
1812<pre>
Chris Lattner5ad632d2009-02-09 10:00:56 +00001813 { \2 * } %x = type { %x* }
Chris Lattner515195a2009-02-02 07:32:36 +00001814 { \2 }* %y = type { %y }*
1815 \1* %z = type %z*
1816</pre>
1817
Bill Wendlingf85859d2009-07-20 02:29:24 +00001818<p>An up reference is needed by the asmprinter for printing out cyclic types
1819 when there is no declared name for a type in the cycle. Because the
1820 asmprinter does not want to print out an infinite type string, it needs a
1821 syntax to handle recursive types that have no names (all names are optional
1822 in llvm IR).</p>
Chris Lattner515195a2009-02-02 07:32:36 +00001823
1824<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00001825
Chris Lattner515195a2009-02-02 07:32:36 +00001826<pre>
1827 \&lt;level&gt;
1828</pre>
1829
Bill Wendlingf85859d2009-07-20 02:29:24 +00001830<p>The level is the count of the lexical type that is being referred to.</p>
Chris Lattner515195a2009-02-02 07:32:36 +00001831
1832<h5>Examples:</h5>
1833
1834<table class="layout">
1835 <tr class="layout">
1836 <td class="left"><tt>\1*</tt></td>
1837 <td class="left">Self-referential pointer.</td>
1838 </tr>
1839 <tr class="layout">
1840 <td class="left"><tt>{ { \3*, i8 }, i32 }</tt></td>
1841 <td class="left">Recursive structure where the upref refers to the out-most
1842 structure.</td>
1843 </tr>
1844</table>
Chris Lattner515195a2009-02-02 07:32:36 +00001845
Bill Wendlingf85859d2009-07-20 02:29:24 +00001846</div>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001847
1848<!-- *********************************************************************** -->
1849<div class="doc_section"> <a name="constants">Constants</a> </div>
1850<!-- *********************************************************************** -->
1851
1852<div class="doc_text">
1853
1854<p>LLVM has several different basic types of constants. This section describes
Bill Wendlingf85859d2009-07-20 02:29:24 +00001855 them all and their syntax.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001856
1857</div>
1858
1859<!-- ======================================================================= -->
1860<div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
1861
1862<div class="doc_text">
1863
1864<dl>
1865 <dt><b>Boolean constants</b></dt>
1866
1867 <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
Bill Wendlingf85859d2009-07-20 02:29:24 +00001868 constants of the <tt><a href="#t_primitive">i1</a></tt> type.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001869
1870 <dt><b>Integer constants</b></dt>
1871
Bill Wendlingf85859d2009-07-20 02:29:24 +00001872 <dd>Standard integers (such as '4') are constants of
1873 the <a href="#t_integer">integer</a> type. Negative numbers may be used
1874 with integer types.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001875
1876 <dt><b>Floating point constants</b></dt>
1877
1878 <dd>Floating point constants use standard decimal notation (e.g. 123.421),
Bill Wendlingf85859d2009-07-20 02:29:24 +00001879 exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
1880 notation (see below). The assembler requires the exact decimal value of a
1881 floating-point constant. For example, the assembler accepts 1.25 but
1882 rejects 1.3 because 1.3 is a repeating decimal in binary. Floating point
1883 constants must have a <a href="#t_floating">floating point</a> type. </dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001884
1885 <dt><b>Null pointer constants</b></dt>
1886
1887 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
Bill Wendlingf85859d2009-07-20 02:29:24 +00001888 and must be of <a href="#t_pointer">pointer type</a>.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001889</dl>
1890
Bill Wendlingf85859d2009-07-20 02:29:24 +00001891<p>The one non-intuitive notation for constants is the hexadecimal form of
1892 floating point constants. For example, the form '<tt>double
1893 0x432ff973cafa8000</tt>' is equivalent to (but harder to read than)
1894 '<tt>double 4.5e+15</tt>'. The only time hexadecimal floating point
1895 constants are required (and the only time that they are generated by the
1896 disassembler) is when a floating point constant must be emitted but it cannot
1897 be represented as a decimal floating point number in a reasonable number of
1898 digits. For example, NaN's, infinities, and other special values are
1899 represented in their IEEE hexadecimal format so that assembly and disassembly
1900 do not cause any bits to change in the constants.</p>
1901
Dale Johannesenf82a52f2009-02-11 22:14:51 +00001902<p>When using the hexadecimal form, constants of types float and double are
Bill Wendlingf85859d2009-07-20 02:29:24 +00001903 represented using the 16-digit form shown above (which matches the IEEE754
1904 representation for double); float values must, however, be exactly
1905 representable as IEE754 single precision. Hexadecimal format is always used
1906 for long double, and there are three forms of long double. The 80-bit format
1907 used by x86 is represented as <tt>0xK</tt> followed by 20 hexadecimal digits.
1908 The 128-bit format used by PowerPC (two adjacent doubles) is represented
1909 by <tt>0xM</tt> followed by 32 hexadecimal digits. The IEEE 128-bit format
1910 is represented by <tt>0xL</tt> followed by 32 hexadecimal digits; no
1911 currently supported target uses this format. Long doubles will only work if
1912 they match the long double format on your target. All hexadecimal formats
1913 are big-endian (sign bit at the left).</p>
1914
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001915</div>
1916
1917<!-- ======================================================================= -->
Chris Lattner97063852009-02-28 18:32:25 +00001918<div class="doc_subsection">
1919<a name="aggregateconstants"> <!-- old anchor -->
1920<a name="complexconstants">Complex Constants</a></a>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001921</div>
1922
1923<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00001924
Chris Lattner97063852009-02-28 18:32:25 +00001925<p>Complex constants are a (potentially recursive) combination of simple
Bill Wendlingf85859d2009-07-20 02:29:24 +00001926 constants and smaller complex constants.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001927
1928<dl>
1929 <dt><b>Structure constants</b></dt>
1930
1931 <dd>Structure constants are represented with notation similar to structure
Bill Wendlingf85859d2009-07-20 02:29:24 +00001932 type definitions (a comma separated list of elements, surrounded by braces
1933 (<tt>{}</tt>)). For example: "<tt>{ i32 4, float 17.0, i32* @G }</tt>",
1934 where "<tt>@G</tt>" is declared as "<tt>@G = external global i32</tt>".
1935 Structure constants must have <a href="#t_struct">structure type</a>, and
1936 the number and types of elements must match those specified by the
1937 type.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001938
1939 <dt><b>Array constants</b></dt>
1940
1941 <dd>Array constants are represented with notation similar to array type
Bill Wendlingf85859d2009-07-20 02:29:24 +00001942 definitions (a comma separated list of elements, surrounded by square
1943 brackets (<tt>[]</tt>)). For example: "<tt>[ i32 42, i32 11, i32 74
1944 ]</tt>". Array constants must have <a href="#t_array">array type</a>, and
1945 the number and types of elements must match those specified by the
1946 type.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001947
1948 <dt><b>Vector constants</b></dt>
1949
1950 <dd>Vector constants are represented with notation similar to vector type
Bill Wendlingf85859d2009-07-20 02:29:24 +00001951 definitions (a comma separated list of elements, surrounded by
1952 less-than/greater-than's (<tt>&lt;&gt;</tt>)). For example: "<tt>&lt; i32
1953 42, i32 11, i32 74, i32 100 &gt;</tt>". Vector constants must
1954 have <a href="#t_vector">vector type</a>, and the number and types of
1955 elements must match those specified by the type.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001956
1957 <dt><b>Zero initialization</b></dt>
1958
1959 <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
Bill Wendlingf85859d2009-07-20 02:29:24 +00001960 value to zero of <em>any</em> type, including scalar and aggregate types.
1961 This is often used to avoid having to print large zero initializers
1962 (e.g. for large arrays) and is always exactly equivalent to using explicit
1963 zero initializers.</dd>
Nick Lewycky4dcf8102009-04-04 07:22:01 +00001964
1965 <dt><b>Metadata node</b></dt>
1966
Nick Lewyckyf122c7e2009-05-30 16:08:30 +00001967 <dd>A metadata node is a structure-like constant with
Bill Wendlingf85859d2009-07-20 02:29:24 +00001968 <a href="#t_metadata">metadata type</a>. For example: "<tt>metadata !{
1969 i32 0, metadata !"test" }</tt>". Unlike other constants that are meant to
1970 be interpreted as part of the instruction stream, metadata is a place to
1971 attach additional information such as debug info.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001972</dl>
1973
1974</div>
1975
1976<!-- ======================================================================= -->
1977<div class="doc_subsection">
1978 <a name="globalconstants">Global Variable and Function Addresses</a>
1979</div>
1980
1981<div class="doc_text">
1982
Bill Wendlingf85859d2009-07-20 02:29:24 +00001983<p>The addresses of <a href="#globalvars">global variables</a>
1984 and <a href="#functionstructure">functions</a> are always implicitly valid
1985 (link-time) constants. These constants are explicitly referenced when
1986 the <a href="#identifiers">identifier for the global</a> is used and always
1987 have <a href="#t_pointer">pointer</a> type. For example, the following is a
1988 legal LLVM file:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001989
1990<div class="doc_code">
1991<pre>
1992@X = global i32 17
1993@Y = global i32 42
1994@Z = global [2 x i32*] [ i32* @X, i32* @Y ]
1995</pre>
1996</div>
1997
1998</div>
1999
2000<!-- ======================================================================= -->
2001<div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
2002<div class="doc_text">
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002003
Bill Wendlingf85859d2009-07-20 02:29:24 +00002004<p>The string '<tt>undef</tt>' is recognized as a type-less constant that has no
2005 specific value. Undefined values may be of any type and be used anywhere a
2006 constant is permitted.</p>
2007
2008<p>Undefined values indicate to the compiler that the program is well defined no
2009 matter what value is used, giving the compiler more freedom to optimize.</p>
2010
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002011</div>
2012
2013<!-- ======================================================================= -->
2014<div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
2015</div>
2016
2017<div class="doc_text">
2018
2019<p>Constant expressions are used to allow expressions involving other constants
Bill Wendlingf85859d2009-07-20 02:29:24 +00002020 to be used as constants. Constant expressions may be of
2021 any <a href="#t_firstclass">first class</a> type and may involve any LLVM
2022 operation that does not have side effects (e.g. load and call are not
2023 supported). The following is the syntax for constant expressions:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002024
2025<dl>
2026 <dt><b><tt>trunc ( CST to TYPE )</tt></b></dt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002027
2028 <dd>Truncate a constant to another type. The bit size of CST must be larger
2029 than the bit size of TYPE. Both types must be integers.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002030
2031 <dt><b><tt>zext ( CST to TYPE )</tt></b></dt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002032
2033 <dd>Zero extend a constant to another type. The bit size of CST must be
2034 smaller or equal to the bit size of TYPE. Both types must be
2035 integers.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002036
2037 <dt><b><tt>sext ( CST to TYPE )</tt></b></dt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002038
2039 <dd>Sign extend a constant to another type. The bit size of CST must be
2040 smaller or equal to the bit size of TYPE. Both types must be
2041 integers.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002042
2043 <dt><b><tt>fptrunc ( CST to TYPE )</tt></b></dt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002044
2045 <dd>Truncate a floating point constant to another floating point type. The
2046 size of CST must be larger than the size of TYPE. Both types must be
2047 floating point.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002048
2049 <dt><b><tt>fpext ( CST to TYPE )</tt></b></dt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002050
2051 <dd>Floating point extend a constant to another type. The size of CST must be
2052 smaller or equal to the size of TYPE. Both types must be floating
2053 point.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002054
Reid Spencere6adee82007-07-31 14:40:14 +00002055 <dt><b><tt>fptoui ( CST to TYPE )</tt></b></dt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002056
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002057 <dd>Convert a floating point constant to the corresponding unsigned integer
Bill Wendlingf85859d2009-07-20 02:29:24 +00002058 constant. TYPE must be a scalar or vector integer type. CST must be of
2059 scalar or vector floating point type. Both CST and TYPE must be scalars,
2060 or vectors of the same number of elements. If the value won't fit in the
2061 integer type, the results are undefined.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002062
2063 <dt><b><tt>fptosi ( CST to TYPE )</tt></b></dt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002064
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002065 <dd>Convert a floating point constant to the corresponding signed integer
Bill Wendlingf85859d2009-07-20 02:29:24 +00002066 constant. TYPE must be a scalar or vector integer type. CST must be of
2067 scalar or vector floating point type. Both CST and TYPE must be scalars,
2068 or vectors of the same number of elements. If the value won't fit in the
2069 integer type, the results are undefined.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002070
2071 <dt><b><tt>uitofp ( CST to TYPE )</tt></b></dt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002072
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002073 <dd>Convert an unsigned integer constant to the corresponding floating point
Bill Wendlingf85859d2009-07-20 02:29:24 +00002074 constant. TYPE must be a scalar or vector floating point type. CST must be
2075 of scalar or vector integer type. Both CST and TYPE must be scalars, or
2076 vectors of the same number of elements. If the value won't fit in the
2077 floating point type, the results are undefined.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002078
2079 <dt><b><tt>sitofp ( CST to TYPE )</tt></b></dt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002080
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002081 <dd>Convert a signed integer constant to the corresponding floating point
Bill Wendlingf85859d2009-07-20 02:29:24 +00002082 constant. TYPE must be a scalar or vector floating point type. CST must be
2083 of scalar or vector integer type. Both CST and TYPE must be scalars, or
2084 vectors of the same number of elements. If the value won't fit in the
2085 floating point type, the results are undefined.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002086
2087 <dt><b><tt>ptrtoint ( CST to TYPE )</tt></b></dt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002088
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002089 <dd>Convert a pointer typed constant to the corresponding integer constant
Bill Wendlingf85859d2009-07-20 02:29:24 +00002090 <tt>TYPE</tt> must be an integer type. <tt>CST</tt> must be of pointer
2091 type. The <tt>CST</tt> value is zero extended, truncated, or unchanged to
2092 make it fit in <tt>TYPE</tt>.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002093
2094 <dt><b><tt>inttoptr ( CST to TYPE )</tt></b></dt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002095
2096 <dd>Convert a integer constant to a pointer constant. TYPE must be a pointer
2097 type. CST must be of integer type. The CST value is zero extended,
2098 truncated, or unchanged to make it fit in a pointer size. This one is
2099 <i>really</i> dangerous!</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002100
2101 <dt><b><tt>bitcast ( CST to TYPE )</tt></b></dt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002102
Chris Lattner557bc5d2009-02-28 18:27:03 +00002103 <dd>Convert a constant, CST, to another TYPE. The constraints of the operands
2104 are the same as those for the <a href="#i_bitcast">bitcast
2105 instruction</a>.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002106
2107 <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
2108
2109 <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
Bill Wendlingf85859d2009-07-20 02:29:24 +00002110 constants. As with the <a href="#i_getelementptr">getelementptr</a>
2111 instruction, the index list may have zero or more indexes, which are
2112 required to make sense for the type of "CSTPTR".</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002113
2114 <dt><b><tt>select ( COND, VAL1, VAL2 )</tt></b></dt>
2115
Bill Wendlingf85859d2009-07-20 02:29:24 +00002116 <dd>Perform the <a href="#i_select">select operation</a> on constants.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002117
2118 <dt><b><tt>icmp COND ( VAL1, VAL2 )</tt></b></dt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002119
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002120 <dd>Performs the <a href="#i_icmp">icmp operation</a> on constants.</dd>
2121
2122 <dt><b><tt>fcmp COND ( VAL1, VAL2 )</tt></b></dt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002123
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002124 <dd>Performs the <a href="#i_fcmp">fcmp operation</a> on constants.</dd>
2125
2126 <dt><b><tt>extractelement ( VAL, IDX )</tt></b></dt>
2127
Bill Wendlingf85859d2009-07-20 02:29:24 +00002128 <dd>Perform the <a href="#i_extractelement">extractelement operation</a> on
2129 constants.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002130
2131 <dt><b><tt>insertelement ( VAL, ELT, IDX )</tt></b></dt>
2132
Bill Wendlingf85859d2009-07-20 02:29:24 +00002133 <dd>Perform the <a href="#i_insertelement">insertelement operation</a> on
2134 constants.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002135
2136 <dt><b><tt>shufflevector ( VEC1, VEC2, IDXMASK )</tt></b></dt>
2137
Bill Wendlingf85859d2009-07-20 02:29:24 +00002138 <dd>Perform the <a href="#i_shufflevector">shufflevector operation</a> on
2139 constants.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002140
2141 <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
2142
Bill Wendlingf85859d2009-07-20 02:29:24 +00002143 <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
2144 be any of the <a href="#binaryops">binary</a>
2145 or <a href="#bitwiseops">bitwise binary</a> operations. The constraints
2146 on operands are the same as those for the corresponding instruction
2147 (e.g. no bitwise operations on floating point values are allowed).</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002148</dl>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002149
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002150</div>
2151
Nick Lewycky4dcf8102009-04-04 07:22:01 +00002152<!-- ======================================================================= -->
2153<div class="doc_subsection"><a name="metadata">Embedded Metadata</a>
2154</div>
2155
2156<div class="doc_text">
2157
Bill Wendlingf85859d2009-07-20 02:29:24 +00002158<p>Embedded metadata provides a way to attach arbitrary data to the instruction
2159 stream without affecting the behaviour of the program. There are two
2160 metadata primitives, strings and nodes. All metadata has the
2161 <tt>metadata</tt> type and is identified in syntax by a preceding exclamation
2162 point ('<tt>!</tt>').</p>
Nick Lewycky4dcf8102009-04-04 07:22:01 +00002163
2164<p>A metadata string is a string surrounded by double quotes. It can contain
Bill Wendlingf85859d2009-07-20 02:29:24 +00002165 any character by escaping non-printable characters with "\xx" where "xx" is
2166 the two digit hex code. For example: "<tt>!"test\00"</tt>".</p>
Nick Lewycky4dcf8102009-04-04 07:22:01 +00002167
2168<p>Metadata nodes are represented with notation similar to structure constants
Bill Wendlingf85859d2009-07-20 02:29:24 +00002169 (a comma separated list of elements, surrounded by braces and preceeded by an
2170 exclamation point). For example: "<tt>!{ metadata !"test\00", i32
2171 10}</tt>".</p>
Nick Lewycky4dcf8102009-04-04 07:22:01 +00002172
Bill Wendlingf85859d2009-07-20 02:29:24 +00002173<p>A metadata node will attempt to track changes to the values it holds. In the
2174 event that a value is deleted, it will be replaced with a typeless
2175 "<tt>null</tt>", such as "<tt>metadata !{null, i32 10}</tt>".</p>
Nick Lewycky117f4382009-05-10 20:57:05 +00002176
Nick Lewycky4dcf8102009-04-04 07:22:01 +00002177<p>Optimizations may rely on metadata to provide additional information about
Bill Wendlingf85859d2009-07-20 02:29:24 +00002178 the program that isn't available in the instructions, or that isn't easily
2179 computable. Similarly, the code generator may expect a certain metadata
2180 format to be used to express debugging information.</p>
2181
Nick Lewycky4dcf8102009-04-04 07:22:01 +00002182</div>
2183
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002184<!-- *********************************************************************** -->
2185<div class="doc_section"> <a name="othervalues">Other Values</a> </div>
2186<!-- *********************************************************************** -->
2187
2188<!-- ======================================================================= -->
2189<div class="doc_subsection">
2190<a name="inlineasm">Inline Assembler Expressions</a>
2191</div>
2192
2193<div class="doc_text">
2194
Bill Wendlingf85859d2009-07-20 02:29:24 +00002195<p>LLVM supports inline assembler expressions (as opposed
2196 to <a href="#moduleasm"> Module-Level Inline Assembly</a>) through the use of
2197 a special value. This value represents the inline assembler as a string
2198 (containing the instructions to emit), a list of operand constraints (stored
2199 as a string), and a flag that indicates whether or not the inline asm
2200 expression has side effects. An example inline assembler expression is:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002201
2202<div class="doc_code">
2203<pre>
2204i32 (i32) asm "bswap $0", "=r,r"
2205</pre>
2206</div>
2207
Bill Wendlingf85859d2009-07-20 02:29:24 +00002208<p>Inline assembler expressions may <b>only</b> be used as the callee operand of
2209 a <a href="#i_call"><tt>call</tt> instruction</a>. Thus, typically we
2210 have:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002211
2212<div class="doc_code">
2213<pre>
2214%X = call i32 asm "<a href="#int_bswap">bswap</a> $0", "=r,r"(i32 %Y)
2215</pre>
2216</div>
2217
Bill Wendlingf85859d2009-07-20 02:29:24 +00002218<p>Inline asms with side effects not visible in the constraint list must be
2219 marked as having side effects. This is done through the use of the
2220 '<tt>sideeffect</tt>' keyword, like so:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002221
2222<div class="doc_code">
2223<pre>
2224call void asm sideeffect "eieio", ""()
2225</pre>
2226</div>
2227
2228<p>TODO: The format of the asm and constraints string still need to be
Bill Wendlingf85859d2009-07-20 02:29:24 +00002229 documented here. Constraints on what can be done (e.g. duplication, moving,
2230 etc need to be documented). This is probably best done by reference to
2231 another document that covers inline asm from a holistic perspective.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002232
2233</div>
2234
2235<!-- *********************************************************************** -->
2236<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
2237<!-- *********************************************************************** -->
2238
2239<div class="doc_text">
2240
Bill Wendlingf85859d2009-07-20 02:29:24 +00002241<p>The LLVM instruction set consists of several different classifications of
2242 instructions: <a href="#terminators">terminator
2243 instructions</a>, <a href="#binaryops">binary instructions</a>,
2244 <a href="#bitwiseops">bitwise binary instructions</a>,
2245 <a href="#memoryops">memory instructions</a>, and
2246 <a href="#otherops">other instructions</a>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002247
2248</div>
2249
2250<!-- ======================================================================= -->
2251<div class="doc_subsection"> <a name="terminators">Terminator
2252Instructions</a> </div>
2253
2254<div class="doc_text">
2255
Bill Wendlingf85859d2009-07-20 02:29:24 +00002256<p>As mentioned <a href="#functionstructure">previously</a>, every basic block
2257 in a program ends with a "Terminator" instruction, which indicates which
2258 block should be executed after the current block is finished. These
2259 terminator instructions typically yield a '<tt>void</tt>' value: they produce
2260 control flow, not values (the one exception being the
2261 '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
2262
2263<p>There are six different terminator instructions: the
2264 '<a href="#i_ret"><tt>ret</tt></a>' instruction, the
2265 '<a href="#i_br"><tt>br</tt></a>' instruction, the
2266 '<a href="#i_switch"><tt>switch</tt></a>' instruction, the
2267 '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the
2268 '<a href="#i_unwind"><tt>unwind</tt></a>' instruction, and the
2269 '<a href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002270
2271</div>
2272
2273<!-- _______________________________________________________________________ -->
2274<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
2275Instruction</a> </div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002276
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002277<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00002278
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002279<h5>Syntax:</h5>
Dan Gohman3e700032008-10-04 19:00:07 +00002280<pre>
2281 ret &lt;type&gt; &lt;value&gt; <i>; Return a value from a non-void function</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002282 ret void <i>; Return from void function</i>
2283</pre>
Chris Lattner43030e72008-04-23 04:59:35 +00002284
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002285<h5>Overview:</h5>
Chris Lattner43030e72008-04-23 04:59:35 +00002286
Bill Wendlingf85859d2009-07-20 02:29:24 +00002287<p>The '<tt>ret</tt>' instruction is used to return control flow (and optionally
2288 a value) from a function back to the caller.</p>
2289
2290<p>There are two forms of the '<tt>ret</tt>' instruction: one that returns a
2291 value and then causes control flow, and one that just causes control flow to
2292 occur.</p>
Chris Lattner43030e72008-04-23 04:59:35 +00002293
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002294<h5>Arguments:</h5>
Chris Lattner43030e72008-04-23 04:59:35 +00002295
Bill Wendlingf85859d2009-07-20 02:29:24 +00002296<p>The '<tt>ret</tt>' instruction optionally accepts a single argument, the
2297 return value. The type of the return value must be a
2298 '<a href="#t_firstclass">first class</a>' type.</p>
Dan Gohman3e700032008-10-04 19:00:07 +00002299
Bill Wendlingf85859d2009-07-20 02:29:24 +00002300<p>A function is not <a href="#wellformed">well formed</a> if it it has a
2301 non-void return type and contains a '<tt>ret</tt>' instruction with no return
2302 value or a return value with a type that does not match its type, or if it
2303 has a void return type and contains a '<tt>ret</tt>' instruction with a
2304 return value.</p>
Chris Lattner43030e72008-04-23 04:59:35 +00002305
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002306<h5>Semantics:</h5>
Chris Lattner43030e72008-04-23 04:59:35 +00002307
Bill Wendlingf85859d2009-07-20 02:29:24 +00002308<p>When the '<tt>ret</tt>' instruction is executed, control flow returns back to
2309 the calling function's context. If the caller is a
2310 "<a href="#i_call"><tt>call</tt></a>" instruction, execution continues at the
2311 instruction after the call. If the caller was an
2312 "<a href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues at
2313 the beginning of the "normal" destination block. If the instruction returns
2314 a value, that value shall set the call or invoke instruction's return
2315 value.</p>
Chris Lattner43030e72008-04-23 04:59:35 +00002316
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002317<h5>Example:</h5>
Chris Lattner43030e72008-04-23 04:59:35 +00002318
2319<pre>
2320 ret i32 5 <i>; Return an integer value of 5</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002321 ret void <i>; Return from a void function</i>
Bill Wendlingd163e2d2009-02-28 22:12:54 +00002322 ret { i32, i8 } { i32 4, i8 2 } <i>; Return a struct of values 4 and 2</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002323</pre>
Dan Gohman60967192009-01-12 23:12:39 +00002324
djge93155c2009-01-24 15:58:40 +00002325<p>Note that the code generator does not yet fully support large
2326 return values. The specific sizes that are currently supported are
2327 dependent on the target. For integers, on 32-bit targets the limit
2328 is often 64 bits, and on 64-bit targets the limit is often 128 bits.
2329 For aggregate types, the current limits are dependent on the element
2330 types; for example targets are often limited to 2 total integer
2331 elements and 2 total floating-point elements.</p>
Dan Gohman60967192009-01-12 23:12:39 +00002332
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002333</div>
2334<!-- _______________________________________________________________________ -->
2335<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002336
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002337<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00002338
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002339<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002340<pre>
2341 br i1 &lt;cond&gt;, label &lt;iftrue&gt;, label &lt;iffalse&gt;<br> br label &lt;dest&gt; <i>; Unconditional branch</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002342</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002343
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002344<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002345<p>The '<tt>br</tt>' instruction is used to cause control flow to transfer to a
2346 different basic block in the current function. There are two forms of this
2347 instruction, corresponding to a conditional branch and an unconditional
2348 branch.</p>
2349
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002350<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002351<p>The conditional branch form of the '<tt>br</tt>' instruction takes a single
2352 '<tt>i1</tt>' value and two '<tt>label</tt>' values. The unconditional form
2353 of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>' value as a
2354 target.</p>
2355
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002356<h5>Semantics:</h5>
2357<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>i1</tt>'
Bill Wendlingf85859d2009-07-20 02:29:24 +00002358 argument is evaluated. If the value is <tt>true</tt>, control flows to the
2359 '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
2360 control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
2361
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002362<h5>Example:</h5>
Chris Lattner95127832009-05-09 18:11:50 +00002363<pre>Test:<br> %cond = <a href="#i_icmp">icmp</a> eq i32 %a, %b<br> br i1 %cond, label %IfEqual, label %IfUnequal<br>IfEqual:<br> <a
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002364 href="#i_ret">ret</a> i32 1<br>IfUnequal:<br> <a href="#i_ret">ret</a> i32 0<br></pre>
2365</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002366
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002367<!-- _______________________________________________________________________ -->
2368<div class="doc_subsubsection">
2369 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
2370</div>
2371
2372<div class="doc_text">
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002373
Bill Wendlingf85859d2009-07-20 02:29:24 +00002374<h5>Syntax:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002375<pre>
2376 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
2377</pre>
2378
2379<h5>Overview:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002380<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
Bill Wendlingf85859d2009-07-20 02:29:24 +00002381 several different places. It is a generalization of the '<tt>br</tt>'
2382 instruction, allowing a branch to occur to one of many possible
2383 destinations.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002384
2385<h5>Arguments:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002386<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
Bill Wendlingf85859d2009-07-20 02:29:24 +00002387 comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination,
2388 and an array of pairs of comparison value constants and '<tt>label</tt>'s.
2389 The table is not allowed to contain duplicate constant entries.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002390
2391<h5>Semantics:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002392<p>The <tt>switch</tt> instruction specifies a table of values and
Bill Wendlingf85859d2009-07-20 02:29:24 +00002393 destinations. When the '<tt>switch</tt>' instruction is executed, this table
2394 is searched for the given value. If the value is found, control flow is
2395 transfered to the corresponding destination; otherwise, control flow is
2396 transfered to the default destination.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002397
2398<h5>Implementation:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002399<p>Depending on properties of the target machine and the particular
Bill Wendlingf85859d2009-07-20 02:29:24 +00002400 <tt>switch</tt> instruction, this instruction may be code generated in
2401 different ways. For example, it could be generated as a series of chained
2402 conditional branches or with a lookup table.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002403
2404<h5>Example:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002405<pre>
2406 <i>; Emulate a conditional br instruction</i>
2407 %Val = <a href="#i_zext">zext</a> i1 %value to i32
Dan Gohman01852382009-01-04 23:44:43 +00002408 switch i32 %Val, label %truedest [ i32 0, label %falsedest ]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002409
2410 <i>; Emulate an unconditional br instruction</i>
2411 switch i32 0, label %dest [ ]
2412
2413 <i>; Implement a jump table:</i>
Dan Gohman01852382009-01-04 23:44:43 +00002414 switch i32 %val, label %otherwise [ i32 0, label %onzero
2415 i32 1, label %onone
2416 i32 2, label %ontwo ]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002417</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002418
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002419</div>
2420
2421<!-- _______________________________________________________________________ -->
2422<div class="doc_subsubsection">
2423 <a name="i_invoke">'<tt>invoke</tt>' Instruction</a>
2424</div>
2425
2426<div class="doc_text">
2427
2428<h5>Syntax:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002429<pre>
Devang Pateld0bfcc72008-10-07 17:48:33 +00002430 &lt;result&gt; = invoke [<a href="#callingconv">cconv</a>] [<a href="#paramattrs">ret attrs</a>] &lt;ptr to function ty&gt; &lt;function ptr val&gt;(&lt;function args&gt;) [<a href="#fnattrs">fn attrs</a>]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002431 to label &lt;normal label&gt; unwind label &lt;exception label&gt;
2432</pre>
2433
2434<h5>Overview:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002435<p>The '<tt>invoke</tt>' instruction causes control to transfer to a specified
Bill Wendlingf85859d2009-07-20 02:29:24 +00002436 function, with the possibility of control flow transfer to either the
2437 '<tt>normal</tt>' label or the '<tt>exception</tt>' label. If the callee
2438 function returns with the "<tt><a href="#i_ret">ret</a></tt>" instruction,
2439 control flow will return to the "normal" label. If the callee (or any
2440 indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
2441 instruction, control is interrupted and continued at the dynamically nearest
2442 "exception" label.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002443
2444<h5>Arguments:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002445<p>This instruction requires several arguments:</p>
2446
2447<ol>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002448 <li>The optional "cconv" marker indicates which <a href="#callingconv">calling
2449 convention</a> the call should use. If none is specified, the call
2450 defaults to using C calling conventions.</li>
Devang Patelac2fc272008-10-06 18:50:38 +00002451
2452 <li>The optional <a href="#paramattrs">Parameter Attributes</a> list for
Bill Wendlingf85859d2009-07-20 02:29:24 +00002453 return values. Only '<tt>zeroext</tt>', '<tt>signext</tt>', and
2454 '<tt>inreg</tt>' attributes are valid here.</li>
Devang Patelac2fc272008-10-06 18:50:38 +00002455
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002456 <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to
Bill Wendlingf85859d2009-07-20 02:29:24 +00002457 function value being invoked. In most cases, this is a direct function
2458 invocation, but indirect <tt>invoke</tt>s are just as possible, branching
2459 off an arbitrary pointer to function value.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002460
2461 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a
Bill Wendlingf85859d2009-07-20 02:29:24 +00002462 function to be invoked. </li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002463
2464 <li>'<tt>function args</tt>': argument list whose types match the function
Bill Wendlingf85859d2009-07-20 02:29:24 +00002465 signature argument types. If the function signature indicates the
2466 function accepts a variable number of arguments, the extra arguments can
2467 be specified.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002468
2469 <li>'<tt>normal label</tt>': the label reached when the called function
Bill Wendlingf85859d2009-07-20 02:29:24 +00002470 executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002471
2472 <li>'<tt>exception label</tt>': the label reached when a callee returns with
Bill Wendlingf85859d2009-07-20 02:29:24 +00002473 the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002474
Devang Pateld0bfcc72008-10-07 17:48:33 +00002475 <li>The optional <a href="#fnattrs">function attributes</a> list. Only
Bill Wendlingf85859d2009-07-20 02:29:24 +00002476 '<tt>noreturn</tt>', '<tt>nounwind</tt>', '<tt>readonly</tt>' and
2477 '<tt>readnone</tt>' attributes are valid here.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002478</ol>
2479
2480<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002481<p>This instruction is designed to operate as a standard
2482 '<tt><a href="#i_call">call</a></tt>' instruction in most regards. The
2483 primary difference is that it establishes an association with a label, which
2484 is used by the runtime library to unwind the stack.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002485
2486<p>This instruction is used in languages with destructors to ensure that proper
Bill Wendlingf85859d2009-07-20 02:29:24 +00002487 cleanup is performed in the case of either a <tt>longjmp</tt> or a thrown
2488 exception. Additionally, this is important for implementation of
2489 '<tt>catch</tt>' clauses in high-level languages that support them.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002490
Bill Wendlingf85859d2009-07-20 02:29:24 +00002491<p>For the purposes of the SSA form, the definition of the value returned by the
2492 '<tt>invoke</tt>' instruction is deemed to occur on the edge from the current
2493 block to the "normal" label. If the callee unwinds then no return value is
2494 available.</p>
Dan Gohman140ba5d2009-05-22 21:47:08 +00002495
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002496<h5>Example:</h5>
2497<pre>
Nick Lewyckya1c11a12008-03-16 07:18:12 +00002498 %retval = invoke i32 @Test(i32 15) to label %Continue
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002499 unwind label %TestCleanup <i>; {i32}:retval set</i>
Nick Lewyckya1c11a12008-03-16 07:18:12 +00002500 %retval = invoke <a href="#callingconv">coldcc</a> i32 %Testfnptr(i32 15) to label %Continue
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002501 unwind label %TestCleanup <i>; {i32}:retval set</i>
2502</pre>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002503
Bill Wendlingf85859d2009-07-20 02:29:24 +00002504</div>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002505
2506<!-- _______________________________________________________________________ -->
2507
2508<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
2509Instruction</a> </div>
2510
2511<div class="doc_text">
2512
2513<h5>Syntax:</h5>
2514<pre>
2515 unwind
2516</pre>
2517
2518<h5>Overview:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002519<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
Bill Wendlingf85859d2009-07-20 02:29:24 +00002520 at the first callee in the dynamic call stack which used
2521 an <a href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call.
2522 This is primarily used to implement exception handling.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002523
2524<h5>Semantics:</h5>
Chris Lattner8b094fc2008-04-19 21:01:16 +00002525<p>The '<tt>unwind</tt>' instruction causes execution of the current function to
Bill Wendlingf85859d2009-07-20 02:29:24 +00002526 immediately halt. The dynamic call stack is then searched for the
2527 first <a href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack.
2528 Once found, execution continues at the "exceptional" destination block
2529 specified by the <tt>invoke</tt> instruction. If there is no <tt>invoke</tt>
2530 instruction in the dynamic call chain, undefined behavior results.</p>
2531
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002532</div>
2533
2534<!-- _______________________________________________________________________ -->
2535
2536<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
2537Instruction</a> </div>
2538
2539<div class="doc_text">
2540
2541<h5>Syntax:</h5>
2542<pre>
2543 unreachable
2544</pre>
2545
2546<h5>Overview:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002547<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
Bill Wendlingf85859d2009-07-20 02:29:24 +00002548 instruction is used to inform the optimizer that a particular portion of the
2549 code is not reachable. This can be used to indicate that the code after a
2550 no-return function cannot be reached, and other facts.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002551
2552<h5>Semantics:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002553<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002554
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002555</div>
2556
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002557<!-- ======================================================================= -->
2558<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002559
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002560<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00002561
2562<p>Binary operators are used to do most of the computation in a program. They
2563 require two operands of the same type, execute an operation on them, and
2564 produce a single value. The operands might represent multiple data, as is
2565 the case with the <a href="#t_vector">vector</a> data type. The result value
2566 has the same type as its operands.</p>
2567
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002568<p>There are several different binary operators:</p>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002569
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002570</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002571
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002572<!-- _______________________________________________________________________ -->
Chris Lattner6704c212008-05-20 20:48:21 +00002573<div class="doc_subsubsection">
2574 <a name="i_add">'<tt>add</tt>' Instruction</a>
2575</div>
2576
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002577<div class="doc_text">
Chris Lattner6704c212008-05-20 20:48:21 +00002578
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002579<h5>Syntax:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002580<pre>
Gabor Greifd9068fe2008-08-07 21:46:00 +00002581 &lt;result&gt; = add &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002582</pre>
Chris Lattner6704c212008-05-20 20:48:21 +00002583
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002584<h5>Overview:</h5>
2585<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002586
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002587<h5>Arguments:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002588
Bill Wendlingf85859d2009-07-20 02:29:24 +00002589<p>The two arguments to the '<tt>add</tt>' instruction must
2590 be <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of
2591 integer values. Both arguments must have identical types.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002592
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002593<h5>Semantics:</h5>
Dan Gohman7ce405e2009-06-04 22:49:04 +00002594<p>The value produced is the integer sum of the two operands.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002595
Bill Wendlingf85859d2009-07-20 02:29:24 +00002596<p>If the sum has unsigned overflow, the result returned is the mathematical
2597 result modulo 2<sup>n</sup>, where n is the bit width of the result.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002598
Bill Wendlingf85859d2009-07-20 02:29:24 +00002599<p>Because LLVM integers use a two's complement representation, this instruction
2600 is appropriate for both signed and unsigned integers.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002601
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002602<h5>Example:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002603<pre>
2604 &lt;result&gt; = add i32 4, %var <i>; yields {i32}:result = 4 + %var</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002605</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002606
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002607</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002608
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002609<!-- _______________________________________________________________________ -->
Chris Lattner6704c212008-05-20 20:48:21 +00002610<div class="doc_subsubsection">
Dan Gohman7ce405e2009-06-04 22:49:04 +00002611 <a name="i_fadd">'<tt>fadd</tt>' Instruction</a>
2612</div>
2613
2614<div class="doc_text">
2615
2616<h5>Syntax:</h5>
Dan Gohman7ce405e2009-06-04 22:49:04 +00002617<pre>
2618 &lt;result&gt; = fadd &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
2619</pre>
2620
2621<h5>Overview:</h5>
Dan Gohman7ce405e2009-06-04 22:49:04 +00002622<p>The '<tt>fadd</tt>' instruction returns the sum of its two operands.</p>
2623
2624<h5>Arguments:</h5>
Dan Gohman7ce405e2009-06-04 22:49:04 +00002625<p>The two arguments to the '<tt>fadd</tt>' instruction must be
Bill Wendlingf85859d2009-07-20 02:29:24 +00002626 <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> of
2627 floating point values. Both arguments must have identical types.</p>
Dan Gohman7ce405e2009-06-04 22:49:04 +00002628
2629<h5>Semantics:</h5>
Dan Gohman7ce405e2009-06-04 22:49:04 +00002630<p>The value produced is the floating point sum of the two operands.</p>
2631
2632<h5>Example:</h5>
Dan Gohman7ce405e2009-06-04 22:49:04 +00002633<pre>
2634 &lt;result&gt; = fadd float 4.0, %var <i>; yields {float}:result = 4.0 + %var</i>
2635</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002636
Dan Gohman7ce405e2009-06-04 22:49:04 +00002637</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002638
Dan Gohman7ce405e2009-06-04 22:49:04 +00002639<!-- _______________________________________________________________________ -->
2640<div class="doc_subsubsection">
Chris Lattner6704c212008-05-20 20:48:21 +00002641 <a name="i_sub">'<tt>sub</tt>' Instruction</a>
2642</div>
2643
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002644<div class="doc_text">
Chris Lattner6704c212008-05-20 20:48:21 +00002645
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002646<h5>Syntax:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002647<pre>
Gabor Greifd9068fe2008-08-07 21:46:00 +00002648 &lt;result&gt; = sub &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002649</pre>
Chris Lattner6704c212008-05-20 20:48:21 +00002650
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002651<h5>Overview:</h5>
2652<p>The '<tt>sub</tt>' instruction returns the difference of its two
Bill Wendlingf85859d2009-07-20 02:29:24 +00002653 operands.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002654
2655<p>Note that the '<tt>sub</tt>' instruction is used to represent the
Bill Wendlingf85859d2009-07-20 02:29:24 +00002656 '<tt>neg</tt>' instruction present in most other intermediate
2657 representations.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002658
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002659<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002660<p>The two arguments to the '<tt>sub</tt>' instruction must
2661 be <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of
2662 integer values. Both arguments must have identical types.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002663
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002664<h5>Semantics:</h5>
Dan Gohman7ce405e2009-06-04 22:49:04 +00002665<p>The value produced is the integer difference of the two operands.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002666
Dan Gohman7ce405e2009-06-04 22:49:04 +00002667<p>If the difference has unsigned overflow, the result returned is the
Bill Wendlingf85859d2009-07-20 02:29:24 +00002668 mathematical result modulo 2<sup>n</sup>, where n is the bit width of the
2669 result.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002670
Bill Wendlingf85859d2009-07-20 02:29:24 +00002671<p>Because LLVM integers use a two's complement representation, this instruction
2672 is appropriate for both signed and unsigned integers.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002673
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002674<h5>Example:</h5>
2675<pre>
2676 &lt;result&gt; = sub i32 4, %var <i>; yields {i32}:result = 4 - %var</i>
2677 &lt;result&gt; = sub i32 0, %val <i>; yields {i32}:result = -%var</i>
2678</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002679
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002680</div>
Chris Lattner6704c212008-05-20 20:48:21 +00002681
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002682<!-- _______________________________________________________________________ -->
Chris Lattner6704c212008-05-20 20:48:21 +00002683<div class="doc_subsubsection">
Dan Gohman7ce405e2009-06-04 22:49:04 +00002684 <a name="i_fsub">'<tt>fsub</tt>' Instruction</a>
2685</div>
2686
2687<div class="doc_text">
2688
2689<h5>Syntax:</h5>
Dan Gohman7ce405e2009-06-04 22:49:04 +00002690<pre>
2691 &lt;result&gt; = fsub &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
2692</pre>
2693
2694<h5>Overview:</h5>
Dan Gohman7ce405e2009-06-04 22:49:04 +00002695<p>The '<tt>fsub</tt>' instruction returns the difference of its two
Bill Wendlingf85859d2009-07-20 02:29:24 +00002696 operands.</p>
Dan Gohman7ce405e2009-06-04 22:49:04 +00002697
2698<p>Note that the '<tt>fsub</tt>' instruction is used to represent the
Bill Wendlingf85859d2009-07-20 02:29:24 +00002699 '<tt>fneg</tt>' instruction present in most other intermediate
2700 representations.</p>
Dan Gohman7ce405e2009-06-04 22:49:04 +00002701
2702<h5>Arguments:</h5>
Dan Gohman7ce405e2009-06-04 22:49:04 +00002703<p>The two arguments to the '<tt>fsub</tt>' instruction must be <a
Bill Wendlingf85859d2009-07-20 02:29:24 +00002704 <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> of
2705 floating point values. Both arguments must have identical types.</p>
Dan Gohman7ce405e2009-06-04 22:49:04 +00002706
2707<h5>Semantics:</h5>
Dan Gohman7ce405e2009-06-04 22:49:04 +00002708<p>The value produced is the floating point difference of the two operands.</p>
2709
2710<h5>Example:</h5>
2711<pre>
2712 &lt;result&gt; = fsub float 4.0, %var <i>; yields {float}:result = 4.0 - %var</i>
2713 &lt;result&gt; = fsub float -0.0, %val <i>; yields {float}:result = -%var</i>
2714</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002715
Dan Gohman7ce405e2009-06-04 22:49:04 +00002716</div>
2717
2718<!-- _______________________________________________________________________ -->
2719<div class="doc_subsubsection">
Chris Lattner6704c212008-05-20 20:48:21 +00002720 <a name="i_mul">'<tt>mul</tt>' Instruction</a>
2721</div>
2722
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002723<div class="doc_text">
Chris Lattner6704c212008-05-20 20:48:21 +00002724
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002725<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002726<pre>
2727 &lt;result&gt; = mul &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002728</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002729
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002730<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002731<p>The '<tt>mul</tt>' instruction returns the product of its two operands.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002732
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002733<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002734<p>The two arguments to the '<tt>mul</tt>' instruction must
2735 be <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of
2736 integer values. Both arguments must have identical types.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002737
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002738<h5>Semantics:</h5>
Dan Gohman7ce405e2009-06-04 22:49:04 +00002739<p>The value produced is the integer product of the two operands.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002740
Bill Wendlingf85859d2009-07-20 02:29:24 +00002741<p>If the result of the multiplication has unsigned overflow, the result
2742 returned is the mathematical result modulo 2<sup>n</sup>, where n is the bit
2743 width of the result.</p>
2744
2745<p>Because LLVM integers use a two's complement representation, and the result
2746 is the same width as the operands, this instruction returns the correct
2747 result for both signed and unsigned integers. If a full product
2748 (e.g. <tt>i32</tt>x<tt>i32</tt>-><tt>i64</tt>) is needed, the operands should
2749 be sign-extended or zero-extended as appropriate to the width of the full
2750 product.</p>
2751
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002752<h5>Example:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002753<pre>
2754 &lt;result&gt; = mul i32 4, %var <i>; yields {i32}:result = 4 * %var</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002755</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002756
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002757</div>
Chris Lattner6704c212008-05-20 20:48:21 +00002758
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002759<!-- _______________________________________________________________________ -->
Dan Gohman7ce405e2009-06-04 22:49:04 +00002760<div class="doc_subsubsection">
2761 <a name="i_fmul">'<tt>fmul</tt>' Instruction</a>
2762</div>
2763
2764<div class="doc_text">
2765
2766<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002767<pre>
2768 &lt;result&gt; = fmul &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Dan Gohman7ce405e2009-06-04 22:49:04 +00002769</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002770
Dan Gohman7ce405e2009-06-04 22:49:04 +00002771<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002772<p>The '<tt>fmul</tt>' instruction returns the product of its two operands.</p>
Dan Gohman7ce405e2009-06-04 22:49:04 +00002773
2774<h5>Arguments:</h5>
Dan Gohman7ce405e2009-06-04 22:49:04 +00002775<p>The two arguments to the '<tt>fmul</tt>' instruction must be
Bill Wendlingf85859d2009-07-20 02:29:24 +00002776 <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> of
2777 floating point values. Both arguments must have identical types.</p>
Dan Gohman7ce405e2009-06-04 22:49:04 +00002778
2779<h5>Semantics:</h5>
Dan Gohman7ce405e2009-06-04 22:49:04 +00002780<p>The value produced is the floating point product of the two operands.</p>
2781
2782<h5>Example:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002783<pre>
2784 &lt;result&gt; = fmul float 4.0, %var <i>; yields {float}:result = 4.0 * %var</i>
Dan Gohman7ce405e2009-06-04 22:49:04 +00002785</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002786
Dan Gohman7ce405e2009-06-04 22:49:04 +00002787</div>
2788
2789<!-- _______________________________________________________________________ -->
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002790<div class="doc_subsubsection"> <a name="i_udiv">'<tt>udiv</tt>' Instruction
2791</a></div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002792
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002793<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00002794
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002795<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002796<pre>
2797 &lt;result&gt; = udiv &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002798</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002799
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002800<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002801<p>The '<tt>udiv</tt>' instruction returns the quotient of its two operands.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002802
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002803<h5>Arguments:</h5>
2804<p>The two arguments to the '<tt>udiv</tt>' instruction must be
Bill Wendlingf85859d2009-07-20 02:29:24 +00002805 <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
2806 values. Both arguments must have identical types.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002807
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002808<h5>Semantics:</h5>
Chris Lattner9aba1e22008-01-28 00:36:27 +00002809<p>The value produced is the unsigned integer quotient of the two operands.</p>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002810
Chris Lattner9aba1e22008-01-28 00:36:27 +00002811<p>Note that unsigned integer division and signed integer division are distinct
Bill Wendlingf85859d2009-07-20 02:29:24 +00002812 operations; for signed integer division, use '<tt>sdiv</tt>'.</p>
2813
Chris Lattner9aba1e22008-01-28 00:36:27 +00002814<p>Division by zero leads to undefined behavior.</p>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002815
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002816<h5>Example:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002817<pre>
2818 &lt;result&gt; = udiv i32 4, %var <i>; yields {i32}:result = 4 / %var</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002819</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002820
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002821</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002822
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002823<!-- _______________________________________________________________________ -->
2824<div class="doc_subsubsection"> <a name="i_sdiv">'<tt>sdiv</tt>' Instruction
2825</a> </div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002826
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002827<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00002828
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002829<h5>Syntax:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002830<pre>
Gabor Greifd9068fe2008-08-07 21:46:00 +00002831 &lt;result&gt; = sdiv &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002832</pre>
Chris Lattner6704c212008-05-20 20:48:21 +00002833
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002834<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002835<p>The '<tt>sdiv</tt>' instruction returns the quotient of its two operands.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002836
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002837<h5>Arguments:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002838<p>The two arguments to the '<tt>sdiv</tt>' instruction must be
Bill Wendlingf85859d2009-07-20 02:29:24 +00002839 <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
2840 values. Both arguments must have identical types.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002841
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002842<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002843<p>The value produced is the signed integer quotient of the two operands rounded
2844 towards zero.</p>
2845
Chris Lattner9aba1e22008-01-28 00:36:27 +00002846<p>Note that signed integer division and unsigned integer division are distinct
Bill Wendlingf85859d2009-07-20 02:29:24 +00002847 operations; for unsigned integer division, use '<tt>udiv</tt>'.</p>
2848
Chris Lattner9aba1e22008-01-28 00:36:27 +00002849<p>Division by zero leads to undefined behavior. Overflow also leads to
Bill Wendlingf85859d2009-07-20 02:29:24 +00002850 undefined behavior; this is a rare case, but can occur, for example, by doing
2851 a 32-bit division of -2147483648 by -1.</p>
2852
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002853<h5>Example:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002854<pre>
2855 &lt;result&gt; = sdiv i32 4, %var <i>; yields {i32}:result = 4 / %var</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002856</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002857
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002858</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002859
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002860<!-- _______________________________________________________________________ -->
2861<div class="doc_subsubsection"> <a name="i_fdiv">'<tt>fdiv</tt>'
2862Instruction</a> </div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002863
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002864<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00002865
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002866<h5>Syntax:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002867<pre>
Gabor Greifd9068fe2008-08-07 21:46:00 +00002868 &lt;result&gt; = fdiv &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002869</pre>
Chris Lattner6704c212008-05-20 20:48:21 +00002870
Bill Wendlingf85859d2009-07-20 02:29:24 +00002871<h5>Overview:</h5>
2872<p>The '<tt>fdiv</tt>' instruction returns the quotient of its two operands.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002873
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002874<h5>Arguments:</h5>
2875<p>The two arguments to the '<tt>fdiv</tt>' instruction must be
Bill Wendlingf85859d2009-07-20 02:29:24 +00002876 <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> of
2877 floating point values. Both arguments must have identical types.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002878
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002879<h5>Semantics:</h5>
2880<p>The value produced is the floating point quotient of the two operands.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002881
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002882<h5>Example:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002883<pre>
2884 &lt;result&gt; = fdiv float 4.0, %var <i>; yields {float}:result = 4.0 / %var</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002885</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002886
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002887</div>
Chris Lattner6704c212008-05-20 20:48:21 +00002888
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002889<!-- _______________________________________________________________________ -->
2890<div class="doc_subsubsection"> <a name="i_urem">'<tt>urem</tt>' Instruction</a>
2891</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002892
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002893<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00002894
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002895<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002896<pre>
2897 &lt;result&gt; = urem &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002898</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002899
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002900<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002901<p>The '<tt>urem</tt>' instruction returns the remainder from the unsigned
2902 division of its two arguments.</p>
2903
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002904<h5>Arguments:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002905<p>The two arguments to the '<tt>urem</tt>' instruction must be
Bill Wendlingf85859d2009-07-20 02:29:24 +00002906 <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
2907 values. Both arguments must have identical types.</p>
2908
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002909<h5>Semantics:</h5>
2910<p>This instruction returns the unsigned integer <i>remainder</i> of a division.
Bill Wendlingf85859d2009-07-20 02:29:24 +00002911 This instruction always performs an unsigned division to get the
2912 remainder.</p>
2913
Chris Lattner9aba1e22008-01-28 00:36:27 +00002914<p>Note that unsigned integer remainder and signed integer remainder are
Bill Wendlingf85859d2009-07-20 02:29:24 +00002915 distinct operations; for signed integer remainder, use '<tt>srem</tt>'.</p>
2916
Chris Lattner9aba1e22008-01-28 00:36:27 +00002917<p>Taking the remainder of a division by zero leads to undefined behavior.</p>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002918
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002919<h5>Example:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002920<pre>
2921 &lt;result&gt; = urem i32 4, %var <i>; yields {i32}:result = 4 % %var</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002922</pre>
2923
2924</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002925
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002926<!-- _______________________________________________________________________ -->
Chris Lattner6704c212008-05-20 20:48:21 +00002927<div class="doc_subsubsection">
2928 <a name="i_srem">'<tt>srem</tt>' Instruction</a>
2929</div>
2930
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002931<div class="doc_text">
Chris Lattner6704c212008-05-20 20:48:21 +00002932
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002933<h5>Syntax:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002934<pre>
Gabor Greifd9068fe2008-08-07 21:46:00 +00002935 &lt;result&gt; = srem &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002936</pre>
Chris Lattner6704c212008-05-20 20:48:21 +00002937
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002938<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002939<p>The '<tt>srem</tt>' instruction returns the remainder from the signed
2940 division of its two operands. This instruction can also take
2941 <a href="#t_vector">vector</a> versions of the values in which case the
2942 elements must be integers.</p>
Chris Lattner08497ce2008-01-04 04:33:49 +00002943
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002944<h5>Arguments:</h5>
2945<p>The two arguments to the '<tt>srem</tt>' instruction must be
Bill Wendlingf85859d2009-07-20 02:29:24 +00002946 <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
2947 values. Both arguments must have identical types.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002948
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002949<h5>Semantics:</h5>
2950<p>This instruction returns the <i>remainder</i> of a division (where the result
Bill Wendlingf85859d2009-07-20 02:29:24 +00002951 has the same sign as the dividend, <tt>op1</tt>), not the <i>modulo</i>
2952 operator (where the result has the same sign as the divisor, <tt>op2</tt>) of
2953 a value. For more information about the difference,
2954 see <a href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
2955 Math Forum</a>. For a table of how this is implemented in various languages,
2956 please see <a href="http://en.wikipedia.org/wiki/Modulo_operation">
2957 Wikipedia: modulo operation</a>.</p>
2958
Chris Lattner9aba1e22008-01-28 00:36:27 +00002959<p>Note that signed integer remainder and unsigned integer remainder are
Bill Wendlingf85859d2009-07-20 02:29:24 +00002960 distinct operations; for unsigned integer remainder, use '<tt>urem</tt>'.</p>
2961
Chris Lattner9aba1e22008-01-28 00:36:27 +00002962<p>Taking the remainder of a division by zero leads to undefined behavior.
Bill Wendlingf85859d2009-07-20 02:29:24 +00002963 Overflow also leads to undefined behavior; this is a rare case, but can
2964 occur, for example, by taking the remainder of a 32-bit division of
2965 -2147483648 by -1. (The remainder doesn't actually overflow, but this rule
2966 lets srem be implemented using instructions that return both the result of
2967 the division and the remainder.)</p>
2968
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002969<h5>Example:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002970<pre>
2971 &lt;result&gt; = srem i32 4, %var <i>; yields {i32}:result = 4 % %var</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002972</pre>
2973
2974</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002975
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002976<!-- _______________________________________________________________________ -->
Chris Lattner6704c212008-05-20 20:48:21 +00002977<div class="doc_subsubsection">
2978 <a name="i_frem">'<tt>frem</tt>' Instruction</a> </div>
2979
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002980<div class="doc_text">
Chris Lattner6704c212008-05-20 20:48:21 +00002981
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002982<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002983<pre>
2984 &lt;result&gt; = frem &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002985</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002986
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002987<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002988<p>The '<tt>frem</tt>' instruction returns the remainder from the division of
2989 its two operands.</p>
2990
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002991<h5>Arguments:</h5>
2992<p>The two arguments to the '<tt>frem</tt>' instruction must be
Bill Wendlingf85859d2009-07-20 02:29:24 +00002993 <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> of
2994 floating point values. Both arguments must have identical types.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002995
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002996<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00002997<p>This instruction returns the <i>remainder</i> of a division. The remainder
2998 has the same sign as the dividend.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002999
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003000<h5>Example:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00003001<pre>
3002 &lt;result&gt; = frem float 4.0, %var <i>; yields {float}:result = 4.0 % %var</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003003</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003004
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003005</div>
3006
3007<!-- ======================================================================= -->
3008<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
3009Operations</a> </div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003010
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003011<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00003012
3013<p>Bitwise binary operators are used to do various forms of bit-twiddling in a
3014 program. They are generally very efficient instructions and can commonly be
3015 strength reduced from other instructions. They require two operands of the
3016 same type, execute an operation on them, and produce a single value. The
3017 resulting value is the same type as its operands.</p>
3018
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003019</div>
3020
3021<!-- _______________________________________________________________________ -->
3022<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
3023Instruction</a> </div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003024
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003025<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00003026
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003027<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003028<pre>
3029 &lt;result&gt; = shl &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003030</pre>
Chris Lattnerd939d9f2007-10-03 21:01:14 +00003031
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003032<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003033<p>The '<tt>shl</tt>' instruction returns the first operand shifted to the left
3034 a specified number of bits.</p>
Chris Lattnerd939d9f2007-10-03 21:01:14 +00003035
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003036<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003037<p>Both arguments to the '<tt>shl</tt>' instruction must be the
3038 same <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of
3039 integer type. '<tt>op2</tt>' is treated as an unsigned value.</p>
Chris Lattnerd939d9f2007-10-03 21:01:14 +00003040
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003041<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003042<p>The value produced is <tt>op1</tt> * 2<sup><tt>op2</tt></sup> mod
3043 2<sup>n</sup>, where <tt>n</tt> is the width of the result. If <tt>op2</tt>
3044 is (statically or dynamically) negative or equal to or larger than the number
3045 of bits in <tt>op1</tt>, the result is undefined. If the arguments are
3046 vectors, each vector element of <tt>op1</tt> is shifted by the corresponding
3047 shift amount in <tt>op2</tt>.</p>
Chris Lattnerd939d9f2007-10-03 21:01:14 +00003048
Bill Wendlingf85859d2009-07-20 02:29:24 +00003049<h5>Example:</h5>
3050<pre>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003051 &lt;result&gt; = shl i32 4, %var <i>; yields {i32}: 4 &lt;&lt; %var</i>
3052 &lt;result&gt; = shl i32 4, 2 <i>; yields {i32}: 16</i>
3053 &lt;result&gt; = shl i32 1, 10 <i>; yields {i32}: 1024</i>
Chris Lattnerd939d9f2007-10-03 21:01:14 +00003054 &lt;result&gt; = shl i32 1, 32 <i>; undefined</i>
Mon P Wang9901e732008-12-09 05:46:39 +00003055 &lt;result&gt; = shl &lt;2 x i32&gt; &lt; i32 1, i32 1&gt;, &lt; i32 1, i32 2&gt; <i>; yields: result=&lt;2 x i32&gt; &lt; i32 2, i32 4&gt;</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003056</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003057
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003058</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003059
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003060<!-- _______________________________________________________________________ -->
3061<div class="doc_subsubsection"> <a name="i_lshr">'<tt>lshr</tt>'
3062Instruction</a> </div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003063
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003064<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00003065
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003066<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003067<pre>
3068 &lt;result&gt; = lshr &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003069</pre>
3070
3071<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003072<p>The '<tt>lshr</tt>' instruction (logical shift right) returns the first
3073 operand shifted to the right a specified number of bits with zero fill.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003074
3075<h5>Arguments:</h5>
3076<p>Both arguments to the '<tt>lshr</tt>' instruction must be the same
Bill Wendlingf85859d2009-07-20 02:29:24 +00003077 <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
3078 type. '<tt>op2</tt>' is treated as an unsigned value.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003079
3080<h5>Semantics:</h5>
3081<p>This instruction always performs a logical shift right operation. The most
Bill Wendlingf85859d2009-07-20 02:29:24 +00003082 significant bits of the result will be filled with zero bits after the shift.
3083 If <tt>op2</tt> is (statically or dynamically) equal to or larger than the
3084 number of bits in <tt>op1</tt>, the result is undefined. If the arguments are
3085 vectors, each vector element of <tt>op1</tt> is shifted by the corresponding
3086 shift amount in <tt>op2</tt>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003087
3088<h5>Example:</h5>
3089<pre>
3090 &lt;result&gt; = lshr i32 4, 1 <i>; yields {i32}:result = 2</i>
3091 &lt;result&gt; = lshr i32 4, 2 <i>; yields {i32}:result = 1</i>
3092 &lt;result&gt; = lshr i8 4, 3 <i>; yields {i8}:result = 0</i>
3093 &lt;result&gt; = lshr i8 -2, 1 <i>; yields {i8}:result = 0x7FFFFFFF </i>
Chris Lattnerd939d9f2007-10-03 21:01:14 +00003094 &lt;result&gt; = lshr i32 1, 32 <i>; undefined</i>
Mon P Wang9901e732008-12-09 05:46:39 +00003095 &lt;result&gt; = lshr &lt;2 x i32&gt; &lt; i32 -2, i32 4&gt;, &lt; i32 1, i32 2&gt; <i>; yields: result=&lt;2 x i32&gt; &lt; i32 0x7FFFFFFF, i32 1&gt;</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003096</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003097
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003098</div>
3099
3100<!-- _______________________________________________________________________ -->
3101<div class="doc_subsubsection"> <a name="i_ashr">'<tt>ashr</tt>'
3102Instruction</a> </div>
3103<div class="doc_text">
3104
3105<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003106<pre>
3107 &lt;result&gt; = ashr &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003108</pre>
3109
3110<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003111<p>The '<tt>ashr</tt>' instruction (arithmetic shift right) returns the first
3112 operand shifted to the right a specified number of bits with sign
3113 extension.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003114
3115<h5>Arguments:</h5>
3116<p>Both arguments to the '<tt>ashr</tt>' instruction must be the same
Bill Wendlingf85859d2009-07-20 02:29:24 +00003117 <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
3118 type. '<tt>op2</tt>' is treated as an unsigned value.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003119
3120<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003121<p>This instruction always performs an arithmetic shift right operation, The
3122 most significant bits of the result will be filled with the sign bit
3123 of <tt>op1</tt>. If <tt>op2</tt> is (statically or dynamically) equal to or
3124 larger than the number of bits in <tt>op1</tt>, the result is undefined. If
3125 the arguments are vectors, each vector element of <tt>op1</tt> is shifted by
3126 the corresponding shift amount in <tt>op2</tt>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003127
3128<h5>Example:</h5>
3129<pre>
3130 &lt;result&gt; = ashr i32 4, 1 <i>; yields {i32}:result = 2</i>
3131 &lt;result&gt; = ashr i32 4, 2 <i>; yields {i32}:result = 1</i>
3132 &lt;result&gt; = ashr i8 4, 3 <i>; yields {i8}:result = 0</i>
3133 &lt;result&gt; = ashr i8 -2, 1 <i>; yields {i8}:result = -1</i>
Chris Lattnerd939d9f2007-10-03 21:01:14 +00003134 &lt;result&gt; = ashr i32 1, 32 <i>; undefined</i>
Mon P Wang9901e732008-12-09 05:46:39 +00003135 &lt;result&gt; = ashr &lt;2 x i32&gt; &lt; i32 -2, i32 4&gt;, &lt; i32 1, i32 3&gt; <i>; yields: result=&lt;2 x i32&gt; &lt; i32 -1, i32 0&gt;</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003136</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003137
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003138</div>
3139
3140<!-- _______________________________________________________________________ -->
3141<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
3142Instruction</a> </div>
Chris Lattner6704c212008-05-20 20:48:21 +00003143
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003144<div class="doc_text">
Chris Lattner6704c212008-05-20 20:48:21 +00003145
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003146<h5>Syntax:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00003147<pre>
Gabor Greifd9068fe2008-08-07 21:46:00 +00003148 &lt;result&gt; = and &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003149</pre>
Chris Lattner6704c212008-05-20 20:48:21 +00003150
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003151<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003152<p>The '<tt>and</tt>' instruction returns the bitwise logical and of its two
3153 operands.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00003154
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003155<h5>Arguments:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00003156<p>The two arguments to the '<tt>and</tt>' instruction must be
Bill Wendlingf85859d2009-07-20 02:29:24 +00003157 <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
3158 values. Both arguments must have identical types.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00003159
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003160<h5>Semantics:</h5>
3161<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003162
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003163<table border="1" cellspacing="0" cellpadding="4">
3164 <tbody>
3165 <tr>
3166 <td>In0</td>
3167 <td>In1</td>
3168 <td>Out</td>
3169 </tr>
3170 <tr>
3171 <td>0</td>
3172 <td>0</td>
3173 <td>0</td>
3174 </tr>
3175 <tr>
3176 <td>0</td>
3177 <td>1</td>
3178 <td>0</td>
3179 </tr>
3180 <tr>
3181 <td>1</td>
3182 <td>0</td>
3183 <td>0</td>
3184 </tr>
3185 <tr>
3186 <td>1</td>
3187 <td>1</td>
3188 <td>1</td>
3189 </tr>
3190 </tbody>
3191</table>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003192
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003193<h5>Example:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00003194<pre>
3195 &lt;result&gt; = and i32 4, %var <i>; yields {i32}:result = 4 &amp; %var</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003196 &lt;result&gt; = and i32 15, 40 <i>; yields {i32}:result = 8</i>
3197 &lt;result&gt; = and i32 4, 8 <i>; yields {i32}:result = 0</i>
3198</pre>
3199</div>
3200<!-- _______________________________________________________________________ -->
3201<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Chris Lattner6704c212008-05-20 20:48:21 +00003202
Bill Wendlingf85859d2009-07-20 02:29:24 +00003203<div class="doc_text">
3204
3205<h5>Syntax:</h5>
3206<pre>
3207 &lt;result&gt; = or &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
3208</pre>
3209
3210<h5>Overview:</h5>
3211<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive or of its
3212 two operands.</p>
3213
3214<h5>Arguments:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00003215<p>The two arguments to the '<tt>or</tt>' instruction must be
Bill Wendlingf85859d2009-07-20 02:29:24 +00003216 <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
3217 values. Both arguments must have identical types.</p>
3218
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003219<h5>Semantics:</h5>
3220<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003221
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003222<table border="1" cellspacing="0" cellpadding="4">
3223 <tbody>
3224 <tr>
3225 <td>In0</td>
3226 <td>In1</td>
3227 <td>Out</td>
3228 </tr>
3229 <tr>
3230 <td>0</td>
3231 <td>0</td>
3232 <td>0</td>
3233 </tr>
3234 <tr>
3235 <td>0</td>
3236 <td>1</td>
3237 <td>1</td>
3238 </tr>
3239 <tr>
3240 <td>1</td>
3241 <td>0</td>
3242 <td>1</td>
3243 </tr>
3244 <tr>
3245 <td>1</td>
3246 <td>1</td>
3247 <td>1</td>
3248 </tr>
3249 </tbody>
3250</table>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003251
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003252<h5>Example:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003253<pre>
3254 &lt;result&gt; = or i32 4, %var <i>; yields {i32}:result = 4 | %var</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003255 &lt;result&gt; = or i32 15, 40 <i>; yields {i32}:result = 47</i>
3256 &lt;result&gt; = or i32 4, 8 <i>; yields {i32}:result = 12</i>
3257</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003258
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003259</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003260
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003261<!-- _______________________________________________________________________ -->
3262<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
3263Instruction</a> </div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003264
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003265<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00003266
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003267<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003268<pre>
3269 &lt;result&gt; = xor &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003270</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003271
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003272<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003273<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive or of
3274 its two operands. The <tt>xor</tt> is used to implement the "one's
3275 complement" operation, which is the "~" operator in C.</p>
3276
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003277<h5>Arguments:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00003278<p>The two arguments to the '<tt>xor</tt>' instruction must be
Bill Wendlingf85859d2009-07-20 02:29:24 +00003279 <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
3280 values. Both arguments must have identical types.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00003281
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003282<h5>Semantics:</h5>
3283<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003284
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003285<table border="1" cellspacing="0" cellpadding="4">
3286 <tbody>
3287 <tr>
3288 <td>In0</td>
3289 <td>In1</td>
3290 <td>Out</td>
3291 </tr>
3292 <tr>
3293 <td>0</td>
3294 <td>0</td>
3295 <td>0</td>
3296 </tr>
3297 <tr>
3298 <td>0</td>
3299 <td>1</td>
3300 <td>1</td>
3301 </tr>
3302 <tr>
3303 <td>1</td>
3304 <td>0</td>
3305 <td>1</td>
3306 </tr>
3307 <tr>
3308 <td>1</td>
3309 <td>1</td>
3310 <td>0</td>
3311 </tr>
3312 </tbody>
3313</table>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003314
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003315<h5>Example:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003316<pre>
3317 &lt;result&gt; = xor i32 4, %var <i>; yields {i32}:result = 4 ^ %var</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003318 &lt;result&gt; = xor i32 15, 40 <i>; yields {i32}:result = 39</i>
3319 &lt;result&gt; = xor i32 4, 8 <i>; yields {i32}:result = 12</i>
3320 &lt;result&gt; = xor i32 %V, -1 <i>; yields {i32}:result = ~%V</i>
3321</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003322
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003323</div>
3324
3325<!-- ======================================================================= -->
3326<div class="doc_subsection">
3327 <a name="vectorops">Vector Operations</a>
3328</div>
3329
3330<div class="doc_text">
3331
3332<p>LLVM supports several instructions to represent vector operations in a
Bill Wendlingf85859d2009-07-20 02:29:24 +00003333 target-independent manner. These instructions cover the element-access and
3334 vector-specific operations needed to process vectors effectively. While LLVM
3335 does directly support these vector operations, many sophisticated algorithms
3336 will want to use target-specific intrinsics to take full advantage of a
3337 specific target.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003338
3339</div>
3340
3341<!-- _______________________________________________________________________ -->
3342<div class="doc_subsubsection">
3343 <a name="i_extractelement">'<tt>extractelement</tt>' Instruction</a>
3344</div>
3345
3346<div class="doc_text">
3347
3348<h5>Syntax:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003349<pre>
3350 &lt;result&gt; = extractelement &lt;n x &lt;ty&gt;&gt; &lt;val&gt;, i32 &lt;idx&gt; <i>; yields &lt;ty&gt;</i>
3351</pre>
3352
3353<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003354<p>The '<tt>extractelement</tt>' instruction extracts a single scalar element
3355 from a vector at a specified index.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003356
3357
3358<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003359<p>The first operand of an '<tt>extractelement</tt>' instruction is a value
3360 of <a href="#t_vector">vector</a> type. The second operand is an index
3361 indicating the position from which to extract the element. The index may be
3362 a variable.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003363
3364<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003365<p>The result is a scalar of the same type as the element type of
3366 <tt>val</tt>. Its value is the value at position <tt>idx</tt> of
3367 <tt>val</tt>. If <tt>idx</tt> exceeds the length of <tt>val</tt>, the
3368 results are undefined.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003369
3370<h5>Example:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003371<pre>
3372 %result = extractelement &lt;4 x i32&gt; %vec, i32 0 <i>; yields i32</i>
3373</pre>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003374
Bill Wendlingf85859d2009-07-20 02:29:24 +00003375</div>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003376
3377<!-- _______________________________________________________________________ -->
3378<div class="doc_subsubsection">
3379 <a name="i_insertelement">'<tt>insertelement</tt>' Instruction</a>
3380</div>
3381
3382<div class="doc_text">
3383
3384<h5>Syntax:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003385<pre>
Dan Gohmanbcc3c502008-05-12 23:38:42 +00003386 &lt;result&gt; = insertelement &lt;n x &lt;ty&gt;&gt; &lt;val&gt;, &lt;ty&gt; &lt;elt&gt;, i32 &lt;idx&gt; <i>; yields &lt;n x &lt;ty&gt;&gt;</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003387</pre>
3388
3389<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003390<p>The '<tt>insertelement</tt>' instruction inserts a scalar element into a
3391 vector at a specified index.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003392
3393<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003394<p>The first operand of an '<tt>insertelement</tt>' instruction is a value
3395 of <a href="#t_vector">vector</a> type. The second operand is a scalar value
3396 whose type must equal the element type of the first operand. The third
3397 operand is an index indicating the position at which to insert the value.
3398 The index may be a variable.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003399
3400<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003401<p>The result is a vector of the same type as <tt>val</tt>. Its element values
3402 are those of <tt>val</tt> except at position <tt>idx</tt>, where it gets the
3403 value <tt>elt</tt>. If <tt>idx</tt> exceeds the length of <tt>val</tt>, the
3404 results are undefined.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003405
3406<h5>Example:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003407<pre>
3408 %result = insertelement &lt;4 x i32&gt; %vec, i32 1, i32 0 <i>; yields &lt;4 x i32&gt;</i>
3409</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003410
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003411</div>
3412
3413<!-- _______________________________________________________________________ -->
3414<div class="doc_subsubsection">
3415 <a name="i_shufflevector">'<tt>shufflevector</tt>' Instruction</a>
3416</div>
3417
3418<div class="doc_text">
3419
3420<h5>Syntax:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003421<pre>
Mon P Wangbff5d9c2008-11-10 04:46:22 +00003422 &lt;result&gt; = shufflevector &lt;n x &lt;ty&gt;&gt; &lt;v1&gt;, &lt;n x &lt;ty&gt;&gt; &lt;v2&gt;, &lt;m x i32&gt; &lt;mask&gt; <i>; yields &lt;m x &lt;ty&gt;&gt;</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003423</pre>
3424
3425<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003426<p>The '<tt>shufflevector</tt>' instruction constructs a permutation of elements
3427 from two input vectors, returning a vector with the same element type as the
3428 input and length that is the same as the shuffle mask.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003429
3430<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003431<p>The first two operands of a '<tt>shufflevector</tt>' instruction are vectors
3432 with types that match each other. The third argument is a shuffle mask whose
3433 element type is always 'i32'. The result of the instruction is a vector
3434 whose length is the same as the shuffle mask and whose element type is the
3435 same as the element type of the first two operands.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003436
Bill Wendlingf85859d2009-07-20 02:29:24 +00003437<p>The shuffle mask operand is required to be a constant vector with either
3438 constant integer or undef values.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003439
3440<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003441<p>The elements of the two input vectors are numbered from left to right across
3442 both of the vectors. The shuffle mask operand specifies, for each element of
3443 the result vector, which element of the two input vectors the result element
3444 gets. The element selector may be undef (meaning "don't care") and the
3445 second operand may be undef if performing a shuffle from only one vector.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003446
3447<h5>Example:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003448<pre>
3449 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; %v2,
3450 &lt;4 x i32&gt; &lt;i32 0, i32 4, i32 1, i32 5&gt; <i>; yields &lt;4 x i32&gt;</i>
3451 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; undef,
3452 &lt;4 x i32&gt; &lt;i32 0, i32 1, i32 2, i32 3&gt; <i>; yields &lt;4 x i32&gt;</i> - Identity shuffle.
Mon P Wangbff5d9c2008-11-10 04:46:22 +00003453 %result = shufflevector &lt;8 x i32&gt; %v1, &lt;8 x i32&gt; undef,
3454 &lt;4 x i32&gt; &lt;i32 0, i32 1, i32 2, i32 3&gt; <i>; yields &lt;4 x i32&gt;</i>
3455 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; %v2,
3456 &lt;8 x i32&gt; &lt;i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 &gt; <i>; yields &lt;8 x i32&gt;</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003457</pre>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003458
Bill Wendlingf85859d2009-07-20 02:29:24 +00003459</div>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003460
3461<!-- ======================================================================= -->
3462<div class="doc_subsection">
Dan Gohman74d6faf2008-05-12 23:51:09 +00003463 <a name="aggregateops">Aggregate Operations</a>
3464</div>
3465
3466<div class="doc_text">
3467
Bill Wendlingf85859d2009-07-20 02:29:24 +00003468<p>LLVM supports several instructions for working with aggregate values.</p>
Dan Gohman74d6faf2008-05-12 23:51:09 +00003469
3470</div>
3471
3472<!-- _______________________________________________________________________ -->
3473<div class="doc_subsubsection">
3474 <a name="i_extractvalue">'<tt>extractvalue</tt>' Instruction</a>
3475</div>
3476
3477<div class="doc_text">
3478
3479<h5>Syntax:</h5>
Dan Gohman74d6faf2008-05-12 23:51:09 +00003480<pre>
3481 &lt;result&gt; = extractvalue &lt;aggregate type&gt; &lt;val&gt;, &lt;idx&gt;{, &lt;idx&gt;}*
3482</pre>
3483
3484<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003485<p>The '<tt>extractvalue</tt>' instruction extracts the value of a struct field
3486 or array element from an aggregate value.</p>
Dan Gohman74d6faf2008-05-12 23:51:09 +00003487
3488<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003489<p>The first operand of an '<tt>extractvalue</tt>' instruction is a value
3490 of <a href="#t_struct">struct</a> or <a href="#t_array">array</a> type. The
3491 operands are constant indices to specify which value to extract in a similar
3492 manner as indices in a
3493 '<tt><a href="#i_getelementptr">getelementptr</a></tt>' instruction.</p>
Dan Gohman74d6faf2008-05-12 23:51:09 +00003494
3495<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003496<p>The result is the value at the position in the aggregate specified by the
3497 index operands.</p>
Dan Gohman74d6faf2008-05-12 23:51:09 +00003498
3499<h5>Example:</h5>
Dan Gohman74d6faf2008-05-12 23:51:09 +00003500<pre>
Dan Gohmane5febe42008-05-31 00:58:22 +00003501 %result = extractvalue {i32, float} %agg, 0 <i>; yields i32</i>
Dan Gohman74d6faf2008-05-12 23:51:09 +00003502</pre>
Dan Gohman74d6faf2008-05-12 23:51:09 +00003503
Bill Wendlingf85859d2009-07-20 02:29:24 +00003504</div>
Dan Gohman74d6faf2008-05-12 23:51:09 +00003505
3506<!-- _______________________________________________________________________ -->
3507<div class="doc_subsubsection">
3508 <a name="i_insertvalue">'<tt>insertvalue</tt>' Instruction</a>
3509</div>
3510
3511<div class="doc_text">
3512
3513<h5>Syntax:</h5>
Dan Gohman74d6faf2008-05-12 23:51:09 +00003514<pre>
Dan Gohmane5febe42008-05-31 00:58:22 +00003515 &lt;result&gt; = insertvalue &lt;aggregate type&gt; &lt;val&gt;, &lt;ty&gt; &lt;val&gt;, &lt;idx&gt; <i>; yields &lt;n x &lt;ty&gt;&gt;</i>
Dan Gohman74d6faf2008-05-12 23:51:09 +00003516</pre>
3517
3518<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003519<p>The '<tt>insertvalue</tt>' instruction inserts a value into a struct field or
3520 array element in an aggregate.</p>
Dan Gohman74d6faf2008-05-12 23:51:09 +00003521
3522
3523<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003524<p>The first operand of an '<tt>insertvalue</tt>' instruction is a value
3525 of <a href="#t_struct">struct</a> or <a href="#t_array">array</a> type. The
3526 second operand is a first-class value to insert. The following operands are
3527 constant indices indicating the position at which to insert the value in a
3528 similar manner as indices in a
3529 '<tt><a href="#i_getelementptr">getelementptr</a></tt>' instruction. The
3530 value to insert must have the same type as the value identified by the
3531 indices.</p>
Dan Gohman74d6faf2008-05-12 23:51:09 +00003532
3533<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003534<p>The result is an aggregate of the same type as <tt>val</tt>. Its value is
3535 that of <tt>val</tt> except that the value at the position specified by the
3536 indices is that of <tt>elt</tt>.</p>
Dan Gohman74d6faf2008-05-12 23:51:09 +00003537
3538<h5>Example:</h5>
Dan Gohman74d6faf2008-05-12 23:51:09 +00003539<pre>
Dan Gohmanb1aab4e2008-06-23 15:26:37 +00003540 %result = insertvalue {i32, float} %agg, i32 1, 0 <i>; yields {i32, float}</i>
Dan Gohman74d6faf2008-05-12 23:51:09 +00003541</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003542
Dan Gohman74d6faf2008-05-12 23:51:09 +00003543</div>
3544
3545
3546<!-- ======================================================================= -->
3547<div class="doc_subsection">
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003548 <a name="memoryops">Memory Access and Addressing Operations</a>
3549</div>
3550
3551<div class="doc_text">
3552
Bill Wendlingf85859d2009-07-20 02:29:24 +00003553<p>A key design point of an SSA-based representation is how it represents
3554 memory. In LLVM, no memory locations are in SSA form, which makes things
3555 very simple. This section describes how to read, write, allocate, and free
3556 memory in LLVM.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003557
3558</div>
3559
3560<!-- _______________________________________________________________________ -->
3561<div class="doc_subsubsection">
3562 <a name="i_malloc">'<tt>malloc</tt>' Instruction</a>
3563</div>
3564
3565<div class="doc_text">
3566
3567<h5>Syntax:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003568<pre>
3569 &lt;result&gt; = malloc &lt;type&gt;[, i32 &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
3570</pre>
3571
3572<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003573<p>The '<tt>malloc</tt>' instruction allocates memory from the system heap and
3574 returns a pointer to it. The object is always allocated in the generic
3575 address space (address space zero).</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003576
3577<h5>Arguments:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003578<p>The '<tt>malloc</tt>' instruction allocates
Bill Wendlingf85859d2009-07-20 02:29:24 +00003579 <tt>sizeof(&lt;type&gt;)*NumElements</tt> bytes of memory from the operating
3580 system and returns a pointer of the appropriate type to the program. If
3581 "NumElements" is specified, it is the number of elements allocated, otherwise
3582 "NumElements" is defaulted to be one. If a constant alignment is specified,
3583 the value result of the allocation is guaranteed to be aligned to at least
3584 that boundary. If not specified, or if zero, the target can choose to align
3585 the allocation on any convenient boundary compatible with the type.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003586
3587<p>'<tt>type</tt>' must be a sized type.</p>
3588
3589<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003590<p>Memory is allocated using the system "<tt>malloc</tt>" function, and a
3591 pointer is returned. The result of a zero byte allocation is undefined. The
3592 result is null if there is insufficient memory available.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003593
3594<h5>Example:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003595<pre>
Dan Gohmanf54f50a2009-01-04 23:49:44 +00003596 %array = malloc [4 x i8] <i>; yields {[%4 x i8]*}:array</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003597
3598 %size = <a href="#i_add">add</a> i32 2, 2 <i>; yields {i32}:size = i32 4</i>
3599 %array1 = malloc i8, i32 4 <i>; yields {i8*}:array1</i>
3600 %array2 = malloc [12 x i8], i32 %size <i>; yields {[12 x i8]*}:array2</i>
3601 %array3 = malloc i32, i32 4, align 1024 <i>; yields {i32*}:array3</i>
3602 %array4 = malloc i32, align 1024 <i>; yields {i32*}:array4</i>
3603</pre>
Dan Gohman60967192009-01-12 23:12:39 +00003604
Bill Wendlingf85859d2009-07-20 02:29:24 +00003605<p>Note that the code generator does not yet respect the alignment value.</p>
Dan Gohman60967192009-01-12 23:12:39 +00003606
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003607</div>
3608
3609<!-- _______________________________________________________________________ -->
3610<div class="doc_subsubsection">
3611 <a name="i_free">'<tt>free</tt>' Instruction</a>
3612</div>
3613
3614<div class="doc_text">
3615
3616<h5>Syntax:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003617<pre>
Dan Gohmanf54f50a2009-01-04 23:49:44 +00003618 free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003619</pre>
3620
3621<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003622<p>The '<tt>free</tt>' instruction returns memory back to the unused memory heap
3623 to be reallocated in the future.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003624
3625<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003626<p>'<tt>value</tt>' shall be a pointer value that points to a value that was
3627 allocated with the '<tt><a href="#i_malloc">malloc</a></tt>' instruction.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003628
3629<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003630<p>Access to the memory pointed to by the pointer is no longer defined after
3631 this instruction executes. If the pointer is null, the operation is a
3632 noop.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003633
3634<h5>Example:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003635<pre>
Dan Gohmanf54f50a2009-01-04 23:49:44 +00003636 %array = <a href="#i_malloc">malloc</a> [4 x i8] <i>; yields {[4 x i8]*}:array</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003637 free [4 x i8]* %array
3638</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003639
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003640</div>
3641
3642<!-- _______________________________________________________________________ -->
3643<div class="doc_subsubsection">
3644 <a name="i_alloca">'<tt>alloca</tt>' Instruction</a>
3645</div>
3646
3647<div class="doc_text">
3648
3649<h5>Syntax:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003650<pre>
3651 &lt;result&gt; = alloca &lt;type&gt;[, i32 &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
3652</pre>
3653
3654<h5>Overview:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003655<p>The '<tt>alloca</tt>' instruction allocates memory on the stack frame of the
Bill Wendlingf85859d2009-07-20 02:29:24 +00003656 currently executing function, to be automatically released when this function
3657 returns to its caller. The object is always allocated in the generic address
3658 space (address space zero).</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003659
3660<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003661<p>The '<tt>alloca</tt>' instruction
3662 allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt> bytes of memory on the
3663 runtime stack, returning a pointer of the appropriate type to the program.
3664 If "NumElements" is specified, it is the number of elements allocated,
3665 otherwise "NumElements" is defaulted to be one. If a constant alignment is
3666 specified, the value result of the allocation is guaranteed to be aligned to
3667 at least that boundary. If not specified, or if zero, the target can choose
3668 to align the allocation on any convenient boundary compatible with the
3669 type.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003670
3671<p>'<tt>type</tt>' may be any sized type.</p>
3672
3673<h5>Semantics:</h5>
Bill Wendling2a454572009-05-08 20:49:29 +00003674<p>Memory is allocated; a pointer is returned. The operation is undefined if
Bill Wendlingf85859d2009-07-20 02:29:24 +00003675 there is insufficient stack space for the allocation. '<tt>alloca</tt>'d
3676 memory is automatically released when the function returns. The
3677 '<tt>alloca</tt>' instruction is commonly used to represent automatic
3678 variables that must have an address available. When the function returns
3679 (either with the <tt><a href="#i_ret">ret</a></tt>
3680 or <tt><a href="#i_unwind">unwind</a></tt> instructions), the memory is
3681 reclaimed. Allocating zero bytes is legal, but the result is undefined.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003682
3683<h5>Example:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003684<pre>
Dan Gohmanf54f50a2009-01-04 23:49:44 +00003685 %ptr = alloca i32 <i>; yields {i32*}:ptr</i>
3686 %ptr = alloca i32, i32 4 <i>; yields {i32*}:ptr</i>
3687 %ptr = alloca i32, i32 4, align 1024 <i>; yields {i32*}:ptr</i>
3688 %ptr = alloca i32, align 1024 <i>; yields {i32*}:ptr</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003689</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003690
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003691</div>
3692
3693<!-- _______________________________________________________________________ -->
3694<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
3695Instruction</a> </div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003696
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003697<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00003698
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003699<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003700<pre>
3701 &lt;result&gt; = load &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;]
3702 &lt;result&gt; = volatile load &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;]
3703</pre>
3704
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003705<h5>Overview:</h5>
3706<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003707
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003708<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003709<p>The argument to the '<tt>load</tt>' instruction specifies the memory address
3710 from which to load. The pointer must point to
3711 a <a href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
3712 marked as <tt>volatile</tt>, then the optimizer is not allowed to modify the
3713 number or order of execution of this <tt>load</tt> with other
3714 volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
3715 instructions. </p>
3716
3717<p>The optional constant "align" argument specifies the alignment of the
3718 operation (that is, the alignment of the memory address). A value of 0 or an
3719 omitted "align" argument means that the operation has the preferential
3720 alignment for the target. It is the responsibility of the code emitter to
3721 ensure that the alignment information is correct. Overestimating the
3722 alignment results in an undefined behavior. Underestimating the alignment may
3723 produce less efficient code. An alignment of 1 is always safe.</p>
3724
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003725<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003726<p>The location of memory pointed to is loaded. If the value being loaded is of
3727 scalar type then the number of bytes read does not exceed the minimum number
3728 of bytes needed to hold all bits of the type. For example, loading an
3729 <tt>i24</tt> reads at most three bytes. When loading a value of a type like
3730 <tt>i20</tt> with a size that is not an integral number of bytes, the result
3731 is undefined if the value was not originally written using a store of the
3732 same type.</p>
3733
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003734<h5>Examples:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003735<pre>
3736 %ptr = <a href="#i_alloca">alloca</a> i32 <i>; yields {i32*}:ptr</i>
3737 <a href="#i_store">store</a> i32 3, i32* %ptr <i>; yields {void}</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003738 %val = load i32* %ptr <i>; yields {i32}:val = i32 3</i>
3739</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003740
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003741</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003742
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003743<!-- _______________________________________________________________________ -->
3744<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
3745Instruction</a> </div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003746
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003747<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00003748
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003749<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003750<pre>
3751 store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;] <i>; yields {void}</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003752 volatile store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;] <i>; yields {void}</i>
3753</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003754
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003755<h5>Overview:</h5>
3756<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003757
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003758<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003759<p>There are two arguments to the '<tt>store</tt>' instruction: a value to store
3760 and an address at which to store it. The type of the
3761 '<tt>&lt;pointer&gt;</tt>' operand must be a pointer to
3762 the <a href="#t_firstclass">first class</a> type of the
3763 '<tt>&lt;value&gt;</tt>' operand. If the <tt>store</tt> is marked
3764 as <tt>volatile</tt>, then the optimizer is not allowed to modify the number
3765 or order of execution of this <tt>store</tt> with other
3766 volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
3767 instructions.</p>
3768
3769<p>The optional constant "align" argument specifies the alignment of the
3770 operation (that is, the alignment of the memory address). A value of 0 or an
3771 omitted "align" argument means that the operation has the preferential
3772 alignment for the target. It is the responsibility of the code emitter to
3773 ensure that the alignment information is correct. Overestimating the
3774 alignment results in an undefined behavior. Underestimating the alignment may
3775 produce less efficient code. An alignment of 1 is always safe.</p>
3776
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003777<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003778<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>' at the
3779 location specified by the '<tt>&lt;pointer&gt;</tt>' operand. If
3780 '<tt>&lt;value&gt;</tt>' is of scalar type then the number of bytes written
3781 does not exceed the minimum number of bytes needed to hold all bits of the
3782 type. For example, storing an <tt>i24</tt> writes at most three bytes. When
3783 writing a value of a type like <tt>i20</tt> with a size that is not an
3784 integral number of bytes, it is unspecified what happens to the extra bits
3785 that do not belong to the type, but they will typically be overwritten.</p>
3786
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003787<h5>Example:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003788<pre>
3789 %ptr = <a href="#i_alloca">alloca</a> i32 <i>; yields {i32*}:ptr</i>
Bill Wendling63ffa142007-10-22 05:10:05 +00003790 store i32 3, i32* %ptr <i>; yields {void}</i>
3791 %val = <a href="#i_load">load</a> i32* %ptr <i>; yields {i32}:val = i32 3</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003792</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003793
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003794</div>
3795
3796<!-- _______________________________________________________________________ -->
3797<div class="doc_subsubsection">
3798 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
3799</div>
3800
3801<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00003802
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003803<h5>Syntax:</h5>
3804<pre>
Matthijs Kooijman32a080e2008-10-13 13:44:15 +00003805 &lt;result&gt; = getelementptr &lt;pty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003806</pre>
3807
3808<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003809<p>The '<tt>getelementptr</tt>' instruction is used to get the address of a
3810 subelement of an aggregate data structure. It performs address calculation
3811 only and does not access memory.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003812
3813<h5>Arguments:</h5>
Matthijs Kooijman32a080e2008-10-13 13:44:15 +00003814<p>The first argument is always a pointer, and forms the basis of the
Bill Wendlingf85859d2009-07-20 02:29:24 +00003815 calculation. The remaining arguments are indices, that indicate which of the
3816 elements of the aggregate object are indexed. The interpretation of each
3817 index is dependent on the type being indexed into. The first index always
3818 indexes the pointer value given as the first argument, the second index
3819 indexes a value of the type pointed to (not necessarily the value directly
3820 pointed to, since the first index can be non-zero), etc. The first type
3821 indexed into must be a pointer value, subsequent types can be arrays, vectors
3822 and structs. Note that subsequent types being indexed into can never be
3823 pointers, since that would require loading the pointer before continuing
3824 calculation.</p>
Matthijs Kooijman32a080e2008-10-13 13:44:15 +00003825
3826<p>The type of each index argument depends on the type it is indexing into.
Bill Wendlingf85859d2009-07-20 02:29:24 +00003827 When indexing into a (packed) structure, only <tt>i32</tt> integer
3828 <b>constants</b> are allowed. When indexing into an array, pointer or
3829 vector, integers of any width are allowed (also non-constants).</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003830
Bill Wendlingf85859d2009-07-20 02:29:24 +00003831<p>For example, let's consider a C code fragment and how it gets compiled to
3832 LLVM:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003833
3834<div class="doc_code">
3835<pre>
3836struct RT {
3837 char A;
3838 int B[10][20];
3839 char C;
3840};
3841struct ST {
3842 int X;
3843 double Y;
3844 struct RT Z;
3845};
3846
3847int *foo(struct ST *s) {
3848 return &amp;s[1].Z.B[5][13];
3849}
3850</pre>
3851</div>
3852
3853<p>The LLVM code generated by the GCC frontend is:</p>
3854
3855<div class="doc_code">
3856<pre>
Chris Lattner5b6dc6e2009-01-11 20:53:49 +00003857%RT = <a href="#namedtypes">type</a> { i8 , [10 x [20 x i32]], i8 }
3858%ST = <a href="#namedtypes">type</a> { i32, double, %RT }
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003859
3860define i32* %foo(%ST* %s) {
3861entry:
3862 %reg = getelementptr %ST* %s, i32 1, i32 2, i32 1, i32 5, i32 13
3863 ret i32* %reg
3864}
3865</pre>
3866</div>
3867
3868<h5>Semantics:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003869<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Bill Wendlingf85859d2009-07-20 02:29:24 +00003870 type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ i32, double, %RT
3871 }</tt>' type, a structure. The second index indexes into the third element
3872 of the structure, yielding a '<tt>%RT</tt>' = '<tt>{ i8 , [10 x [20 x i32]],
3873 i8 }</tt>' type, another structure. The third index indexes into the second
3874 element of the structure, yielding a '<tt>[10 x [20 x i32]]</tt>' type, an
3875 array. The two dimensions of the array are subscripted into, yielding an
3876 '<tt>i32</tt>' type. The '<tt>getelementptr</tt>' instruction returns a
3877 pointer to this element, thus computing a value of '<tt>i32*</tt>' type.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003878
Bill Wendlingf85859d2009-07-20 02:29:24 +00003879<p>Note that it is perfectly legal to index partially through a structure,
3880 returning a pointer to an inner element. Because of this, the LLVM code for
3881 the given testcase is equivalent to:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003882
3883<pre>
3884 define i32* %foo(%ST* %s) {
3885 %t1 = getelementptr %ST* %s, i32 1 <i>; yields %ST*:%t1</i>
3886 %t2 = getelementptr %ST* %t1, i32 0, i32 2 <i>; yields %RT*:%t2</i>
3887 %t3 = getelementptr %RT* %t2, i32 0, i32 1 <i>; yields [10 x [20 x i32]]*:%t3</i>
3888 %t4 = getelementptr [10 x [20 x i32]]* %t3, i32 0, i32 5 <i>; yields [20 x i32]*:%t4</i>
3889 %t5 = getelementptr [20 x i32]* %t4, i32 0, i32 13 <i>; yields i32*:%t5</i>
3890 ret i32* %t5
3891 }
3892</pre>
3893
Bill Wendlingf85859d2009-07-20 02:29:24 +00003894<p>Note that it is undefined to access an array out of bounds: array and pointer
3895 indexes must always be within the defined bounds of the array type when
3896 accessed with an instruction that dereferences the pointer (e.g. a load or
3897 store instruction). The one exception for this rule is zero length arrays.
3898 These arrays are defined to be accessible as variable length arrays, which
3899 requires access beyond the zero'th element.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003900
Bill Wendlingf85859d2009-07-20 02:29:24 +00003901<p>The getelementptr instruction is often confusing. For some more insight into
3902 how it works, see <a href="GetElementPtr.html">the getelementptr FAQ</a>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003903
3904<h5>Example:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003905<pre>
3906 <i>; yields [12 x i8]*:aptr</i>
Matthijs Kooijman32a080e2008-10-13 13:44:15 +00003907 %aptr = getelementptr {i32, [12 x i8]}* %saptr, i64 0, i32 1
3908 <i>; yields i8*:vptr</i>
Dan Gohman2672f3e2008-10-14 16:51:45 +00003909 %vptr = getelementptr {i32, &lt;2 x i8&gt;}* %svptr, i64 0, i32 1, i32 1
Matthijs Kooijman32a080e2008-10-13 13:44:15 +00003910 <i>; yields i8*:eptr</i>
3911 %eptr = getelementptr [12 x i8]* %aptr, i64 0, i32 1
Sanjiv Gupta4f9a0dc2009-04-25 07:27:44 +00003912 <i>; yields i32*:iptr</i>
Sanjiv Gupta1e46c582009-04-24 16:38:13 +00003913 %iptr = getelementptr [10 x i32]* @arr, i16 0, i16 0
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003914</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003915
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003916</div>
3917
3918<!-- ======================================================================= -->
3919<div class="doc_subsection"> <a name="convertops">Conversion Operations</a>
3920</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003921
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003922<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00003923
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003924<p>The instructions in this category are the conversion instructions (casting)
Bill Wendlingf85859d2009-07-20 02:29:24 +00003925 which all take a single operand and a type. They perform various bit
3926 conversions on the operand.</p>
3927
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003928</div>
3929
3930<!-- _______________________________________________________________________ -->
3931<div class="doc_subsubsection">
3932 <a name="i_trunc">'<tt>trunc .. to</tt>' Instruction</a>
3933</div>
3934<div class="doc_text">
3935
3936<h5>Syntax:</h5>
3937<pre>
3938 &lt;result&gt; = trunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3939</pre>
3940
3941<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003942<p>The '<tt>trunc</tt>' instruction truncates its operand to the
3943 type <tt>ty2</tt>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003944
3945<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003946<p>The '<tt>trunc</tt>' instruction takes a <tt>value</tt> to trunc, which must
3947 be an <a href="#t_integer">integer</a> type, and a type that specifies the
3948 size and type of the result, which must be
3949 an <a href="#t_integer">integer</a> type. The bit size of <tt>value</tt> must
3950 be larger than the bit size of <tt>ty2</tt>. Equal sized types are not
3951 allowed.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003952
3953<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003954<p>The '<tt>trunc</tt>' instruction truncates the high order bits
3955 in <tt>value</tt> and converts the remaining bits to <tt>ty2</tt>. Since the
3956 source size must be larger than the destination size, <tt>trunc</tt> cannot
3957 be a <i>no-op cast</i>. It will always truncate bits.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003958
3959<h5>Example:</h5>
3960<pre>
3961 %X = trunc i32 257 to i8 <i>; yields i8:1</i>
3962 %Y = trunc i32 123 to i1 <i>; yields i1:true</i>
3963 %Y = trunc i32 122 to i1 <i>; yields i1:false</i>
3964</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00003965
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003966</div>
3967
3968<!-- _______________________________________________________________________ -->
3969<div class="doc_subsubsection">
3970 <a name="i_zext">'<tt>zext .. to</tt>' Instruction</a>
3971</div>
3972<div class="doc_text">
3973
3974<h5>Syntax:</h5>
3975<pre>
3976 &lt;result&gt; = zext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3977</pre>
3978
3979<h5>Overview:</h5>
3980<p>The '<tt>zext</tt>' instruction zero extends its operand to type
Bill Wendlingf85859d2009-07-20 02:29:24 +00003981 <tt>ty2</tt>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003982
3983
3984<h5>Arguments:</h5>
3985<p>The '<tt>zext</tt>' instruction takes a value to cast, which must be of
Bill Wendlingf85859d2009-07-20 02:29:24 +00003986 <a href="#t_integer">integer</a> type, and a type to cast it to, which must
3987 also be of <a href="#t_integer">integer</a> type. The bit size of the
3988 <tt>value</tt> must be smaller than the bit size of the destination type,
3989 <tt>ty2</tt>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003990
3991<h5>Semantics:</h5>
3992<p>The <tt>zext</tt> fills the high order bits of the <tt>value</tt> with zero
Bill Wendlingf85859d2009-07-20 02:29:24 +00003993 bits until it reaches the size of the destination type, <tt>ty2</tt>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003994
3995<p>When zero extending from i1, the result will always be either 0 or 1.</p>
3996
3997<h5>Example:</h5>
3998<pre>
3999 %X = zext i32 257 to i64 <i>; yields i64:257</i>
4000 %Y = zext i1 true to i32 <i>; yields i32:1</i>
4001</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004002
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004003</div>
4004
4005<!-- _______________________________________________________________________ -->
4006<div class="doc_subsubsection">
4007 <a name="i_sext">'<tt>sext .. to</tt>' Instruction</a>
4008</div>
4009<div class="doc_text">
4010
4011<h5>Syntax:</h5>
4012<pre>
4013 &lt;result&gt; = sext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4014</pre>
4015
4016<h5>Overview:</h5>
4017<p>The '<tt>sext</tt>' sign extends <tt>value</tt> to the type <tt>ty2</tt>.</p>
4018
4019<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004020<p>The '<tt>sext</tt>' instruction takes a value to cast, which must be of
4021 <a href="#t_integer">integer</a> type, and a type to cast it to, which must
4022 also be of <a href="#t_integer">integer</a> type. The bit size of the
4023 <tt>value</tt> must be smaller than the bit size of the destination type,
4024 <tt>ty2</tt>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004025
4026<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004027<p>The '<tt>sext</tt>' instruction performs a sign extension by copying the sign
4028 bit (highest order bit) of the <tt>value</tt> until it reaches the bit size
4029 of the type <tt>ty2</tt>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004030
4031<p>When sign extending from i1, the extension always results in -1 or 0.</p>
4032
4033<h5>Example:</h5>
4034<pre>
4035 %X = sext i8 -1 to i16 <i>; yields i16 :65535</i>
4036 %Y = sext i1 true to i32 <i>; yields i32:-1</i>
4037</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004038
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004039</div>
4040
4041<!-- _______________________________________________________________________ -->
4042<div class="doc_subsubsection">
4043 <a name="i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a>
4044</div>
4045
4046<div class="doc_text">
4047
4048<h5>Syntax:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004049<pre>
4050 &lt;result&gt; = fptrunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4051</pre>
4052
4053<h5>Overview:</h5>
4054<p>The '<tt>fptrunc</tt>' instruction truncates <tt>value</tt> to type
Bill Wendlingf85859d2009-07-20 02:29:24 +00004055 <tt>ty2</tt>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004056
4057<h5>Arguments:</h5>
4058<p>The '<tt>fptrunc</tt>' instruction takes a <a href="#t_floating">floating
Bill Wendlingf85859d2009-07-20 02:29:24 +00004059 point</a> value to cast and a <a href="#t_floating">floating point</a> type
4060 to cast it to. The size of <tt>value</tt> must be larger than the size of
4061 <tt>ty2</tt>. This implies that <tt>fptrunc</tt> cannot be used to make a
4062 <i>no-op cast</i>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004063
4064<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004065<p>The '<tt>fptrunc</tt>' instruction truncates a <tt>value</tt> from a larger
4066 <a href="#t_floating">floating point</a> type to a smaller
4067 <a href="#t_floating">floating point</a> type. If the value cannot fit
4068 within the destination type, <tt>ty2</tt>, then the results are
4069 undefined.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004070
4071<h5>Example:</h5>
4072<pre>
4073 %X = fptrunc double 123.0 to float <i>; yields float:123.0</i>
4074 %Y = fptrunc double 1.0E+300 to float <i>; yields undefined</i>
4075</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004076
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004077</div>
4078
4079<!-- _______________________________________________________________________ -->
4080<div class="doc_subsubsection">
4081 <a name="i_fpext">'<tt>fpext .. to</tt>' Instruction</a>
4082</div>
4083<div class="doc_text">
4084
4085<h5>Syntax:</h5>
4086<pre>
4087 &lt;result&gt; = fpext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4088</pre>
4089
4090<h5>Overview:</h5>
4091<p>The '<tt>fpext</tt>' extends a floating point <tt>value</tt> to a larger
Bill Wendlingf85859d2009-07-20 02:29:24 +00004092 floating point value.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004093
4094<h5>Arguments:</h5>
4095<p>The '<tt>fpext</tt>' instruction takes a
Bill Wendlingf85859d2009-07-20 02:29:24 +00004096 <a href="#t_floating">floating point</a> <tt>value</tt> to cast, and
4097 a <a href="#t_floating">floating point</a> type to cast it to. The source
4098 type must be smaller than the destination type.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004099
4100<h5>Semantics:</h5>
4101<p>The '<tt>fpext</tt>' instruction extends the <tt>value</tt> from a smaller
Bill Wendlingf85859d2009-07-20 02:29:24 +00004102 <a href="#t_floating">floating point</a> type to a larger
4103 <a href="#t_floating">floating point</a> type. The <tt>fpext</tt> cannot be
4104 used to make a <i>no-op cast</i> because it always changes bits. Use
4105 <tt>bitcast</tt> to make a <i>no-op cast</i> for a floating point cast.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004106
4107<h5>Example:</h5>
4108<pre>
4109 %X = fpext float 3.1415 to double <i>; yields double:3.1415</i>
4110 %Y = fpext float 1.0 to float <i>; yields float:1.0 (no-op)</i>
4111</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004112
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004113</div>
4114
4115<!-- _______________________________________________________________________ -->
4116<div class="doc_subsubsection">
4117 <a name="i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a>
4118</div>
4119<div class="doc_text">
4120
4121<h5>Syntax:</h5>
4122<pre>
Reid Spencere6adee82007-07-31 14:40:14 +00004123 &lt;result&gt; = fptoui &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004124</pre>
4125
4126<h5>Overview:</h5>
Reid Spencere6adee82007-07-31 14:40:14 +00004127<p>The '<tt>fptoui</tt>' converts a floating point <tt>value</tt> to its
Bill Wendlingf85859d2009-07-20 02:29:24 +00004128 unsigned integer equivalent of type <tt>ty2</tt>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004129
4130<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004131<p>The '<tt>fptoui</tt>' instruction takes a value to cast, which must be a
4132 scalar or vector <a href="#t_floating">floating point</a> value, and a type
4133 to cast it to <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a>
4134 type. If <tt>ty</tt> is a vector floating point type, <tt>ty2</tt> must be a
4135 vector integer type with the same number of elements as <tt>ty</tt></p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004136
4137<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004138<p>The '<tt>fptoui</tt>' instruction converts its
4139 <a href="#t_floating">floating point</a> operand into the nearest (rounding
4140 towards zero) unsigned integer value. If the value cannot fit
4141 in <tt>ty2</tt>, the results are undefined.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004142
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004143<h5>Example:</h5>
4144<pre>
Reid Spencere6adee82007-07-31 14:40:14 +00004145 %X = fptoui double 123.0 to i32 <i>; yields i32:123</i>
Chris Lattner681f1e82007-09-22 03:17:52 +00004146 %Y = fptoui float 1.0E+300 to i1 <i>; yields undefined:1</i>
Reid Spencere6adee82007-07-31 14:40:14 +00004147 %X = fptoui float 1.04E+17 to i8 <i>; yields undefined:1</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004148</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004149
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004150</div>
4151
4152<!-- _______________________________________________________________________ -->
4153<div class="doc_subsubsection">
4154 <a name="i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a>
4155</div>
4156<div class="doc_text">
4157
4158<h5>Syntax:</h5>
4159<pre>
4160 &lt;result&gt; = fptosi &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4161</pre>
4162
4163<h5>Overview:</h5>
4164<p>The '<tt>fptosi</tt>' instruction converts
Bill Wendlingf85859d2009-07-20 02:29:24 +00004165 <a href="#t_floating">floating point</a> <tt>value</tt> to
4166 type <tt>ty2</tt>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004167
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004168<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004169<p>The '<tt>fptosi</tt>' instruction takes a value to cast, which must be a
4170 scalar or vector <a href="#t_floating">floating point</a> value, and a type
4171 to cast it to <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a>
4172 type. If <tt>ty</tt> is a vector floating point type, <tt>ty2</tt> must be a
4173 vector integer type with the same number of elements as <tt>ty</tt></p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004174
4175<h5>Semantics:</h5>
4176<p>The '<tt>fptosi</tt>' instruction converts its
Bill Wendlingf85859d2009-07-20 02:29:24 +00004177 <a href="#t_floating">floating point</a> operand into the nearest (rounding
4178 towards zero) signed integer value. If the value cannot fit in <tt>ty2</tt>,
4179 the results are undefined.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004180
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004181<h5>Example:</h5>
4182<pre>
4183 %X = fptosi double -123.0 to i32 <i>; yields i32:-123</i>
Chris Lattner681f1e82007-09-22 03:17:52 +00004184 %Y = fptosi float 1.0E-247 to i1 <i>; yields undefined:1</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004185 %X = fptosi float 1.04E+17 to i8 <i>; yields undefined:1</i>
4186</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004187
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004188</div>
4189
4190<!-- _______________________________________________________________________ -->
4191<div class="doc_subsubsection">
4192 <a name="i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a>
4193</div>
4194<div class="doc_text">
4195
4196<h5>Syntax:</h5>
4197<pre>
4198 &lt;result&gt; = uitofp &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4199</pre>
4200
4201<h5>Overview:</h5>
4202<p>The '<tt>uitofp</tt>' instruction regards <tt>value</tt> as an unsigned
Bill Wendlingf85859d2009-07-20 02:29:24 +00004203 integer and converts that value to the <tt>ty2</tt> type.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004204
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004205<h5>Arguments:</h5>
Nate Begeman78246ca2007-11-17 03:58:34 +00004206<p>The '<tt>uitofp</tt>' instruction takes a value to cast, which must be a
Bill Wendlingf85859d2009-07-20 02:29:24 +00004207 scalar or vector <a href="#t_integer">integer</a> value, and a type to cast
4208 it to <tt>ty2</tt>, which must be an <a href="#t_floating">floating point</a>
4209 type. If <tt>ty</tt> is a vector integer type, <tt>ty2</tt> must be a vector
4210 floating point type with the same number of elements as <tt>ty</tt></p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004211
4212<h5>Semantics:</h5>
4213<p>The '<tt>uitofp</tt>' instruction interprets its operand as an unsigned
Bill Wendlingf85859d2009-07-20 02:29:24 +00004214 integer quantity and converts it to the corresponding floating point
4215 value. If the value cannot fit in the floating point value, the results are
4216 undefined.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004217
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004218<h5>Example:</h5>
4219<pre>
4220 %X = uitofp i32 257 to float <i>; yields float:257.0</i>
Dan Gohman2672f3e2008-10-14 16:51:45 +00004221 %Y = uitofp i8 -1 to double <i>; yields double:255.0</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004222</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004223
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004224</div>
4225
4226<!-- _______________________________________________________________________ -->
4227<div class="doc_subsubsection">
4228 <a name="i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a>
4229</div>
4230<div class="doc_text">
4231
4232<h5>Syntax:</h5>
4233<pre>
4234 &lt;result&gt; = sitofp &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4235</pre>
4236
4237<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004238<p>The '<tt>sitofp</tt>' instruction regards <tt>value</tt> as a signed integer
4239 and converts that value to the <tt>ty2</tt> type.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004240
4241<h5>Arguments:</h5>
Nate Begeman78246ca2007-11-17 03:58:34 +00004242<p>The '<tt>sitofp</tt>' instruction takes a value to cast, which must be a
Bill Wendlingf85859d2009-07-20 02:29:24 +00004243 scalar or vector <a href="#t_integer">integer</a> value, and a type to cast
4244 it to <tt>ty2</tt>, which must be an <a href="#t_floating">floating point</a>
4245 type. If <tt>ty</tt> is a vector integer type, <tt>ty2</tt> must be a vector
4246 floating point type with the same number of elements as <tt>ty</tt></p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004247
4248<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004249<p>The '<tt>sitofp</tt>' instruction interprets its operand as a signed integer
4250 quantity and converts it to the corresponding floating point value. If the
4251 value cannot fit in the floating point value, the results are undefined.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004252
4253<h5>Example:</h5>
4254<pre>
4255 %X = sitofp i32 257 to float <i>; yields float:257.0</i>
Dan Gohman2672f3e2008-10-14 16:51:45 +00004256 %Y = sitofp i8 -1 to double <i>; yields double:-1.0</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004257</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004258
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004259</div>
4260
4261<!-- _______________________________________________________________________ -->
4262<div class="doc_subsubsection">
4263 <a name="i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a>
4264</div>
4265<div class="doc_text">
4266
4267<h5>Syntax:</h5>
4268<pre>
4269 &lt;result&gt; = ptrtoint &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4270</pre>
4271
4272<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004273<p>The '<tt>ptrtoint</tt>' instruction converts the pointer <tt>value</tt> to
4274 the integer type <tt>ty2</tt>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004275
4276<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004277<p>The '<tt>ptrtoint</tt>' instruction takes a <tt>value</tt> to cast, which
4278 must be a <a href="#t_pointer">pointer</a> value, and a type to cast it to
4279 <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a> type.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004280
4281<h5>Semantics:</h5>
4282<p>The '<tt>ptrtoint</tt>' instruction converts <tt>value</tt> to integer type
Bill Wendlingf85859d2009-07-20 02:29:24 +00004283 <tt>ty2</tt> by interpreting the pointer value as an integer and either
4284 truncating or zero extending that value to the size of the integer type. If
4285 <tt>value</tt> is smaller than <tt>ty2</tt> then a zero extension is done. If
4286 <tt>value</tt> is larger than <tt>ty2</tt> then a truncation is done. If they
4287 are the same size, then nothing is done (<i>no-op cast</i>) other than a type
4288 change.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004289
4290<h5>Example:</h5>
4291<pre>
4292 %X = ptrtoint i32* %X to i8 <i>; yields truncation on 32-bit architecture</i>
4293 %Y = ptrtoint i32* %x to i64 <i>; yields zero extension on 32-bit architecture</i>
4294</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004295
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004296</div>
4297
4298<!-- _______________________________________________________________________ -->
4299<div class="doc_subsubsection">
4300 <a name="i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a>
4301</div>
4302<div class="doc_text">
4303
4304<h5>Syntax:</h5>
4305<pre>
4306 &lt;result&gt; = inttoptr &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4307</pre>
4308
4309<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004310<p>The '<tt>inttoptr</tt>' instruction converts an integer <tt>value</tt> to a
4311 pointer type, <tt>ty2</tt>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004312
4313<h5>Arguments:</h5>
4314<p>The '<tt>inttoptr</tt>' instruction takes an <a href="#t_integer">integer</a>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004315 value to cast, and a type to cast it to, which must be a
4316 <a href="#t_pointer">pointer</a> type.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004317
4318<h5>Semantics:</h5>
4319<p>The '<tt>inttoptr</tt>' instruction converts <tt>value</tt> to type
Bill Wendlingf85859d2009-07-20 02:29:24 +00004320 <tt>ty2</tt> by applying either a zero extension or a truncation depending on
4321 the size of the integer <tt>value</tt>. If <tt>value</tt> is larger than the
4322 size of a pointer then a truncation is done. If <tt>value</tt> is smaller
4323 than the size of a pointer then a zero extension is done. If they are the
4324 same size, nothing is done (<i>no-op cast</i>).</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004325
4326<h5>Example:</h5>
4327<pre>
4328 %X = inttoptr i32 255 to i32* <i>; yields zero extension on 64-bit architecture</i>
4329 %X = inttoptr i32 255 to i32* <i>; yields no-op on 32-bit architecture</i>
4330 %Y = inttoptr i64 0 to i32* <i>; yields truncation on 32-bit architecture</i>
4331</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004332
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004333</div>
4334
4335<!-- _______________________________________________________________________ -->
4336<div class="doc_subsubsection">
4337 <a name="i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a>
4338</div>
4339<div class="doc_text">
4340
4341<h5>Syntax:</h5>
4342<pre>
4343 &lt;result&gt; = bitcast &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4344</pre>
4345
4346<h5>Overview:</h5>
4347<p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
Bill Wendlingf85859d2009-07-20 02:29:24 +00004348 <tt>ty2</tt> without changing any bits.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004349
4350<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004351<p>The '<tt>bitcast</tt>' instruction takes a value to cast, which must be a
4352 non-aggregate first class value, and a type to cast it to, which must also be
4353 a non-aggregate <a href="#t_firstclass">first class</a> type. The bit sizes
4354 of <tt>value</tt> and the destination type, <tt>ty2</tt>, must be
4355 identical. If the source type is a pointer, the destination type must also be
4356 a pointer. This instruction supports bitwise conversion of vectors to
4357 integers and to vectors of other types (as long as they have the same
4358 size).</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004359
4360<h5>Semantics:</h5>
4361<p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
Bill Wendlingf85859d2009-07-20 02:29:24 +00004362 <tt>ty2</tt>. It is always a <i>no-op cast</i> because no bits change with
4363 this conversion. The conversion is done as if the <tt>value</tt> had been
4364 stored to memory and read back as type <tt>ty2</tt>. Pointer types may only
4365 be converted to other pointer types with this instruction. To convert
4366 pointers to other types, use the <a href="#i_inttoptr">inttoptr</a> or
4367 <a href="#i_ptrtoint">ptrtoint</a> instructions first.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004368
4369<h5>Example:</h5>
4370<pre>
4371 %X = bitcast i8 255 to i8 <i>; yields i8 :-1</i>
4372 %Y = bitcast i32* %x to sint* <i>; yields sint*:%x</i>
Dan Gohman2672f3e2008-10-14 16:51:45 +00004373 %Z = bitcast &lt;2 x int&gt; %V to i64; <i>; yields i64: %V</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004374</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004375
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004376</div>
4377
4378<!-- ======================================================================= -->
4379<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004380
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004381<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00004382
4383<p>The instructions in this category are the "miscellaneous" instructions, which
4384 defy better classification.</p>
4385
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004386</div>
4387
4388<!-- _______________________________________________________________________ -->
4389<div class="doc_subsubsection"><a name="i_icmp">'<tt>icmp</tt>' Instruction</a>
4390</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004391
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004392<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00004393
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004394<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004395<pre>
4396 &lt;result&gt; = icmp &lt;cond&gt; &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {i1} or {&lt;N x i1&gt;}:result</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004397</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004398
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004399<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004400<p>The '<tt>icmp</tt>' instruction returns a boolean value or a vector of
4401 boolean values based on comparison of its two integer, integer vector, or
4402 pointer operands.</p>
4403
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004404<h5>Arguments:</h5>
4405<p>The '<tt>icmp</tt>' instruction takes three operands. The first operand is
Bill Wendlingf85859d2009-07-20 02:29:24 +00004406 the condition code indicating the kind of comparison to perform. It is not a
4407 value, just a keyword. The possible condition code are:</p>
4408
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004409<ol>
4410 <li><tt>eq</tt>: equal</li>
4411 <li><tt>ne</tt>: not equal </li>
4412 <li><tt>ugt</tt>: unsigned greater than</li>
4413 <li><tt>uge</tt>: unsigned greater or equal</li>
4414 <li><tt>ult</tt>: unsigned less than</li>
4415 <li><tt>ule</tt>: unsigned less or equal</li>
4416 <li><tt>sgt</tt>: signed greater than</li>
4417 <li><tt>sge</tt>: signed greater or equal</li>
4418 <li><tt>slt</tt>: signed less than</li>
4419 <li><tt>sle</tt>: signed less or equal</li>
4420</ol>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004421
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004422<p>The remaining two arguments must be <a href="#t_integer">integer</a> or
Bill Wendlingf85859d2009-07-20 02:29:24 +00004423 <a href="#t_pointer">pointer</a> or integer <a href="#t_vector">vector</a>
4424 typed. They must also be identical types.</p>
4425
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004426<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004427<p>The '<tt>icmp</tt>' compares <tt>op1</tt> and <tt>op2</tt> according to the
4428 condition code given as <tt>cond</tt>. The comparison performed always yields
4429 either an <a href="#t_primitive"><tt>i1</tt></a> or vector of <tt>i1</tt>
4430 result, as follows:</p>
4431
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004432<ol>
4433 <li><tt>eq</tt>: yields <tt>true</tt> if the operands are equal,
Bill Wendlingf85859d2009-07-20 02:29:24 +00004434 <tt>false</tt> otherwise. No sign interpretation is necessary or
4435 performed.</li>
4436
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004437 <li><tt>ne</tt>: yields <tt>true</tt> if the operands are unequal,
Bill Wendlingf85859d2009-07-20 02:29:24 +00004438 <tt>false</tt> otherwise. No sign interpretation is necessary or
4439 performed.</li>
4440
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004441 <li><tt>ugt</tt>: interprets the operands as unsigned values and yields
Bill Wendlingf85859d2009-07-20 02:29:24 +00004442 <tt>true</tt> if <tt>op1</tt> is greater than <tt>op2</tt>.</li>
4443
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004444 <li><tt>uge</tt>: interprets the operands as unsigned values and yields
Bill Wendlingf85859d2009-07-20 02:29:24 +00004445 <tt>true</tt> if <tt>op1</tt> is greater than or equal
4446 to <tt>op2</tt>.</li>
4447
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004448 <li><tt>ult</tt>: interprets the operands as unsigned values and yields
Bill Wendlingf85859d2009-07-20 02:29:24 +00004449 <tt>true</tt> if <tt>op1</tt> is less than <tt>op2</tt>.</li>
4450
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004451 <li><tt>ule</tt>: interprets the operands as unsigned values and yields
Bill Wendlingf85859d2009-07-20 02:29:24 +00004452 <tt>true</tt> if <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li>
4453
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004454 <li><tt>sgt</tt>: interprets the operands as signed values and yields
Bill Wendlingf85859d2009-07-20 02:29:24 +00004455 <tt>true</tt> if <tt>op1</tt> is greater than <tt>op2</tt>.</li>
4456
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004457 <li><tt>sge</tt>: interprets the operands as signed values and yields
Bill Wendlingf85859d2009-07-20 02:29:24 +00004458 <tt>true</tt> if <tt>op1</tt> is greater than or equal
4459 to <tt>op2</tt>.</li>
4460
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004461 <li><tt>slt</tt>: interprets the operands as signed values and yields
Bill Wendlingf85859d2009-07-20 02:29:24 +00004462 <tt>true</tt> if <tt>op1</tt> is less than <tt>op2</tt>.</li>
4463
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004464 <li><tt>sle</tt>: interprets the operands as signed values and yields
Bill Wendlingf85859d2009-07-20 02:29:24 +00004465 <tt>true</tt> if <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004466</ol>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004467
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004468<p>If the operands are <a href="#t_pointer">pointer</a> typed, the pointer
Bill Wendlingf85859d2009-07-20 02:29:24 +00004469 values are compared as if they were integers.</p>
4470
4471<p>If the operands are integer vectors, then they are compared element by
4472 element. The result is an <tt>i1</tt> vector with the same number of elements
4473 as the values being compared. Otherwise, the result is an <tt>i1</tt>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004474
4475<h5>Example:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004476<pre>
4477 &lt;result&gt; = icmp eq i32 4, 5 <i>; yields: result=false</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004478 &lt;result&gt; = icmp ne float* %X, %X <i>; yields: result=false</i>
4479 &lt;result&gt; = icmp ult i16 4, 5 <i>; yields: result=true</i>
4480 &lt;result&gt; = icmp sgt i16 4, 5 <i>; yields: result=false</i>
4481 &lt;result&gt; = icmp ule i16 -4, 5 <i>; yields: result=false</i>
4482 &lt;result&gt; = icmp sge i16 4, 5 <i>; yields: result=false</i>
4483</pre>
Dan Gohmana53eb382009-01-22 01:39:38 +00004484
4485<p>Note that the code generator does not yet support vector types with
4486 the <tt>icmp</tt> instruction.</p>
4487
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004488</div>
4489
4490<!-- _______________________________________________________________________ -->
4491<div class="doc_subsubsection"><a name="i_fcmp">'<tt>fcmp</tt>' Instruction</a>
4492</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004493
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004494<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00004495
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004496<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004497<pre>
4498 &lt;result&gt; = fcmp &lt;cond&gt; &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {i1} or {&lt;N x i1&gt;}:result</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004499</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004500
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004501<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004502<p>The '<tt>fcmp</tt>' instruction returns a boolean value or vector of boolean
4503 values based on comparison of its operands.</p>
4504
4505<p>If the operands are floating point scalars, then the result type is a boolean
4506(<a href="#t_primitive"><tt>i1</tt></a>).</p>
4507
4508<p>If the operands are floating point vectors, then the result type is a vector
4509 of boolean with the same number of elements as the operands being
4510 compared.</p>
4511
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004512<h5>Arguments:</h5>
4513<p>The '<tt>fcmp</tt>' instruction takes three operands. The first operand is
Bill Wendlingf85859d2009-07-20 02:29:24 +00004514 the condition code indicating the kind of comparison to perform. It is not a
4515 value, just a keyword. The possible condition code are:</p>
4516
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004517<ol>
4518 <li><tt>false</tt>: no comparison, always returns false</li>
4519 <li><tt>oeq</tt>: ordered and equal</li>
4520 <li><tt>ogt</tt>: ordered and greater than </li>
4521 <li><tt>oge</tt>: ordered and greater than or equal</li>
4522 <li><tt>olt</tt>: ordered and less than </li>
4523 <li><tt>ole</tt>: ordered and less than or equal</li>
4524 <li><tt>one</tt>: ordered and not equal</li>
4525 <li><tt>ord</tt>: ordered (no nans)</li>
4526 <li><tt>ueq</tt>: unordered or equal</li>
4527 <li><tt>ugt</tt>: unordered or greater than </li>
4528 <li><tt>uge</tt>: unordered or greater than or equal</li>
4529 <li><tt>ult</tt>: unordered or less than </li>
4530 <li><tt>ule</tt>: unordered or less than or equal</li>
4531 <li><tt>une</tt>: unordered or not equal</li>
4532 <li><tt>uno</tt>: unordered (either nans)</li>
4533 <li><tt>true</tt>: no comparison, always returns true</li>
4534</ol>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004535
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004536<p><i>Ordered</i> means that neither operand is a QNAN while
Bill Wendlingf85859d2009-07-20 02:29:24 +00004537 <i>unordered</i> means that either operand may be a QNAN.</p>
4538
4539<p>Each of <tt>val1</tt> and <tt>val2</tt> arguments must be either
4540 a <a href="#t_floating">floating point</a> type or
4541 a <a href="#t_vector">vector</a> of floating point type. They must have
4542 identical types.</p>
4543
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004544<h5>Semantics:</h5>
Gabor Greifd9068fe2008-08-07 21:46:00 +00004545<p>The '<tt>fcmp</tt>' instruction compares <tt>op1</tt> and <tt>op2</tt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004546 according to the condition code given as <tt>cond</tt>. If the operands are
4547 vectors, then the vectors are compared element by element. Each comparison
4548 performed always yields an <a href="#t_primitive">i1</a> result, as
4549 follows:</p>
4550
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004551<ol>
4552 <li><tt>false</tt>: always yields <tt>false</tt>, regardless of operands.</li>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004553
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004554 <li><tt>oeq</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Bill Wendlingf85859d2009-07-20 02:29:24 +00004555 <tt>op1</tt> is equal to <tt>op2</tt>.</li>
4556
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004557 <li><tt>ogt</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Bill Wendlingf85859d2009-07-20 02:29:24 +00004558 <tt>op1</tt> is greather than <tt>op2</tt>.</li>
4559
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004560 <li><tt>oge</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Bill Wendlingf85859d2009-07-20 02:29:24 +00004561 <tt>op1</tt> is greater than or equal to <tt>op2</tt>.</li>
4562
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004563 <li><tt>olt</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Bill Wendlingf85859d2009-07-20 02:29:24 +00004564 <tt>op1</tt> is less than <tt>op2</tt>.</li>
4565
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004566 <li><tt>ole</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Bill Wendlingf85859d2009-07-20 02:29:24 +00004567 <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li>
4568
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004569 <li><tt>one</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Bill Wendlingf85859d2009-07-20 02:29:24 +00004570 <tt>op1</tt> is not equal to <tt>op2</tt>.</li>
4571
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004572 <li><tt>ord</tt>: yields <tt>true</tt> if both operands are not a QNAN.</li>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004573
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004574 <li><tt>ueq</tt>: yields <tt>true</tt> if either operand is a QNAN or
Bill Wendlingf85859d2009-07-20 02:29:24 +00004575 <tt>op1</tt> is equal to <tt>op2</tt>.</li>
4576
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004577 <li><tt>ugt</tt>: yields <tt>true</tt> if either operand is a QNAN or
Bill Wendlingf85859d2009-07-20 02:29:24 +00004578 <tt>op1</tt> is greater than <tt>op2</tt>.</li>
4579
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004580 <li><tt>uge</tt>: yields <tt>true</tt> if either operand is a QNAN or
Bill Wendlingf85859d2009-07-20 02:29:24 +00004581 <tt>op1</tt> is greater than or equal to <tt>op2</tt>.</li>
4582
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004583 <li><tt>ult</tt>: yields <tt>true</tt> if either operand is a QNAN or
Bill Wendlingf85859d2009-07-20 02:29:24 +00004584 <tt>op1</tt> is less than <tt>op2</tt>.</li>
4585
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004586 <li><tt>ule</tt>: yields <tt>true</tt> if either operand is a QNAN or
Bill Wendlingf85859d2009-07-20 02:29:24 +00004587 <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li>
4588
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004589 <li><tt>une</tt>: yields <tt>true</tt> if either operand is a QNAN or
Bill Wendlingf85859d2009-07-20 02:29:24 +00004590 <tt>op1</tt> is not equal to <tt>op2</tt>.</li>
4591
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004592 <li><tt>uno</tt>: yields <tt>true</tt> if either operand is a QNAN.</li>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004593
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004594 <li><tt>true</tt>: always yields <tt>true</tt>, regardless of operands.</li>
4595</ol>
4596
4597<h5>Example:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004598<pre>
4599 &lt;result&gt; = fcmp oeq float 4.0, 5.0 <i>; yields: result=false</i>
Dan Gohmanb60ca3c2008-09-09 01:02:47 +00004600 &lt;result&gt; = fcmp one float 4.0, 5.0 <i>; yields: result=true</i>
4601 &lt;result&gt; = fcmp olt float 4.0, 5.0 <i>; yields: result=true</i>
4602 &lt;result&gt; = fcmp ueq double 1.0, 2.0 <i>; yields: result=false</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004603</pre>
Dan Gohmana53eb382009-01-22 01:39:38 +00004604
4605<p>Note that the code generator does not yet support vector types with
4606 the <tt>fcmp</tt> instruction.</p>
4607
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004608</div>
4609
4610<!-- _______________________________________________________________________ -->
Nate Begeman646fa482008-05-12 19:01:56 +00004611<div class="doc_subsubsection">
Chris Lattner6704c212008-05-20 20:48:21 +00004612 <a name="i_phi">'<tt>phi</tt>' Instruction</a>
4613</div>
4614
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004615<div class="doc_text">
Chris Lattner6704c212008-05-20 20:48:21 +00004616
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004617<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004618<pre>
4619 &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...
4620</pre>
Chris Lattner6704c212008-05-20 20:48:21 +00004621
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004622<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004623<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in the
4624 SSA graph representing the function.</p>
4625
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004626<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004627<p>The type of the incoming values is specified with the first type field. After
4628 this, the '<tt>phi</tt>' instruction takes a list of pairs as arguments, with
4629 one pair for each predecessor basic block of the current block. Only values
4630 of <a href="#t_firstclass">first class</a> type may be used as the value
4631 arguments to the PHI node. Only labels may be used as the label
4632 arguments.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00004633
Bill Wendlingf85859d2009-07-20 02:29:24 +00004634<p>There must be no non-phi instructions between the start of a basic block and
4635 the PHI instructions: i.e. PHI instructions must be first in a basic
4636 block.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00004637
Bill Wendlingf85859d2009-07-20 02:29:24 +00004638<p>For the purposes of the SSA form, the use of each incoming value is deemed to
4639 occur on the edge from the corresponding predecessor block to the current
4640 block (but after any definition of an '<tt>invoke</tt>' instruction's return
4641 value on the same edge).</p>
Jay Foad8e2fd2c2009-06-03 10:20:10 +00004642
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004643<h5>Semantics:</h5>
4644<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the value
Bill Wendlingf85859d2009-07-20 02:29:24 +00004645 specified by the pair corresponding to the predecessor basic block that
4646 executed just prior to the current block.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00004647
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004648<h5>Example:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00004649<pre>
4650Loop: ; Infinite loop that counts from 0 on up...
4651 %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]
4652 %nextindvar = add i32 %indvar, 1
4653 br label %Loop
4654</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004655
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004656</div>
4657
4658<!-- _______________________________________________________________________ -->
4659<div class="doc_subsubsection">
4660 <a name="i_select">'<tt>select</tt>' Instruction</a>
4661</div>
4662
4663<div class="doc_text">
4664
4665<h5>Syntax:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004666<pre>
Dan Gohmanb60ca3c2008-09-09 01:02:47 +00004667 &lt;result&gt; = select <i>selty</i> &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
4668
Dan Gohman2672f3e2008-10-14 16:51:45 +00004669 <i>selty</i> is either i1 or {&lt;N x i1&gt;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004670</pre>
4671
4672<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004673<p>The '<tt>select</tt>' instruction is used to choose one value based on a
4674 condition, without branching.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004675
4676
4677<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004678<p>The '<tt>select</tt>' instruction requires an 'i1' value or a vector of 'i1'
4679 values indicating the condition, and two values of the
4680 same <a href="#t_firstclass">first class</a> type. If the val1/val2 are
4681 vectors and the condition is a scalar, then entire vectors are selected, not
4682 individual elements.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004683
4684<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004685<p>If the condition is an i1 and it evaluates to 1, the instruction returns the
4686 first value argument; otherwise, it returns the second value argument.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004687
Bill Wendlingf85859d2009-07-20 02:29:24 +00004688<p>If the condition is a vector of i1, then the value arguments must be vectors
4689 of the same size, and the selection is done element by element.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004690
4691<h5>Example:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004692<pre>
4693 %X = select i1 true, i8 17, i8 42 <i>; yields i8:17</i>
4694</pre>
Dan Gohmana53eb382009-01-22 01:39:38 +00004695
4696<p>Note that the code generator does not yet support conditions
4697 with vector type.</p>
4698
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004699</div>
4700
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004701<!-- _______________________________________________________________________ -->
4702<div class="doc_subsubsection">
4703 <a name="i_call">'<tt>call</tt>' Instruction</a>
4704</div>
4705
4706<div class="doc_text">
4707
4708<h5>Syntax:</h5>
4709<pre>
Devang Pateld0bfcc72008-10-07 17:48:33 +00004710 &lt;result&gt; = [tail] call [<a href="#callingconv">cconv</a>] [<a href="#paramattrs">ret attrs</a>] &lt;ty&gt; [&lt;fnty&gt;*] &lt;fnptrval&gt;(&lt;function args&gt;) [<a href="#fnattrs">fn attrs</a>]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004711</pre>
4712
4713<h5>Overview:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004714<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
4715
4716<h5>Arguments:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004717<p>This instruction requires several arguments:</p>
4718
4719<ol>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004720 <li>The optional "tail" marker indicates whether the callee function accesses
4721 any allocas or varargs in the caller. If the "tail" marker is present,
4722 the function call is eligible for tail call optimization. Note that calls
4723 may be marked "tail" even if they do not occur before
4724 a <a href="#i_ret"><tt>ret</tt></a> instruction.</li>
Devang Patelac2fc272008-10-06 18:50:38 +00004725
Bill Wendlingf85859d2009-07-20 02:29:24 +00004726 <li>The optional "cconv" marker indicates which <a href="#callingconv">calling
4727 convention</a> the call should use. If none is specified, the call
4728 defaults to using C calling conventions.</li>
Devang Patelac2fc272008-10-06 18:50:38 +00004729
Bill Wendlingf85859d2009-07-20 02:29:24 +00004730 <li>The optional <a href="#paramattrs">Parameter Attributes</a> list for
4731 return values. Only '<tt>zeroext</tt>', '<tt>signext</tt>', and
4732 '<tt>inreg</tt>' attributes are valid here.</li>
4733
4734 <li>'<tt>ty</tt>': the type of the call instruction itself which is also the
4735 type of the return value. Functions that return no value are marked
4736 <tt><a href="#t_void">void</a></tt>.</li>
4737
4738 <li>'<tt>fnty</tt>': shall be the signature of the pointer to function value
4739 being invoked. The argument types must match the types implied by this
4740 signature. This type can be omitted if the function is not varargs and if
4741 the function type does not return a pointer to a function.</li>
4742
4743 <li>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to
4744 be invoked. In most cases, this is a direct function invocation, but
4745 indirect <tt>call</tt>s are just as possible, calling an arbitrary pointer
4746 to function value.</li>
4747
4748 <li>'<tt>function args</tt>': argument list whose types match the function
4749 signature argument types. All arguments must be of
4750 <a href="#t_firstclass">first class</a> type. If the function signature
4751 indicates the function accepts a variable number of arguments, the extra
4752 arguments can be specified.</li>
4753
4754 <li>The optional <a href="#fnattrs">function attributes</a> list. Only
4755 '<tt>noreturn</tt>', '<tt>nounwind</tt>', '<tt>readonly</tt>' and
4756 '<tt>readnone</tt>' attributes are valid here.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004757</ol>
4758
4759<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004760<p>The '<tt>call</tt>' instruction is used to cause control flow to transfer to
4761 a specified function, with its incoming arguments bound to the specified
4762 values. Upon a '<tt><a href="#i_ret">ret</a></tt>' instruction in the called
4763 function, control flow continues with the instruction after the function
4764 call, and the return value of the function is bound to the result
4765 argument.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004766
4767<h5>Example:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004768<pre>
Nick Lewycky93082fc2007-09-08 13:57:50 +00004769 %retval = call i32 @test(i32 %argc)
Chris Lattner5e893ef2008-03-21 17:24:17 +00004770 call i32 (i8 *, ...)* @printf(i8 * %msg, i32 12, i8 42) <i>; yields i32</i>
4771 %X = tail call i32 @foo() <i>; yields i32</i>
4772 %Y = tail call <a href="#callingconv">fastcc</a> i32 @foo() <i>; yields i32</i>
4773 call void %foo(i8 97 signext)
Devang Patela3cc5372008-03-10 20:49:15 +00004774
4775 %struct.A = type { i32, i8 }
Devang Patelac2fc272008-10-06 18:50:38 +00004776 %r = call %struct.A @foo() <i>; yields { 32, i8 }</i>
Dan Gohman3e700032008-10-04 19:00:07 +00004777 %gr = extractvalue %struct.A %r, 0 <i>; yields i32</i>
4778 %gr1 = extractvalue %struct.A %r, 1 <i>; yields i8</i>
Chris Lattnerac454b32008-10-08 06:26:11 +00004779 %Z = call void @foo() noreturn <i>; indicates that %foo never returns normally</i>
Matthijs Kooijman2c4e05a2008-10-07 10:03:45 +00004780 %ZZ = call zeroext i32 @bar() <i>; Return value is %zero extended</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004781</pre>
4782
4783</div>
4784
4785<!-- _______________________________________________________________________ -->
4786<div class="doc_subsubsection">
4787 <a name="i_va_arg">'<tt>va_arg</tt>' Instruction</a>
4788</div>
4789
4790<div class="doc_text">
4791
4792<h5>Syntax:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004793<pre>
4794 &lt;resultval&gt; = va_arg &lt;va_list*&gt; &lt;arglist&gt;, &lt;argty&gt;
4795</pre>
4796
4797<h5>Overview:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004798<p>The '<tt>va_arg</tt>' instruction is used to access arguments passed through
Bill Wendlingf85859d2009-07-20 02:29:24 +00004799 the "variable argument" area of a function call. It is used to implement the
4800 <tt>va_arg</tt> macro in C.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004801
4802<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004803<p>This instruction takes a <tt>va_list*</tt> value and the type of the
4804 argument. It returns a value of the specified argument type and increments
4805 the <tt>va_list</tt> to point to the next argument. The actual type
4806 of <tt>va_list</tt> is target specific.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004807
4808<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004809<p>The '<tt>va_arg</tt>' instruction loads an argument of the specified type
4810 from the specified <tt>va_list</tt> and causes the <tt>va_list</tt> to point
4811 to the next argument. For more information, see the variable argument
4812 handling <a href="#int_varargs">Intrinsic Functions</a>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004813
4814<p>It is legal for this instruction to be called in a function which does not
Bill Wendlingf85859d2009-07-20 02:29:24 +00004815 take a variable number of arguments, for example, the <tt>vfprintf</tt>
4816 function.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004817
Bill Wendlingf85859d2009-07-20 02:29:24 +00004818<p><tt>va_arg</tt> is an LLVM instruction instead of
4819 an <a href="#intrinsics">intrinsic function</a> because it takes a type as an
4820 argument.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004821
4822<h5>Example:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004823<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
4824
Bill Wendlingf85859d2009-07-20 02:29:24 +00004825<p>Note that the code generator does not yet fully support va_arg on many
4826 targets. Also, it does not currently support va_arg with aggregate types on
4827 any target.</p>
Dan Gohman60967192009-01-12 23:12:39 +00004828
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004829</div>
4830
4831<!-- *********************************************************************** -->
4832<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
4833<!-- *********************************************************************** -->
4834
4835<div class="doc_text">
4836
4837<p>LLVM supports the notion of an "intrinsic function". These functions have
Bill Wendlingf85859d2009-07-20 02:29:24 +00004838 well known names and semantics and are required to follow certain
4839 restrictions. Overall, these intrinsics represent an extension mechanism for
4840 the LLVM language that does not require changing all of the transformations
4841 in LLVM when adding to the language (or the bitcode reader/writer, the
4842 parser, etc...).</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004843
4844<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix. This
Bill Wendlingf85859d2009-07-20 02:29:24 +00004845 prefix is reserved in LLVM for intrinsic names; thus, function names may not
4846 begin with this prefix. Intrinsic functions must always be external
4847 functions: you cannot define the body of intrinsic functions. Intrinsic
4848 functions may only be used in call or invoke instructions: it is illegal to
4849 take the address of an intrinsic function. Additionally, because intrinsic
4850 functions are part of the LLVM language, it is required if any are added that
4851 they be documented here.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004852
Bill Wendlingf85859d2009-07-20 02:29:24 +00004853<p>Some intrinsic functions can be overloaded, i.e., the intrinsic represents a
4854 family of functions that perform the same operation but on different data
4855 types. Because LLVM can represent over 8 million different integer types,
4856 overloading is used commonly to allow an intrinsic function to operate on any
4857 integer type. One or more of the argument types or the result type can be
4858 overloaded to accept any integer type. Argument types may also be defined as
4859 exactly matching a previous argument's type or the result type. This allows
4860 an intrinsic function which accepts multiple arguments, but needs all of them
4861 to be of the same type, to only be overloaded with respect to a single
4862 argument or the result.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004863
Bill Wendlingf85859d2009-07-20 02:29:24 +00004864<p>Overloaded intrinsics will have the names of its overloaded argument types
4865 encoded into its function name, each preceded by a period. Only those types
4866 which are overloaded result in a name suffix. Arguments whose type is matched
4867 against another type do not. For example, the <tt>llvm.ctpop</tt> function
4868 can take an integer of any width and returns an integer of exactly the same
4869 integer width. This leads to a family of functions such as
4870 <tt>i8 @llvm.ctpop.i8(i8 %val)</tt> and <tt>i29 @llvm.ctpop.i29(i29
4871 %val)</tt>. Only one type, the return type, is overloaded, and only one type
4872 suffix is required. Because the argument's type is matched against the return
4873 type, it does not require its own name suffix.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004874
4875<p>To learn how to add an intrinsic function, please see the
Bill Wendlingf85859d2009-07-20 02:29:24 +00004876 <a href="ExtendingLLVM.html">Extending LLVM Guide</a>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004877
4878</div>
4879
4880<!-- ======================================================================= -->
4881<div class="doc_subsection">
4882 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
4883</div>
4884
4885<div class="doc_text">
4886
Bill Wendlingf85859d2009-07-20 02:29:24 +00004887<p>Variable argument support is defined in LLVM with
4888 the <a href="#i_va_arg"><tt>va_arg</tt></a> instruction and these three
4889 intrinsic functions. These functions are related to the similarly named
4890 macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004891
Bill Wendlingf85859d2009-07-20 02:29:24 +00004892<p>All of these functions operate on arguments that use a target-specific value
4893 type "<tt>va_list</tt>". The LLVM assembly language reference manual does
4894 not define what this type is, so all transformations should be prepared to
4895 handle these functions regardless of the type used.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004896
4897<p>This example shows how the <a href="#i_va_arg"><tt>va_arg</tt></a>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004898 instruction and the variable argument handling intrinsic functions are
4899 used.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004900
4901<div class="doc_code">
4902<pre>
4903define i32 @test(i32 %X, ...) {
4904 ; Initialize variable argument processing
4905 %ap = alloca i8*
4906 %ap2 = bitcast i8** %ap to i8*
4907 call void @llvm.va_start(i8* %ap2)
4908
4909 ; Read a single integer argument
4910 %tmp = va_arg i8** %ap, i32
4911
4912 ; Demonstrate usage of llvm.va_copy and llvm.va_end
4913 %aq = alloca i8*
4914 %aq2 = bitcast i8** %aq to i8*
4915 call void @llvm.va_copy(i8* %aq2, i8* %ap2)
4916 call void @llvm.va_end(i8* %aq2)
4917
4918 ; Stop processing of arguments.
4919 call void @llvm.va_end(i8* %ap2)
4920 ret i32 %tmp
4921}
4922
4923declare void @llvm.va_start(i8*)
4924declare void @llvm.va_copy(i8*, i8*)
4925declare void @llvm.va_end(i8*)
4926</pre>
4927</div>
4928
4929</div>
4930
4931<!-- _______________________________________________________________________ -->
4932<div class="doc_subsubsection">
4933 <a name="int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
4934</div>
4935
4936
4937<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00004938
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004939<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004940<pre>
4941 declare void %llvm.va_start(i8* &lt;arglist&gt;)
4942</pre>
4943
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004944<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004945<p>The '<tt>llvm.va_start</tt>' intrinsic initializes <tt>*&lt;arglist&gt;</tt>
4946 for subsequent use by <tt><a href="#i_va_arg">va_arg</a></tt>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004947
4948<h5>Arguments:</h5>
Dan Gohman2672f3e2008-10-14 16:51:45 +00004949<p>The argument is a pointer to a <tt>va_list</tt> element to initialize.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004950
4951<h5>Semantics:</h5>
Dan Gohman2672f3e2008-10-14 16:51:45 +00004952<p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004953 macro available in C. In a target-dependent way, it initializes
4954 the <tt>va_list</tt> element to which the argument points, so that the next
4955 call to <tt>va_arg</tt> will produce the first variable argument passed to
4956 the function. Unlike the C <tt>va_start</tt> macro, this intrinsic does not
4957 need to know the last argument of the function as the compiler can figure
4958 that out.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004959
4960</div>
4961
4962<!-- _______________________________________________________________________ -->
4963<div class="doc_subsubsection">
4964 <a name="int_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
4965</div>
4966
4967<div class="doc_text">
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004968
Bill Wendlingf85859d2009-07-20 02:29:24 +00004969<h5>Syntax:</h5>
4970<pre>
4971 declare void @llvm.va_end(i8* &lt;arglist&gt;)
4972</pre>
4973
4974<h5>Overview:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004975<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>*&lt;arglist&gt;</tt>,
Bill Wendlingf85859d2009-07-20 02:29:24 +00004976 which has been initialized previously
4977 with <tt><a href="#int_va_start">llvm.va_start</a></tt>
4978 or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004979
4980<h5>Arguments:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004981<p>The argument is a pointer to a <tt>va_list</tt> to destroy.</p>
4982
4983<h5>Semantics:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004984<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00004985 macro available in C. In a target-dependent way, it destroys
4986 the <tt>va_list</tt> element to which the argument points. Calls
4987 to <a href="#int_va_start"><tt>llvm.va_start</tt></a>
4988 and <a href="#int_va_copy"> <tt>llvm.va_copy</tt></a> must be matched exactly
4989 with calls to <tt>llvm.va_end</tt>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004990
4991</div>
4992
4993<!-- _______________________________________________________________________ -->
4994<div class="doc_subsubsection">
4995 <a name="int_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
4996</div>
4997
4998<div class="doc_text">
4999
5000<h5>Syntax:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005001<pre>
5002 declare void @llvm.va_copy(i8* &lt;destarglist&gt;, i8* &lt;srcarglist&gt;)
5003</pre>
5004
5005<h5>Overview:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005006<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position
Bill Wendlingf85859d2009-07-20 02:29:24 +00005007 from the source argument list to the destination argument list.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005008
5009<h5>Arguments:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005010<p>The first argument is a pointer to a <tt>va_list</tt> element to initialize.
Bill Wendlingf85859d2009-07-20 02:29:24 +00005011 The second argument is a pointer to a <tt>va_list</tt> element to copy
5012 from.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005013
5014<h5>Semantics:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005015<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005016 macro available in C. In a target-dependent way, it copies the
5017 source <tt>va_list</tt> element into the destination <tt>va_list</tt>
5018 element. This intrinsic is necessary because
5019 the <tt><a href="#int_va_start"> llvm.va_start</a></tt> intrinsic may be
5020 arbitrarily complex and require, for example, memory allocation.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005021
5022</div>
5023
5024<!-- ======================================================================= -->
5025<div class="doc_subsection">
5026 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
5027</div>
5028
5029<div class="doc_text">
5030
Bill Wendlingf85859d2009-07-20 02:29:24 +00005031<p>LLVM support for <a href="GarbageCollection.html">Accurate Garbage
Chris Lattner96451482008-08-05 18:29:16 +00005032Collection</a> (GC) requires the implementation and generation of these
Bill Wendlingf85859d2009-07-20 02:29:24 +00005033intrinsics. These intrinsics allow identification of <a href="#int_gcroot">GC
5034roots on the stack</a>, as well as garbage collector implementations that
5035require <a href="#int_gcread">read</a> and <a href="#int_gcwrite">write</a>
5036barriers. Front-ends for type-safe garbage collected languages should generate
5037these intrinsics to make use of the LLVM garbage collectors. For more details,
5038see <a href="GarbageCollection.html">Accurate Garbage Collection with
5039LLVM</a>.</p>
Christopher Lambcfe00962007-12-17 01:00:21 +00005040
Bill Wendlingf85859d2009-07-20 02:29:24 +00005041<p>The garbage collection intrinsics only operate on objects in the generic
5042 address space (address space zero).</p>
Christopher Lambcfe00962007-12-17 01:00:21 +00005043
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005044</div>
5045
5046<!-- _______________________________________________________________________ -->
5047<div class="doc_subsubsection">
5048 <a name="int_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
5049</div>
5050
5051<div class="doc_text">
5052
5053<h5>Syntax:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005054<pre>
Chris Lattner38bd5dd2007-09-21 17:30:40 +00005055 declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005056</pre>
5057
5058<h5>Overview:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005059<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
Bill Wendlingf85859d2009-07-20 02:29:24 +00005060 the code generator, and allows some metadata to be associated with it.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005061
5062<h5>Arguments:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005063<p>The first argument specifies the address of a stack object that contains the
Bill Wendlingf85859d2009-07-20 02:29:24 +00005064 root pointer. The second pointer (which must be either a constant or a
5065 global value address) contains the meta-data to be associated with the
5066 root.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005067
5068<h5>Semantics:</h5>
Chris Lattnera7d94ba2008-04-24 05:59:56 +00005069<p>At runtime, a call to this intrinsic stores a null pointer into the "ptrloc"
Bill Wendlingf85859d2009-07-20 02:29:24 +00005070 location. At compile-time, the code generator generates information to allow
5071 the runtime to find the pointer at GC safe points. The '<tt>llvm.gcroot</tt>'
5072 intrinsic may only be used in a function which <a href="#gc">specifies a GC
5073 algorithm</a>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005074
5075</div>
5076
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005077<!-- _______________________________________________________________________ -->
5078<div class="doc_subsubsection">
5079 <a name="int_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
5080</div>
5081
5082<div class="doc_text">
5083
5084<h5>Syntax:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005085<pre>
Chris Lattner38bd5dd2007-09-21 17:30:40 +00005086 declare i8* @llvm.gcread(i8* %ObjPtr, i8** %Ptr)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005087</pre>
5088
5089<h5>Overview:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005090<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
Bill Wendlingf85859d2009-07-20 02:29:24 +00005091 locations, allowing garbage collector implementations that require read
5092 barriers.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005093
5094<h5>Arguments:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005095<p>The second argument is the address to read from, which should be an address
Bill Wendlingf85859d2009-07-20 02:29:24 +00005096 allocated from the garbage collector. The first object is a pointer to the
5097 start of the referenced object, if needed by the language runtime (otherwise
5098 null).</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005099
5100<h5>Semantics:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005101<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
Bill Wendlingf85859d2009-07-20 02:29:24 +00005102 instruction, but may be replaced with substantially more complex code by the
5103 garbage collector runtime, as needed. The '<tt>llvm.gcread</tt>' intrinsic
5104 may only be used in a function which <a href="#gc">specifies a GC
5105 algorithm</a>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005106
5107</div>
5108
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005109<!-- _______________________________________________________________________ -->
5110<div class="doc_subsubsection">
5111 <a name="int_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
5112</div>
5113
5114<div class="doc_text">
5115
5116<h5>Syntax:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005117<pre>
Chris Lattner38bd5dd2007-09-21 17:30:40 +00005118 declare void @llvm.gcwrite(i8* %P1, i8* %Obj, i8** %P2)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005119</pre>
5120
5121<h5>Overview:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005122<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
Bill Wendlingf85859d2009-07-20 02:29:24 +00005123 locations, allowing garbage collector implementations that require write
5124 barriers (such as generational or reference counting collectors).</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005125
5126<h5>Arguments:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005127<p>The first argument is the reference to store, the second is the start of the
Bill Wendlingf85859d2009-07-20 02:29:24 +00005128 object to store it to, and the third is the address of the field of Obj to
5129 store to. If the runtime does not require a pointer to the object, Obj may
5130 be null.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005131
5132<h5>Semantics:</h5>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005133<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
Bill Wendlingf85859d2009-07-20 02:29:24 +00005134 instruction, but may be replaced with substantially more complex code by the
5135 garbage collector runtime, as needed. The '<tt>llvm.gcwrite</tt>' intrinsic
5136 may only be used in a function which <a href="#gc">specifies a GC
5137 algorithm</a>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005138
5139</div>
5140
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005141<!-- ======================================================================= -->
5142<div class="doc_subsection">
5143 <a name="int_codegen">Code Generator Intrinsics</a>
5144</div>
5145
5146<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00005147
5148<p>These intrinsics are provided by LLVM to expose special features that may
5149 only be implemented with code generator support.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005150
5151</div>
5152
5153<!-- _______________________________________________________________________ -->
5154<div class="doc_subsubsection">
5155 <a name="int_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
5156</div>
5157
5158<div class="doc_text">
5159
5160<h5>Syntax:</h5>
5161<pre>
5162 declare i8 *@llvm.returnaddress(i32 &lt;level&gt;)
5163</pre>
5164
5165<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005166<p>The '<tt>llvm.returnaddress</tt>' intrinsic attempts to compute a
5167 target-specific value indicating the return address of the current function
5168 or one of its callers.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005169
5170<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005171<p>The argument to this intrinsic indicates which function to return the address
5172 for. Zero indicates the calling function, one indicates its caller, etc.
5173 The argument is <b>required</b> to be a constant integer value.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005174
5175<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005176<p>The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer
5177 indicating the return address of the specified call frame, or zero if it
5178 cannot be identified. The value returned by this intrinsic is likely to be
5179 incorrect or 0 for arguments other than zero, so it should only be used for
5180 debugging purposes.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005181
Bill Wendlingf85859d2009-07-20 02:29:24 +00005182<p>Note that calling this intrinsic does not prevent function inlining or other
5183 aggressive transformations, so the value returned may not be that of the
5184 obvious source-language caller.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005185
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005186</div>
5187
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005188<!-- _______________________________________________________________________ -->
5189<div class="doc_subsubsection">
5190 <a name="int_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
5191</div>
5192
5193<div class="doc_text">
5194
5195<h5>Syntax:</h5>
5196<pre>
Chris Lattner38bd5dd2007-09-21 17:30:40 +00005197 declare i8 *@llvm.frameaddress(i32 &lt;level&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005198</pre>
5199
5200<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005201<p>The '<tt>llvm.frameaddress</tt>' intrinsic attempts to return the
5202 target-specific frame pointer value for the specified stack frame.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005203
5204<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005205<p>The argument to this intrinsic indicates which function to return the frame
5206 pointer for. Zero indicates the calling function, one indicates its caller,
5207 etc. The argument is <b>required</b> to be a constant integer value.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005208
5209<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005210<p>The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer
5211 indicating the frame address of the specified call frame, or zero if it
5212 cannot be identified. The value returned by this intrinsic is likely to be
5213 incorrect or 0 for arguments other than zero, so it should only be used for
5214 debugging purposes.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005215
Bill Wendlingf85859d2009-07-20 02:29:24 +00005216<p>Note that calling this intrinsic does not prevent function inlining or other
5217 aggressive transformations, so the value returned may not be that of the
5218 obvious source-language caller.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005219
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005220</div>
5221
5222<!-- _______________________________________________________________________ -->
5223<div class="doc_subsubsection">
5224 <a name="int_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a>
5225</div>
5226
5227<div class="doc_text">
5228
5229<h5>Syntax:</h5>
5230<pre>
Chris Lattner38bd5dd2007-09-21 17:30:40 +00005231 declare i8 *@llvm.stacksave()
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005232</pre>
5233
5234<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005235<p>The '<tt>llvm.stacksave</tt>' intrinsic is used to remember the current state
5236 of the function stack, for use
5237 with <a href="#int_stackrestore"> <tt>llvm.stackrestore</tt></a>. This is
5238 useful for implementing language features like scoped automatic variable
5239 sized arrays in C99.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005240
5241<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005242<p>This intrinsic returns a opaque pointer value that can be passed
5243 to <a href="#int_stackrestore"><tt>llvm.stackrestore</tt></a>. When
5244 an <tt>llvm.stackrestore</tt> intrinsic is executed with a value saved
5245 from <tt>llvm.stacksave</tt>, it effectively restores the state of the stack
5246 to the state it was in when the <tt>llvm.stacksave</tt> intrinsic executed.
5247 In practice, this pops any <a href="#i_alloca">alloca</a> blocks from the
5248 stack that were allocated after the <tt>llvm.stacksave</tt> was executed.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005249
5250</div>
5251
5252<!-- _______________________________________________________________________ -->
5253<div class="doc_subsubsection">
5254 <a name="int_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a>
5255</div>
5256
5257<div class="doc_text">
5258
5259<h5>Syntax:</h5>
5260<pre>
5261 declare void @llvm.stackrestore(i8 * %ptr)
5262</pre>
5263
5264<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005265<p>The '<tt>llvm.stackrestore</tt>' intrinsic is used to restore the state of
5266 the function stack to the state it was in when the
5267 corresponding <a href="#int_stacksave"><tt>llvm.stacksave</tt></a> intrinsic
5268 executed. This is useful for implementing language features like scoped
5269 automatic variable sized arrays in C99.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005270
5271<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005272<p>See the description
5273 for <a href="#int_stacksave"><tt>llvm.stacksave</tt></a>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005274
5275</div>
5276
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005277<!-- _______________________________________________________________________ -->
5278<div class="doc_subsubsection">
5279 <a name="int_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a>
5280</div>
5281
5282<div class="doc_text">
5283
5284<h5>Syntax:</h5>
5285<pre>
Chris Lattner38bd5dd2007-09-21 17:30:40 +00005286 declare void @llvm.prefetch(i8* &lt;address&gt;, i32 &lt;rw&gt;, i32 &lt;locality&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005287</pre>
5288
5289<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005290<p>The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to
5291 insert a prefetch instruction if supported; otherwise, it is a noop.
5292 Prefetches have no effect on the behavior of the program but can change its
5293 performance characteristics.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005294
5295<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005296<p><tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the
5297 specifier determining if the fetch should be for a read (0) or write (1),
5298 and <tt>locality</tt> is a temporal locality specifier ranging from (0) - no
5299 locality, to (3) - extremely local keep in cache. The <tt>rw</tt>
5300 and <tt>locality</tt> arguments must be constant integers.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005301
5302<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005303<p>This intrinsic does not modify the behavior of the program. In particular,
5304 prefetches cannot trap and do not produce a value. On targets that support
5305 this intrinsic, the prefetch can provide hints to the processor cache for
5306 better performance.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005307
5308</div>
5309
5310<!-- _______________________________________________________________________ -->
5311<div class="doc_subsubsection">
5312 <a name="int_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a>
5313</div>
5314
5315<div class="doc_text">
5316
5317<h5>Syntax:</h5>
5318<pre>
Chris Lattner38bd5dd2007-09-21 17:30:40 +00005319 declare void @llvm.pcmarker(i32 &lt;id&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005320</pre>
5321
5322<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005323<p>The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a Program
5324 Counter (PC) in a region of code to simulators and other tools. The method
5325 is target specific, but it is expected that the marker will use exported
5326 symbols to transmit the PC of the marker. The marker makes no guarantees
5327 that it will remain with any specific instruction after optimizations. It is
5328 possible that the presence of a marker will inhibit optimizations. The
5329 intended use is to be inserted after optimizations to allow correlations of
5330 simulation runs.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005331
5332<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005333<p><tt>id</tt> is a numerical id identifying the marker.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005334
5335<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005336<p>This intrinsic does not modify the behavior of the program. Backends that do
5337 not support this intrinisic may ignore it.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005338
5339</div>
5340
5341<!-- _______________________________________________________________________ -->
5342<div class="doc_subsubsection">
5343 <a name="int_readcyclecounter">'<tt>llvm.readcyclecounter</tt>' Intrinsic</a>
5344</div>
5345
5346<div class="doc_text">
5347
5348<h5>Syntax:</h5>
5349<pre>
5350 declare i64 @llvm.readcyclecounter( )
5351</pre>
5352
5353<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005354<p>The '<tt>llvm.readcyclecounter</tt>' intrinsic provides access to the cycle
5355 counter register (or similar low latency, high accuracy clocks) on those
5356 targets that support it. On X86, it should map to RDTSC. On Alpha, it
5357 should map to RPCC. As the backing counters overflow quickly (on the order
5358 of 9 seconds on alpha), this should only be used for small timings.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005359
5360<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005361<p>When directly supported, reading the cycle counter should not modify any
5362 memory. Implementations are allowed to either return a application specific
5363 value or a system wide value. On backends without support, this is lowered
5364 to a constant 0.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005365
5366</div>
5367
5368<!-- ======================================================================= -->
5369<div class="doc_subsection">
5370 <a name="int_libc">Standard C Library Intrinsics</a>
5371</div>
5372
5373<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00005374
5375<p>LLVM provides intrinsics for a few important standard C library functions.
5376 These intrinsics allow source-language front-ends to pass information about
5377 the alignment of the pointer arguments to the code generator, providing
5378 opportunity for more efficient code generation.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005379
5380</div>
5381
5382<!-- _______________________________________________________________________ -->
5383<div class="doc_subsubsection">
5384 <a name="int_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
5385</div>
5386
5387<div class="doc_text">
5388
5389<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005390<p>This is an overloaded intrinsic. You can use <tt>llvm.memcpy</tt> on any
5391 integer bit width. Not all targets support all bit widths however.</p>
5392
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005393<pre>
Chris Lattner82c2e432008-11-21 16:42:48 +00005394 declare void @llvm.memcpy.i8(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Bill Wendlingf85859d2009-07-20 02:29:24 +00005395 i8 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattner82c2e432008-11-21 16:42:48 +00005396 declare void @llvm.memcpy.i16(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5397 i16 &lt;len&gt;, i32 &lt;align&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005398 declare void @llvm.memcpy.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5399 i32 &lt;len&gt;, i32 &lt;align&gt;)
5400 declare void @llvm.memcpy.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5401 i64 &lt;len&gt;, i32 &lt;align&gt;)
5402</pre>
5403
5404<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005405<p>The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the
5406 source location to the destination location.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005407
Bill Wendlingf85859d2009-07-20 02:29:24 +00005408<p>Note that, unlike the standard libc function, the <tt>llvm.memcpy.*</tt>
5409 intrinsics do not return a value, and takes an extra alignment argument.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005410
5411<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005412<p>The first argument is a pointer to the destination, the second is a pointer
5413 to the source. The third argument is an integer argument specifying the
5414 number of bytes to copy, and the fourth argument is the alignment of the
5415 source and destination locations.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005416
Bill Wendlingf85859d2009-07-20 02:29:24 +00005417<p>If the call to this intrinisic has an alignment value that is not 0 or 1,
5418 then the caller guarantees that both the source and destination pointers are
5419 aligned to that boundary.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005420
5421<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005422<p>The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the
5423 source location to the destination location, which are not allowed to
5424 overlap. It copies "len" bytes of memory over. If the argument is known to
5425 be aligned to some boundary, this can be specified as the fourth argument,
5426 otherwise it should be set to 0 or 1.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005427
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005428</div>
5429
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005430<!-- _______________________________________________________________________ -->
5431<div class="doc_subsubsection">
5432 <a name="int_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
5433</div>
5434
5435<div class="doc_text">
5436
5437<h5>Syntax:</h5>
Chris Lattner82c2e432008-11-21 16:42:48 +00005438<p>This is an overloaded intrinsic. You can use llvm.memmove on any integer bit
Bill Wendlingf85859d2009-07-20 02:29:24 +00005439 width. Not all targets support all bit widths however.</p>
5440
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005441<pre>
Chris Lattner82c2e432008-11-21 16:42:48 +00005442 declare void @llvm.memmove.i8(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Bill Wendlingf85859d2009-07-20 02:29:24 +00005443 i8 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattner82c2e432008-11-21 16:42:48 +00005444 declare void @llvm.memmove.i16(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5445 i16 &lt;len&gt;, i32 &lt;align&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005446 declare void @llvm.memmove.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5447 i32 &lt;len&gt;, i32 &lt;align&gt;)
5448 declare void @llvm.memmove.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5449 i64 &lt;len&gt;, i32 &lt;align&gt;)
5450</pre>
5451
5452<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005453<p>The '<tt>llvm.memmove.*</tt>' intrinsics move a block of memory from the
5454 source location to the destination location. It is similar to the
5455 '<tt>llvm.memcpy</tt>' intrinsic but allows the two memory locations to
5456 overlap.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005457
Bill Wendlingf85859d2009-07-20 02:29:24 +00005458<p>Note that, unlike the standard libc function, the <tt>llvm.memmove.*</tt>
5459 intrinsics do not return a value, and takes an extra alignment argument.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005460
5461<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005462<p>The first argument is a pointer to the destination, the second is a pointer
5463 to the source. The third argument is an integer argument specifying the
5464 number of bytes to copy, and the fourth argument is the alignment of the
5465 source and destination locations.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005466
Bill Wendlingf85859d2009-07-20 02:29:24 +00005467<p>If the call to this intrinisic has an alignment value that is not 0 or 1,
5468 then the caller guarantees that the source and destination pointers are
5469 aligned to that boundary.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005470
5471<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005472<p>The '<tt>llvm.memmove.*</tt>' intrinsics copy a block of memory from the
5473 source location to the destination location, which may overlap. It copies
5474 "len" bytes of memory over. If the argument is known to be aligned to some
5475 boundary, this can be specified as the fourth argument, otherwise it should
5476 be set to 0 or 1.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005477
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005478</div>
5479
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005480<!-- _______________________________________________________________________ -->
5481<div class="doc_subsubsection">
5482 <a name="int_memset">'<tt>llvm.memset.*</tt>' Intrinsics</a>
5483</div>
5484
5485<div class="doc_text">
5486
5487<h5>Syntax:</h5>
Chris Lattner82c2e432008-11-21 16:42:48 +00005488<p>This is an overloaded intrinsic. You can use llvm.memset on any integer bit
Bill Wendlingf85859d2009-07-20 02:29:24 +00005489 width. Not all targets support all bit widths however.</p>
5490
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005491<pre>
Chris Lattner82c2e432008-11-21 16:42:48 +00005492 declare void @llvm.memset.i8(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
Bill Wendlingf85859d2009-07-20 02:29:24 +00005493 i8 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattner82c2e432008-11-21 16:42:48 +00005494 declare void @llvm.memset.i16(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
5495 i16 &lt;len&gt;, i32 &lt;align&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005496 declare void @llvm.memset.i32(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
5497 i32 &lt;len&gt;, i32 &lt;align&gt;)
5498 declare void @llvm.memset.i64(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
5499 i64 &lt;len&gt;, i32 &lt;align&gt;)
5500</pre>
5501
5502<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005503<p>The '<tt>llvm.memset.*</tt>' intrinsics fill a block of memory with a
5504 particular byte value.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005505
Bill Wendlingf85859d2009-07-20 02:29:24 +00005506<p>Note that, unlike the standard libc function, the <tt>llvm.memset</tt>
5507 intrinsic does not return a value, and takes an extra alignment argument.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005508
5509<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005510<p>The first argument is a pointer to the destination to fill, the second is the
5511 byte value to fill it with, the third argument is an integer argument
5512 specifying the number of bytes to fill, and the fourth argument is the known
5513 alignment of destination location.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005514
Bill Wendlingf85859d2009-07-20 02:29:24 +00005515<p>If the call to this intrinisic has an alignment value that is not 0 or 1,
5516 then the caller guarantees that the destination pointer is aligned to that
5517 boundary.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005518
5519<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005520<p>The '<tt>llvm.memset.*</tt>' intrinsics fill "len" bytes of memory starting
5521 at the destination location. If the argument is known to be aligned to some
5522 boundary, this can be specified as the fourth argument, otherwise it should
5523 be set to 0 or 1.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005524
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005525</div>
5526
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005527<!-- _______________________________________________________________________ -->
5528<div class="doc_subsubsection">
5529 <a name="int_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a>
5530</div>
5531
5532<div class="doc_text">
5533
5534<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005535<p>This is an overloaded intrinsic. You can use <tt>llvm.sqrt</tt> on any
5536 floating point or vector of floating point type. Not all targets support all
5537 types however.</p>
5538
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005539<pre>
Dale Johannesenf9adbb62007-10-02 17:47:38 +00005540 declare float @llvm.sqrt.f32(float %Val)
5541 declare double @llvm.sqrt.f64(double %Val)
5542 declare x86_fp80 @llvm.sqrt.f80(x86_fp80 %Val)
5543 declare fp128 @llvm.sqrt.f128(fp128 %Val)
5544 declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005545</pre>
5546
5547<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005548<p>The '<tt>llvm.sqrt</tt>' intrinsics return the sqrt of the specified operand,
5549 returning the same value as the libm '<tt>sqrt</tt>' functions would.
5550 Unlike <tt>sqrt</tt> in libm, however, <tt>llvm.sqrt</tt> has undefined
5551 behavior for negative numbers other than -0.0 (which allows for better
5552 optimization, because there is no need to worry about errno being
5553 set). <tt>llvm.sqrt(-0.0)</tt> is defined to return -0.0 like IEEE sqrt.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005554
5555<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005556<p>The argument and return value are floating point numbers of the same
5557 type.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005558
5559<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005560<p>This function returns the sqrt of the specified operand if it is a
5561 nonnegative floating point number.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005562
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005563</div>
5564
5565<!-- _______________________________________________________________________ -->
5566<div class="doc_subsubsection">
5567 <a name="int_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a>
5568</div>
5569
5570<div class="doc_text">
5571
5572<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005573<p>This is an overloaded intrinsic. You can use <tt>llvm.powi</tt> on any
5574 floating point or vector of floating point type. Not all targets support all
5575 types however.</p>
5576
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005577<pre>
Dale Johannesenf9adbb62007-10-02 17:47:38 +00005578 declare float @llvm.powi.f32(float %Val, i32 %power)
5579 declare double @llvm.powi.f64(double %Val, i32 %power)
5580 declare x86_fp80 @llvm.powi.f80(x86_fp80 %Val, i32 %power)
5581 declare fp128 @llvm.powi.f128(fp128 %Val, i32 %power)
5582 declare ppc_fp128 @llvm.powi.ppcf128(ppc_fp128 %Val, i32 %power)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005583</pre>
5584
5585<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005586<p>The '<tt>llvm.powi.*</tt>' intrinsics return the first operand raised to the
5587 specified (positive or negative) power. The order of evaluation of
5588 multiplications is not defined. When a vector of floating point type is
5589 used, the second argument remains a scalar integer value.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005590
5591<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005592<p>The second argument is an integer power, and the first is a value to raise to
5593 that power.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005594
5595<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005596<p>This function returns the first value raised to the second power with an
5597 unspecified sequence of rounding operations.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005598
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005599</div>
5600
Dan Gohman361079c2007-10-15 20:30:11 +00005601<!-- _______________________________________________________________________ -->
5602<div class="doc_subsubsection">
5603 <a name="int_sin">'<tt>llvm.sin.*</tt>' Intrinsic</a>
5604</div>
5605
5606<div class="doc_text">
5607
5608<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005609<p>This is an overloaded intrinsic. You can use <tt>llvm.sin</tt> on any
5610 floating point or vector of floating point type. Not all targets support all
5611 types however.</p>
5612
Dan Gohman361079c2007-10-15 20:30:11 +00005613<pre>
5614 declare float @llvm.sin.f32(float %Val)
5615 declare double @llvm.sin.f64(double %Val)
5616 declare x86_fp80 @llvm.sin.f80(x86_fp80 %Val)
5617 declare fp128 @llvm.sin.f128(fp128 %Val)
5618 declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128 %Val)
5619</pre>
5620
5621<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005622<p>The '<tt>llvm.sin.*</tt>' intrinsics return the sine of the operand.</p>
Dan Gohman361079c2007-10-15 20:30:11 +00005623
5624<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005625<p>The argument and return value are floating point numbers of the same
5626 type.</p>
Dan Gohman361079c2007-10-15 20:30:11 +00005627
5628<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005629<p>This function returns the sine of the specified operand, returning the same
5630 values as the libm <tt>sin</tt> functions would, and handles error conditions
5631 in the same way.</p>
Dan Gohman361079c2007-10-15 20:30:11 +00005632
Dan Gohman361079c2007-10-15 20:30:11 +00005633</div>
5634
5635<!-- _______________________________________________________________________ -->
5636<div class="doc_subsubsection">
5637 <a name="int_cos">'<tt>llvm.cos.*</tt>' Intrinsic</a>
5638</div>
5639
5640<div class="doc_text">
5641
5642<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005643<p>This is an overloaded intrinsic. You can use <tt>llvm.cos</tt> on any
5644 floating point or vector of floating point type. Not all targets support all
5645 types however.</p>
5646
Dan Gohman361079c2007-10-15 20:30:11 +00005647<pre>
5648 declare float @llvm.cos.f32(float %Val)
5649 declare double @llvm.cos.f64(double %Val)
5650 declare x86_fp80 @llvm.cos.f80(x86_fp80 %Val)
5651 declare fp128 @llvm.cos.f128(fp128 %Val)
5652 declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128 %Val)
5653</pre>
5654
5655<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005656<p>The '<tt>llvm.cos.*</tt>' intrinsics return the cosine of the operand.</p>
Dan Gohman361079c2007-10-15 20:30:11 +00005657
5658<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005659<p>The argument and return value are floating point numbers of the same
5660 type.</p>
Dan Gohman361079c2007-10-15 20:30:11 +00005661
5662<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005663<p>This function returns the cosine of the specified operand, returning the same
5664 values as the libm <tt>cos</tt> functions would, and handles error conditions
5665 in the same way.</p>
Dan Gohman361079c2007-10-15 20:30:11 +00005666
Dan Gohman361079c2007-10-15 20:30:11 +00005667</div>
5668
5669<!-- _______________________________________________________________________ -->
5670<div class="doc_subsubsection">
5671 <a name="int_pow">'<tt>llvm.pow.*</tt>' Intrinsic</a>
5672</div>
5673
5674<div class="doc_text">
5675
5676<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005677<p>This is an overloaded intrinsic. You can use <tt>llvm.pow</tt> on any
5678 floating point or vector of floating point type. Not all targets support all
5679 types however.</p>
5680
Dan Gohman361079c2007-10-15 20:30:11 +00005681<pre>
5682 declare float @llvm.pow.f32(float %Val, float %Power)
5683 declare double @llvm.pow.f64(double %Val, double %Power)
5684 declare x86_fp80 @llvm.pow.f80(x86_fp80 %Val, x86_fp80 %Power)
5685 declare fp128 @llvm.pow.f128(fp128 %Val, fp128 %Power)
5686 declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128 %Val, ppc_fp128 Power)
5687</pre>
5688
5689<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005690<p>The '<tt>llvm.pow.*</tt>' intrinsics return the first operand raised to the
5691 specified (positive or negative) power.</p>
Dan Gohman361079c2007-10-15 20:30:11 +00005692
5693<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005694<p>The second argument is a floating point power, and the first is a value to
5695 raise to that power.</p>
Dan Gohman361079c2007-10-15 20:30:11 +00005696
5697<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005698<p>This function returns the first value raised to the second power, returning
5699 the same values as the libm <tt>pow</tt> functions would, and handles error
5700 conditions in the same way.</p>
Dan Gohman361079c2007-10-15 20:30:11 +00005701
Dan Gohman361079c2007-10-15 20:30:11 +00005702</div>
5703
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005704<!-- ======================================================================= -->
5705<div class="doc_subsection">
5706 <a name="int_manip">Bit Manipulation Intrinsics</a>
5707</div>
5708
5709<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00005710
5711<p>LLVM provides intrinsics for a few important bit manipulation operations.
5712 These allow efficient code generation for some algorithms.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005713
5714</div>
5715
5716<!-- _______________________________________________________________________ -->
5717<div class="doc_subsubsection">
5718 <a name="int_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a>
5719</div>
5720
5721<div class="doc_text">
5722
5723<h5>Syntax:</h5>
5724<p>This is an overloaded intrinsic function. You can use bswap on any integer
Bill Wendlingf85859d2009-07-20 02:29:24 +00005725 type that is an even number of bytes (i.e. BitWidth % 16 == 0).</p>
5726
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005727<pre>
Chandler Carrutha228e392007-08-04 01:51:18 +00005728 declare i16 @llvm.bswap.i16(i16 &lt;id&gt;)
5729 declare i32 @llvm.bswap.i32(i32 &lt;id&gt;)
5730 declare i64 @llvm.bswap.i64(i64 &lt;id&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005731</pre>
5732
5733<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005734<p>The '<tt>llvm.bswap</tt>' family of intrinsics is used to byte swap integer
5735 values with an even number of bytes (positive multiple of 16 bits). These
5736 are useful for performing operations on data that is not in the target's
5737 native byte order.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005738
5739<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005740<p>The <tt>llvm.bswap.i16</tt> intrinsic returns an i16 value that has the high
5741 and low byte of the input i16 swapped. Similarly,
5742 the <tt>llvm.bswap.i32</tt> intrinsic returns an i32 value that has the four
5743 bytes of the input i32 swapped, so that if the input bytes are numbered 0, 1,
5744 2, 3 then the returned i32 will have its bytes in 3, 2, 1, 0 order.
5745 The <tt>llvm.bswap.i48</tt>, <tt>llvm.bswap.i64</tt> and other intrinsics
5746 extend this concept to additional even-byte lengths (6 bytes, 8 bytes and
5747 more, respectively).</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005748
5749</div>
5750
5751<!-- _______________________________________________________________________ -->
5752<div class="doc_subsubsection">
5753 <a name="int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic</a>
5754</div>
5755
5756<div class="doc_text">
5757
5758<h5>Syntax:</h5>
5759<p>This is an overloaded intrinsic. You can use llvm.ctpop on any integer bit
Bill Wendlingf85859d2009-07-20 02:29:24 +00005760 width. Not all targets support all bit widths however.</p>
5761
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005762<pre>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005763 declare i8 @llvm.ctpop.i8(i8 &lt;src&gt;)
Chandler Carrutha228e392007-08-04 01:51:18 +00005764 declare i16 @llvm.ctpop.i16(i16 &lt;src&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005765 declare i32 @llvm.ctpop.i32(i32 &lt;src&gt;)
Chandler Carrutha228e392007-08-04 01:51:18 +00005766 declare i64 @llvm.ctpop.i64(i64 &lt;src&gt;)
5767 declare i256 @llvm.ctpop.i256(i256 &lt;src&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005768</pre>
5769
5770<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005771<p>The '<tt>llvm.ctpop</tt>' family of intrinsics counts the number of bits set
5772 in a value.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005773
5774<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005775<p>The only argument is the value to be counted. The argument may be of any
5776 integer type. The return type must match the argument type.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005777
5778<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005779<p>The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005780
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005781</div>
5782
5783<!-- _______________________________________________________________________ -->
5784<div class="doc_subsubsection">
5785 <a name="int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic</a>
5786</div>
5787
5788<div class="doc_text">
5789
5790<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005791<p>This is an overloaded intrinsic. You can use <tt>llvm.ctlz</tt> on any
5792 integer bit width. Not all targets support all bit widths however.</p>
5793
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005794<pre>
Chandler Carrutha228e392007-08-04 01:51:18 +00005795 declare i8 @llvm.ctlz.i8 (i8 &lt;src&gt;)
5796 declare i16 @llvm.ctlz.i16(i16 &lt;src&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005797 declare i32 @llvm.ctlz.i32(i32 &lt;src&gt;)
Chandler Carrutha228e392007-08-04 01:51:18 +00005798 declare i64 @llvm.ctlz.i64(i64 &lt;src&gt;)
5799 declare i256 @llvm.ctlz.i256(i256 &lt;src&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005800</pre>
5801
5802<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005803<p>The '<tt>llvm.ctlz</tt>' family of intrinsic functions counts the number of
5804 leading zeros in a variable.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005805
5806<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005807<p>The only argument is the value to be counted. The argument may be of any
5808 integer type. The return type must match the argument type.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005809
5810<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005811<p>The '<tt>llvm.ctlz</tt>' intrinsic counts the leading (most significant)
5812 zeros in a variable. If the src == 0 then the result is the size in bits of
5813 the type of src. For example, <tt>llvm.ctlz(i32 2) = 30</tt>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005814
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005815</div>
5816
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005817<!-- _______________________________________________________________________ -->
5818<div class="doc_subsubsection">
5819 <a name="int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic</a>
5820</div>
5821
5822<div class="doc_text">
5823
5824<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005825<p>This is an overloaded intrinsic. You can use <tt>llvm.cttz</tt> on any
5826 integer bit width. Not all targets support all bit widths however.</p>
5827
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005828<pre>
Chandler Carrutha228e392007-08-04 01:51:18 +00005829 declare i8 @llvm.cttz.i8 (i8 &lt;src&gt;)
5830 declare i16 @llvm.cttz.i16(i16 &lt;src&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005831 declare i32 @llvm.cttz.i32(i32 &lt;src&gt;)
Chandler Carrutha228e392007-08-04 01:51:18 +00005832 declare i64 @llvm.cttz.i64(i64 &lt;src&gt;)
5833 declare i256 @llvm.cttz.i256(i256 &lt;src&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005834</pre>
5835
5836<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005837<p>The '<tt>llvm.cttz</tt>' family of intrinsic functions counts the number of
5838 trailing zeros.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005839
5840<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005841<p>The only argument is the value to be counted. The argument may be of any
5842 integer type. The return type must match the argument type.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005843
5844<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005845<p>The '<tt>llvm.cttz</tt>' intrinsic counts the trailing (least significant)
5846 zeros in a variable. If the src == 0 then the result is the size in bits of
5847 the type of src. For example, <tt>llvm.cttz(2) = 1</tt>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005848
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005849</div>
5850
Bill Wendling3e1258b2009-02-08 04:04:40 +00005851<!-- ======================================================================= -->
5852<div class="doc_subsection">
5853 <a name="int_overflow">Arithmetic with Overflow Intrinsics</a>
5854</div>
5855
5856<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00005857
5858<p>LLVM provides intrinsics for some arithmetic with overflow operations.</p>
Bill Wendling3e1258b2009-02-08 04:04:40 +00005859
5860</div>
5861
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005862<!-- _______________________________________________________________________ -->
5863<div class="doc_subsubsection">
Bill Wendling3e1258b2009-02-08 04:04:40 +00005864 <a name="int_sadd_overflow">'<tt>llvm.sadd.with.overflow.*</tt>' Intrinsics</a>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005865</div>
5866
5867<div class="doc_text">
5868
5869<h5>Syntax:</h5>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005870<p>This is an overloaded intrinsic. You can use <tt>llvm.sadd.with.overflow</tt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005871 on any integer bit width.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005872
5873<pre>
5874 declare {i16, i1} @llvm.sadd.with.overflow.i16(i16 %a, i16 %b)
5875 declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
5876 declare {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 %b)
5877</pre>
5878
5879<h5>Overview:</h5>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005880<p>The '<tt>llvm.sadd.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingf85859d2009-07-20 02:29:24 +00005881 a signed addition of the two arguments, and indicate whether an overflow
5882 occurred during the signed summation.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005883
5884<h5>Arguments:</h5>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005885<p>The arguments (%a and %b) and the first element of the result structure may
Bill Wendlingf85859d2009-07-20 02:29:24 +00005886 be of integer types of any bit width, but they must have the same bit
5887 width. The second element of the result structure must be of
5888 type <tt>i1</tt>. <tt>%a</tt> and <tt>%b</tt> are the two values that will
5889 undergo signed addition.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005890
5891<h5>Semantics:</h5>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005892<p>The '<tt>llvm.sadd.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingf85859d2009-07-20 02:29:24 +00005893 a signed addition of the two variables. They return a structure &mdash; the
5894 first element of which is the signed summation, and the second element of
5895 which is a bit specifying if the signed summation resulted in an
5896 overflow.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005897
5898<h5>Examples:</h5>
5899<pre>
5900 %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
5901 %sum = extractvalue {i32, i1} %res, 0
5902 %obit = extractvalue {i32, i1} %res, 1
5903 br i1 %obit, label %overflow, label %normal
5904</pre>
5905
5906</div>
5907
5908<!-- _______________________________________________________________________ -->
5909<div class="doc_subsubsection">
Bill Wendling3e1258b2009-02-08 04:04:40 +00005910 <a name="int_uadd_overflow">'<tt>llvm.uadd.with.overflow.*</tt>' Intrinsics</a>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005911</div>
5912
5913<div class="doc_text">
5914
5915<h5>Syntax:</h5>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005916<p>This is an overloaded intrinsic. You can use <tt>llvm.uadd.with.overflow</tt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005917 on any integer bit width.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005918
5919<pre>
5920 declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b)
5921 declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
5922 declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b)
5923</pre>
5924
5925<h5>Overview:</h5>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005926<p>The '<tt>llvm.uadd.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingf85859d2009-07-20 02:29:24 +00005927 an unsigned addition of the two arguments, and indicate whether a carry
5928 occurred during the unsigned summation.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005929
5930<h5>Arguments:</h5>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005931<p>The arguments (%a and %b) and the first element of the result structure may
Bill Wendlingf85859d2009-07-20 02:29:24 +00005932 be of integer types of any bit width, but they must have the same bit
5933 width. The second element of the result structure must be of
5934 type <tt>i1</tt>. <tt>%a</tt> and <tt>%b</tt> are the two values that will
5935 undergo unsigned addition.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005936
5937<h5>Semantics:</h5>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005938<p>The '<tt>llvm.uadd.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingf85859d2009-07-20 02:29:24 +00005939 an unsigned addition of the two arguments. They return a structure &mdash;
5940 the first element of which is the sum, and the second element of which is a
5941 bit specifying if the unsigned summation resulted in a carry.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005942
5943<h5>Examples:</h5>
5944<pre>
5945 %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
5946 %sum = extractvalue {i32, i1} %res, 0
5947 %obit = extractvalue {i32, i1} %res, 1
5948 br i1 %obit, label %carry, label %normal
5949</pre>
5950
5951</div>
5952
5953<!-- _______________________________________________________________________ -->
5954<div class="doc_subsubsection">
Bill Wendling3e1258b2009-02-08 04:04:40 +00005955 <a name="int_ssub_overflow">'<tt>llvm.ssub.with.overflow.*</tt>' Intrinsics</a>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005956</div>
5957
5958<div class="doc_text">
5959
5960<h5>Syntax:</h5>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005961<p>This is an overloaded intrinsic. You can use <tt>llvm.ssub.with.overflow</tt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00005962 on any integer bit width.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005963
5964<pre>
5965 declare {i16, i1} @llvm.ssub.with.overflow.i16(i16 %a, i16 %b)
5966 declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
5967 declare {i64, i1} @llvm.ssub.with.overflow.i64(i64 %a, i64 %b)
5968</pre>
5969
5970<h5>Overview:</h5>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005971<p>The '<tt>llvm.ssub.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingf85859d2009-07-20 02:29:24 +00005972 a signed subtraction of the two arguments, and indicate whether an overflow
5973 occurred during the signed subtraction.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005974
5975<h5>Arguments:</h5>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005976<p>The arguments (%a and %b) and the first element of the result structure may
Bill Wendlingf85859d2009-07-20 02:29:24 +00005977 be of integer types of any bit width, but they must have the same bit
5978 width. The second element of the result structure must be of
5979 type <tt>i1</tt>. <tt>%a</tt> and <tt>%b</tt> are the two values that will
5980 undergo signed subtraction.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005981
5982<h5>Semantics:</h5>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005983<p>The '<tt>llvm.ssub.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingf85859d2009-07-20 02:29:24 +00005984 a signed subtraction of the two arguments. They return a structure &mdash;
5985 the first element of which is the subtraction, and the second element of
5986 which is a bit specifying if the signed subtraction resulted in an
5987 overflow.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005988
5989<h5>Examples:</h5>
5990<pre>
5991 %res = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
5992 %sum = extractvalue {i32, i1} %res, 0
5993 %obit = extractvalue {i32, i1} %res, 1
5994 br i1 %obit, label %overflow, label %normal
5995</pre>
5996
5997</div>
5998
5999<!-- _______________________________________________________________________ -->
6000<div class="doc_subsubsection">
Bill Wendling3e1258b2009-02-08 04:04:40 +00006001 <a name="int_usub_overflow">'<tt>llvm.usub.with.overflow.*</tt>' Intrinsics</a>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006002</div>
6003
6004<div class="doc_text">
6005
6006<h5>Syntax:</h5>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006007<p>This is an overloaded intrinsic. You can use <tt>llvm.usub.with.overflow</tt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006008 on any integer bit width.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006009
6010<pre>
6011 declare {i16, i1} @llvm.usub.with.overflow.i16(i16 %a, i16 %b)
6012 declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
6013 declare {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b)
6014</pre>
6015
6016<h5>Overview:</h5>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006017<p>The '<tt>llvm.usub.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingf85859d2009-07-20 02:29:24 +00006018 an unsigned subtraction of the two arguments, and indicate whether an
6019 overflow occurred during the unsigned subtraction.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006020
6021<h5>Arguments:</h5>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006022<p>The arguments (%a and %b) and the first element of the result structure may
Bill Wendlingf85859d2009-07-20 02:29:24 +00006023 be of integer types of any bit width, but they must have the same bit
6024 width. The second element of the result structure must be of
6025 type <tt>i1</tt>. <tt>%a</tt> and <tt>%b</tt> are the two values that will
6026 undergo unsigned subtraction.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006027
6028<h5>Semantics:</h5>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006029<p>The '<tt>llvm.usub.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingf85859d2009-07-20 02:29:24 +00006030 an unsigned subtraction of the two arguments. They return a structure &mdash;
6031 the first element of which is the subtraction, and the second element of
6032 which is a bit specifying if the unsigned subtraction resulted in an
6033 overflow.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006034
6035<h5>Examples:</h5>
6036<pre>
6037 %res = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
6038 %sum = extractvalue {i32, i1} %res, 0
6039 %obit = extractvalue {i32, i1} %res, 1
6040 br i1 %obit, label %overflow, label %normal
6041</pre>
6042
6043</div>
6044
6045<!-- _______________________________________________________________________ -->
6046<div class="doc_subsubsection">
Bill Wendling3e1258b2009-02-08 04:04:40 +00006047 <a name="int_smul_overflow">'<tt>llvm.smul.with.overflow.*</tt>' Intrinsics</a>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006048</div>
6049
6050<div class="doc_text">
6051
6052<h5>Syntax:</h5>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006053<p>This is an overloaded intrinsic. You can use <tt>llvm.smul.with.overflow</tt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006054 on any integer bit width.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006055
6056<pre>
6057 declare {i16, i1} @llvm.smul.with.overflow.i16(i16 %a, i16 %b)
6058 declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
6059 declare {i64, i1} @llvm.smul.with.overflow.i64(i64 %a, i64 %b)
6060</pre>
6061
6062<h5>Overview:</h5>
6063
6064<p>The '<tt>llvm.smul.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingf85859d2009-07-20 02:29:24 +00006065 a signed multiplication of the two arguments, and indicate whether an
6066 overflow occurred during the signed multiplication.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006067
6068<h5>Arguments:</h5>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006069<p>The arguments (%a and %b) and the first element of the result structure may
Bill Wendlingf85859d2009-07-20 02:29:24 +00006070 be of integer types of any bit width, but they must have the same bit
6071 width. The second element of the result structure must be of
6072 type <tt>i1</tt>. <tt>%a</tt> and <tt>%b</tt> are the two values that will
6073 undergo signed multiplication.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006074
6075<h5>Semantics:</h5>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006076<p>The '<tt>llvm.smul.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingf85859d2009-07-20 02:29:24 +00006077 a signed multiplication of the two arguments. They return a structure &mdash;
6078 the first element of which is the multiplication, and the second element of
6079 which is a bit specifying if the signed multiplication resulted in an
6080 overflow.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006081
6082<h5>Examples:</h5>
6083<pre>
6084 %res = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
6085 %sum = extractvalue {i32, i1} %res, 0
6086 %obit = extractvalue {i32, i1} %res, 1
6087 br i1 %obit, label %overflow, label %normal
6088</pre>
6089
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006090</div>
6091
Bill Wendlingbda98b62009-02-08 23:00:09 +00006092<!-- _______________________________________________________________________ -->
6093<div class="doc_subsubsection">
6094 <a name="int_umul_overflow">'<tt>llvm.umul.with.overflow.*</tt>' Intrinsics</a>
6095</div>
6096
6097<div class="doc_text">
6098
6099<h5>Syntax:</h5>
Bill Wendlingbda98b62009-02-08 23:00:09 +00006100<p>This is an overloaded intrinsic. You can use <tt>llvm.umul.with.overflow</tt>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006101 on any integer bit width.</p>
Bill Wendlingbda98b62009-02-08 23:00:09 +00006102
6103<pre>
6104 declare {i16, i1} @llvm.umul.with.overflow.i16(i16 %a, i16 %b)
6105 declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
6106 declare {i64, i1} @llvm.umul.with.overflow.i64(i64 %a, i64 %b)
6107</pre>
6108
6109<h5>Overview:</h5>
Bill Wendlingbda98b62009-02-08 23:00:09 +00006110<p>The '<tt>llvm.umul.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingf85859d2009-07-20 02:29:24 +00006111 a unsigned multiplication of the two arguments, and indicate whether an
6112 overflow occurred during the unsigned multiplication.</p>
Bill Wendlingbda98b62009-02-08 23:00:09 +00006113
6114<h5>Arguments:</h5>
Bill Wendlingbda98b62009-02-08 23:00:09 +00006115<p>The arguments (%a and %b) and the first element of the result structure may
Bill Wendlingf85859d2009-07-20 02:29:24 +00006116 be of integer types of any bit width, but they must have the same bit
6117 width. The second element of the result structure must be of
6118 type <tt>i1</tt>. <tt>%a</tt> and <tt>%b</tt> are the two values that will
6119 undergo unsigned multiplication.</p>
Bill Wendlingbda98b62009-02-08 23:00:09 +00006120
6121<h5>Semantics:</h5>
Bill Wendlingbda98b62009-02-08 23:00:09 +00006122<p>The '<tt>llvm.umul.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingf85859d2009-07-20 02:29:24 +00006123 an unsigned multiplication of the two arguments. They return a structure
6124 &mdash; the first element of which is the multiplication, and the second
6125 element of which is a bit specifying if the unsigned multiplication resulted
6126 in an overflow.</p>
Bill Wendlingbda98b62009-02-08 23:00:09 +00006127
6128<h5>Examples:</h5>
6129<pre>
6130 %res = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
6131 %sum = extractvalue {i32, i1} %res, 0
6132 %obit = extractvalue {i32, i1} %res, 1
6133 br i1 %obit, label %overflow, label %normal
6134</pre>
6135
6136</div>
6137
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006138<!-- ======================================================================= -->
6139<div class="doc_subsection">
6140 <a name="int_debugger">Debugger Intrinsics</a>
6141</div>
6142
6143<div class="doc_text">
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006144
Bill Wendlingf85859d2009-07-20 02:29:24 +00006145<p>The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt>
6146 prefix), are described in
6147 the <a href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source
6148 Level Debugging</a> document.</p>
6149
6150</div>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006151
6152<!-- ======================================================================= -->
6153<div class="doc_subsection">
6154 <a name="int_eh">Exception Handling Intrinsics</a>
6155</div>
6156
6157<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00006158
6159<p>The LLVM exception handling intrinsics (which all start with
6160 <tt>llvm.eh.</tt> prefix), are described in
6161 the <a href="ExceptionHandling.html#format_common_intrinsics">LLVM Exception
6162 Handling</a> document.</p>
6163
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006164</div>
6165
6166<!-- ======================================================================= -->
6167<div class="doc_subsection">
Duncan Sands7407a9f2007-09-11 14:10:23 +00006168 <a name="int_trampoline">Trampoline Intrinsic</a>
Duncan Sands38947cd2007-07-27 12:58:54 +00006169</div>
6170
6171<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00006172
6173<p>This intrinsic makes it possible to excise one parameter, marked with
6174 the <tt>nest</tt> attribute, from a function. The result is a callable
6175 function pointer lacking the nest parameter - the caller does not need to
6176 provide a value for it. Instead, the value to use is stored in advance in a
6177 "trampoline", a block of memory usually allocated on the stack, which also
6178 contains code to splice the nest value into the argument list. This is used
6179 to implement the GCC nested function address extension.</p>
6180
6181<p>For example, if the function is
6182 <tt>i32 f(i8* nest %c, i32 %x, i32 %y)</tt> then the resulting function
6183 pointer has signature <tt>i32 (i32, i32)*</tt>. It can be created as
6184 follows:</p>
6185
6186<div class="doc_code">
Duncan Sands38947cd2007-07-27 12:58:54 +00006187<pre>
Duncan Sands7407a9f2007-09-11 14:10:23 +00006188 %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86
6189 %tramp1 = getelementptr [10 x i8]* %tramp, i32 0, i32 0
6190 %p = call i8* @llvm.init.trampoline( i8* %tramp1, i8* bitcast (i32 (i8* nest , i32, i32)* @f to i8*), i8* %nval )
6191 %fp = bitcast i8* %p to i32 (i32, i32)*
Duncan Sands38947cd2007-07-27 12:58:54 +00006192</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006193</div>
6194
6195<p>The call <tt>%val = call i32 %fp( i32 %x, i32 %y )</tt> is then equivalent
6196 to <tt>%val = call i32 %f( i8* %nval, i32 %x, i32 %y )</tt>.</p>
6197
Duncan Sands38947cd2007-07-27 12:58:54 +00006198</div>
6199
6200<!-- _______________________________________________________________________ -->
6201<div class="doc_subsubsection">
6202 <a name="int_it">'<tt>llvm.init.trampoline</tt>' Intrinsic</a>
6203</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006204
Duncan Sands38947cd2007-07-27 12:58:54 +00006205<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00006206
Duncan Sands38947cd2007-07-27 12:58:54 +00006207<h5>Syntax:</h5>
6208<pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006209 declare i8* @llvm.init.trampoline(i8* &lt;tramp&gt;, i8* &lt;func&gt;, i8* &lt;nval&gt;)
Duncan Sands38947cd2007-07-27 12:58:54 +00006210</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006211
Duncan Sands38947cd2007-07-27 12:58:54 +00006212<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006213<p>This fills the memory pointed to by <tt>tramp</tt> with code and returns a
6214 function pointer suitable for executing it.</p>
6215
Duncan Sands38947cd2007-07-27 12:58:54 +00006216<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006217<p>The <tt>llvm.init.trampoline</tt> intrinsic takes three arguments, all
6218 pointers. The <tt>tramp</tt> argument must point to a sufficiently large and
6219 sufficiently aligned block of memory; this memory is written to by the
6220 intrinsic. Note that the size and the alignment are target-specific - LLVM
6221 currently provides no portable way of determining them, so a front-end that
6222 generates this intrinsic needs to have some target-specific knowledge.
6223 The <tt>func</tt> argument must hold a function bitcast to
6224 an <tt>i8*</tt>.</p>
6225
Duncan Sands38947cd2007-07-27 12:58:54 +00006226<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006227<p>The block of memory pointed to by <tt>tramp</tt> is filled with target
6228 dependent code, turning it into a function. A pointer to this function is
6229 returned, but needs to be bitcast to an <a href="#int_trampoline">appropriate
6230 function pointer type</a> before being called. The new function's signature
6231 is the same as that of <tt>func</tt> with any arguments marked with
6232 the <tt>nest</tt> attribute removed. At most one such <tt>nest</tt> argument
6233 is allowed, and it must be of pointer type. Calling the new function is
6234 equivalent to calling <tt>func</tt> with the same argument list, but
6235 with <tt>nval</tt> used for the missing <tt>nest</tt> argument. If, after
6236 calling <tt>llvm.init.trampoline</tt>, the memory pointed to
6237 by <tt>tramp</tt> is modified, then the effect of any later call to the
6238 returned function pointer is undefined.</p>
6239
Duncan Sands38947cd2007-07-27 12:58:54 +00006240</div>
6241
6242<!-- ======================================================================= -->
6243<div class="doc_subsection">
Andrew Lenharth785610d2008-02-16 01:24:58 +00006244 <a name="int_atomics">Atomic Operations and Synchronization Intrinsics</a>
6245</div>
6246
6247<div class="doc_text">
Andrew Lenharth785610d2008-02-16 01:24:58 +00006248
Bill Wendlingf85859d2009-07-20 02:29:24 +00006249<p>These intrinsic functions expand the "universal IR" of LLVM to represent
6250 hardware constructs for atomic operations and memory synchronization. This
6251 provides an interface to the hardware, not an interface to the programmer. It
6252 is aimed at a low enough level to allow any programming models or APIs
6253 (Application Programming Interfaces) which need atomic behaviors to map
6254 cleanly onto it. It is also modeled primarily on hardware behavior. Just as
6255 hardware provides a "universal IR" for source languages, it also provides a
6256 starting point for developing a "universal" atomic operation and
6257 synchronization IR.</p>
6258
6259<p>These do <em>not</em> form an API such as high-level threading libraries,
6260 software transaction memory systems, atomic primitives, and intrinsic
6261 functions as found in BSD, GNU libc, atomic_ops, APR, and other system and
6262 application libraries. The hardware interface provided by LLVM should allow
6263 a clean implementation of all of these APIs and parallel programming models.
6264 No one model or paradigm should be selected above others unless the hardware
6265 itself ubiquitously does so.</p>
6266
Andrew Lenharth785610d2008-02-16 01:24:58 +00006267</div>
6268
6269<!-- _______________________________________________________________________ -->
6270<div class="doc_subsubsection">
6271 <a name="int_memory_barrier">'<tt>llvm.memory.barrier</tt>' Intrinsic</a>
6272</div>
6273<div class="doc_text">
6274<h5>Syntax:</h5>
6275<pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006276 declare void @llvm.memory.barrier( i1 &lt;ll&gt;, i1 &lt;ls&gt;, i1 &lt;sl&gt;, i1 &lt;ss&gt;, i1 &lt;device&gt; )
Andrew Lenharth785610d2008-02-16 01:24:58 +00006277</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006278
Andrew Lenharth785610d2008-02-16 01:24:58 +00006279<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006280<p>The <tt>llvm.memory.barrier</tt> intrinsic guarantees ordering between
6281 specific pairs of memory access types.</p>
6282
Andrew Lenharth785610d2008-02-16 01:24:58 +00006283<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006284<p>The <tt>llvm.memory.barrier</tt> intrinsic requires five boolean arguments.
6285 The first four arguments enables a specific barrier as listed below. The
6286 fith argument specifies that the barrier applies to io or device or uncached
6287 memory.</p>
Andrew Lenharth785610d2008-02-16 01:24:58 +00006288
Bill Wendlingf85859d2009-07-20 02:29:24 +00006289<ul>
6290 <li><tt>ll</tt>: load-load barrier</li>
6291 <li><tt>ls</tt>: load-store barrier</li>
6292 <li><tt>sl</tt>: store-load barrier</li>
6293 <li><tt>ss</tt>: store-store barrier</li>
6294 <li><tt>device</tt>: barrier applies to device and uncached memory also.</li>
6295</ul>
6296
Andrew Lenharth785610d2008-02-16 01:24:58 +00006297<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006298<p>This intrinsic causes the system to enforce some ordering constraints upon
6299 the loads and stores of the program. This barrier does not
6300 indicate <em>when</em> any events will occur, it only enforces
6301 an <em>order</em> in which they occur. For any of the specified pairs of load
6302 and store operations (f.ex. load-load, or store-load), all of the first
6303 operations preceding the barrier will complete before any of the second
6304 operations succeeding the barrier begin. Specifically the semantics for each
6305 pairing is as follows:</p>
Andrew Lenharth785610d2008-02-16 01:24:58 +00006306
Bill Wendlingf85859d2009-07-20 02:29:24 +00006307<ul>
6308 <li><tt>ll</tt>: All loads before the barrier must complete before any load
6309 after the barrier begins.</li>
6310 <li><tt>ls</tt>: All loads before the barrier must complete before any
6311 store after the barrier begins.</li>
6312 <li><tt>ss</tt>: All stores before the barrier must complete before any
6313 store after the barrier begins.</li>
6314 <li><tt>sl</tt>: All stores before the barrier must complete before any
6315 load after the barrier begins.</li>
6316</ul>
6317
6318<p>These semantics are applied with a logical "and" behavior when more than one
6319 is enabled in a single memory barrier intrinsic.</p>
6320
6321<p>Backends may implement stronger barriers than those requested when they do
6322 not support as fine grained a barrier as requested. Some architectures do
6323 not need all types of barriers and on such architectures, these become
6324 noops.</p>
6325
Andrew Lenharth785610d2008-02-16 01:24:58 +00006326<h5>Example:</h5>
6327<pre>
6328%ptr = malloc i32
6329 store i32 4, %ptr
6330
6331%result1 = load i32* %ptr <i>; yields {i32}:result1 = 4</i>
6332 call void @llvm.memory.barrier( i1 false, i1 true, i1 false, i1 false )
6333 <i>; guarantee the above finishes</i>
6334 store i32 8, %ptr <i>; before this begins</i>
6335</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006336
Andrew Lenharth785610d2008-02-16 01:24:58 +00006337</div>
6338
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006339<!-- _______________________________________________________________________ -->
6340<div class="doc_subsubsection">
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006341 <a name="int_atomic_cmp_swap">'<tt>llvm.atomic.cmp.swap.*</tt>' Intrinsic</a>
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006342</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006343
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006344<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00006345
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006346<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006347<p>This is an overloaded intrinsic. You can use <tt>llvm.atomic.cmp.swap</tt> on
6348 any integer bit width and for different address spaces. Not all targets
6349 support all bit widths however.</p>
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006350
6351<pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006352 declare i8 @llvm.atomic.cmp.swap.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;cmp&gt;, i8 &lt;val&gt; )
6353 declare i16 @llvm.atomic.cmp.swap.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;cmp&gt;, i16 &lt;val&gt; )
6354 declare i32 @llvm.atomic.cmp.swap.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;cmp&gt;, i32 &lt;val&gt; )
6355 declare i64 @llvm.atomic.cmp.swap.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;cmp&gt;, i64 &lt;val&gt; )
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006356</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006357
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006358<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006359<p>This loads a value in memory and compares it to a given value. If they are
6360 equal, it stores a new value into the memory.</p>
6361
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006362<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006363<p>The <tt>llvm.atomic.cmp.swap</tt> intrinsic takes three arguments. The result
6364 as well as both <tt>cmp</tt> and <tt>val</tt> must be integer values with the
6365 same bit width. The <tt>ptr</tt> argument must be a pointer to a value of
6366 this integer type. While any bit width integer may be used, targets may only
6367 lower representations they support in hardware.</p>
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006368
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006369<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006370<p>This entire intrinsic must be executed atomically. It first loads the value
6371 in memory pointed to by <tt>ptr</tt> and compares it with the
6372 value <tt>cmp</tt>. If they are equal, <tt>val</tt> is stored into the
6373 memory. The loaded value is yielded in all cases. This provides the
6374 equivalent of an atomic compare-and-swap operation within the SSA
6375 framework.</p>
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006376
Bill Wendlingf85859d2009-07-20 02:29:24 +00006377<h5>Examples:</h5>
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006378<pre>
6379%ptr = malloc i32
6380 store i32 4, %ptr
6381
6382%val1 = add i32 4, 4
Mon P Wangce3ac892008-07-30 04:36:53 +00006383%result1 = call i32 @llvm.atomic.cmp.swap.i32.p0i32( i32* %ptr, i32 4, %val1 )
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006384 <i>; yields {i32}:result1 = 4</i>
6385%stored1 = icmp eq i32 %result1, 4 <i>; yields {i1}:stored1 = true</i>
6386%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 8</i>
6387
6388%val2 = add i32 1, 1
Mon P Wangce3ac892008-07-30 04:36:53 +00006389%result2 = call i32 @llvm.atomic.cmp.swap.i32.p0i32( i32* %ptr, i32 5, %val2 )
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006390 <i>; yields {i32}:result2 = 8</i>
6391%stored2 = icmp eq i32 %result2, 5 <i>; yields {i1}:stored2 = false</i>
6392
6393%memval2 = load i32* %ptr <i>; yields {i32}:memval2 = 8</i>
6394</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006395
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006396</div>
6397
6398<!-- _______________________________________________________________________ -->
6399<div class="doc_subsubsection">
6400 <a name="int_atomic_swap">'<tt>llvm.atomic.swap.*</tt>' Intrinsic</a>
6401</div>
6402<div class="doc_text">
6403<h5>Syntax:</h5>
6404
Bill Wendlingf85859d2009-07-20 02:29:24 +00006405<p>This is an overloaded intrinsic. You can use <tt>llvm.atomic.swap</tt> on any
6406 integer bit width. Not all targets support all bit widths however.</p>
6407
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006408<pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006409 declare i8 @llvm.atomic.swap.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;val&gt; )
6410 declare i16 @llvm.atomic.swap.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;val&gt; )
6411 declare i32 @llvm.atomic.swap.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;val&gt; )
6412 declare i64 @llvm.atomic.swap.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;val&gt; )
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006413</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006414
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006415<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006416<p>This intrinsic loads the value stored in memory at <tt>ptr</tt> and yields
6417 the value from memory. It then stores the value in <tt>val</tt> in the memory
6418 at <tt>ptr</tt>.</p>
6419
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006420<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006421<p>The <tt>llvm.atomic.swap</tt> intrinsic takes two arguments. Both
6422 the <tt>val</tt> argument and the result must be integers of the same bit
6423 width. The first argument, <tt>ptr</tt>, must be a pointer to a value of this
6424 integer type. The targets may only lower integer representations they
6425 support.</p>
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006426
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006427<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006428<p>This intrinsic loads the value pointed to by <tt>ptr</tt>, yields it, and
6429 stores <tt>val</tt> back into <tt>ptr</tt> atomically. This provides the
6430 equivalent of an atomic swap operation within the SSA framework.</p>
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006431
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006432<h5>Examples:</h5>
6433<pre>
6434%ptr = malloc i32
6435 store i32 4, %ptr
6436
6437%val1 = add i32 4, 4
Mon P Wangce3ac892008-07-30 04:36:53 +00006438%result1 = call i32 @llvm.atomic.swap.i32.p0i32( i32* %ptr, i32 %val1 )
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006439 <i>; yields {i32}:result1 = 4</i>
6440%stored1 = icmp eq i32 %result1, 4 <i>; yields {i1}:stored1 = true</i>
6441%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 8</i>
6442
6443%val2 = add i32 1, 1
Mon P Wangce3ac892008-07-30 04:36:53 +00006444%result2 = call i32 @llvm.atomic.swap.i32.p0i32( i32* %ptr, i32 %val2 )
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006445 <i>; yields {i32}:result2 = 8</i>
6446
6447%stored2 = icmp eq i32 %result2, 8 <i>; yields {i1}:stored2 = true</i>
6448%memval2 = load i32* %ptr <i>; yields {i32}:memval2 = 2</i>
6449</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006450
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006451</div>
6452
6453<!-- _______________________________________________________________________ -->
6454<div class="doc_subsubsection">
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006455 <a name="int_atomic_load_add">'<tt>llvm.atomic.load.add.*</tt>' Intrinsic</a>
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006456
6457</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006458
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006459<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00006460
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006461<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006462<p>This is an overloaded intrinsic. You can use <tt>llvm.atomic.load.add</tt> on
6463 any integer bit width. Not all targets support all bit widths however.</p>
6464
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006465<pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006466 declare i8 @llvm.atomic.load.add.i8..p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6467 declare i16 @llvm.atomic.load.add.i16..p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6468 declare i32 @llvm.atomic.load.add.i32..p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6469 declare i64 @llvm.atomic.load.add.i64..p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006470</pre>
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006471
Bill Wendlingf85859d2009-07-20 02:29:24 +00006472<h5>Overview:</h5>
6473<p>This intrinsic adds <tt>delta</tt> to the value stored in memory
6474 at <tt>ptr</tt>. It yields the original value at <tt>ptr</tt>.</p>
6475
6476<h5>Arguments:</h5>
6477<p>The intrinsic takes two arguments, the first a pointer to an integer value
6478 and the second an integer value. The result is also an integer value. These
6479 integer types can have any bit width, but they must all have the same bit
6480 width. The targets may only lower integer representations they support.</p>
6481
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006482<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006483<p>This intrinsic does a series of operations atomically. It first loads the
6484 value stored at <tt>ptr</tt>. It then adds <tt>delta</tt>, stores the result
6485 to <tt>ptr</tt>. It yields the original value stored at <tt>ptr</tt>.</p>
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006486
6487<h5>Examples:</h5>
6488<pre>
6489%ptr = malloc i32
6490 store i32 4, %ptr
Mon P Wangce3ac892008-07-30 04:36:53 +00006491%result1 = call i32 @llvm.atomic.load.add.i32.p0i32( i32* %ptr, i32 4 )
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006492 <i>; yields {i32}:result1 = 4</i>
Mon P Wangce3ac892008-07-30 04:36:53 +00006493%result2 = call i32 @llvm.atomic.load.add.i32.p0i32( i32* %ptr, i32 2 )
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006494 <i>; yields {i32}:result2 = 8</i>
Mon P Wangce3ac892008-07-30 04:36:53 +00006495%result3 = call i32 @llvm.atomic.load.add.i32.p0i32( i32* %ptr, i32 5 )
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006496 <i>; yields {i32}:result3 = 10</i>
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006497%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 15</i>
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006498</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006499
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006500</div>
6501
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006502<!-- _______________________________________________________________________ -->
6503<div class="doc_subsubsection">
6504 <a name="int_atomic_load_sub">'<tt>llvm.atomic.load.sub.*</tt>' Intrinsic</a>
6505
6506</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006507
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006508<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00006509
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006510<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006511<p>This is an overloaded intrinsic. You can use <tt>llvm.atomic.load.sub</tt> on
6512 any integer bit width and for different address spaces. Not all targets
6513 support all bit widths however.</p>
6514
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006515<pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006516 declare i8 @llvm.atomic.load.sub.i8.p0i32( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6517 declare i16 @llvm.atomic.load.sub.i16.p0i32( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6518 declare i32 @llvm.atomic.load.sub.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6519 declare i64 @llvm.atomic.load.sub.i64.p0i32( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006520</pre>
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006521
Bill Wendlingf85859d2009-07-20 02:29:24 +00006522<h5>Overview:</h5>
6523<p>This intrinsic subtracts <tt>delta</tt> to the value stored in memory at
6524 <tt>ptr</tt>. It yields the original value at <tt>ptr</tt>.</p>
6525
6526<h5>Arguments:</h5>
6527<p>The intrinsic takes two arguments, the first a pointer to an integer value
6528 and the second an integer value. The result is also an integer value. These
6529 integer types can have any bit width, but they must all have the same bit
6530 width. The targets may only lower integer representations they support.</p>
6531
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006532<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006533<p>This intrinsic does a series of operations atomically. It first loads the
6534 value stored at <tt>ptr</tt>. It then subtracts <tt>delta</tt>, stores the
6535 result to <tt>ptr</tt>. It yields the original value stored
6536 at <tt>ptr</tt>.</p>
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006537
6538<h5>Examples:</h5>
6539<pre>
6540%ptr = malloc i32
6541 store i32 8, %ptr
Mon P Wangce3ac892008-07-30 04:36:53 +00006542%result1 = call i32 @llvm.atomic.load.sub.i32.p0i32( i32* %ptr, i32 4 )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006543 <i>; yields {i32}:result1 = 8</i>
Mon P Wangce3ac892008-07-30 04:36:53 +00006544%result2 = call i32 @llvm.atomic.load.sub.i32.p0i32( i32* %ptr, i32 2 )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006545 <i>; yields {i32}:result2 = 4</i>
Mon P Wangce3ac892008-07-30 04:36:53 +00006546%result3 = call i32 @llvm.atomic.load.sub.i32.p0i32( i32* %ptr, i32 5 )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006547 <i>; yields {i32}:result3 = 2</i>
6548%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = -3</i>
6549</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006550
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006551</div>
6552
6553<!-- _______________________________________________________________________ -->
6554<div class="doc_subsubsection">
6555 <a name="int_atomic_load_and">'<tt>llvm.atomic.load.and.*</tt>' Intrinsic</a><br>
6556 <a name="int_atomic_load_nand">'<tt>llvm.atomic.load.nand.*</tt>' Intrinsic</a><br>
6557 <a name="int_atomic_load_or">'<tt>llvm.atomic.load.or.*</tt>' Intrinsic</a><br>
6558 <a name="int_atomic_load_xor">'<tt>llvm.atomic.load.xor.*</tt>' Intrinsic</a><br>
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006559</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006560
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006561<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00006562
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006563<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006564<p>These are overloaded intrinsics. You can
6565 use <tt>llvm.atomic.load_and</tt>, <tt>llvm.atomic.load_nand</tt>,
6566 <tt>llvm.atomic.load_or</tt>, and <tt>llvm.atomic.load_xor</tt> on any integer
6567 bit width and for different address spaces. Not all targets support all bit
6568 widths however.</p>
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006569
Bill Wendlingf85859d2009-07-20 02:29:24 +00006570<pre>
6571 declare i8 @llvm.atomic.load.and.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6572 declare i16 @llvm.atomic.load.and.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6573 declare i32 @llvm.atomic.load.and.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6574 declare i64 @llvm.atomic.load.and.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006575</pre>
6576
6577<pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006578 declare i8 @llvm.atomic.load.or.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6579 declare i16 @llvm.atomic.load.or.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6580 declare i32 @llvm.atomic.load.or.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6581 declare i64 @llvm.atomic.load.or.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006582</pre>
6583
6584<pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006585 declare i8 @llvm.atomic.load.nand.i8.p0i32( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6586 declare i16 @llvm.atomic.load.nand.i16.p0i32( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6587 declare i32 @llvm.atomic.load.nand.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6588 declare i64 @llvm.atomic.load.nand.i64.p0i32( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006589</pre>
6590
6591<pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006592 declare i8 @llvm.atomic.load.xor.i8.p0i32( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6593 declare i16 @llvm.atomic.load.xor.i16.p0i32( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6594 declare i32 @llvm.atomic.load.xor.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6595 declare i64 @llvm.atomic.load.xor.i64.p0i32( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006596</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006597
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006598<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006599<p>These intrinsics bitwise the operation (and, nand, or, xor) <tt>delta</tt> to
6600 the value stored in memory at <tt>ptr</tt>. It yields the original value
6601 at <tt>ptr</tt>.</p>
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006602
Bill Wendlingf85859d2009-07-20 02:29:24 +00006603<h5>Arguments:</h5>
6604<p>These intrinsics take two arguments, the first a pointer to an integer value
6605 and the second an integer value. The result is also an integer value. These
6606 integer types can have any bit width, but they must all have the same bit
6607 width. The targets may only lower integer representations they support.</p>
6608
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006609<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006610<p>These intrinsics does a series of operations atomically. They first load the
6611 value stored at <tt>ptr</tt>. They then do the bitwise
6612 operation <tt>delta</tt>, store the result to <tt>ptr</tt>. They yield the
6613 original value stored at <tt>ptr</tt>.</p>
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006614
6615<h5>Examples:</h5>
6616<pre>
6617%ptr = malloc i32
6618 store i32 0x0F0F, %ptr
Mon P Wangce3ac892008-07-30 04:36:53 +00006619%result0 = call i32 @llvm.atomic.load.nand.i32.p0i32( i32* %ptr, i32 0xFF )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006620 <i>; yields {i32}:result0 = 0x0F0F</i>
Mon P Wangce3ac892008-07-30 04:36:53 +00006621%result1 = call i32 @llvm.atomic.load.and.i32.p0i32( i32* %ptr, i32 0xFF )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006622 <i>; yields {i32}:result1 = 0xFFFFFFF0</i>
Mon P Wangce3ac892008-07-30 04:36:53 +00006623%result2 = call i32 @llvm.atomic.load.or.i32.p0i32( i32* %ptr, i32 0F )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006624 <i>; yields {i32}:result2 = 0xF0</i>
Mon P Wangce3ac892008-07-30 04:36:53 +00006625%result3 = call i32 @llvm.atomic.load.xor.i32.p0i32( i32* %ptr, i32 0F )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006626 <i>; yields {i32}:result3 = FF</i>
6627%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = F0</i>
6628</pre>
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006629
Bill Wendlingf85859d2009-07-20 02:29:24 +00006630</div>
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006631
6632<!-- _______________________________________________________________________ -->
6633<div class="doc_subsubsection">
6634 <a name="int_atomic_load_max">'<tt>llvm.atomic.load.max.*</tt>' Intrinsic</a><br>
6635 <a name="int_atomic_load_min">'<tt>llvm.atomic.load.min.*</tt>' Intrinsic</a><br>
6636 <a name="int_atomic_load_umax">'<tt>llvm.atomic.load.umax.*</tt>' Intrinsic</a><br>
6637 <a name="int_atomic_load_umin">'<tt>llvm.atomic.load.umin.*</tt>' Intrinsic</a><br>
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006638</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006639
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006640<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00006641
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006642<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006643<p>These are overloaded intrinsics. You can use <tt>llvm.atomic.load_max</tt>,
6644 <tt>llvm.atomic.load_min</tt>, <tt>llvm.atomic.load_umax</tt>, and
6645 <tt>llvm.atomic.load_umin</tt> on any integer bit width and for different
6646 address spaces. Not all targets support all bit widths however.</p>
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006647
Bill Wendlingf85859d2009-07-20 02:29:24 +00006648<pre>
6649 declare i8 @llvm.atomic.load.max.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6650 declare i16 @llvm.atomic.load.max.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6651 declare i32 @llvm.atomic.load.max.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6652 declare i64 @llvm.atomic.load.max.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006653</pre>
6654
6655<pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006656 declare i8 @llvm.atomic.load.min.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6657 declare i16 @llvm.atomic.load.min.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6658 declare i32 @llvm.atomic.load.min.i32..p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6659 declare i64 @llvm.atomic.load.min.i64..p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006660</pre>
6661
6662<pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006663 declare i8 @llvm.atomic.load.umax.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6664 declare i16 @llvm.atomic.load.umax.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6665 declare i32 @llvm.atomic.load.umax.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6666 declare i64 @llvm.atomic.load.umax.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006667</pre>
6668
6669<pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006670 declare i8 @llvm.atomic.load.umin.i8..p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6671 declare i16 @llvm.atomic.load.umin.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6672 declare i32 @llvm.atomic.load.umin.i32..p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6673 declare i64 @llvm.atomic.load.umin.i64..p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006674</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006675
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006676<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006677<p>These intrinsics takes the signed or unsigned minimum or maximum of
6678 <tt>delta</tt> and the value stored in memory at <tt>ptr</tt>. It yields the
6679 original value at <tt>ptr</tt>.</p>
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006680
Bill Wendlingf85859d2009-07-20 02:29:24 +00006681<h5>Arguments:</h5>
6682<p>These intrinsics take two arguments, the first a pointer to an integer value
6683 and the second an integer value. The result is also an integer value. These
6684 integer types can have any bit width, but they must all have the same bit
6685 width. The targets may only lower integer representations they support.</p>
6686
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006687<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006688<p>These intrinsics does a series of operations atomically. They first load the
6689 value stored at <tt>ptr</tt>. They then do the signed or unsigned min or
6690 max <tt>delta</tt> and the value, store the result to <tt>ptr</tt>. They
6691 yield the original value stored at <tt>ptr</tt>.</p>
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006692
6693<h5>Examples:</h5>
6694<pre>
6695%ptr = malloc i32
6696 store i32 7, %ptr
Mon P Wangce3ac892008-07-30 04:36:53 +00006697%result0 = call i32 @llvm.atomic.load.min.i32.p0i32( i32* %ptr, i32 -2 )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006698 <i>; yields {i32}:result0 = 7</i>
Mon P Wangce3ac892008-07-30 04:36:53 +00006699%result1 = call i32 @llvm.atomic.load.max.i32.p0i32( i32* %ptr, i32 8 )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006700 <i>; yields {i32}:result1 = -2</i>
Mon P Wangce3ac892008-07-30 04:36:53 +00006701%result2 = call i32 @llvm.atomic.load.umin.i32.p0i32( i32* %ptr, i32 10 )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006702 <i>; yields {i32}:result2 = 8</i>
Mon P Wangce3ac892008-07-30 04:36:53 +00006703%result3 = call i32 @llvm.atomic.load.umax.i32.p0i32( i32* %ptr, i32 30 )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006704 <i>; yields {i32}:result3 = 8</i>
6705%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 30</i>
6706</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006707
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006708</div>
Andrew Lenharth785610d2008-02-16 01:24:58 +00006709
6710<!-- ======================================================================= -->
6711<div class="doc_subsection">
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006712 <a name="int_general">General Intrinsics</a>
6713</div>
6714
6715<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00006716
6717<p>This class of intrinsics is designed to be generic and has no specific
6718 purpose.</p>
6719
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006720</div>
6721
6722<!-- _______________________________________________________________________ -->
6723<div class="doc_subsubsection">
6724 <a name="int_var_annotation">'<tt>llvm.var.annotation</tt>' Intrinsic</a>
6725</div>
6726
6727<div class="doc_text">
6728
6729<h5>Syntax:</h5>
6730<pre>
6731 declare void @llvm.var.annotation(i8* &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
6732</pre>
6733
6734<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006735<p>The '<tt>llvm.var.annotation</tt>' intrinsic.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006736
6737<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006738<p>The first argument is a pointer to a value, the second is a pointer to a
6739 global string, the third is a pointer to a global string which is the source
6740 file name, and the last argument is the line number.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006741
6742<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006743<p>This intrinsic allows annotation of local variables with arbitrary strings.
6744 This can be useful for special purpose optimizations that want to look for
6745 these annotations. These have no other defined use, they are ignored by code
6746 generation and optimization.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006747
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006748</div>
6749
Tanya Lattnerb306a9e2007-09-21 22:59:12 +00006750<!-- _______________________________________________________________________ -->
6751<div class="doc_subsubsection">
Tanya Lattnerc9869b12007-09-21 23:57:59 +00006752 <a name="int_annotation">'<tt>llvm.annotation.*</tt>' Intrinsic</a>
Tanya Lattnerb306a9e2007-09-21 22:59:12 +00006753</div>
6754
6755<div class="doc_text">
6756
6757<h5>Syntax:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006758<p>This is an overloaded intrinsic. You can use '<tt>llvm.annotation</tt>' on
6759 any integer bit width.</p>
6760
Tanya Lattnerb306a9e2007-09-21 22:59:12 +00006761<pre>
Tanya Lattner09161fe2007-09-22 00:03:01 +00006762 declare i8 @llvm.annotation.i8(i8 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
6763 declare i16 @llvm.annotation.i16(i16 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
6764 declare i32 @llvm.annotation.i32(i32 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
6765 declare i64 @llvm.annotation.i64(i64 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
6766 declare i256 @llvm.annotation.i256(i256 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
Tanya Lattnerb306a9e2007-09-21 22:59:12 +00006767</pre>
6768
6769<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006770<p>The '<tt>llvm.annotation</tt>' intrinsic.</p>
Tanya Lattnerb306a9e2007-09-21 22:59:12 +00006771
6772<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006773<p>The first argument is an integer value (result of some expression), the
6774 second is a pointer to a global string, the third is a pointer to a global
6775 string which is the source file name, and the last argument is the line
6776 number. It returns the value of the first argument.</p>
Tanya Lattnerb306a9e2007-09-21 22:59:12 +00006777
6778<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006779<p>This intrinsic allows annotations to be put on arbitrary expressions with
6780 arbitrary strings. This can be useful for special purpose optimizations that
6781 want to look for these annotations. These have no other defined use, they
6782 are ignored by code generation and optimization.</p>
Tanya Lattnerb306a9e2007-09-21 22:59:12 +00006783
Tanya Lattnerb306a9e2007-09-21 22:59:12 +00006784</div>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006785
Anton Korobeynikove6e764f2008-01-15 22:31:34 +00006786<!-- _______________________________________________________________________ -->
6787<div class="doc_subsubsection">
6788 <a name="int_trap">'<tt>llvm.trap</tt>' Intrinsic</a>
6789</div>
6790
6791<div class="doc_text">
6792
6793<h5>Syntax:</h5>
6794<pre>
6795 declare void @llvm.trap()
6796</pre>
6797
6798<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006799<p>The '<tt>llvm.trap</tt>' intrinsic.</p>
Anton Korobeynikove6e764f2008-01-15 22:31:34 +00006800
6801<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006802<p>None.</p>
Anton Korobeynikove6e764f2008-01-15 22:31:34 +00006803
6804<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006805<p>This intrinsics is lowered to the target dependent trap instruction. If the
6806 target does not have a trap instruction, this intrinsic will be lowered to
6807 the call of the <tt>abort()</tt> function.</p>
Anton Korobeynikove6e764f2008-01-15 22:31:34 +00006808
Anton Korobeynikove6e764f2008-01-15 22:31:34 +00006809</div>
6810
Bill Wendlinge4164592008-11-19 05:56:17 +00006811<!-- _______________________________________________________________________ -->
6812<div class="doc_subsubsection">
Misha Brukman5dd7f4d2008-11-22 23:55:29 +00006813 <a name="int_stackprotector">'<tt>llvm.stackprotector</tt>' Intrinsic</a>
Bill Wendlinge4164592008-11-19 05:56:17 +00006814</div>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006815
Bill Wendlinge4164592008-11-19 05:56:17 +00006816<div class="doc_text">
Bill Wendlingf85859d2009-07-20 02:29:24 +00006817
Bill Wendlinge4164592008-11-19 05:56:17 +00006818<h5>Syntax:</h5>
6819<pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006820 declare void @llvm.stackprotector( i8* &lt;guard&gt;, i8** &lt;slot&gt; )
Bill Wendlinge4164592008-11-19 05:56:17 +00006821</pre>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006822
Bill Wendlinge4164592008-11-19 05:56:17 +00006823<h5>Overview:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006824<p>The <tt>llvm.stackprotector</tt> intrinsic takes the <tt>guard</tt> and
6825 stores it onto the stack at <tt>slot</tt>. The stack slot is adjusted to
6826 ensure that it is placed on the stack before local variables.</p>
6827
Bill Wendlinge4164592008-11-19 05:56:17 +00006828<h5>Arguments:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006829<p>The <tt>llvm.stackprotector</tt> intrinsic requires two pointer
6830 arguments. The first argument is the value loaded from the stack
6831 guard <tt>@__stack_chk_guard</tt>. The second variable is an <tt>alloca</tt>
6832 that has enough space to hold the value of the guard.</p>
6833
Bill Wendlinge4164592008-11-19 05:56:17 +00006834<h5>Semantics:</h5>
Bill Wendlingf85859d2009-07-20 02:29:24 +00006835<p>This intrinsic causes the prologue/epilogue inserter to force the position of
6836 the <tt>AllocaInst</tt> stack slot to be before local variables on the
6837 stack. This is to ensure that if a local variable on the stack is
6838 overwritten, it will destroy the value of the guard. When the function exits,
6839 the guard on the stack is checked against the original guard. If they're
6840 different, then the program aborts by calling the <tt>__stack_chk_fail()</tt>
6841 function.</p>
6842
Bill Wendlinge4164592008-11-19 05:56:17 +00006843</div>
6844
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006845<!-- *********************************************************************** -->
6846<hr>
6847<address>
6848 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
Misha Brukman947321d2008-12-11 17:34:48 +00006849 src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006850 <a href="http://validator.w3.org/check/referer"><img
Misha Brukman947321d2008-12-11 17:34:48 +00006851 src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006852
6853 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
6854 <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
6855 Last modified: $Date$
6856</address>
Chris Lattner08497ce2008-01-04 04:33:49 +00006857
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006858</body>
6859</html>