blob: 4fb712ee3bba7d24bccd1dee5d1a32f611d4204c [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">
290<p>This document is a reference manual for the LLVM assembly language.
Bill Wendlinge7846a52008-08-05 22:29:16 +0000291LLVM is a Static Single Assignment (SSA) based representation that provides
Chris Lattner96451482008-08-05 18:29:16 +0000292type safety, low-level operations, flexibility, and the capability of
293representing 'all' high-level languages cleanly. It is the common code
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000294representation used throughout all phases of the LLVM compilation
295strategy.</p>
296</div>
297
298<!-- *********************************************************************** -->
299<div class="doc_section"> <a name="introduction">Introduction</a> </div>
300<!-- *********************************************************************** -->
301
302<div class="doc_text">
303
304<p>The LLVM code representation is designed to be used in three
305different forms: as an in-memory compiler IR, as an on-disk bitcode
306representation (suitable for fast loading by a Just-In-Time compiler),
307and as a human readable assembly language representation. This allows
308LLVM to provide a powerful intermediate representation for efficient
309compiler transformations and analysis, while providing a natural means
310to debug and visualize the transformations. The three different forms
311of LLVM are all equivalent. This document describes the human readable
312representation and notation.</p>
313
314<p>The LLVM representation aims to be light-weight and low-level
315while being expressive, typed, and extensible at the same time. It
316aims to be a "universal IR" of sorts, by being at a low enough level
317that high-level ideas may be cleanly mapped to it (similar to how
318microprocessors are "universal IR's", allowing many source languages to
319be mapped to them). By providing type information, LLVM can be used as
320the target of optimizations: for example, through pointer analysis, it
321can be proven that a C automatic variable is never accessed outside of
322the current function... allowing it to be promoted to a simple SSA
323value instead of a memory location.</p>
324
325</div>
326
327<!-- _______________________________________________________________________ -->
328<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
329
330<div class="doc_text">
331
332<p>It is important to note that this document describes 'well formed'
333LLVM assembly language. There is a difference between what the parser
334accepts and what is considered 'well formed'. For example, the
335following instruction is syntactically okay, but not well formed:</p>
336
337<div class="doc_code">
338<pre>
339%x = <a href="#i_add">add</a> i32 1, %x
340</pre>
341</div>
342
343<p>...because the definition of <tt>%x</tt> does not dominate all of
344its uses. The LLVM infrastructure provides a verification pass that may
345be used to verify that an LLVM module is well formed. This pass is
346automatically run by the parser after parsing input assembly and by
347the optimizer before it outputs bitcode. The violations pointed out
348by the verifier pass indicate bugs in transformation passes or input to
349the parser.</p>
350</div>
351
Chris Lattnera83fdc02007-10-03 17:34:29 +0000352<!-- Describe the typesetting conventions here. -->
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000353
354<!-- *********************************************************************** -->
355<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
356<!-- *********************************************************************** -->
357
358<div class="doc_text">
359
Reid Spencerc8245b02007-08-07 14:34:28 +0000360 <p>LLVM identifiers come in two basic types: global and local. Global
361 identifiers (functions, global variables) begin with the @ character. Local
362 identifiers (register names, types) begin with the % character. Additionally,
Dan Gohman2672f3e2008-10-14 16:51:45 +0000363 there are three different formats 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.
367 For example, %foo, @DivisionByZero, %a.really.long.identifier. The actual
368 regular expression used is '<tt>[%@][a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000369 Identifiers which require other characters in their names can be surrounded
Daniel Dunbar73f9a772008-10-14 23:51:43 +0000370 with quotes. Special characters may be escaped using "\xx" where xx is the
371 ASCII code for the character in hexadecimal. In this way, any character can
372 be used in a name value, even quotes themselves.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000373
Reid Spencerc8245b02007-08-07 14:34:28 +0000374 <li>Unnamed values are represented as an unsigned numeric value with their
375 prefix. For example, %12, @2, %44.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000376
377 <li>Constants, which are described in a <a href="#constants">section about
378 constants</a>, below.</li>
379</ol>
380
Reid Spencerc8245b02007-08-07 14:34:28 +0000381<p>LLVM requires that values start with a prefix for two reasons: Compilers
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000382don't need to worry about name clashes with reserved words, and the set of
383reserved words may be expanded in the future without penalty. Additionally,
384unnamed identifiers allow a compiler to quickly come up with a temporary
385variable without having to avoid symbol table conflicts.</p>
386
387<p>Reserved words in LLVM are very similar to reserved words in other
388languages. There are keywords for different opcodes
389('<tt><a href="#i_add">add</a></tt>',
390 '<tt><a href="#i_bitcast">bitcast</a></tt>',
391 '<tt><a href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
392href="#t_void">void</a></tt>', '<tt><a href="#t_primitive">i32</a></tt>', etc...),
393and others. These reserved words cannot conflict with variable names, because
Reid Spencerc8245b02007-08-07 14:34:28 +0000394none of them start with a prefix character ('%' or '@').</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000395
396<p>Here is an example of LLVM code to multiply the integer variable
397'<tt>%X</tt>' by 8:</p>
398
399<p>The easy way:</p>
400
401<div class="doc_code">
402<pre>
403%result = <a href="#i_mul">mul</a> i32 %X, 8
404</pre>
405</div>
406
407<p>After strength reduction:</p>
408
409<div class="doc_code">
410<pre>
411%result = <a href="#i_shl">shl</a> i32 %X, i8 3
412</pre>
413</div>
414
415<p>And the hard way:</p>
416
417<div class="doc_code">
418<pre>
419<a href="#i_add">add</a> i32 %X, %X <i>; yields {i32}:%0</i>
420<a href="#i_add">add</a> i32 %0, %0 <i>; yields {i32}:%1</i>
421%result = <a href="#i_add">add</a> i32 %1, %1
422</pre>
423</div>
424
425<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
426important lexical features of LLVM:</p>
427
428<ol>
429
430 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
431 line.</li>
432
433 <li>Unnamed temporaries are created when the result of a computation is not
434 assigned to a named value.</li>
435
436 <li>Unnamed temporaries are numbered sequentially</li>
437
438</ol>
439
440<p>...and it also shows a convention that we follow in this document. When
441demonstrating instructions, we will follow an instruction with a comment that
442defines the type and name of value produced. Comments are shown in italic
443text.</p>
444
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
457<p>LLVM programs are composed of "Module"s, each of which is a
458translation unit of the input programs. Each module consists of
459functions, global variables, and symbol table entries. Modules may be
460combined together with the LLVM linker, which merges function (and
461global variable) definitions, resolves forward declarations, and merges
462symbol table entries. Here is an example of the "hello world" module:</p>
463
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>
470<a href="#functionstructure">declare</a> i32 @puts(i8 *) <i>; i32(i8 *)* </i>
471
472<i>; Definition of main function</i>
473define 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
Dan Gohman01852382009-01-04 23:44:43 +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
480 href="#i_call">call</a> i32 @puts(i8 * %cast210) <i>; i32</i>
481 <a
482 href="#i_ret">ret</a> i32 0<br>}<br>
483</pre>
484</div>
485
486<p>This example is made up of a <a href="#globalvars">global variable</a>
487named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
488function, and a <a href="#functionstructure">function definition</a>
489for "<tt>main</tt>".</p>
490
491<p>In general, a module is made up of a list of global values,
492where both functions and global variables are global values. Global values are
493represented by a pointer to a memory location (in this case, a pointer to an
494array of char, and a pointer to a function), and have one of the following <a
495href="#linkage">linkage types</a>.</p>
496
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
506<p>
507All Global Variables and Functions have one of the following types of linkage:
508</p>
509
510<dl>
511
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000512 <dt><tt><b><a name="linkage_private">private</a></b></tt>: </dt>
513
514 <dd>Global values with private linkage are only directly accessible by
515 objects in the current module. In particular, linking code into a module with
516 an private global value may cause the private to be renamed as necessary to
517 avoid collisions. Because the symbol is private to the module, all
518 references can be updated. This doesn't show up in any symbol table in the
519 object file.
520 </dd>
521
Bill Wendling41a07852009-07-20 01:03:30 +0000522 <dt><tt><b><a name="linkage_linker_private">linker_private</a></b></tt>: </dt>
523
524 <dd>Similar to private, but the symbol is passed through the assembler and
525 removed by the linker after evaluation.</dd>
526
Dale Johannesen96e7e092008-05-23 23:13:41 +0000527 <dt><tt><b><a name="linkage_internal">internal</a></b></tt>: </dt>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000528
Duncan Sandsa75223a2009-01-16 09:29:46 +0000529 <dd> Similar to private, but the value shows as a local symbol (STB_LOCAL in
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000530 the case of ELF) in the object file. This corresponds to the notion of the
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000531 '<tt>static</tt>' keyword in C.
532 </dd>
533
Bill Wendling41a07852009-07-20 01:03:30 +0000534 <dt><tt><b><a name="linkage_available_externally">available_externally</a></b></tt>:
Chris Lattner68433442009-04-13 05:44:34 +0000535 </dt>
536
537 <dd>Globals with "<tt>available_externally</tt>" linkage are never emitted
538 into the object file corresponding to the LLVM module. They exist to
539 allow inlining and other optimizations to take place given knowledge of the
540 definition of the global, which is known to be somewhere outside the module.
541 Globals with <tt>available_externally</tt> linkage are allowed to be discarded
542 at will, and are otherwise the same as <tt>linkonce_odr</tt>. This linkage
543 type is only allowed on definitions, not declarations.</dd>
544
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000545 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
546
547 <dd>Globals with "<tt>linkonce</tt>" linkage are merged with other globals of
548 the same name when linkage occurs. This is typically used to implement
549 inline functions, templates, or other code which must be generated in each
550 translation unit that uses it. Unreferenced <tt>linkonce</tt> globals are
551 allowed to be discarded.
552 </dd>
553
Dale Johannesen96e7e092008-05-23 23:13:41 +0000554 <dt><tt><b><a name="linkage_common">common</a></b></tt>: </dt>
555
556 <dd>"<tt>common</tt>" linkage is exactly the same as <tt>linkonce</tt>
557 linkage, except that unreferenced <tt>common</tt> globals may not be
558 discarded. This is used for globals that may be emitted in multiple
559 translation units, but that are not guaranteed to be emitted into every
560 translation unit that uses them. One example of this is tentative
561 definitions in C, such as "<tt>int X;</tt>" at global scope.
562 </dd>
563
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000564 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
565
Dale Johannesen96e7e092008-05-23 23:13:41 +0000566 <dd>"<tt>weak</tt>" linkage is the same as <tt>common</tt> linkage, except
567 that some targets may choose to emit different assembly sequences for them
568 for target-dependent reasons. This is used for globals that are declared
569 "weak" in C source code.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000570 </dd>
571
572 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
573
574 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
575 pointer to array type. When two global variables with appending linkage are
576 linked together, the two global arrays are appended together. This is the
577 LLVM, typesafe, equivalent of having the system linker append together
578 "sections" with identical names when .o files are linked.
579 </dd>
580
581 <dt><tt><b><a name="linkage_externweak">extern_weak</a></b></tt>: </dt>
Duncan Sands19d161f2009-03-07 15:45:40 +0000582
Chris Lattner96451482008-08-05 18:29:16 +0000583 <dd>The semantics of this linkage follow the ELF object file model: the
584 symbol is weak until linked, if not linked, the symbol becomes null instead
585 of being an undefined reference.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000586 </dd>
587
Duncan Sands19d161f2009-03-07 15:45:40 +0000588 <dt><tt><b><a name="linkage_linkonce">linkonce_odr</a></b></tt>: </dt>
Duncan Sands19d161f2009-03-07 15:45:40 +0000589 <dt><tt><b><a name="linkage_weak">weak_odr</a></b></tt>: </dt>
Chris Lattner68433442009-04-13 05:44:34 +0000590 <dd>Some languages allow differing globals to be merged, such as two
Duncan Sands19d161f2009-03-07 15:45:40 +0000591 functions with different semantics. Other languages, such as <tt>C++</tt>,
592 ensure that only equivalent globals are ever merged (the "one definition
Chris Lattner68433442009-04-13 05:44:34 +0000593 rule" - "ODR"). Such languages can use the <tt>linkonce_odr</tt>
Duncan Sandsb95df792009-03-11 20:14:15 +0000594 and <tt>weak_odr</tt> linkage types to indicate that the global will only
595 be merged with equivalent globals. These linkage types are otherwise the
596 same as their non-<tt>odr</tt> versions.
Duncan Sands19d161f2009-03-07 15:45:40 +0000597 </dd>
598
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000599 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
600
601 <dd>If none of the above identifiers are used, the global is externally
602 visible, meaning that it participates in linkage and can be used to resolve
603 external symbol references.
604 </dd>
605</dl>
606
607 <p>
608 The next two types of linkage are targeted for Microsoft Windows platform
609 only. They are designed to support importing (exporting) symbols from (to)
Chris Lattner96451482008-08-05 18:29:16 +0000610 DLLs (Dynamic Link Libraries).
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000611 </p>
612
613 <dl>
614 <dt><tt><b><a name="linkage_dllimport">dllimport</a></b></tt>: </dt>
615
616 <dd>"<tt>dllimport</tt>" linkage causes the compiler to reference a function
617 or variable via a global pointer to a pointer that is set up by the DLL
618 exporting the symbol. On Microsoft Windows targets, the pointer name is
Dan Gohman5ec99832009-01-12 21:35:55 +0000619 formed by combining <code>__imp_</code> and the function or variable name.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000620 </dd>
621
622 <dt><tt><b><a name="linkage_dllexport">dllexport</a></b></tt>: </dt>
623
624 <dd>"<tt>dllexport</tt>" linkage causes the compiler to provide a global
625 pointer to a pointer in a DLL, so that it can be referenced with the
626 <tt>dllimport</tt> attribute. On Microsoft Windows targets, the pointer
Dan Gohman5ec99832009-01-12 21:35:55 +0000627 name is formed by combining <code>__imp_</code> and the function or variable
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000628 name.
629 </dd>
630
631</dl>
632
Dan Gohman4dfac702008-11-24 17:18:39 +0000633<p>For example, since the "<tt>.LC0</tt>"
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000634variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
635variable and was linked with this one, one of the two would be renamed,
636preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
637external (i.e., lacking any linkage declarations), they are accessible
638outside of the current module.</p>
639<p>It is illegal for a function <i>declaration</i>
Duncan Sands565f65d2009-03-11 08:08:06 +0000640to have any linkage type other than "externally visible", <tt>dllimport</tt>
641or <tt>extern_weak</tt>.</p>
Duncan Sands19d161f2009-03-07 15:45:40 +0000642<p>Aliases can have only <tt>external</tt>, <tt>internal</tt>, <tt>weak</tt>
643or <tt>weak_odr</tt> linkages.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000644</div>
645
646<!-- ======================================================================= -->
647<div class="doc_subsection">
648 <a name="callingconv">Calling Conventions</a>
649</div>
650
651<div class="doc_text">
652
653<p>LLVM <a href="#functionstructure">functions</a>, <a href="#i_call">calls</a>
654and <a href="#i_invoke">invokes</a> can all have an optional calling convention
655specified for the call. The calling convention of any pair of dynamic
656caller/callee must match, or the behavior of the program is undefined. The
657following calling conventions are supported by LLVM, and more may be added in
658the future:</p>
659
660<dl>
661 <dt><b>"<tt>ccc</tt>" - The C calling convention</b>:</dt>
662
663 <dd>This calling convention (the default if no other calling convention is
664 specified) matches the target C calling conventions. This calling convention
665 supports varargs function calls and tolerates some mismatch in the declared
666 prototype and implemented declaration of the function (as does normal C).
667 </dd>
668
669 <dt><b>"<tt>fastcc</tt>" - The fast calling convention</b>:</dt>
670
671 <dd>This calling convention attempts to make calls as fast as possible
672 (e.g. by passing things in registers). This calling convention allows the
673 target to use whatever tricks it wants to produce fast code for the target,
Chris Lattner96451482008-08-05 18:29:16 +0000674 without having to conform to an externally specified ABI (Application Binary
675 Interface). Implementations of this convention should allow arbitrary
Arnold Schwaighofer07444922008-05-14 09:17:12 +0000676 <a href="CodeGenerator.html#tailcallopt">tail call optimization</a> to be
677 supported. This calling convention does not support varargs and requires the
678 prototype of all callees to exactly match the prototype of the function
679 definition.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000680 </dd>
681
682 <dt><b>"<tt>coldcc</tt>" - The cold calling convention</b>:</dt>
683
684 <dd>This calling convention attempts to make code in the caller as efficient
685 as possible under the assumption that the call is not commonly executed. As
686 such, these calls often preserve all registers so that the call does not break
687 any live ranges in the caller side. This calling convention does not support
688 varargs and requires the prototype of all callees to exactly match the
689 prototype of the function definition.
690 </dd>
691
692 <dt><b>"<tt>cc &lt;<em>n</em>&gt;</tt>" - Numbered convention</b>:</dt>
693
694 <dd>Any calling convention may be specified by number, allowing
695 target-specific calling conventions to be used. Target specific calling
696 conventions start at 64.
697 </dd>
698</dl>
699
700<p>More calling conventions can be added/defined on an as-needed basis, to
701support pascal conventions or any other well-known target-independent
702convention.</p>
703
704</div>
705
706<!-- ======================================================================= -->
707<div class="doc_subsection">
708 <a name="visibility">Visibility Styles</a>
709</div>
710
711<div class="doc_text">
712
713<p>
714All Global Variables and Functions have one of the following visibility styles:
715</p>
716
717<dl>
718 <dt><b>"<tt>default</tt>" - Default style</b>:</dt>
719
Chris Lattner96451482008-08-05 18:29:16 +0000720 <dd>On targets that use the ELF object file format, default visibility means
721 that the declaration is visible to other
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000722 modules and, in shared libraries, means that the declared entity may be
723 overridden. On Darwin, default visibility means that the declaration is
724 visible to other modules. Default visibility corresponds to "external
725 linkage" in the language.
726 </dd>
727
728 <dt><b>"<tt>hidden</tt>" - Hidden style</b>:</dt>
729
730 <dd>Two declarations of an object with hidden visibility refer to the same
731 object if they are in the same shared object. Usually, hidden visibility
732 indicates that the symbol will not be placed into the dynamic symbol table,
733 so no other module (executable or shared library) can reference it
734 directly.
735 </dd>
736
737 <dt><b>"<tt>protected</tt>" - Protected style</b>:</dt>
738
739 <dd>On ELF, protected visibility indicates that the symbol will be placed in
740 the dynamic symbol table, but that references within the defining module will
741 bind to the local symbol. That is, the symbol cannot be overridden by another
742 module.
743 </dd>
744</dl>
745
746</div>
747
748<!-- ======================================================================= -->
749<div class="doc_subsection">
Chris Lattner5b6dc6e2009-01-11 20:53:49 +0000750 <a name="namedtypes">Named Types</a>
751</div>
752
753<div class="doc_text">
754
755<p>LLVM IR allows you to specify name aliases for certain types. This can make
756it easier to read the IR and make the IR more condensed (particularly when
757recursive types are involved). An example of a name specification is:
758</p>
759
760<div class="doc_code">
761<pre>
762%mytype = type { %mytype*, i32 }
763</pre>
764</div>
765
766<p>You may give a name to any <a href="#typesystem">type</a> except "<a
767href="t_void">void</a>". Type name aliases may be used anywhere a type is
768expected with the syntax "%mytype".</p>
769
770<p>Note that type names are aliases for the structural type that they indicate,
771and that you can therefore specify multiple names for the same type. This often
772leads to confusing behavior when dumping out a .ll file. Since LLVM IR uses
773structural typing, the name is not part of the type. When printing out LLVM IR,
774the printer will pick <em>one name</em> to render all types of a particular
775shape. This means that if you have code where two different source types end up
776having the same LLVM type, that the dumper will sometimes print the "wrong" or
777unexpected type. This is an important design point and isn't going to
778change.</p>
779
780</div>
781
Chris Lattner5b6dc6e2009-01-11 20:53:49 +0000782<!-- ======================================================================= -->
783<div class="doc_subsection">
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000784 <a name="globalvars">Global Variables</a>
785</div>
786
787<div class="doc_text">
788
789<p>Global variables define regions of memory allocated at compilation time
790instead of run-time. Global variables may optionally be initialized, may have
791an explicit section to be placed in, and may have an optional explicit alignment
792specified. A variable may be defined as "thread_local", which means that it
793will not be shared by threads (each thread will have a separated copy of the
794variable). A variable may be defined as a global "constant," which indicates
795that the contents of the variable will <b>never</b> be modified (enabling better
796optimization, allowing the global data to be placed in the read-only section of
797an executable, etc). Note that variables that need runtime initialization
798cannot be marked "constant" as there is a store to the variable.</p>
799
800<p>
801LLVM explicitly allows <em>declarations</em> of global variables to be marked
802constant, even if the final definition of the global is not. This capability
803can be used to enable slightly better optimization of the program, but requires
804the language definition to guarantee that optimizations based on the
805'constantness' are valid for the translation units that do not include the
806definition.
807</p>
808
809<p>As SSA values, global variables define pointer values that are in
810scope (i.e. they dominate) all basic blocks in the program. Global
811variables always define a pointer to their "content" type because they
812describe a region of memory, and all memory objects in LLVM are
813accessed through pointers.</p>
814
Chris Lattner990e7652009-07-18 21:47:15 +0000815<p>A global variable may be declared to reside in a target-specific numbered
Christopher Lambdd0049d2007-12-11 09:31:00 +0000816address space. For targets that support them, address spaces may affect how
817optimizations are performed and/or what target instructions are used to access
Christopher Lamb20a39e92007-12-12 08:44:39 +0000818the variable. The default address space is zero. The address space qualifier
819must precede any other attributes.</p>
Christopher Lambdd0049d2007-12-11 09:31:00 +0000820
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000821<p>LLVM allows an explicit section to be specified for globals. If the target
822supports it, it will emit globals to the section specified.</p>
823
824<p>An explicit alignment may be specified for a global. If not present, or if
825the alignment is set to zero, the alignment of the global is set by the target
826to whatever it feels convenient. If an explicit alignment is specified, the
827global is forced to have at least that much alignment. All alignments must be
828a power of 2.</p>
829
Christopher Lambdd0049d2007-12-11 09:31:00 +0000830<p>For example, the following defines a global in a numbered address space with
831an initializer, section, and alignment:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000832
833<div class="doc_code">
834<pre>
Dan Gohman21ef02c2009-01-11 00:40:00 +0000835@G = addrspace(5) constant float 1.0, section "foo", align 4
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000836</pre>
837</div>
838
839</div>
840
841
842<!-- ======================================================================= -->
843<div class="doc_subsection">
844 <a name="functionstructure">Functions</a>
845</div>
846
847<div class="doc_text">
848
849<p>LLVM function definitions consist of the "<tt>define</tt>" keyord,
850an optional <a href="#linkage">linkage type</a>, an optional
851<a href="#visibility">visibility style</a>, an optional
852<a href="#callingconv">calling convention</a>, a return type, an optional
853<a href="#paramattrs">parameter attribute</a> for the return type, a function
854name, a (possibly empty) argument list (each with optional
Devang Patelac2fc272008-10-06 18:50:38 +0000855<a href="#paramattrs">parameter attributes</a>), optional
856<a href="#fnattrs">function attributes</a>, an optional section,
857an optional alignment, an optional <a href="#gc">garbage collector name</a>,
Chris Lattneree202542008-10-04 18:10:21 +0000858an opening curly brace, a list of basic blocks, and a closing curly brace.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000859
860LLVM function declarations consist of the "<tt>declare</tt>" keyword, an
861optional <a href="#linkage">linkage type</a>, an optional
862<a href="#visibility">visibility style</a>, an optional
863<a href="#callingconv">calling convention</a>, a return type, an optional
864<a href="#paramattrs">parameter attribute</a> for the return type, a function
Gordon Henriksen13fe5e32007-12-10 03:18:06 +0000865name, a possibly empty list of arguments, an optional alignment, and an optional
Gordon Henriksend606f5b2007-12-10 03:30:21 +0000866<a href="#gc">garbage collector name</a>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000867
Chris Lattner96451482008-08-05 18:29:16 +0000868<p>A function definition contains a list of basic blocks, forming the CFG
869(Control Flow Graph) for
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000870the function. Each basic block may optionally start with a label (giving the
871basic block a symbol table entry), contains a list of instructions, and ends
872with a <a href="#terminators">terminator</a> instruction (such as a branch or
873function return).</p>
874
875<p>The first basic block in a function is special in two ways: it is immediately
876executed on entrance to the function, and it is not allowed to have predecessor
877basic blocks (i.e. there can not be any branches to the entry block of a
878function). Because the block can have no predecessors, it also cannot have any
879<a href="#i_phi">PHI nodes</a>.</p>
880
881<p>LLVM allows an explicit section to be specified for functions. If the target
882supports it, it will emit functions to the section specified.</p>
883
884<p>An explicit alignment may be specified for a function. If not present, or if
885the alignment is set to zero, the alignment of the function is set by the target
886to whatever it feels convenient. If an explicit alignment is specified, the
887function is forced to have at least that much alignment. All alignments must be
888a power of 2.</p>
889
Devang Pateld0bfcc72008-10-07 17:48:33 +0000890 <h5>Syntax:</h5>
891
892<div class="doc_code">
Chris Lattner1e5c5cd02008-10-13 16:55:18 +0000893<tt>
894define [<a href="#linkage">linkage</a>] [<a href="#visibility">visibility</a>]
895 [<a href="#callingconv">cconv</a>] [<a href="#paramattrs">ret attrs</a>]
896 &lt;ResultType&gt; @&lt;FunctionName&gt; ([argument list])
897 [<a href="#fnattrs">fn Attrs</a>] [section "name"] [align N]
898 [<a href="#gc">gc</a>] { ... }
899</tt>
Devang Pateld0bfcc72008-10-07 17:48:33 +0000900</div>
901
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000902</div>
903
904
905<!-- ======================================================================= -->
906<div class="doc_subsection">
907 <a name="aliasstructure">Aliases</a>
908</div>
909<div class="doc_text">
910 <p>Aliases act as "second name" for the aliasee value (which can be either
Anton Korobeynikov96822812008-03-22 08:36:14 +0000911 function, global variable, another alias or bitcast of global value). Aliases
912 may have an optional <a href="#linkage">linkage type</a>, and an
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000913 optional <a href="#visibility">visibility style</a>.</p>
914
915 <h5>Syntax:</h5>
916
917<div class="doc_code">
918<pre>
Duncan Sandsd7bfabf2008-09-12 20:48:21 +0000919@&lt;Name&gt; = alias [Linkage] [Visibility] &lt;AliaseeTy&gt; @&lt;Aliasee&gt;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000920</pre>
921</div>
922
923</div>
924
925
926
927<!-- ======================================================================= -->
928<div class="doc_subsection"><a name="paramattrs">Parameter Attributes</a></div>
929<div class="doc_text">
930 <p>The return type and each parameter of a function type may have a set of
931 <i>parameter attributes</i> associated with them. Parameter attributes are
932 used to communicate additional information about the result or parameters of
Duncan Sandsf5588dc2007-11-27 13:23:08 +0000933 a function. Parameter attributes are considered to be part of the function,
934 not of the function type, so functions with different parameter attributes
935 can have the same function type.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000936
937 <p>Parameter attributes are simple keywords that follow the type specified. If
938 multiple parameter attributes are needed, they are space separated. For
939 example:</p>
940
941<div class="doc_code">
942<pre>
Nick Lewycky3022a742009-02-15 23:06:14 +0000943declare i32 @printf(i8* noalias nocapture, ...)
Chris Lattnerf33b8452008-10-04 18:33:34 +0000944declare i32 @atoi(i8 zeroext)
945declare signext i8 @returns_signed_char()
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000946</pre>
947</div>
948
Duncan Sandsf5588dc2007-11-27 13:23:08 +0000949 <p>Note that any attributes for the function result (<tt>nounwind</tt>,
950 <tt>readonly</tt>) come immediately after the argument list.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000951
952 <p>Currently, only the following parameter attributes are defined:</p>
953 <dl>
Reid Spencerf234bed2007-07-19 23:13:04 +0000954 <dt><tt>zeroext</tt></dt>
Chris Lattnerf33b8452008-10-04 18:33:34 +0000955 <dd>This indicates to the code generator that the parameter or return value
956 should be zero-extended to a 32-bit value by the caller (for a parameter)
957 or the callee (for a return value).</dd>
Chris Lattner275e6be2008-01-11 06:20:47 +0000958
Reid Spencerf234bed2007-07-19 23:13:04 +0000959 <dt><tt>signext</tt></dt>
Chris Lattnerf33b8452008-10-04 18:33:34 +0000960 <dd>This indicates to the code generator that the parameter or return value
961 should be sign-extended to a 32-bit value by the caller (for a parameter)
962 or the callee (for a return value).</dd>
Chris Lattner275e6be2008-01-11 06:20:47 +0000963
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000964 <dt><tt>inreg</tt></dt>
Dale Johannesenc08a0e22008-09-25 20:47:45 +0000965 <dd>This indicates that this parameter or return value should be treated
966 in a special target-dependent fashion during while emitting code for a
967 function call or return (usually, by putting it in a register as opposed
Chris Lattnerf33b8452008-10-04 18:33:34 +0000968 to memory, though some targets use it to distinguish between two different
969 kinds of registers). Use of this attribute is target-specific.</dd>
Chris Lattner275e6be2008-01-11 06:20:47 +0000970
Duncan Sands7d94e5a2008-10-06 08:14:18 +0000971 <dt><tt><a name="byval">byval</a></tt></dt>
Chris Lattner04c86182008-01-15 04:34:22 +0000972 <dd>This indicates that the pointer parameter should really be passed by
973 value to the function. The attribute implies that a hidden copy of the
974 pointee is made between the caller and the callee, so the callee is unable
Chris Lattner6a9f3c42008-08-05 18:21:08 +0000975 to modify the value in the callee. This attribute is only valid on LLVM
Chris Lattner04c86182008-01-15 04:34:22 +0000976 pointer arguments. It is generally used to pass structs and arrays by
Duncan Sands7d94e5a2008-10-06 08:14:18 +0000977 value, but is also valid on pointers to scalars. The copy is considered to
978 belong to the caller not the callee (for example,
979 <tt><a href="#readonly">readonly</a></tt> functions should not write to
Devang Patelac2fc272008-10-06 18:50:38 +0000980 <tt>byval</tt> parameters). This is not a valid attribute for return
Chris Lattnere39c5bf2009-02-05 05:42:28 +0000981 values. The byval attribute also supports specifying an alignment with the
982 align attribute. This has a target-specific effect on the code generator
983 that usually indicates a desired alignment for the synthesized stack
984 slot.</dd>
Chris Lattner275e6be2008-01-11 06:20:47 +0000985
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000986 <dt><tt>sret</tt></dt>
Duncan Sands616cc032008-02-18 04:19:38 +0000987 <dd>This indicates that the pointer parameter specifies the address of a
988 structure that is the return value of the function in the source program.
Chris Lattnerf33b8452008-10-04 18:33:34 +0000989 This pointer must be guaranteed by the caller to be valid: loads and stores
990 to the structure may be assumed by the callee to not to trap. This may only
Devang Patelac2fc272008-10-06 18:50:38 +0000991 be applied to the first parameter. This is not a valid attribute for
992 return values. </dd>
Chris Lattner275e6be2008-01-11 06:20:47 +0000993
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000994 <dt><tt>noalias</tt></dt>
Nick Lewyckyff384472008-11-24 03:41:24 +0000995 <dd>This indicates that the pointer does not alias any global or any other
996 parameter. The caller is responsible for ensuring that this is the
Nick Lewyckya604a942008-11-24 05:00:44 +0000997 case. On a function return value, <tt>noalias</tt> additionally indicates
998 that the pointer does not alias any other pointers visible to the
Nick Lewycky40fb6f22008-12-19 06:39:12 +0000999 caller. For further details, please see the discussion of the NoAlias
1000 response in
1001 <a href="http://llvm.org/docs/AliasAnalysis.html#MustMayNo">alias
1002 analysis</a>.</dd>
1003
1004 <dt><tt>nocapture</tt></dt>
1005 <dd>This indicates that the callee does not make any copies of the pointer
1006 that outlive the callee itself. This is not a valid attribute for return
1007 values.</dd>
Chris Lattner275e6be2008-01-11 06:20:47 +00001008
Duncan Sands4ee46812007-07-27 19:57:41 +00001009 <dt><tt>nest</tt></dt>
Duncan Sandsf1a7d4c2008-07-08 09:27:25 +00001010 <dd>This indicates that the pointer parameter can be excised using the
Devang Patelac2fc272008-10-06 18:50:38 +00001011 <a href="#int_trampoline">trampoline intrinsics</a>. This is not a valid
1012 attribute for return values.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001013 </dl>
1014
1015</div>
1016
1017<!-- ======================================================================= -->
1018<div class="doc_subsection">
Gordon Henriksen13fe5e32007-12-10 03:18:06 +00001019 <a name="gc">Garbage Collector Names</a>
1020</div>
1021
1022<div class="doc_text">
1023<p>Each function may specify a garbage collector name, which is simply a
1024string.</p>
1025
1026<div class="doc_code"><pre
1027>define void @f() gc "name" { ...</pre></div>
1028
1029<p>The compiler declares the supported values of <i>name</i>. Specifying a
1030collector which will cause the compiler to alter its output in order to support
1031the named garbage collection algorithm.</p>
1032</div>
1033
1034<!-- ======================================================================= -->
1035<div class="doc_subsection">
Devang Patel008cd3e2008-09-26 23:51:19 +00001036 <a name="fnattrs">Function Attributes</a>
Devang Pateld468f1c2008-09-04 23:05:13 +00001037</div>
1038
1039<div class="doc_text">
Devang Patel008cd3e2008-09-26 23:51:19 +00001040
1041<p>Function attributes are set to communicate additional information about
1042 a function. Function attributes are considered to be part of the function,
1043 not of the function type, so functions with different parameter attributes
1044 can have the same function type.</p>
1045
1046 <p>Function attributes are simple keywords that follow the type specified. If
1047 multiple attributes are needed, they are space separated. For
1048 example:</p>
Devang Pateld468f1c2008-09-04 23:05:13 +00001049
1050<div class="doc_code">
Bill Wendling74d3eac2008-09-07 10:26:33 +00001051<pre>
Devang Patel008cd3e2008-09-26 23:51:19 +00001052define void @f() noinline { ... }
1053define void @f() alwaysinline { ... }
1054define void @f() alwaysinline optsize { ... }
1055define void @f() optsize
Bill Wendling74d3eac2008-09-07 10:26:33 +00001056</pre>
Devang Pateld468f1c2008-09-04 23:05:13 +00001057</div>
1058
Bill Wendling74d3eac2008-09-07 10:26:33 +00001059<dl>
Devang Patel008cd3e2008-09-26 23:51:19 +00001060<dt><tt>alwaysinline</tt></dt>
Chris Lattner82d70f92008-10-04 18:23:17 +00001061<dd>This attribute indicates that the inliner should attempt to inline this
1062function into callers whenever possible, ignoring any active inlining size
1063threshold for this caller.</dd>
Bill Wendling74d3eac2008-09-07 10:26:33 +00001064
Devang Patel008cd3e2008-09-26 23:51:19 +00001065<dt><tt>noinline</tt></dt>
Chris Lattner82d70f92008-10-04 18:23:17 +00001066<dd>This attribute indicates that the inliner should never inline this function
Chris Lattner377f3ae2008-10-05 17:14:59 +00001067in any situation. This attribute may not be used together with the
Chris Lattner82d70f92008-10-04 18:23:17 +00001068<tt>alwaysinline</tt> attribute.</dd>
Bill Wendling74d3eac2008-09-07 10:26:33 +00001069
Devang Patel008cd3e2008-09-26 23:51:19 +00001070<dt><tt>optsize</tt></dt>
Devang Patelc29099b2008-09-29 18:34:44 +00001071<dd>This attribute suggests that optimization passes and code generator passes
Chris Lattner82d70f92008-10-04 18:23:17 +00001072make choices that keep the code size of this function low, and otherwise do
1073optimizations specifically to reduce code size.</dd>
Bill Wendling74d3eac2008-09-07 10:26:33 +00001074
Devang Patel008cd3e2008-09-26 23:51:19 +00001075<dt><tt>noreturn</tt></dt>
Chris Lattner82d70f92008-10-04 18:23:17 +00001076<dd>This function attribute indicates that the function never returns normally.
1077This produces undefined behavior at runtime if the function ever does
1078dynamically return.</dd>
Devang Patel008cd3e2008-09-26 23:51:19 +00001079
1080<dt><tt>nounwind</tt></dt>
Chris Lattner82d70f92008-10-04 18:23:17 +00001081<dd>This function attribute indicates that the function never returns with an
1082unwind or exceptional control flow. If the function does unwind, its runtime
1083behavior is undefined.</dd>
1084
1085<dt><tt>readnone</tt></dt>
Duncan Sands2f500832009-05-06 06:49:50 +00001086<dd>This attribute indicates that the function computes its result (or decides to
1087unwind an exception) based strictly on its arguments, without dereferencing any
Duncan Sands7d94e5a2008-10-06 08:14:18 +00001088pointer arguments or otherwise accessing any mutable state (e.g. memory, control
1089registers, etc) visible to caller functions. It does not write through any
1090pointer arguments (including <tt><a href="#byval">byval</a></tt> arguments) and
Duncan Sands2f500832009-05-06 06:49:50 +00001091never changes any state visible to callers. This means that it cannot unwind
1092exceptions by calling the <tt>C++</tt> exception throwing methods, but could
1093use the <tt>unwind</tt> instruction.</dd>
Devang Patel008cd3e2008-09-26 23:51:19 +00001094
Duncan Sands7d94e5a2008-10-06 08:14:18 +00001095<dt><tt><a name="readonly">readonly</a></tt></dt>
1096<dd>This attribute indicates that the function does not write through any
1097pointer arguments (including <tt><a href="#byval">byval</a></tt> arguments)
1098or otherwise modify any state (e.g. memory, control registers, etc) visible to
1099caller functions. It may dereference pointer arguments and read state that may
Duncan Sands2f500832009-05-06 06:49:50 +00001100be set in the caller. A readonly function always returns the same value (or
1101unwinds an exception identically) when called with the same set of arguments
1102and global state. It cannot unwind an exception by calling the <tt>C++</tt>
1103exception throwing methods, but may use the <tt>unwind</tt> instruction.</dd>
Bill Wendlingdfaabba2008-11-13 01:02:51 +00001104
1105<dt><tt><a name="ssp">ssp</a></tt></dt>
Bill Wendling34f70d82008-11-26 19:19:05 +00001106<dd>This attribute indicates that the function should emit a stack smashing
Bill Wendlingdfaabba2008-11-13 01:02:51 +00001107protector. It is in the form of a "canary"&mdash;a random value placed on the
1108stack before the local variables that's checked upon return from the function to
1109see if it has been overwritten. A heuristic is used to determine if a function
Bill Wendling34f70d82008-11-26 19:19:05 +00001110needs stack protectors or not.
Bill Wendlingdfaabba2008-11-13 01:02:51 +00001111
Devang Patela2f9f412009-06-12 19:45:19 +00001112<br><br>If a function that has an <tt>ssp</tt> attribute is inlined into a function
Bill Wendlingbe9ec3f2008-11-26 19:07:40 +00001113that doesn't have an <tt>ssp</tt> attribute, then the resulting function will
Devang Patela2f9f412009-06-12 19:45:19 +00001114have an <tt>ssp</tt> attribute.</dd>
Bill Wendlingbe9ec3f2008-11-26 19:07:40 +00001115
1116<dt><tt>sspreq</tt></dt>
Bill Wendling34f70d82008-11-26 19:19:05 +00001117<dd>This attribute indicates that the function should <em>always</em> emit a
Bill Wendlingdfaabba2008-11-13 01:02:51 +00001118stack smashing protector. This overrides the <tt><a href="#ssp">ssp</a></tt>
Bill Wendling34f70d82008-11-26 19:19:05 +00001119function attribute.
Bill Wendlingbe9ec3f2008-11-26 19:07:40 +00001120
Devang Patela2f9f412009-06-12 19:45:19 +00001121If a function that has an <tt>sspreq</tt> attribute is inlined into a
Bill Wendlingbe9ec3f2008-11-26 19:07:40 +00001122function that doesn't have an <tt>sspreq</tt> attribute or which has
1123an <tt>ssp</tt> attribute, then the resulting function will have
Devang Patela2f9f412009-06-12 19:45:19 +00001124an <tt>sspreq</tt> attribute.</dd>
1125
1126<dt><tt>noredzone</tt></dt>
Dan Gohman06c9b732009-06-15 17:37:09 +00001127<dd>This attribute indicates that the code generator should not use a
Dan Gohmanf958d5c2009-06-15 21:18:01 +00001128red zone, even if the target-specific ABI normally permits it.
Dan Gohman06c9b732009-06-15 17:37:09 +00001129</dd>
Devang Patela2f9f412009-06-12 19:45:19 +00001130
1131<dt><tt>noimplicitfloat</tt></dt>
1132<dd>This attributes disables implicit floating point instructions.</dd>
1133
Anton Korobeynikovedd7d112009-07-17 18:07:26 +00001134<dt><tt>naked</tt></dt>
Chris Lattnerc529b882009-07-17 21:14:28 +00001135<dd>This attribute disables prologue / epilogue emission for the function.
1136This can have very system-specific consequences.</dd>
Anton Korobeynikovedd7d112009-07-17 18:07:26 +00001137
Bill Wendling74d3eac2008-09-07 10:26:33 +00001138</dl>
1139
Devang Pateld468f1c2008-09-04 23:05:13 +00001140</div>
1141
1142<!-- ======================================================================= -->
1143<div class="doc_subsection">
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001144 <a name="moduleasm">Module-Level Inline Assembly</a>
1145</div>
1146
1147<div class="doc_text">
1148<p>
1149Modules may contain "module-level inline asm" blocks, which corresponds to the
1150GCC "file scope inline asm" blocks. These blocks are internally concatenated by
1151LLVM and treated as a single unit, but may be separated in the .ll file if
1152desired. The syntax is very simple:
1153</p>
1154
1155<div class="doc_code">
1156<pre>
1157module asm "inline asm code goes here"
1158module asm "more can go here"
1159</pre>
1160</div>
1161
1162<p>The strings can contain any character by escaping non-printable characters.
1163 The escape sequence used is simply "\xx" where "xx" is the two digit hex code
1164 for the number.
1165</p>
1166
1167<p>
1168 The inline asm code is simply printed to the machine code .s file when
1169 assembly code is generated.
1170</p>
1171</div>
1172
1173<!-- ======================================================================= -->
1174<div class="doc_subsection">
1175 <a name="datalayout">Data Layout</a>
1176</div>
1177
1178<div class="doc_text">
1179<p>A module may specify a target specific data layout string that specifies how
1180data is to be laid out in memory. The syntax for the data layout is simply:</p>
1181<pre> target datalayout = "<i>layout specification</i>"</pre>
1182<p>The <i>layout specification</i> consists of a list of specifications
1183separated by the minus sign character ('-'). Each specification starts with a
1184letter and may include other information after the letter to define some
1185aspect of the data layout. The specifications accepted are as follows: </p>
1186<dl>
1187 <dt><tt>E</tt></dt>
1188 <dd>Specifies that the target lays out data in big-endian form. That is, the
1189 bits with the most significance have the lowest address location.</dd>
1190 <dt><tt>e</tt></dt>
Chris Lattner96451482008-08-05 18:29:16 +00001191 <dd>Specifies that the target lays out data in little-endian form. That is,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001192 the bits with the least significance have the lowest address location.</dd>
1193 <dt><tt>p:<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1194 <dd>This specifies the <i>size</i> of a pointer and its <i>abi</i> and
1195 <i>preferred</i> alignments. All sizes are in bits. Specifying the <i>pref</i>
1196 alignment is optional. If omitted, the preceding <tt>:</tt> should be omitted
1197 too.</dd>
1198 <dt><tt>i<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1199 <dd>This specifies the alignment for an integer type of a given bit
1200 <i>size</i>. The value of <i>size</i> must be in the range [1,2^23).</dd>
1201 <dt><tt>v<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1202 <dd>This specifies the alignment for a vector type of a given bit
1203 <i>size</i>.</dd>
1204 <dt><tt>f<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1205 <dd>This specifies the alignment for a floating point type of a given bit
1206 <i>size</i>. The value of <i>size</i> must be either 32 (float) or 64
1207 (double).</dd>
1208 <dt><tt>a<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1209 <dd>This specifies the alignment for an aggregate type of a given bit
1210 <i>size</i>.</dd>
Daniel Dunbard88a97b2009-06-08 22:17:53 +00001211 <dt><tt>s<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1212 <dd>This specifies the alignment for a stack object of a given bit
1213 <i>size</i>.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001214</dl>
1215<p>When constructing the data layout for a given target, LLVM starts with a
1216default set of specifications which are then (possibly) overriden by the
1217specifications in the <tt>datalayout</tt> keyword. The default specifications
1218are given in this list:</p>
1219<ul>
1220 <li><tt>E</tt> - big endian</li>
1221 <li><tt>p:32:64:64</tt> - 32-bit pointers with 64-bit alignment</li>
1222 <li><tt>i1:8:8</tt> - i1 is 8-bit (byte) aligned</li>
1223 <li><tt>i8:8:8</tt> - i8 is 8-bit (byte) aligned</li>
1224 <li><tt>i16:16:16</tt> - i16 is 16-bit aligned</li>
1225 <li><tt>i32:32:32</tt> - i32 is 32-bit aligned</li>
Chris Lattner96451482008-08-05 18:29:16 +00001226 <li><tt>i64:32:64</tt> - i64 has ABI alignment of 32-bits but preferred
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001227 alignment of 64-bits</li>
1228 <li><tt>f32:32:32</tt> - float is 32-bit aligned</li>
1229 <li><tt>f64:64:64</tt> - double is 64-bit aligned</li>
1230 <li><tt>v64:64:64</tt> - 64-bit vector is 64-bit aligned</li>
1231 <li><tt>v128:128:128</tt> - 128-bit vector is 128-bit aligned</li>
1232 <li><tt>a0:0:1</tt> - aggregates are 8-bit aligned</li>
Daniel Dunbard88a97b2009-06-08 22:17:53 +00001233 <li><tt>s0:64:64</tt> - stack objects are 64-bit aligned</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001234</ul>
Chris Lattner6a9f3c42008-08-05 18:21:08 +00001235<p>When LLVM is determining the alignment for a given type, it uses the
Dan Gohman2672f3e2008-10-14 16:51:45 +00001236following rules:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001237<ol>
1238 <li>If the type sought is an exact match for one of the specifications, that
1239 specification is used.</li>
1240 <li>If no match is found, and the type sought is an integer type, then the
1241 smallest integer type that is larger than the bitwidth of the sought type is
1242 used. If none of the specifications are larger than the bitwidth then the the
1243 largest integer type is used. For example, given the default specifications
1244 above, the i7 type will use the alignment of i8 (next largest) while both
1245 i65 and i256 will use the alignment of i64 (largest specified).</li>
1246 <li>If no match is found, and the type sought is a vector type, then the
1247 largest vector type that is smaller than the sought vector type will be used
Dan Gohman2672f3e2008-10-14 16:51:45 +00001248 as a fall back. This happens because &lt;128 x double&gt; can be implemented
1249 in terms of 64 &lt;2 x double&gt;, for example.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001250</ol>
1251</div>
1252
1253<!-- *********************************************************************** -->
1254<div class="doc_section"> <a name="typesystem">Type System</a> </div>
1255<!-- *********************************************************************** -->
1256
1257<div class="doc_text">
1258
1259<p>The LLVM type system is one of the most important features of the
1260intermediate representation. Being typed enables a number of
Chris Lattner96451482008-08-05 18:29:16 +00001261optimizations to be performed on the intermediate representation directly,
1262without having to do
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001263extra analyses on the side before the transformation. A strong type
1264system makes it easier to read the generated code and enables novel
1265analyses and transformations that are not feasible to perform on normal
1266three address code representations.</p>
1267
1268</div>
1269
1270<!-- ======================================================================= -->
Chris Lattner488772f2008-01-04 04:32:38 +00001271<div class="doc_subsection"> <a name="t_classifications">Type
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001272Classifications</a> </div>
1273<div class="doc_text">
Chris Lattner488772f2008-01-04 04:32:38 +00001274<p>The types fall into a few useful
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001275classifications:</p>
1276
1277<table border="1" cellspacing="0" cellpadding="4">
1278 <tbody>
1279 <tr><th>Classification</th><th>Types</th></tr>
1280 <tr>
Chris Lattner488772f2008-01-04 04:32:38 +00001281 <td><a href="#t_integer">integer</a></td>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001282 <td><tt>i1, i2, i3, ... i8, ... i16, ... i32, ... i64, ... </tt></td>
1283 </tr>
1284 <tr>
Chris Lattner488772f2008-01-04 04:32:38 +00001285 <td><a href="#t_floating">floating point</a></td>
1286 <td><tt>float, double, x86_fp80, fp128, ppc_fp128</tt></td>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001287 </tr>
1288 <tr>
1289 <td><a name="t_firstclass">first class</a></td>
Chris Lattner488772f2008-01-04 04:32:38 +00001290 <td><a href="#t_integer">integer</a>,
1291 <a href="#t_floating">floating point</a>,
1292 <a href="#t_pointer">pointer</a>,
Dan Gohmanf6237db2008-06-18 18:42:13 +00001293 <a href="#t_vector">vector</a>,
Dan Gohman74d6faf2008-05-12 23:51:09 +00001294 <a href="#t_struct">structure</a>,
1295 <a href="#t_array">array</a>,
Nick Lewycky29aaef82009-05-30 05:06:04 +00001296 <a href="#t_label">label</a>,
1297 <a href="#t_metadata">metadata</a>.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001298 </td>
1299 </tr>
Chris Lattner488772f2008-01-04 04:32:38 +00001300 <tr>
1301 <td><a href="#t_primitive">primitive</a></td>
1302 <td><a href="#t_label">label</a>,
1303 <a href="#t_void">void</a>,
Nick Lewycky29aaef82009-05-30 05:06:04 +00001304 <a href="#t_floating">floating point</a>,
1305 <a href="#t_metadata">metadata</a>.</td>
Chris Lattner488772f2008-01-04 04:32:38 +00001306 </tr>
1307 <tr>
1308 <td><a href="#t_derived">derived</a></td>
1309 <td><a href="#t_integer">integer</a>,
1310 <a href="#t_array">array</a>,
1311 <a href="#t_function">function</a>,
1312 <a href="#t_pointer">pointer</a>,
1313 <a href="#t_struct">structure</a>,
1314 <a href="#t_pstruct">packed structure</a>,
1315 <a href="#t_vector">vector</a>,
1316 <a href="#t_opaque">opaque</a>.
Dan Gohman032ba852008-10-14 16:32:04 +00001317 </td>
Chris Lattner488772f2008-01-04 04:32:38 +00001318 </tr>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001319 </tbody>
1320</table>
1321
1322<p>The <a href="#t_firstclass">first class</a> types are perhaps the
1323most important. Values of these types are the only ones which can be
1324produced by instructions, passed as arguments, or used as operands to
Dan Gohman4f29e422008-05-23 21:53:15 +00001325instructions.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001326</div>
1327
1328<!-- ======================================================================= -->
Chris Lattner488772f2008-01-04 04:32:38 +00001329<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Chris Lattner86437612008-01-04 04:34:14 +00001330
Chris Lattner488772f2008-01-04 04:32:38 +00001331<div class="doc_text">
1332<p>The primitive types are the fundamental building blocks of the LLVM
1333system.</p>
1334
Chris Lattner86437612008-01-04 04:34:14 +00001335</div>
1336
Chris Lattner488772f2008-01-04 04:32:38 +00001337<!-- _______________________________________________________________________ -->
1338<div class="doc_subsubsection"> <a name="t_floating">Floating Point Types</a> </div>
1339
1340<div class="doc_text">
1341 <table>
1342 <tbody>
1343 <tr><th>Type</th><th>Description</th></tr>
1344 <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr>
1345 <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr>
1346 <tr><td><tt>fp128</tt></td><td>128-bit floating point value (112-bit mantissa)</td></tr>
1347 <tr><td><tt>x86_fp80</tt></td><td>80-bit floating point value (X87)</td></tr>
1348 <tr><td><tt>ppc_fp128</tt></td><td>128-bit floating point value (two 64-bits)</td></tr>
1349 </tbody>
1350 </table>
1351</div>
1352
1353<!-- _______________________________________________________________________ -->
1354<div class="doc_subsubsection"> <a name="t_void">Void Type</a> </div>
1355
1356<div class="doc_text">
1357<h5>Overview:</h5>
1358<p>The void type does not represent any value and has no size.</p>
1359
1360<h5>Syntax:</h5>
1361
1362<pre>
1363 void
1364</pre>
1365</div>
1366
1367<!-- _______________________________________________________________________ -->
1368<div class="doc_subsubsection"> <a name="t_label">Label Type</a> </div>
1369
1370<div class="doc_text">
1371<h5>Overview:</h5>
1372<p>The label type represents code labels.</p>
1373
1374<h5>Syntax:</h5>
1375
1376<pre>
1377 label
1378</pre>
1379</div>
1380
Nick Lewycky29aaef82009-05-30 05:06:04 +00001381<!-- _______________________________________________________________________ -->
1382<div class="doc_subsubsection"> <a name="t_metadata">Metadata Type</a> </div>
1383
1384<div class="doc_text">
1385<h5>Overview:</h5>
1386<p>The metadata type represents embedded metadata. The only derived type that
1387may contain metadata is <tt>metadata*</tt> or a function type that returns or
1388takes metadata typed parameters, but not pointer to metadata types.</p>
1389
1390<h5>Syntax:</h5>
1391
1392<pre>
1393 metadata
1394</pre>
1395</div>
1396
Chris Lattner488772f2008-01-04 04:32:38 +00001397
1398<!-- ======================================================================= -->
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001399<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
1400
1401<div class="doc_text">
1402
1403<p>The real power in LLVM comes from the derived types in the system.
1404This is what allows a programmer to represent arrays, functions,
1405pointers, and other useful types. Note that these derived types may be
1406recursive: For example, it is possible to have a two dimensional array.</p>
1407
1408</div>
1409
1410<!-- _______________________________________________________________________ -->
1411<div class="doc_subsubsection"> <a name="t_integer">Integer Type</a> </div>
1412
1413<div class="doc_text">
1414
1415<h5>Overview:</h5>
1416<p>The integer type is a very simple derived type that simply specifies an
1417arbitrary bit width for the integer type desired. Any bit width from 1 bit to
14182^23-1 (about 8 million) can be specified.</p>
1419
1420<h5>Syntax:</h5>
1421
1422<pre>
1423 iN
1424</pre>
1425
1426<p>The number of bits the integer will occupy is specified by the <tt>N</tt>
1427value.</p>
1428
1429<h5>Examples:</h5>
1430<table class="layout">
Nick Lewycky39382d62009-05-24 02:46:06 +00001431 <tr class="layout">
1432 <td class="left"><tt>i1</tt></td>
1433 <td class="left">a single-bit integer.</td>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001434 </tr>
Nick Lewycky39382d62009-05-24 02:46:06 +00001435 <tr class="layout">
1436 <td class="left"><tt>i32</tt></td>
1437 <td class="left">a 32-bit integer.</td>
1438 </tr>
1439 <tr class="layout">
1440 <td class="left"><tt>i1942652</tt></td>
1441 <td class="left">a really big integer of over 1 million bits.</td>
1442 </tr>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001443</table>
djge93155c2009-01-24 15:58:40 +00001444
1445<p>Note that the code generator does not yet support large integer types
1446to be used as function return types. The specific limit on how large a
1447return type the code generator can currently handle is target-dependent;
1448currently it's often 64 bits for 32-bit targets and 128 bits for 64-bit
1449targets.</p>
1450
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001451</div>
1452
1453<!-- _______________________________________________________________________ -->
1454<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
1455
1456<div class="doc_text">
1457
1458<h5>Overview:</h5>
1459
1460<p>The array type is a very simple derived type that arranges elements
1461sequentially in memory. The array type requires a size (number of
1462elements) and an underlying data type.</p>
1463
1464<h5>Syntax:</h5>
1465
1466<pre>
1467 [&lt;# elements&gt; x &lt;elementtype&gt;]
1468</pre>
1469
1470<p>The number of elements is a constant integer value; elementtype may
1471be any type with a size.</p>
1472
1473<h5>Examples:</h5>
1474<table class="layout">
1475 <tr class="layout">
Chris Lattner7311d222007-12-19 05:04:11 +00001476 <td class="left"><tt>[40 x i32]</tt></td>
1477 <td class="left">Array of 40 32-bit integer values.</td>
1478 </tr>
1479 <tr class="layout">
1480 <td class="left"><tt>[41 x i32]</tt></td>
1481 <td class="left">Array of 41 32-bit integer values.</td>
1482 </tr>
1483 <tr class="layout">
1484 <td class="left"><tt>[4 x i8]</tt></td>
1485 <td class="left">Array of 4 8-bit integer values.</td>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001486 </tr>
1487</table>
1488<p>Here are some examples of multidimensional arrays:</p>
1489<table class="layout">
1490 <tr class="layout">
Chris Lattner7311d222007-12-19 05:04:11 +00001491 <td class="left"><tt>[3 x [4 x i32]]</tt></td>
1492 <td class="left">3x4 array of 32-bit integer values.</td>
1493 </tr>
1494 <tr class="layout">
1495 <td class="left"><tt>[12 x [10 x float]]</tt></td>
1496 <td class="left">12x10 array of single precision floating point values.</td>
1497 </tr>
1498 <tr class="layout">
1499 <td class="left"><tt>[2 x [3 x [4 x i16]]]</tt></td>
1500 <td class="left">2x3x4 array of 16-bit integer values.</td>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001501 </tr>
1502</table>
1503
1504<p>Note that 'variable sized arrays' can be implemented in LLVM with a zero
1505length array. Normally, accesses past the end of an array are undefined in
1506LLVM (e.g. it is illegal to access the 5th element of a 3 element array).
1507As a special case, however, zero length arrays are recognized to be variable
1508length. This allows implementation of 'pascal style arrays' with the LLVM
1509type "{ i32, [0 x float]}", for example.</p>
1510
djge93155c2009-01-24 15:58:40 +00001511<p>Note that the code generator does not yet support large aggregate types
1512to be used as function return types. The specific limit on how large an
1513aggregate return type the code generator can currently handle is
1514target-dependent, and also dependent on the aggregate element types.</p>
1515
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001516</div>
1517
1518<!-- _______________________________________________________________________ -->
1519<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
1520<div class="doc_text">
Chris Lattner43030e72008-04-23 04:59:35 +00001521
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001522<h5>Overview:</h5>
Chris Lattner43030e72008-04-23 04:59:35 +00001523
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001524<p>The function type can be thought of as a function signature. It
Devang Pateld4ba41d2008-03-24 05:35:41 +00001525consists of a return type and a list of formal parameter types. The
Chris Lattner43030e72008-04-23 04:59:35 +00001526return type of a function type is a scalar type, a void type, or a struct type.
Devang Pateld5404c02008-03-24 20:52:42 +00001527If the return type is a struct type then all struct elements must be of first
Chris Lattner43030e72008-04-23 04:59:35 +00001528class types, and the struct must have at least one element.</p>
Devang Patela3cc5372008-03-10 20:49:15 +00001529
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001530<h5>Syntax:</h5>
Chris Lattner43030e72008-04-23 04:59:35 +00001531
1532<pre>
1533 &lt;returntype list&gt; (&lt;parameter list&gt;)
1534</pre>
1535
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001536<p>...where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
1537specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
1538which indicates that the function takes a variable number of arguments.
1539Variable argument functions can access their arguments with the <a
Devang Patela3cc5372008-03-10 20:49:15 +00001540 href="#int_varargs">variable argument handling intrinsic</a> functions.
1541'<tt>&lt;returntype list&gt;</tt>' is a comma-separated list of
1542<a href="#t_firstclass">first class</a> type specifiers.</p>
Chris Lattner43030e72008-04-23 04:59:35 +00001543
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001544<h5>Examples:</h5>
1545<table class="layout">
1546 <tr class="layout">
1547 <td class="left"><tt>i32 (i32)</tt></td>
1548 <td class="left">function taking an <tt>i32</tt>, returning an <tt>i32</tt>
1549 </td>
1550 </tr><tr class="layout">
Reid Spencerf234bed2007-07-19 23:13:04 +00001551 <td class="left"><tt>float&nbsp;(i16&nbsp;signext,&nbsp;i32&nbsp;*)&nbsp;*
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001552 </tt></td>
1553 <td class="left"><a href="#t_pointer">Pointer</a> to a function that takes
1554 an <tt>i16</tt> that should be sign extended and a
1555 <a href="#t_pointer">pointer</a> to <tt>i32</tt>, returning
1556 <tt>float</tt>.
1557 </td>
1558 </tr><tr class="layout">
1559 <td class="left"><tt>i32 (i8*, ...)</tt></td>
1560 <td class="left">A vararg function that takes at least one
1561 <a href="#t_pointer">pointer</a> to <tt>i8 </tt> (char in C),
1562 which returns an integer. This is the signature for <tt>printf</tt> in
1563 LLVM.
1564 </td>
Devang Pateld4ba41d2008-03-24 05:35:41 +00001565 </tr><tr class="layout">
1566 <td class="left"><tt>{i32, i32} (i32)</tt></td>
Misha Brukmanafc88b02008-11-27 06:41:20 +00001567 <td class="left">A function taking an <tt>i32</tt>, returning two
1568 <tt>i32</tt> values as an aggregate of type <tt>{ i32, i32 }</tt>
Devang Pateld4ba41d2008-03-24 05:35:41 +00001569 </td>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001570 </tr>
1571</table>
1572
1573</div>
1574<!-- _______________________________________________________________________ -->
1575<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
1576<div class="doc_text">
1577<h5>Overview:</h5>
1578<p>The structure type is used to represent a collection of data members
1579together in memory. The packing of the field types is defined to match
1580the ABI of the underlying processor. The elements of a structure may
1581be any type that has a size.</p>
1582<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
1583and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
1584field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
1585instruction.</p>
1586<h5>Syntax:</h5>
1587<pre> { &lt;type list&gt; }<br></pre>
1588<h5>Examples:</h5>
1589<table class="layout">
1590 <tr class="layout">
1591 <td class="left"><tt>{ i32, i32, i32 }</tt></td>
1592 <td class="left">A triple of three <tt>i32</tt> values</td>
1593 </tr><tr class="layout">
1594 <td class="left"><tt>{&nbsp;float,&nbsp;i32&nbsp;(i32)&nbsp;*&nbsp;}</tt></td>
1595 <td class="left">A pair, where the first element is a <tt>float</tt> and the
1596 second element is a <a href="#t_pointer">pointer</a> to a
1597 <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning
1598 an <tt>i32</tt>.</td>
1599 </tr>
1600</table>
djge93155c2009-01-24 15:58:40 +00001601
1602<p>Note that the code generator does not yet support large aggregate types
1603to be used as function return types. The specific limit on how large an
1604aggregate return type the code generator can currently handle is
1605target-dependent, and also dependent on the aggregate element types.</p>
1606
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001607</div>
1608
1609<!-- _______________________________________________________________________ -->
1610<div class="doc_subsubsection"> <a name="t_pstruct">Packed Structure Type</a>
1611</div>
1612<div class="doc_text">
1613<h5>Overview:</h5>
1614<p>The packed structure type is used to represent a collection of data members
1615together in memory. There is no padding between fields. Further, the alignment
1616of a packed structure is 1 byte. The elements of a packed structure may
1617be any type that has a size.</p>
1618<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
1619and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
1620field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
1621instruction.</p>
1622<h5>Syntax:</h5>
1623<pre> &lt; { &lt;type list&gt; } &gt; <br></pre>
1624<h5>Examples:</h5>
1625<table class="layout">
1626 <tr class="layout">
1627 <td class="left"><tt>&lt; { i32, i32, i32 } &gt;</tt></td>
1628 <td class="left">A triple of three <tt>i32</tt> values</td>
1629 </tr><tr class="layout">
Bill Wendling74d3eac2008-09-07 10:26:33 +00001630 <td class="left">
1631<tt>&lt;&nbsp;{&nbsp;float,&nbsp;i32&nbsp;(i32)*&nbsp;}&nbsp;&gt;</tt></td>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001632 <td class="left">A pair, where the first element is a <tt>float</tt> and the
1633 second element is a <a href="#t_pointer">pointer</a> to a
1634 <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning
1635 an <tt>i32</tt>.</td>
1636 </tr>
1637</table>
1638</div>
1639
1640<!-- _______________________________________________________________________ -->
1641<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
1642<div class="doc_text">
1643<h5>Overview:</h5>
1644<p>As in many languages, the pointer type represents a pointer or
Christopher Lambdd0049d2007-12-11 09:31:00 +00001645reference to another object, which must live in memory. Pointer types may have
1646an optional address space attribute defining the target-specific numbered
1647address space where the pointed-to object resides. The default address space is
1648zero.</p>
Chris Lattner96edbd32009-02-08 19:53:29 +00001649
1650<p>Note that LLVM does not permit pointers to void (<tt>void*</tt>) nor does
Chris Lattner0d879e02009-02-08 22:21:28 +00001651it permit pointers to labels (<tt>label*</tt>). Use <tt>i8*</tt> instead.</p>
Chris Lattner96edbd32009-02-08 19:53:29 +00001652
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001653<h5>Syntax:</h5>
1654<pre> &lt;type&gt; *<br></pre>
1655<h5>Examples:</h5>
1656<table class="layout">
1657 <tr class="layout">
Dan Gohman01852382009-01-04 23:44:43 +00001658 <td class="left"><tt>[4 x i32]*</tt></td>
Chris Lattner7311d222007-12-19 05:04:11 +00001659 <td class="left">A <a href="#t_pointer">pointer</a> to <a
1660 href="#t_array">array</a> of four <tt>i32</tt> values.</td>
1661 </tr>
1662 <tr class="layout">
1663 <td class="left"><tt>i32 (i32 *) *</tt></td>
1664 <td class="left"> A <a href="#t_pointer">pointer</a> to a <a
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001665 href="#t_function">function</a> that takes an <tt>i32*</tt>, returning an
Chris Lattner7311d222007-12-19 05:04:11 +00001666 <tt>i32</tt>.</td>
1667 </tr>
1668 <tr class="layout">
1669 <td class="left"><tt>i32 addrspace(5)*</tt></td>
1670 <td class="left">A <a href="#t_pointer">pointer</a> to an <tt>i32</tt> value
1671 that resides in address space #5.</td>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001672 </tr>
1673</table>
1674</div>
1675
1676<!-- _______________________________________________________________________ -->
1677<div class="doc_subsubsection"> <a name="t_vector">Vector Type</a> </div>
1678<div class="doc_text">
1679
1680<h5>Overview:</h5>
1681
1682<p>A vector type is a simple derived type that represents a vector
1683of elements. Vector types are used when multiple primitive data
1684are operated in parallel using a single instruction (SIMD).
1685A vector type requires a size (number of
1686elements) and an underlying primitive data type. Vectors must have a power
1687of two length (1, 2, 4, 8, 16 ...). Vector types are
1688considered <a href="#t_firstclass">first class</a>.</p>
1689
1690<h5>Syntax:</h5>
1691
1692<pre>
1693 &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;
1694</pre>
1695
1696<p>The number of elements is a constant integer value; elementtype may
1697be any integer or floating point type.</p>
1698
1699<h5>Examples:</h5>
1700
1701<table class="layout">
1702 <tr class="layout">
Chris Lattner7311d222007-12-19 05:04:11 +00001703 <td class="left"><tt>&lt;4 x i32&gt;</tt></td>
1704 <td class="left">Vector of 4 32-bit integer values.</td>
1705 </tr>
1706 <tr class="layout">
1707 <td class="left"><tt>&lt;8 x float&gt;</tt></td>
1708 <td class="left">Vector of 8 32-bit floating-point values.</td>
1709 </tr>
1710 <tr class="layout">
1711 <td class="left"><tt>&lt;2 x i64&gt;</tt></td>
1712 <td class="left">Vector of 2 64-bit integer values.</td>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001713 </tr>
1714</table>
djge93155c2009-01-24 15:58:40 +00001715
1716<p>Note that the code generator does not yet support large vector types
1717to be used as function return types. The specific limit on how large a
1718vector return type codegen can currently handle is target-dependent;
1719currently it's often a few times longer than a hardware vector register.</p>
1720
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001721</div>
1722
1723<!-- _______________________________________________________________________ -->
1724<div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div>
1725<div class="doc_text">
1726
1727<h5>Overview:</h5>
1728
1729<p>Opaque types are used to represent unknown types in the system. This
Gordon Henriksenda0706e2007-10-14 00:34:53 +00001730corresponds (for example) to the C notion of a forward declared structure type.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001731In LLVM, opaque types can eventually be resolved to any type (not just a
1732structure type).</p>
1733
1734<h5>Syntax:</h5>
1735
1736<pre>
1737 opaque
1738</pre>
1739
1740<h5>Examples:</h5>
1741
1742<table class="layout">
1743 <tr class="layout">
Chris Lattner7311d222007-12-19 05:04:11 +00001744 <td class="left"><tt>opaque</tt></td>
1745 <td class="left">An opaque type.</td>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001746 </tr>
1747</table>
1748</div>
1749
Chris Lattner515195a2009-02-02 07:32:36 +00001750<!-- ======================================================================= -->
1751<div class="doc_subsection">
1752 <a name="t_uprefs">Type Up-references</a>
1753</div>
1754
1755<div class="doc_text">
1756<h5>Overview:</h5>
1757<p>
1758An "up reference" allows you to refer to a lexically enclosing type without
1759requiring it to have a name. For instance, a structure declaration may contain a
1760pointer to any of the types it is lexically a member of. Example of up
1761references (with their equivalent as named type declarations) include:</p>
1762
1763<pre>
Chris Lattner5ad632d2009-02-09 10:00:56 +00001764 { \2 * } %x = type { %x* }
Chris Lattner515195a2009-02-02 07:32:36 +00001765 { \2 }* %y = type { %y }*
1766 \1* %z = type %z*
1767</pre>
1768
1769<p>
1770An up reference is needed by the asmprinter for printing out cyclic types when
1771there is no declared name for a type in the cycle. Because the asmprinter does
1772not want to print out an infinite type string, it needs a syntax to handle
1773recursive types that have no names (all names are optional in llvm IR).
1774</p>
1775
1776<h5>Syntax:</h5>
1777<pre>
1778 \&lt;level&gt;
1779</pre>
1780
1781<p>
1782The level is the count of the lexical type that is being referred to.
1783</p>
1784
1785<h5>Examples:</h5>
1786
1787<table class="layout">
1788 <tr class="layout">
1789 <td class="left"><tt>\1*</tt></td>
1790 <td class="left">Self-referential pointer.</td>
1791 </tr>
1792 <tr class="layout">
1793 <td class="left"><tt>{ { \3*, i8 }, i32 }</tt></td>
1794 <td class="left">Recursive structure where the upref refers to the out-most
1795 structure.</td>
1796 </tr>
1797</table>
1798</div>
1799
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001800
1801<!-- *********************************************************************** -->
1802<div class="doc_section"> <a name="constants">Constants</a> </div>
1803<!-- *********************************************************************** -->
1804
1805<div class="doc_text">
1806
1807<p>LLVM has several different basic types of constants. This section describes
1808them all and their syntax.</p>
1809
1810</div>
1811
1812<!-- ======================================================================= -->
1813<div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
1814
1815<div class="doc_text">
1816
1817<dl>
1818 <dt><b>Boolean constants</b></dt>
1819
1820 <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
1821 constants of the <tt><a href="#t_primitive">i1</a></tt> type.
1822 </dd>
1823
1824 <dt><b>Integer constants</b></dt>
1825
1826 <dd>Standard integers (such as '4') are constants of the <a
1827 href="#t_integer">integer</a> type. Negative numbers may be used with
1828 integer types.
1829 </dd>
1830
1831 <dt><b>Floating point constants</b></dt>
1832
1833 <dd>Floating point constants use standard decimal notation (e.g. 123.421),
1834 exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
Chris Lattnerdc15b1d2008-04-01 18:45:27 +00001835 notation (see below). The assembler requires the exact decimal value of
1836 a floating-point constant. For example, the assembler accepts 1.25 but
1837 rejects 1.3 because 1.3 is a repeating decimal in binary. Floating point
1838 constants must have a <a href="#t_floating">floating point</a> type. </dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001839
1840 <dt><b>Null pointer constants</b></dt>
1841
1842 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
1843 and must be of <a href="#t_pointer">pointer type</a>.</dd>
1844
1845</dl>
1846
Dale Johannesenf82a52f2009-02-11 22:14:51 +00001847<p>The one non-intuitive notation for constants is the hexadecimal form
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001848of floating point constants. For example, the form '<tt>double
18490x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
18504.5e+15</tt>'. The only time hexadecimal floating point constants are required
1851(and the only time that they are generated by the disassembler) is when a
1852floating point constant must be emitted but it cannot be represented as a
Dale Johannesenf82a52f2009-02-11 22:14:51 +00001853decimal floating point number in a reasonable number of digits. For example,
1854NaN's, infinities, and other
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001855special values are represented in their IEEE hexadecimal format so that
1856assembly and disassembly do not cause any bits to change in the constants.</p>
Dale Johannesenf82a52f2009-02-11 22:14:51 +00001857<p>When using the hexadecimal form, constants of types float and double are
1858represented using the 16-digit form shown above (which matches the IEEE754
1859representation for double); float values must, however, be exactly representable
1860as IEE754 single precision.
1861Hexadecimal format is always used for long
1862double, and there are three forms of long double. The 80-bit
1863format used by x86 is represented as <tt>0xK</tt>
1864followed by 20 hexadecimal digits.
1865The 128-bit format used by PowerPC (two adjacent doubles) is represented
1866by <tt>0xM</tt> followed by 32 hexadecimal digits. The IEEE 128-bit
1867format is represented
1868by <tt>0xL</tt> followed by 32 hexadecimal digits; no currently supported
1869target uses this format. Long doubles will only work if they match
1870the long double format on your target. All hexadecimal formats are big-endian
1871(sign bit at the left).</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001872</div>
1873
1874<!-- ======================================================================= -->
Chris Lattner97063852009-02-28 18:32:25 +00001875<div class="doc_subsection">
1876<a name="aggregateconstants"> <!-- old anchor -->
1877<a name="complexconstants">Complex Constants</a></a>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001878</div>
1879
1880<div class="doc_text">
Chris Lattner97063852009-02-28 18:32:25 +00001881<p>Complex constants are a (potentially recursive) combination of simple
1882constants and smaller complex constants.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001883
1884<dl>
1885 <dt><b>Structure constants</b></dt>
1886
1887 <dd>Structure constants are represented with notation similar to structure
1888 type definitions (a comma separated list of elements, surrounded by braces
Chris Lattner6c8de962007-12-25 20:34:52 +00001889 (<tt>{}</tt>)). For example: "<tt>{ i32 4, float 17.0, i32* @G }</tt>",
1890 where "<tt>@G</tt>" is declared as "<tt>@G = external global i32</tt>". Structure constants
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001891 must have <a href="#t_struct">structure type</a>, and the number and
1892 types of elements must match those specified by the type.
1893 </dd>
1894
1895 <dt><b>Array constants</b></dt>
1896
1897 <dd>Array constants are represented with notation similar to array type
1898 definitions (a comma separated list of elements, surrounded by square brackets
1899 (<tt>[]</tt>)). For example: "<tt>[ i32 42, i32 11, i32 74 ]</tt>". Array
1900 constants must have <a href="#t_array">array type</a>, and the number and
1901 types of elements must match those specified by the type.
1902 </dd>
1903
1904 <dt><b>Vector constants</b></dt>
1905
1906 <dd>Vector constants are represented with notation similar to vector type
1907 definitions (a comma separated list of elements, surrounded by
1908 less-than/greater-than's (<tt>&lt;&gt;</tt>)). For example: "<tt>&lt; i32 42,
1909 i32 11, i32 74, i32 100 &gt;</tt>". Vector constants must have <a
1910 href="#t_vector">vector type</a>, and the number and types of elements must
1911 match those specified by the type.
1912 </dd>
1913
1914 <dt><b>Zero initialization</b></dt>
1915
1916 <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
1917 value to zero of <em>any</em> type, including scalar and aggregate types.
1918 This is often used to avoid having to print large zero initializers (e.g. for
1919 large arrays) and is always exactly equivalent to using explicit zero
1920 initializers.
1921 </dd>
Nick Lewycky4dcf8102009-04-04 07:22:01 +00001922
1923 <dt><b>Metadata node</b></dt>
1924
Nick Lewyckyf122c7e2009-05-30 16:08:30 +00001925 <dd>A metadata node is a structure-like constant with
1926 <a href="#t_metadata">metadata type</a>. For example:
1927 "<tt>metadata !{ i32 0, metadata !"test" }</tt>". Unlike other constants
1928 that are meant to be interpreted as part of the instruction stream, metadata
1929 is a place to attach additional information such as debug info.
Nick Lewycky4dcf8102009-04-04 07:22:01 +00001930 </dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001931</dl>
1932
1933</div>
1934
1935<!-- ======================================================================= -->
1936<div class="doc_subsection">
1937 <a name="globalconstants">Global Variable and Function Addresses</a>
1938</div>
1939
1940<div class="doc_text">
1941
1942<p>The addresses of <a href="#globalvars">global variables</a> and <a
1943href="#functionstructure">functions</a> are always implicitly valid (link-time)
1944constants. These constants are explicitly referenced when the <a
1945href="#identifiers">identifier for the global</a> is used and always have <a
1946href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
1947file:</p>
1948
1949<div class="doc_code">
1950<pre>
1951@X = global i32 17
1952@Y = global i32 42
1953@Z = global [2 x i32*] [ i32* @X, i32* @Y ]
1954</pre>
1955</div>
1956
1957</div>
1958
1959<!-- ======================================================================= -->
1960<div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
1961<div class="doc_text">
1962 <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has
1963 no specific value. Undefined values may be of any type and be used anywhere
1964 a constant is permitted.</p>
1965
1966 <p>Undefined values indicate to the compiler that the program is well defined
1967 no matter what value is used, giving the compiler more freedom to optimize.
1968 </p>
1969</div>
1970
1971<!-- ======================================================================= -->
1972<div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
1973</div>
1974
1975<div class="doc_text">
1976
1977<p>Constant expressions are used to allow expressions involving other constants
1978to be used as constants. Constant expressions may be of any <a
1979href="#t_firstclass">first class</a> type and may involve any LLVM operation
1980that does not have side effects (e.g. load and call are not supported). The
1981following is the syntax for constant expressions:</p>
1982
1983<dl>
1984 <dt><b><tt>trunc ( CST to TYPE )</tt></b></dt>
1985 <dd>Truncate a constant to another type. The bit size of CST must be larger
1986 than the bit size of TYPE. Both types must be integers.</dd>
1987
1988 <dt><b><tt>zext ( CST to TYPE )</tt></b></dt>
1989 <dd>Zero extend a constant to another type. The bit size of CST must be
1990 smaller or equal to the bit size of TYPE. Both types must be integers.</dd>
1991
1992 <dt><b><tt>sext ( CST to TYPE )</tt></b></dt>
1993 <dd>Sign extend a constant to another type. The bit size of CST must be
1994 smaller or equal to the bit size of TYPE. Both types must be integers.</dd>
1995
1996 <dt><b><tt>fptrunc ( CST to TYPE )</tt></b></dt>
1997 <dd>Truncate a floating point constant to another floating point type. The
1998 size of CST must be larger than the size of TYPE. Both types must be
1999 floating point.</dd>
2000
2001 <dt><b><tt>fpext ( CST to TYPE )</tt></b></dt>
2002 <dd>Floating point extend a constant to another type. The size of CST must be
2003 smaller or equal to the size of TYPE. Both types must be floating point.</dd>
2004
Reid Spencere6adee82007-07-31 14:40:14 +00002005 <dt><b><tt>fptoui ( CST to TYPE )</tt></b></dt>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002006 <dd>Convert a floating point constant to the corresponding unsigned integer
Nate Begeman78246ca2007-11-17 03:58:34 +00002007 constant. TYPE must be a scalar or vector integer type. CST must be of scalar
2008 or vector floating point type. Both CST and TYPE must be scalars, or vectors
2009 of the same number of elements. If the value won't fit in the integer type,
2010 the results are undefined.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002011
2012 <dt><b><tt>fptosi ( CST to TYPE )</tt></b></dt>
2013 <dd>Convert a floating point constant to the corresponding signed integer
Nate Begeman78246ca2007-11-17 03:58:34 +00002014 constant. TYPE must be a scalar or vector integer type. CST must be of scalar
2015 or vector floating point type. Both CST and TYPE must be scalars, or vectors
2016 of the same number of elements. If the value won't fit in the integer type,
2017 the results are undefined.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002018
2019 <dt><b><tt>uitofp ( CST to TYPE )</tt></b></dt>
2020 <dd>Convert an unsigned integer constant to the corresponding floating point
Nate Begeman78246ca2007-11-17 03:58:34 +00002021 constant. TYPE must be a scalar or vector floating point type. CST must be of
2022 scalar or vector integer type. Both CST and TYPE must be scalars, or vectors
2023 of the same number of elements. If the value won't fit in the floating point
2024 type, the results are undefined.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002025
2026 <dt><b><tt>sitofp ( CST to TYPE )</tt></b></dt>
2027 <dd>Convert a signed integer constant to the corresponding floating point
Nate Begeman78246ca2007-11-17 03:58:34 +00002028 constant. TYPE must be a scalar or vector floating point type. CST must be of
2029 scalar or vector integer type. Both CST and TYPE must be scalars, or vectors
2030 of the same number of elements. If the value won't fit in the floating point
2031 type, the results are undefined.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002032
2033 <dt><b><tt>ptrtoint ( CST to TYPE )</tt></b></dt>
2034 <dd>Convert a pointer typed constant to the corresponding integer constant
2035 TYPE must be an integer type. CST must be of pointer type. The CST value is
2036 zero extended, truncated, or unchanged to make it fit in TYPE.</dd>
2037
2038 <dt><b><tt>inttoptr ( CST to TYPE )</tt></b></dt>
2039 <dd>Convert a integer constant to a pointer constant. TYPE must be a
2040 pointer type. CST must be of integer type. The CST value is zero extended,
2041 truncated, or unchanged to make it fit in a pointer size. This one is
2042 <i>really</i> dangerous!</dd>
2043
2044 <dt><b><tt>bitcast ( CST to TYPE )</tt></b></dt>
Chris Lattner557bc5d2009-02-28 18:27:03 +00002045 <dd>Convert a constant, CST, to another TYPE. The constraints of the operands
2046 are the same as those for the <a href="#i_bitcast">bitcast
2047 instruction</a>.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002048
2049 <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
2050
2051 <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
2052 constants. As with the <a href="#i_getelementptr">getelementptr</a>
2053 instruction, the index list may have zero or more indexes, which are required
2054 to make sense for the type of "CSTPTR".</dd>
2055
2056 <dt><b><tt>select ( COND, VAL1, VAL2 )</tt></b></dt>
2057
2058 <dd>Perform the <a href="#i_select">select operation</a> on
2059 constants.</dd>
2060
2061 <dt><b><tt>icmp COND ( VAL1, VAL2 )</tt></b></dt>
2062 <dd>Performs the <a href="#i_icmp">icmp operation</a> on constants.</dd>
2063
2064 <dt><b><tt>fcmp COND ( VAL1, VAL2 )</tt></b></dt>
2065 <dd>Performs the <a href="#i_fcmp">fcmp operation</a> on constants.</dd>
2066
2067 <dt><b><tt>extractelement ( VAL, IDX )</tt></b></dt>
2068
2069 <dd>Perform the <a href="#i_extractelement">extractelement
Dan Gohman2672f3e2008-10-14 16:51:45 +00002070 operation</a> on constants.</dd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002071
2072 <dt><b><tt>insertelement ( VAL, ELT, IDX )</tt></b></dt>
2073
2074 <dd>Perform the <a href="#i_insertelement">insertelement
2075 operation</a> on constants.</dd>
2076
2077
2078 <dt><b><tt>shufflevector ( VEC1, VEC2, IDXMASK )</tt></b></dt>
2079
2080 <dd>Perform the <a href="#i_shufflevector">shufflevector
2081 operation</a> on constants.</dd>
2082
2083 <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
2084
2085 <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
2086 be any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise
2087 binary</a> operations. The constraints on operands are the same as those for
2088 the corresponding instruction (e.g. no bitwise operations on floating point
2089 values are allowed).</dd>
2090</dl>
2091</div>
2092
Nick Lewycky4dcf8102009-04-04 07:22:01 +00002093<!-- ======================================================================= -->
2094<div class="doc_subsection"><a name="metadata">Embedded Metadata</a>
2095</div>
2096
2097<div class="doc_text">
2098
2099<p>Embedded metadata provides a way to attach arbitrary data to the
2100instruction stream without affecting the behaviour of the program. There are
Nick Lewycky29aaef82009-05-30 05:06:04 +00002101two metadata primitives, strings and nodes. All metadata has the
2102<tt>metadata</tt> type and is identified in syntax by a preceding exclamation
2103point ('<tt>!</tt>').
Nick Lewycky4dcf8102009-04-04 07:22:01 +00002104</p>
2105
2106<p>A metadata string is a string surrounded by double quotes. It can contain
2107any character by escaping non-printable characters with "\xx" where "xx" is
2108the two digit hex code. For example: "<tt>!"test\00"</tt>".
2109</p>
2110
2111<p>Metadata nodes are represented with notation similar to structure constants
2112(a comma separated list of elements, surrounded by braces and preceeded by an
Nick Lewycky29aaef82009-05-30 05:06:04 +00002113exclamation point). For example: "<tt>!{ metadata !"test\00", i32 10}</tt>".
Nick Lewycky4dcf8102009-04-04 07:22:01 +00002114</p>
2115
Nick Lewycky117f4382009-05-10 20:57:05 +00002116<p>A metadata node will attempt to track changes to the values it holds. In
2117the event that a value is deleted, it will be replaced with a typeless
Nick Lewycky29aaef82009-05-30 05:06:04 +00002118"<tt>null</tt>", such as "<tt>metadata !{null, i32 10}</tt>".</p>
Nick Lewycky117f4382009-05-10 20:57:05 +00002119
Nick Lewycky4dcf8102009-04-04 07:22:01 +00002120<p>Optimizations may rely on metadata to provide additional information about
2121the program that isn't available in the instructions, or that isn't easily
2122computable. Similarly, the code generator may expect a certain metadata format
2123to be used to express debugging information.</p>
2124</div>
2125
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002126<!-- *********************************************************************** -->
2127<div class="doc_section"> <a name="othervalues">Other Values</a> </div>
2128<!-- *********************************************************************** -->
2129
2130<!-- ======================================================================= -->
2131<div class="doc_subsection">
2132<a name="inlineasm">Inline Assembler Expressions</a>
2133</div>
2134
2135<div class="doc_text">
2136
2137<p>
2138LLVM supports inline assembler expressions (as opposed to <a href="#moduleasm">
2139Module-Level Inline Assembly</a>) through the use of a special value. This
2140value represents the inline assembler as a string (containing the instructions
2141to emit), a list of operand constraints (stored as a string), and a flag that
2142indicates whether or not the inline asm expression has side effects. An example
2143inline assembler expression is:
2144</p>
2145
2146<div class="doc_code">
2147<pre>
2148i32 (i32) asm "bswap $0", "=r,r"
2149</pre>
2150</div>
2151
2152<p>
2153Inline assembler expressions may <b>only</b> be used as the callee operand of
2154a <a href="#i_call"><tt>call</tt> instruction</a>. Thus, typically we have:
2155</p>
2156
2157<div class="doc_code">
2158<pre>
2159%X = call i32 asm "<a href="#int_bswap">bswap</a> $0", "=r,r"(i32 %Y)
2160</pre>
2161</div>
2162
2163<p>
2164Inline asms with side effects not visible in the constraint list must be marked
2165as having side effects. This is done through the use of the
2166'<tt>sideeffect</tt>' keyword, like so:
2167</p>
2168
2169<div class="doc_code">
2170<pre>
2171call void asm sideeffect "eieio", ""()
2172</pre>
2173</div>
2174
2175<p>TODO: The format of the asm and constraints string still need to be
2176documented here. Constraints on what can be done (e.g. duplication, moving, etc
Chris Lattner1cdd64e2008-10-04 18:36:02 +00002177need to be documented). This is probably best done by reference to another
2178document that covers inline asm from a holistic perspective.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002179</p>
2180
2181</div>
2182
2183<!-- *********************************************************************** -->
2184<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
2185<!-- *********************************************************************** -->
2186
2187<div class="doc_text">
2188
2189<p>The LLVM instruction set consists of several different
2190classifications of instructions: <a href="#terminators">terminator
2191instructions</a>, <a href="#binaryops">binary instructions</a>,
2192<a href="#bitwiseops">bitwise binary instructions</a>, <a
2193 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
2194instructions</a>.</p>
2195
2196</div>
2197
2198<!-- ======================================================================= -->
2199<div class="doc_subsection"> <a name="terminators">Terminator
2200Instructions</a> </div>
2201
2202<div class="doc_text">
2203
2204<p>As mentioned <a href="#functionstructure">previously</a>, every
2205basic block in a program ends with a "Terminator" instruction, which
2206indicates which block should be executed after the current block is
2207finished. These terminator instructions typically yield a '<tt>void</tt>'
2208value: they produce control flow, not values (the one exception being
2209the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
2210<p>There are six different terminator instructions: the '<a
2211 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
2212instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
2213the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
2214 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
2215 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
2216
2217</div>
2218
2219<!-- _______________________________________________________________________ -->
2220<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
2221Instruction</a> </div>
2222<div class="doc_text">
2223<h5>Syntax:</h5>
Dan Gohman3e700032008-10-04 19:00:07 +00002224<pre>
2225 ret &lt;type&gt; &lt;value&gt; <i>; Return a value from a non-void function</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002226 ret void <i>; Return from void function</i>
2227</pre>
Chris Lattner43030e72008-04-23 04:59:35 +00002228
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002229<h5>Overview:</h5>
Chris Lattner43030e72008-04-23 04:59:35 +00002230
Dan Gohman3e700032008-10-04 19:00:07 +00002231<p>The '<tt>ret</tt>' instruction is used to return control flow (and
2232optionally a value) from a function back to the caller.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002233<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Dan Gohman3e700032008-10-04 19:00:07 +00002234returns a value and then causes control flow, and one that just causes
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002235control flow to occur.</p>
Chris Lattner43030e72008-04-23 04:59:35 +00002236
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002237<h5>Arguments:</h5>
Chris Lattner43030e72008-04-23 04:59:35 +00002238
Dan Gohman3e700032008-10-04 19:00:07 +00002239<p>The '<tt>ret</tt>' instruction optionally accepts a single argument,
2240the return value. The type of the return value must be a
2241'<a href="#t_firstclass">first class</a>' type.</p>
2242
2243<p>A function is not <a href="#wellformed">well formed</a> if
2244it it has a non-void return type and contains a '<tt>ret</tt>'
2245instruction with no return value or a return value with a type that
2246does not match its type, or if it has a void return type and contains
2247a '<tt>ret</tt>' instruction with a return value.</p>
Chris Lattner43030e72008-04-23 04:59:35 +00002248
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002249<h5>Semantics:</h5>
Chris Lattner43030e72008-04-23 04:59:35 +00002250
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002251<p>When the '<tt>ret</tt>' instruction is executed, control flow
2252returns back to the calling function's context. If the caller is a "<a
2253 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
2254the instruction after the call. If the caller was an "<a
2255 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
2256at the beginning of the "normal" destination block. If the instruction
2257returns a value, that value shall set the call or invoke instruction's
Dan Gohman2672f3e2008-10-14 16:51:45 +00002258return value.</p>
Chris Lattner43030e72008-04-23 04:59:35 +00002259
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002260<h5>Example:</h5>
Chris Lattner43030e72008-04-23 04:59:35 +00002261
2262<pre>
2263 ret i32 5 <i>; Return an integer value of 5</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002264 ret void <i>; Return from a void function</i>
Bill Wendlingd163e2d2009-02-28 22:12:54 +00002265 ret { i32, i8 } { i32 4, i8 2 } <i>; Return a struct of values 4 and 2</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002266</pre>
Dan Gohman60967192009-01-12 23:12:39 +00002267
djge93155c2009-01-24 15:58:40 +00002268<p>Note that the code generator does not yet fully support large
2269 return values. The specific sizes that are currently supported are
2270 dependent on the target. For integers, on 32-bit targets the limit
2271 is often 64 bits, and on 64-bit targets the limit is often 128 bits.
2272 For aggregate types, the current limits are dependent on the element
2273 types; for example targets are often limited to 2 total integer
2274 elements and 2 total floating-point elements.</p>
Dan Gohman60967192009-01-12 23:12:39 +00002275
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002276</div>
2277<!-- _______________________________________________________________________ -->
2278<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
2279<div class="doc_text">
2280<h5>Syntax:</h5>
2281<pre> br i1 &lt;cond&gt;, label &lt;iftrue&gt;, label &lt;iffalse&gt;<br> br label &lt;dest&gt; <i>; Unconditional branch</i>
2282</pre>
2283<h5>Overview:</h5>
2284<p>The '<tt>br</tt>' instruction is used to cause control flow to
2285transfer to a different basic block in the current function. There are
2286two forms of this instruction, corresponding to a conditional branch
2287and an unconditional branch.</p>
2288<h5>Arguments:</h5>
2289<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
2290single '<tt>i1</tt>' value and two '<tt>label</tt>' values. The
2291unconditional form of the '<tt>br</tt>' instruction takes a single
2292'<tt>label</tt>' value as a target.</p>
2293<h5>Semantics:</h5>
2294<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>i1</tt>'
2295argument is evaluated. If the value is <tt>true</tt>, control flows
2296to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
2297control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
2298<h5>Example:</h5>
Chris Lattner95127832009-05-09 18:11:50 +00002299<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 +00002300 href="#i_ret">ret</a> i32 1<br>IfUnequal:<br> <a href="#i_ret">ret</a> i32 0<br></pre>
2301</div>
2302<!-- _______________________________________________________________________ -->
2303<div class="doc_subsubsection">
2304 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
2305</div>
2306
2307<div class="doc_text">
2308<h5>Syntax:</h5>
2309
2310<pre>
2311 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
2312</pre>
2313
2314<h5>Overview:</h5>
2315
2316<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
2317several different places. It is a generalization of the '<tt>br</tt>'
2318instruction, allowing a branch to occur to one of many possible
2319destinations.</p>
2320
2321
2322<h5>Arguments:</h5>
2323
2324<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
2325comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
2326an array of pairs of comparison value constants and '<tt>label</tt>'s. The
2327table is not allowed to contain duplicate constant entries.</p>
2328
2329<h5>Semantics:</h5>
2330
2331<p>The <tt>switch</tt> instruction specifies a table of values and
2332destinations. When the '<tt>switch</tt>' instruction is executed, this
2333table is searched for the given value. If the value is found, control flow is
2334transfered to the corresponding destination; otherwise, control flow is
2335transfered to the default destination.</p>
2336
2337<h5>Implementation:</h5>
2338
2339<p>Depending on properties of the target machine and the particular
2340<tt>switch</tt> instruction, this instruction may be code generated in different
2341ways. For example, it could be generated as a series of chained conditional
2342branches or with a lookup table.</p>
2343
2344<h5>Example:</h5>
2345
2346<pre>
2347 <i>; Emulate a conditional br instruction</i>
2348 %Val = <a href="#i_zext">zext</a> i1 %value to i32
Dan Gohman01852382009-01-04 23:44:43 +00002349 switch i32 %Val, label %truedest [ i32 0, label %falsedest ]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002350
2351 <i>; Emulate an unconditional br instruction</i>
2352 switch i32 0, label %dest [ ]
2353
2354 <i>; Implement a jump table:</i>
Dan Gohman01852382009-01-04 23:44:43 +00002355 switch i32 %val, label %otherwise [ i32 0, label %onzero
2356 i32 1, label %onone
2357 i32 2, label %ontwo ]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002358</pre>
2359</div>
2360
2361<!-- _______________________________________________________________________ -->
2362<div class="doc_subsubsection">
2363 <a name="i_invoke">'<tt>invoke</tt>' Instruction</a>
2364</div>
2365
2366<div class="doc_text">
2367
2368<h5>Syntax:</h5>
2369
2370<pre>
Devang Pateld0bfcc72008-10-07 17:48:33 +00002371 &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 +00002372 to label &lt;normal label&gt; unwind label &lt;exception label&gt;
2373</pre>
2374
2375<h5>Overview:</h5>
2376
2377<p>The '<tt>invoke</tt>' instruction causes control to transfer to a specified
2378function, with the possibility of control flow transfer to either the
2379'<tt>normal</tt>' label or the
2380'<tt>exception</tt>' label. If the callee function returns with the
2381"<tt><a href="#i_ret">ret</a></tt>" instruction, control flow will return to the
2382"normal" label. If the callee (or any indirect callees) returns with the "<a
2383href="#i_unwind"><tt>unwind</tt></a>" instruction, control is interrupted and
Dan Gohman2672f3e2008-10-14 16:51:45 +00002384continued at the dynamically nearest "exception" label.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002385
2386<h5>Arguments:</h5>
2387
2388<p>This instruction requires several arguments:</p>
2389
2390<ol>
2391 <li>
2392 The optional "cconv" marker indicates which <a href="#callingconv">calling
2393 convention</a> the call should use. If none is specified, the call defaults
2394 to using C calling conventions.
2395 </li>
Devang Patelac2fc272008-10-06 18:50:38 +00002396
2397 <li>The optional <a href="#paramattrs">Parameter Attributes</a> list for
2398 return values. Only '<tt>zeroext</tt>', '<tt>signext</tt>',
2399 and '<tt>inreg</tt>' attributes are valid here.</li>
2400
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002401 <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to
2402 function value being invoked. In most cases, this is a direct function
2403 invocation, but indirect <tt>invoke</tt>s are just as possible, branching off
2404 an arbitrary pointer to function value.
2405 </li>
2406
2407 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a
2408 function to be invoked. </li>
2409
2410 <li>'<tt>function args</tt>': argument list whose types match the function
2411 signature argument types. If the function signature indicates the function
2412 accepts a variable number of arguments, the extra arguments can be
2413 specified. </li>
2414
2415 <li>'<tt>normal label</tt>': the label reached when the called function
2416 executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
2417
2418 <li>'<tt>exception label</tt>': the label reached when a callee returns with
2419 the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
2420
Devang Pateld0bfcc72008-10-07 17:48:33 +00002421 <li>The optional <a href="#fnattrs">function attributes</a> list. Only
Devang Patelac2fc272008-10-06 18:50:38 +00002422 '<tt>noreturn</tt>', '<tt>nounwind</tt>', '<tt>readonly</tt>' and
2423 '<tt>readnone</tt>' attributes are valid here.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002424</ol>
2425
2426<h5>Semantics:</h5>
2427
2428<p>This instruction is designed to operate as a standard '<tt><a
2429href="#i_call">call</a></tt>' instruction in most regards. The primary
2430difference is that it establishes an association with a label, which is used by
2431the runtime library to unwind the stack.</p>
2432
2433<p>This instruction is used in languages with destructors to ensure that proper
2434cleanup is performed in the case of either a <tt>longjmp</tt> or a thrown
2435exception. Additionally, this is important for implementation of
2436'<tt>catch</tt>' clauses in high-level languages that support them.</p>
2437
Jay Foad8e2fd2c2009-06-03 10:20:10 +00002438<p>For the purposes of the SSA form, the definition of the value
2439returned by the '<tt>invoke</tt>' instruction is deemed to occur on
2440the edge from the current block to the "normal" label. If the callee
2441unwinds then no return value is available.</p>
Dan Gohman140ba5d2009-05-22 21:47:08 +00002442
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002443<h5>Example:</h5>
2444<pre>
Nick Lewyckya1c11a12008-03-16 07:18:12 +00002445 %retval = invoke i32 @Test(i32 15) to label %Continue
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002446 unwind label %TestCleanup <i>; {i32}:retval set</i>
Nick Lewyckya1c11a12008-03-16 07:18:12 +00002447 %retval = invoke <a href="#callingconv">coldcc</a> i32 %Testfnptr(i32 15) to label %Continue
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002448 unwind label %TestCleanup <i>; {i32}:retval set</i>
2449</pre>
2450</div>
2451
2452
2453<!-- _______________________________________________________________________ -->
2454
2455<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
2456Instruction</a> </div>
2457
2458<div class="doc_text">
2459
2460<h5>Syntax:</h5>
2461<pre>
2462 unwind
2463</pre>
2464
2465<h5>Overview:</h5>
2466
2467<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
2468at the first callee in the dynamic call stack which used an <a
2469href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
2470primarily used to implement exception handling.</p>
2471
2472<h5>Semantics:</h5>
2473
Chris Lattner8b094fc2008-04-19 21:01:16 +00002474<p>The '<tt>unwind</tt>' instruction causes execution of the current function to
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002475immediately halt. The dynamic call stack is then searched for the first <a
2476href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
2477execution continues at the "exceptional" destination block specified by the
2478<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
2479dynamic call chain, undefined behavior results.</p>
2480</div>
2481
2482<!-- _______________________________________________________________________ -->
2483
2484<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
2485Instruction</a> </div>
2486
2487<div class="doc_text">
2488
2489<h5>Syntax:</h5>
2490<pre>
2491 unreachable
2492</pre>
2493
2494<h5>Overview:</h5>
2495
2496<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
2497instruction is used to inform the optimizer that a particular portion of the
2498code is not reachable. This can be used to indicate that the code after a
2499no-return function cannot be reached, and other facts.</p>
2500
2501<h5>Semantics:</h5>
2502
2503<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
2504</div>
2505
2506
2507
2508<!-- ======================================================================= -->
2509<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
2510<div class="doc_text">
2511<p>Binary operators are used to do most of the computation in a
Chris Lattnerab596d92008-04-01 18:47:32 +00002512program. They require two operands of the same type, execute an operation on them, and
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002513produce a single value. The operands might represent
2514multiple data, as is the case with the <a href="#t_vector">vector</a> data type.
Chris Lattnerab596d92008-04-01 18:47:32 +00002515The result value has the same type as its operands.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002516<p>There are several different binary operators:</p>
2517</div>
2518<!-- _______________________________________________________________________ -->
Chris Lattner6704c212008-05-20 20:48:21 +00002519<div class="doc_subsubsection">
2520 <a name="i_add">'<tt>add</tt>' Instruction</a>
2521</div>
2522
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002523<div class="doc_text">
Chris Lattner6704c212008-05-20 20:48:21 +00002524
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002525<h5>Syntax:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002526
2527<pre>
Gabor Greifd9068fe2008-08-07 21:46:00 +00002528 &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 +00002529</pre>
Chris Lattner6704c212008-05-20 20:48:21 +00002530
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002531<h5>Overview:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002532
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002533<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002534
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002535<h5>Arguments:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002536
2537<p>The two arguments to the '<tt>add</tt>' instruction must be <a
Dan Gohman7ce405e2009-06-04 22:49:04 +00002538 href="#t_integer">integer</a> or
2539 <a href="#t_vector">vector</a> of integer values. Both arguments must
2540 have identical types.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002541
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002542<h5>Semantics:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002543
Dan Gohman7ce405e2009-06-04 22:49:04 +00002544<p>The value produced is the integer sum of the two operands.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002545
Dan Gohman7ce405e2009-06-04 22:49:04 +00002546<p>If the sum has unsigned overflow, the result returned is the
Chris Lattner9aba1e22008-01-28 00:36:27 +00002547mathematical result modulo 2<sup>n</sup>, where n is the bit width of
2548the result.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002549
Chris Lattner9aba1e22008-01-28 00:36:27 +00002550<p>Because LLVM integers use a two's complement representation, this
2551instruction is appropriate for both signed and unsigned integers.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002552
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002553<h5>Example:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002554
2555<pre>
2556 &lt;result&gt; = add i32 4, %var <i>; yields {i32}:result = 4 + %var</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002557</pre>
2558</div>
2559<!-- _______________________________________________________________________ -->
Chris Lattner6704c212008-05-20 20:48:21 +00002560<div class="doc_subsubsection">
Dan Gohman7ce405e2009-06-04 22:49:04 +00002561 <a name="i_fadd">'<tt>fadd</tt>' Instruction</a>
2562</div>
2563
2564<div class="doc_text">
2565
2566<h5>Syntax:</h5>
2567
2568<pre>
2569 &lt;result&gt; = fadd &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
2570</pre>
2571
2572<h5>Overview:</h5>
2573
2574<p>The '<tt>fadd</tt>' instruction returns the sum of its two operands.</p>
2575
2576<h5>Arguments:</h5>
2577
2578<p>The two arguments to the '<tt>fadd</tt>' instruction must be
2579<a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> of
2580floating point values. Both arguments must have identical types.</p>
2581
2582<h5>Semantics:</h5>
2583
2584<p>The value produced is the floating point sum of the two operands.</p>
2585
2586<h5>Example:</h5>
2587
2588<pre>
2589 &lt;result&gt; = fadd float 4.0, %var <i>; yields {float}:result = 4.0 + %var</i>
2590</pre>
2591</div>
2592<!-- _______________________________________________________________________ -->
2593<div class="doc_subsubsection">
Chris Lattner6704c212008-05-20 20:48:21 +00002594 <a name="i_sub">'<tt>sub</tt>' Instruction</a>
2595</div>
2596
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002597<div class="doc_text">
Chris Lattner6704c212008-05-20 20:48:21 +00002598
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002599<h5>Syntax:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002600
2601<pre>
Gabor Greifd9068fe2008-08-07 21:46:00 +00002602 &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 +00002603</pre>
Chris Lattner6704c212008-05-20 20:48:21 +00002604
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002605<h5>Overview:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002606
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002607<p>The '<tt>sub</tt>' instruction returns the difference of its two
2608operands.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002609
2610<p>Note that the '<tt>sub</tt>' instruction is used to represent the
2611'<tt>neg</tt>' instruction present in most other intermediate
2612representations.</p>
2613
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002614<h5>Arguments:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002615
2616<p>The two arguments to the '<tt>sub</tt>' instruction must be <a
Dan Gohman7ce405e2009-06-04 22:49:04 +00002617 href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of
2618 integer values. Both arguments must have identical types.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002619
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002620<h5>Semantics:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002621
Dan Gohman7ce405e2009-06-04 22:49:04 +00002622<p>The value produced is the integer difference of the two operands.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002623
Dan Gohman7ce405e2009-06-04 22:49:04 +00002624<p>If the difference has unsigned overflow, the result returned is the
Chris Lattner9aba1e22008-01-28 00:36:27 +00002625mathematical result modulo 2<sup>n</sup>, where n is the bit width of
2626the result.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002627
Chris Lattner9aba1e22008-01-28 00:36:27 +00002628<p>Because LLVM integers use a two's complement representation, this
2629instruction is appropriate for both signed and unsigned integers.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002630
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002631<h5>Example:</h5>
2632<pre>
2633 &lt;result&gt; = sub i32 4, %var <i>; yields {i32}:result = 4 - %var</i>
2634 &lt;result&gt; = sub i32 0, %val <i>; yields {i32}:result = -%var</i>
2635</pre>
2636</div>
Chris Lattner6704c212008-05-20 20:48:21 +00002637
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002638<!-- _______________________________________________________________________ -->
Chris Lattner6704c212008-05-20 20:48:21 +00002639<div class="doc_subsubsection">
Dan Gohman7ce405e2009-06-04 22:49:04 +00002640 <a name="i_fsub">'<tt>fsub</tt>' Instruction</a>
2641</div>
2642
2643<div class="doc_text">
2644
2645<h5>Syntax:</h5>
2646
2647<pre>
2648 &lt;result&gt; = fsub &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
2649</pre>
2650
2651<h5>Overview:</h5>
2652
2653<p>The '<tt>fsub</tt>' instruction returns the difference of its two
2654operands.</p>
2655
2656<p>Note that the '<tt>fsub</tt>' instruction is used to represent the
2657'<tt>fneg</tt>' instruction present in most other intermediate
2658representations.</p>
2659
2660<h5>Arguments:</h5>
2661
2662<p>The two arguments to the '<tt>fsub</tt>' instruction must be <a
2663 <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a>
2664 of floating point values. Both arguments must have identical types.</p>
2665
2666<h5>Semantics:</h5>
2667
2668<p>The value produced is the floating point difference of the two operands.</p>
2669
2670<h5>Example:</h5>
2671<pre>
2672 &lt;result&gt; = fsub float 4.0, %var <i>; yields {float}:result = 4.0 - %var</i>
2673 &lt;result&gt; = fsub float -0.0, %val <i>; yields {float}:result = -%var</i>
2674</pre>
2675</div>
2676
2677<!-- _______________________________________________________________________ -->
2678<div class="doc_subsubsection">
Chris Lattner6704c212008-05-20 20:48:21 +00002679 <a name="i_mul">'<tt>mul</tt>' Instruction</a>
2680</div>
2681
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002682<div class="doc_text">
Chris Lattner6704c212008-05-20 20:48:21 +00002683
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002684<h5>Syntax:</h5>
Gabor Greifd9068fe2008-08-07 21:46:00 +00002685<pre> &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 +00002686</pre>
2687<h5>Overview:</h5>
2688<p>The '<tt>mul</tt>' instruction returns the product of its two
2689operands.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002690
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002691<h5>Arguments:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002692
2693<p>The two arguments to the '<tt>mul</tt>' instruction must be <a
Dan Gohman7ce405e2009-06-04 22:49:04 +00002694href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
2695values. Both arguments must have identical types.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002696
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002697<h5>Semantics:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002698
Dan Gohman7ce405e2009-06-04 22:49:04 +00002699<p>The value produced is the integer product of the two operands.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002700
Dan Gohman7ce405e2009-06-04 22:49:04 +00002701<p>If the result of the multiplication has unsigned overflow,
Chris Lattner9aba1e22008-01-28 00:36:27 +00002702the result returned is the mathematical result modulo
27032<sup>n</sup>, where n is the bit width of the result.</p>
2704<p>Because LLVM integers use a two's complement representation, and the
2705result is the same width as the operands, this instruction returns the
2706correct result for both signed and unsigned integers. If a full product
2707(e.g. <tt>i32</tt>x<tt>i32</tt>-><tt>i64</tt>) is needed, the operands
2708should be sign-extended or zero-extended as appropriate to the
2709width of the full product.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002710<h5>Example:</h5>
2711<pre> &lt;result&gt; = mul i32 4, %var <i>; yields {i32}:result = 4 * %var</i>
2712</pre>
2713</div>
Chris Lattner6704c212008-05-20 20:48:21 +00002714
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002715<!-- _______________________________________________________________________ -->
Dan Gohman7ce405e2009-06-04 22:49:04 +00002716<div class="doc_subsubsection">
2717 <a name="i_fmul">'<tt>fmul</tt>' Instruction</a>
2718</div>
2719
2720<div class="doc_text">
2721
2722<h5>Syntax:</h5>
2723<pre> &lt;result&gt; = fmul &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
2724</pre>
2725<h5>Overview:</h5>
2726<p>The '<tt>fmul</tt>' instruction returns the product of its two
2727operands.</p>
2728
2729<h5>Arguments:</h5>
2730
2731<p>The two arguments to the '<tt>fmul</tt>' instruction must be
2732<a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a>
2733of floating point values. Both arguments must have identical types.</p>
2734
2735<h5>Semantics:</h5>
2736
2737<p>The value produced is the floating point product of the two operands.</p>
2738
2739<h5>Example:</h5>
2740<pre> &lt;result&gt; = fmul float 4.0, %var <i>; yields {float}:result = 4.0 * %var</i>
2741</pre>
2742</div>
2743
2744<!-- _______________________________________________________________________ -->
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002745<div class="doc_subsubsection"> <a name="i_udiv">'<tt>udiv</tt>' Instruction
2746</a></div>
2747<div class="doc_text">
2748<h5>Syntax:</h5>
Gabor Greifd9068fe2008-08-07 21:46:00 +00002749<pre> &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 +00002750</pre>
2751<h5>Overview:</h5>
2752<p>The '<tt>udiv</tt>' instruction returns the quotient of its two
2753operands.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002754
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002755<h5>Arguments:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002756
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002757<p>The two arguments to the '<tt>udiv</tt>' instruction must be
Chris Lattner6704c212008-05-20 20:48:21 +00002758<a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
2759values. Both arguments must have identical types.</p>
2760
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002761<h5>Semantics:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002762
Chris Lattner9aba1e22008-01-28 00:36:27 +00002763<p>The value produced is the unsigned integer quotient of the two operands.</p>
2764<p>Note that unsigned integer division and signed integer division are distinct
2765operations; for signed integer division, use '<tt>sdiv</tt>'.</p>
2766<p>Division by zero leads to undefined behavior.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002767<h5>Example:</h5>
2768<pre> &lt;result&gt; = udiv i32 4, %var <i>; yields {i32}:result = 4 / %var</i>
2769</pre>
2770</div>
2771<!-- _______________________________________________________________________ -->
2772<div class="doc_subsubsection"> <a name="i_sdiv">'<tt>sdiv</tt>' Instruction
2773</a> </div>
2774<div class="doc_text">
2775<h5>Syntax:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002776<pre>
Gabor Greifd9068fe2008-08-07 21:46:00 +00002777 &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 +00002778</pre>
Chris Lattner6704c212008-05-20 20:48:21 +00002779
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002780<h5>Overview:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002781
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002782<p>The '<tt>sdiv</tt>' instruction returns the quotient of its two
2783operands.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002784
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002785<h5>Arguments:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002786
2787<p>The two arguments to the '<tt>sdiv</tt>' instruction must be
2788<a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
2789values. Both arguments must have identical types.</p>
2790
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002791<h5>Semantics:</h5>
Chris Lattnerdc15b1d2008-04-01 18:45:27 +00002792<p>The value produced is the signed integer quotient of the two operands rounded towards zero.</p>
Chris Lattner9aba1e22008-01-28 00:36:27 +00002793<p>Note that signed integer division and unsigned integer division are distinct
2794operations; for unsigned integer division, use '<tt>udiv</tt>'.</p>
2795<p>Division by zero leads to undefined behavior. Overflow also leads to
2796undefined behavior; this is a rare case, but can occur, for example,
2797by doing a 32-bit division of -2147483648 by -1.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002798<h5>Example:</h5>
2799<pre> &lt;result&gt; = sdiv i32 4, %var <i>; yields {i32}:result = 4 / %var</i>
2800</pre>
2801</div>
2802<!-- _______________________________________________________________________ -->
2803<div class="doc_subsubsection"> <a name="i_fdiv">'<tt>fdiv</tt>'
2804Instruction</a> </div>
2805<div class="doc_text">
2806<h5>Syntax:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002807<pre>
Gabor Greifd9068fe2008-08-07 21:46:00 +00002808 &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 +00002809</pre>
2810<h5>Overview:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002811
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002812<p>The '<tt>fdiv</tt>' instruction returns the quotient of its two
2813operands.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002814
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002815<h5>Arguments:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002816
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002817<p>The two arguments to the '<tt>fdiv</tt>' instruction must be
Chris Lattner6704c212008-05-20 20:48:21 +00002818<a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a>
2819of floating point values. Both arguments must have identical types.</p>
2820
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002821<h5>Semantics:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002822
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002823<p>The value produced is the floating point quotient of the two operands.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002824
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002825<h5>Example:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002826
2827<pre>
2828 &lt;result&gt; = fdiv float 4.0, %var <i>; yields {float}:result = 4.0 / %var</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002829</pre>
2830</div>
Chris Lattner6704c212008-05-20 20:48:21 +00002831
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002832<!-- _______________________________________________________________________ -->
2833<div class="doc_subsubsection"> <a name="i_urem">'<tt>urem</tt>' Instruction</a>
2834</div>
2835<div class="doc_text">
2836<h5>Syntax:</h5>
Gabor Greifd9068fe2008-08-07 21:46:00 +00002837<pre> &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 +00002838</pre>
2839<h5>Overview:</h5>
2840<p>The '<tt>urem</tt>' instruction returns the remainder from the
2841unsigned division of its two arguments.</p>
2842<h5>Arguments:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002843<p>The two arguments to the '<tt>urem</tt>' instruction must be
2844<a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
2845values. Both arguments must have identical types.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002846<h5>Semantics:</h5>
2847<p>This instruction returns the unsigned integer <i>remainder</i> of a division.
Chris Lattnerdc15b1d2008-04-01 18:45:27 +00002848This instruction always performs an unsigned division to get the remainder.</p>
Chris Lattner9aba1e22008-01-28 00:36:27 +00002849<p>Note that unsigned integer remainder and signed integer remainder are
2850distinct operations; for signed integer remainder, use '<tt>srem</tt>'.</p>
2851<p>Taking the remainder of a division by zero leads to undefined behavior.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002852<h5>Example:</h5>
2853<pre> &lt;result&gt; = urem i32 4, %var <i>; yields {i32}:result = 4 % %var</i>
2854</pre>
2855
2856</div>
2857<!-- _______________________________________________________________________ -->
Chris Lattner6704c212008-05-20 20:48:21 +00002858<div class="doc_subsubsection">
2859 <a name="i_srem">'<tt>srem</tt>' Instruction</a>
2860</div>
2861
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002862<div class="doc_text">
Chris Lattner6704c212008-05-20 20:48:21 +00002863
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002864<h5>Syntax:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002865
2866<pre>
Gabor Greifd9068fe2008-08-07 21:46:00 +00002867 &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 +00002868</pre>
Chris Lattner6704c212008-05-20 20:48:21 +00002869
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002870<h5>Overview:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002871
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002872<p>The '<tt>srem</tt>' instruction returns the remainder from the
Dan Gohman3e3fd8c2007-11-05 23:35:22 +00002873signed division of its two operands. This instruction can also take
2874<a href="#t_vector">vector</a> versions of the values in which case
2875the elements must be integers.</p>
Chris Lattner08497ce2008-01-04 04:33:49 +00002876
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002877<h5>Arguments:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002878
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002879<p>The two arguments to the '<tt>srem</tt>' instruction must be
Chris Lattner6704c212008-05-20 20:48:21 +00002880<a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
2881values. Both arguments must have identical types.</p>
2882
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002883<h5>Semantics:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002884
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002885<p>This instruction returns the <i>remainder</i> of a division (where the result
Gabor Greifd9068fe2008-08-07 21:46:00 +00002886has the same sign as the dividend, <tt>op1</tt>), not the <i>modulo</i>
2887operator (where the result has the same sign as the divisor, <tt>op2</tt>) of
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002888a value. For more information about the difference, see <a
2889 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
2890Math Forum</a>. For a table of how this is implemented in various languages,
2891please see <a href="http://en.wikipedia.org/wiki/Modulo_operation">
2892Wikipedia: modulo operation</a>.</p>
Chris Lattner9aba1e22008-01-28 00:36:27 +00002893<p>Note that signed integer remainder and unsigned integer remainder are
2894distinct operations; for unsigned integer remainder, use '<tt>urem</tt>'.</p>
2895<p>Taking the remainder of a division by zero leads to undefined behavior.
2896Overflow also leads to undefined behavior; this is a rare case, but can occur,
2897for example, by taking the remainder of a 32-bit division of -2147483648 by -1.
2898(The remainder doesn't actually overflow, but this rule lets srem be
2899implemented using instructions that return both the result of the division
2900and the remainder.)</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002901<h5>Example:</h5>
2902<pre> &lt;result&gt; = srem i32 4, %var <i>; yields {i32}:result = 4 % %var</i>
2903</pre>
2904
2905</div>
2906<!-- _______________________________________________________________________ -->
Chris Lattner6704c212008-05-20 20:48:21 +00002907<div class="doc_subsubsection">
2908 <a name="i_frem">'<tt>frem</tt>' Instruction</a> </div>
2909
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002910<div class="doc_text">
Chris Lattner6704c212008-05-20 20:48:21 +00002911
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002912<h5>Syntax:</h5>
Gabor Greifd9068fe2008-08-07 21:46:00 +00002913<pre> &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 +00002914</pre>
2915<h5>Overview:</h5>
2916<p>The '<tt>frem</tt>' instruction returns the remainder from the
2917division of its two operands.</p>
2918<h5>Arguments:</h5>
2919<p>The two arguments to the '<tt>frem</tt>' instruction must be
Chris Lattner6704c212008-05-20 20:48:21 +00002920<a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a>
2921of floating point values. Both arguments must have identical types.</p>
2922
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002923<h5>Semantics:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002924
Chris Lattnerdc15b1d2008-04-01 18:45:27 +00002925<p>This instruction returns the <i>remainder</i> of a division.
2926The remainder has the same sign as the dividend.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00002927
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002928<h5>Example:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00002929
2930<pre>
2931 &lt;result&gt; = frem float 4.0, %var <i>; yields {float}:result = 4.0 % %var</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002932</pre>
2933</div>
2934
2935<!-- ======================================================================= -->
2936<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
2937Operations</a> </div>
2938<div class="doc_text">
2939<p>Bitwise binary operators are used to do various forms of
2940bit-twiddling in a program. They are generally very efficient
2941instructions and can commonly be strength reduced from other
Chris Lattnerdc15b1d2008-04-01 18:45:27 +00002942instructions. They require two operands of the same type, execute an operation on them,
2943and produce a single value. The resulting value is the same type as its operands.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002944</div>
2945
2946<!-- _______________________________________________________________________ -->
2947<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
2948Instruction</a> </div>
2949<div class="doc_text">
2950<h5>Syntax:</h5>
Gabor Greifd9068fe2008-08-07 21:46:00 +00002951<pre> &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 +00002952</pre>
Chris Lattnerd939d9f2007-10-03 21:01:14 +00002953
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002954<h5>Overview:</h5>
Chris Lattnerd939d9f2007-10-03 21:01:14 +00002955
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002956<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
2957the left a specified number of bits.</p>
Chris Lattnerd939d9f2007-10-03 21:01:14 +00002958
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002959<h5>Arguments:</h5>
Chris Lattnerd939d9f2007-10-03 21:01:14 +00002960
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002961<p>Both arguments to the '<tt>shl</tt>' instruction must be the same <a
Nate Begemanbb1ce942008-07-29 15:49:41 +00002962 href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
Gabor Greifd9068fe2008-08-07 21:46:00 +00002963type. '<tt>op2</tt>' is treated as an unsigned value.</p>
Chris Lattnerd939d9f2007-10-03 21:01:14 +00002964
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002965<h5>Semantics:</h5>
Chris Lattnerd939d9f2007-10-03 21:01:14 +00002966
Gabor Greifd9068fe2008-08-07 21:46:00 +00002967<p>The value produced is <tt>op1</tt> * 2<sup><tt>op2</tt></sup> mod 2<sup>n</sup>,
2968where n is the width of the result. If <tt>op2</tt> is (statically or dynamically) negative or
Mon P Wangb0f51822008-12-10 08:55:09 +00002969equal to or larger than the number of bits in <tt>op1</tt>, the result is undefined.
2970If the arguments are vectors, each vector element of <tt>op1</tt> is shifted by the
2971corresponding shift amount in <tt>op2</tt>.</p>
Chris Lattnerd939d9f2007-10-03 21:01:14 +00002972
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002973<h5>Example:</h5><pre>
2974 &lt;result&gt; = shl i32 4, %var <i>; yields {i32}: 4 &lt;&lt; %var</i>
2975 &lt;result&gt; = shl i32 4, 2 <i>; yields {i32}: 16</i>
2976 &lt;result&gt; = shl i32 1, 10 <i>; yields {i32}: 1024</i>
Chris Lattnerd939d9f2007-10-03 21:01:14 +00002977 &lt;result&gt; = shl i32 1, 32 <i>; undefined</i>
Mon P Wang9901e732008-12-09 05:46:39 +00002978 &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 +00002979</pre>
2980</div>
2981<!-- _______________________________________________________________________ -->
2982<div class="doc_subsubsection"> <a name="i_lshr">'<tt>lshr</tt>'
2983Instruction</a> </div>
2984<div class="doc_text">
2985<h5>Syntax:</h5>
Gabor Greifd9068fe2008-08-07 21:46:00 +00002986<pre> &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 +00002987</pre>
2988
2989<h5>Overview:</h5>
2990<p>The '<tt>lshr</tt>' instruction (logical shift right) returns the first
2991operand shifted to the right a specified number of bits with zero fill.</p>
2992
2993<h5>Arguments:</h5>
2994<p>Both arguments to the '<tt>lshr</tt>' instruction must be the same
Nate Begemanbb1ce942008-07-29 15:49:41 +00002995<a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
Gabor Greifd9068fe2008-08-07 21:46:00 +00002996type. '<tt>op2</tt>' is treated as an unsigned value.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002997
2998<h5>Semantics:</h5>
Chris Lattnerd939d9f2007-10-03 21:01:14 +00002999
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003000<p>This instruction always performs a logical shift right operation. The most
3001significant bits of the result will be filled with zero bits after the
Gabor Greifd9068fe2008-08-07 21:46:00 +00003002shift. If <tt>op2</tt> is (statically or dynamically) equal to or larger than
Mon P Wangb0f51822008-12-10 08:55:09 +00003003the number of bits in <tt>op1</tt>, the result is undefined. If the arguments are
3004vectors, each vector element of <tt>op1</tt> is shifted by the corresponding shift
3005amount in <tt>op2</tt>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003006
3007<h5>Example:</h5>
3008<pre>
3009 &lt;result&gt; = lshr i32 4, 1 <i>; yields {i32}:result = 2</i>
3010 &lt;result&gt; = lshr i32 4, 2 <i>; yields {i32}:result = 1</i>
3011 &lt;result&gt; = lshr i8 4, 3 <i>; yields {i8}:result = 0</i>
3012 &lt;result&gt; = lshr i8 -2, 1 <i>; yields {i8}:result = 0x7FFFFFFF </i>
Chris Lattnerd939d9f2007-10-03 21:01:14 +00003013 &lt;result&gt; = lshr i32 1, 32 <i>; undefined</i>
Mon P Wang9901e732008-12-09 05:46:39 +00003014 &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 +00003015</pre>
3016</div>
3017
3018<!-- _______________________________________________________________________ -->
3019<div class="doc_subsubsection"> <a name="i_ashr">'<tt>ashr</tt>'
3020Instruction</a> </div>
3021<div class="doc_text">
3022
3023<h5>Syntax:</h5>
Gabor Greifd9068fe2008-08-07 21:46:00 +00003024<pre> &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 +00003025</pre>
3026
3027<h5>Overview:</h5>
3028<p>The '<tt>ashr</tt>' instruction (arithmetic shift right) returns the first
3029operand shifted to the right a specified number of bits with sign extension.</p>
3030
3031<h5>Arguments:</h5>
3032<p>Both arguments to the '<tt>ashr</tt>' instruction must be the same
Nate Begemanbb1ce942008-07-29 15:49:41 +00003033<a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
Gabor Greifd9068fe2008-08-07 21:46:00 +00003034type. '<tt>op2</tt>' is treated as an unsigned value.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003035
3036<h5>Semantics:</h5>
3037<p>This instruction always performs an arithmetic shift right operation,
3038The most significant bits of the result will be filled with the sign bit
Gabor Greifd9068fe2008-08-07 21:46:00 +00003039of <tt>op1</tt>. If <tt>op2</tt> is (statically or dynamically) equal to or
Mon P Wangb0f51822008-12-10 08:55:09 +00003040larger than the number of bits in <tt>op1</tt>, the result is undefined. If the
3041arguments are vectors, each vector element of <tt>op1</tt> is shifted by the
3042corresponding shift amount in <tt>op2</tt>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003043
3044<h5>Example:</h5>
3045<pre>
3046 &lt;result&gt; = ashr i32 4, 1 <i>; yields {i32}:result = 2</i>
3047 &lt;result&gt; = ashr i32 4, 2 <i>; yields {i32}:result = 1</i>
3048 &lt;result&gt; = ashr i8 4, 3 <i>; yields {i8}:result = 0</i>
3049 &lt;result&gt; = ashr i8 -2, 1 <i>; yields {i8}:result = -1</i>
Chris Lattnerd939d9f2007-10-03 21:01:14 +00003050 &lt;result&gt; = ashr i32 1, 32 <i>; undefined</i>
Mon P Wang9901e732008-12-09 05:46:39 +00003051 &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 +00003052</pre>
3053</div>
3054
3055<!-- _______________________________________________________________________ -->
3056<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
3057Instruction</a> </div>
Chris Lattner6704c212008-05-20 20:48:21 +00003058
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003059<div class="doc_text">
Chris Lattner6704c212008-05-20 20:48:21 +00003060
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003061<h5>Syntax:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00003062
3063<pre>
Gabor Greifd9068fe2008-08-07 21:46:00 +00003064 &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 +00003065</pre>
Chris Lattner6704c212008-05-20 20:48:21 +00003066
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003067<h5>Overview:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00003068
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003069<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
3070its two operands.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00003071
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003072<h5>Arguments:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00003073
3074<p>The two arguments to the '<tt>and</tt>' instruction must be
3075<a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
3076values. Both arguments must have identical types.</p>
3077
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003078<h5>Semantics:</h5>
3079<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
3080<p> </p>
Bill Wendling1e19eac2008-09-07 10:29:20 +00003081<div>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003082<table border="1" cellspacing="0" cellpadding="4">
3083 <tbody>
3084 <tr>
3085 <td>In0</td>
3086 <td>In1</td>
3087 <td>Out</td>
3088 </tr>
3089 <tr>
3090 <td>0</td>
3091 <td>0</td>
3092 <td>0</td>
3093 </tr>
3094 <tr>
3095 <td>0</td>
3096 <td>1</td>
3097 <td>0</td>
3098 </tr>
3099 <tr>
3100 <td>1</td>
3101 <td>0</td>
3102 <td>0</td>
3103 </tr>
3104 <tr>
3105 <td>1</td>
3106 <td>1</td>
3107 <td>1</td>
3108 </tr>
3109 </tbody>
3110</table>
3111</div>
3112<h5>Example:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00003113<pre>
3114 &lt;result&gt; = and i32 4, %var <i>; yields {i32}:result = 4 &amp; %var</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003115 &lt;result&gt; = and i32 15, 40 <i>; yields {i32}:result = 8</i>
3116 &lt;result&gt; = and i32 4, 8 <i>; yields {i32}:result = 0</i>
3117</pre>
3118</div>
3119<!-- _______________________________________________________________________ -->
3120<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
3121<div class="doc_text">
3122<h5>Syntax:</h5>
Gabor Greifd9068fe2008-08-07 21:46:00 +00003123<pre> &lt;result&gt; = or &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003124</pre>
3125<h5>Overview:</h5>
3126<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
3127or of its two operands.</p>
3128<h5>Arguments:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00003129
3130<p>The two arguments to the '<tt>or</tt>' instruction must be
3131<a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
3132values. Both arguments must have identical types.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003133<h5>Semantics:</h5>
3134<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
3135<p> </p>
Bill Wendling1e19eac2008-09-07 10:29:20 +00003136<div>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003137<table border="1" cellspacing="0" cellpadding="4">
3138 <tbody>
3139 <tr>
3140 <td>In0</td>
3141 <td>In1</td>
3142 <td>Out</td>
3143 </tr>
3144 <tr>
3145 <td>0</td>
3146 <td>0</td>
3147 <td>0</td>
3148 </tr>
3149 <tr>
3150 <td>0</td>
3151 <td>1</td>
3152 <td>1</td>
3153 </tr>
3154 <tr>
3155 <td>1</td>
3156 <td>0</td>
3157 <td>1</td>
3158 </tr>
3159 <tr>
3160 <td>1</td>
3161 <td>1</td>
3162 <td>1</td>
3163 </tr>
3164 </tbody>
3165</table>
3166</div>
3167<h5>Example:</h5>
3168<pre> &lt;result&gt; = or i32 4, %var <i>; yields {i32}:result = 4 | %var</i>
3169 &lt;result&gt; = or i32 15, 40 <i>; yields {i32}:result = 47</i>
3170 &lt;result&gt; = or i32 4, 8 <i>; yields {i32}:result = 12</i>
3171</pre>
3172</div>
3173<!-- _______________________________________________________________________ -->
3174<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
3175Instruction</a> </div>
3176<div class="doc_text">
3177<h5>Syntax:</h5>
Gabor Greifd9068fe2008-08-07 21:46:00 +00003178<pre> &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 +00003179</pre>
3180<h5>Overview:</h5>
3181<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
3182or of its two operands. The <tt>xor</tt> is used to implement the
3183"one's complement" operation, which is the "~" operator in C.</p>
3184<h5>Arguments:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00003185<p>The two arguments to the '<tt>xor</tt>' instruction must be
3186<a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
3187values. Both arguments must have identical types.</p>
3188
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003189<h5>Semantics:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00003190
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003191<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
3192<p> </p>
Bill Wendling1e19eac2008-09-07 10:29:20 +00003193<div>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003194<table border="1" cellspacing="0" cellpadding="4">
3195 <tbody>
3196 <tr>
3197 <td>In0</td>
3198 <td>In1</td>
3199 <td>Out</td>
3200 </tr>
3201 <tr>
3202 <td>0</td>
3203 <td>0</td>
3204 <td>0</td>
3205 </tr>
3206 <tr>
3207 <td>0</td>
3208 <td>1</td>
3209 <td>1</td>
3210 </tr>
3211 <tr>
3212 <td>1</td>
3213 <td>0</td>
3214 <td>1</td>
3215 </tr>
3216 <tr>
3217 <td>1</td>
3218 <td>1</td>
3219 <td>0</td>
3220 </tr>
3221 </tbody>
3222</table>
3223</div>
3224<p> </p>
3225<h5>Example:</h5>
3226<pre> &lt;result&gt; = xor i32 4, %var <i>; yields {i32}:result = 4 ^ %var</i>
3227 &lt;result&gt; = xor i32 15, 40 <i>; yields {i32}:result = 39</i>
3228 &lt;result&gt; = xor i32 4, 8 <i>; yields {i32}:result = 12</i>
3229 &lt;result&gt; = xor i32 %V, -1 <i>; yields {i32}:result = ~%V</i>
3230</pre>
3231</div>
3232
3233<!-- ======================================================================= -->
3234<div class="doc_subsection">
3235 <a name="vectorops">Vector Operations</a>
3236</div>
3237
3238<div class="doc_text">
3239
3240<p>LLVM supports several instructions to represent vector operations in a
3241target-independent manner. These instructions cover the element-access and
3242vector-specific operations needed to process vectors effectively. While LLVM
3243does directly support these vector operations, many sophisticated algorithms
3244will want to use target-specific intrinsics to take full advantage of a specific
3245target.</p>
3246
3247</div>
3248
3249<!-- _______________________________________________________________________ -->
3250<div class="doc_subsubsection">
3251 <a name="i_extractelement">'<tt>extractelement</tt>' Instruction</a>
3252</div>
3253
3254<div class="doc_text">
3255
3256<h5>Syntax:</h5>
3257
3258<pre>
3259 &lt;result&gt; = extractelement &lt;n x &lt;ty&gt;&gt; &lt;val&gt;, i32 &lt;idx&gt; <i>; yields &lt;ty&gt;</i>
3260</pre>
3261
3262<h5>Overview:</h5>
3263
3264<p>
3265The '<tt>extractelement</tt>' instruction extracts a single scalar
3266element from a vector at a specified index.
3267</p>
3268
3269
3270<h5>Arguments:</h5>
3271
3272<p>
3273The first operand of an '<tt>extractelement</tt>' instruction is a
3274value of <a href="#t_vector">vector</a> type. The second operand is
3275an index indicating the position from which to extract the element.
3276The index may be a variable.</p>
3277
3278<h5>Semantics:</h5>
3279
3280<p>
3281The result is a scalar of the same type as the element type of
3282<tt>val</tt>. Its value is the value at position <tt>idx</tt> of
3283<tt>val</tt>. If <tt>idx</tt> exceeds the length of <tt>val</tt>, the
3284results are undefined.
3285</p>
3286
3287<h5>Example:</h5>
3288
3289<pre>
3290 %result = extractelement &lt;4 x i32&gt; %vec, i32 0 <i>; yields i32</i>
3291</pre>
3292</div>
3293
3294
3295<!-- _______________________________________________________________________ -->
3296<div class="doc_subsubsection">
3297 <a name="i_insertelement">'<tt>insertelement</tt>' Instruction</a>
3298</div>
3299
3300<div class="doc_text">
3301
3302<h5>Syntax:</h5>
3303
3304<pre>
Dan Gohmanbcc3c502008-05-12 23:38:42 +00003305 &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 +00003306</pre>
3307
3308<h5>Overview:</h5>
3309
3310<p>
3311The '<tt>insertelement</tt>' instruction inserts a scalar
3312element into a vector at a specified index.
3313</p>
3314
3315
3316<h5>Arguments:</h5>
3317
3318<p>
3319The first operand of an '<tt>insertelement</tt>' instruction is a
3320value of <a href="#t_vector">vector</a> type. The second operand is a
3321scalar value whose type must equal the element type of the first
3322operand. The third operand is an index indicating the position at
3323which to insert the value. The index may be a variable.</p>
3324
3325<h5>Semantics:</h5>
3326
3327<p>
3328The result is a vector of the same type as <tt>val</tt>. Its
3329element values are those of <tt>val</tt> except at position
3330<tt>idx</tt>, where it gets the value <tt>elt</tt>. If <tt>idx</tt>
3331exceeds the length of <tt>val</tt>, the results are undefined.
3332</p>
3333
3334<h5>Example:</h5>
3335
3336<pre>
3337 %result = insertelement &lt;4 x i32&gt; %vec, i32 1, i32 0 <i>; yields &lt;4 x i32&gt;</i>
3338</pre>
3339</div>
3340
3341<!-- _______________________________________________________________________ -->
3342<div class="doc_subsubsection">
3343 <a name="i_shufflevector">'<tt>shufflevector</tt>' Instruction</a>
3344</div>
3345
3346<div class="doc_text">
3347
3348<h5>Syntax:</h5>
3349
3350<pre>
Mon P Wangbff5d9c2008-11-10 04:46:22 +00003351 &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 +00003352</pre>
3353
3354<h5>Overview:</h5>
3355
3356<p>
3357The '<tt>shufflevector</tt>' instruction constructs a permutation of elements
Mon P Wangbff5d9c2008-11-10 04:46:22 +00003358from two input vectors, returning a vector with the same element type as
3359the input and length that is the same as the shuffle mask.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003360</p>
3361
3362<h5>Arguments:</h5>
3363
3364<p>
Mon P Wangbff5d9c2008-11-10 04:46:22 +00003365The first two operands of a '<tt>shufflevector</tt>' instruction are vectors
3366with types that match each other. The third argument is a shuffle mask whose
3367element type is always 'i32'. The result of the instruction is a vector whose
3368length is the same as the shuffle mask and whose element type is the same as
3369the element type of the first two operands.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003370</p>
3371
3372<p>
3373The shuffle mask operand is required to be a constant vector with either
3374constant integer or undef values.
3375</p>
3376
3377<h5>Semantics:</h5>
3378
3379<p>
3380The elements of the two input vectors are numbered from left to right across
3381both of the vectors. The shuffle mask operand specifies, for each element of
Mon P Wangbff5d9c2008-11-10 04:46:22 +00003382the result vector, which element of the two input vectors the result element
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003383gets. The element selector may be undef (meaning "don't care") and the second
3384operand may be undef if performing a shuffle from only one vector.
3385</p>
3386
3387<h5>Example:</h5>
3388
3389<pre>
3390 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; %v2,
3391 &lt;4 x i32&gt; &lt;i32 0, i32 4, i32 1, i32 5&gt; <i>; yields &lt;4 x i32&gt;</i>
3392 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; undef,
3393 &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 +00003394 %result = shufflevector &lt;8 x i32&gt; %v1, &lt;8 x i32&gt; undef,
3395 &lt;4 x i32&gt; &lt;i32 0, i32 1, i32 2, i32 3&gt; <i>; yields &lt;4 x i32&gt;</i>
3396 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; %v2,
3397 &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 +00003398</pre>
3399</div>
3400
3401
3402<!-- ======================================================================= -->
3403<div class="doc_subsection">
Dan Gohman74d6faf2008-05-12 23:51:09 +00003404 <a name="aggregateops">Aggregate Operations</a>
3405</div>
3406
3407<div class="doc_text">
3408
3409<p>LLVM supports several instructions for working with aggregate values.
3410</p>
3411
3412</div>
3413
3414<!-- _______________________________________________________________________ -->
3415<div class="doc_subsubsection">
3416 <a name="i_extractvalue">'<tt>extractvalue</tt>' Instruction</a>
3417</div>
3418
3419<div class="doc_text">
3420
3421<h5>Syntax:</h5>
3422
3423<pre>
3424 &lt;result&gt; = extractvalue &lt;aggregate type&gt; &lt;val&gt;, &lt;idx&gt;{, &lt;idx&gt;}*
3425</pre>
3426
3427<h5>Overview:</h5>
3428
3429<p>
Dan Gohman6c6dea02008-05-13 18:16:06 +00003430The '<tt>extractvalue</tt>' instruction extracts the value of a struct field
3431or array element from an aggregate value.
Dan Gohman74d6faf2008-05-12 23:51:09 +00003432</p>
3433
3434
3435<h5>Arguments:</h5>
3436
3437<p>
3438The first operand of an '<tt>extractvalue</tt>' instruction is a
3439value of <a href="#t_struct">struct</a> or <a href="#t_array">array</a>
Dan Gohman6c6dea02008-05-13 18:16:06 +00003440type. The operands are constant indices to specify which value to extract
Dan Gohmane5febe42008-05-31 00:58:22 +00003441in a similar manner as indices in a
Dan Gohman74d6faf2008-05-12 23:51:09 +00003442'<tt><a href="#i_getelementptr">getelementptr</a></tt>' instruction.
3443</p>
3444
3445<h5>Semantics:</h5>
3446
3447<p>
3448The result is the value at the position in the aggregate specified by
3449the index operands.
3450</p>
3451
3452<h5>Example:</h5>
3453
3454<pre>
Dan Gohmane5febe42008-05-31 00:58:22 +00003455 %result = extractvalue {i32, float} %agg, 0 <i>; yields i32</i>
Dan Gohman74d6faf2008-05-12 23:51:09 +00003456</pre>
3457</div>
3458
3459
3460<!-- _______________________________________________________________________ -->
3461<div class="doc_subsubsection">
3462 <a name="i_insertvalue">'<tt>insertvalue</tt>' Instruction</a>
3463</div>
3464
3465<div class="doc_text">
3466
3467<h5>Syntax:</h5>
3468
3469<pre>
Dan Gohmane5febe42008-05-31 00:58:22 +00003470 &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 +00003471</pre>
3472
3473<h5>Overview:</h5>
3474
3475<p>
3476The '<tt>insertvalue</tt>' instruction inserts a value
Dan Gohman6c6dea02008-05-13 18:16:06 +00003477into a struct field or array element in an aggregate.
Dan Gohman74d6faf2008-05-12 23:51:09 +00003478</p>
3479
3480
3481<h5>Arguments:</h5>
3482
3483<p>
3484The first operand of an '<tt>insertvalue</tt>' instruction is a
3485value of <a href="#t_struct">struct</a> or <a href="#t_array">array</a> type.
3486The second operand is a first-class value to insert.
Dan Gohman4f29e422008-05-23 21:53:15 +00003487The following operands are constant indices
Dan Gohmane5febe42008-05-31 00:58:22 +00003488indicating the position at which to insert the value in a similar manner as
Dan Gohman6c6dea02008-05-13 18:16:06 +00003489indices in a
Dan Gohman74d6faf2008-05-12 23:51:09 +00003490'<tt><a href="#i_getelementptr">getelementptr</a></tt>' instruction.
3491The value to insert must have the same type as the value identified
Dan Gohman6c6dea02008-05-13 18:16:06 +00003492by the indices.
Dan Gohman2672f3e2008-10-14 16:51:45 +00003493</p>
Dan Gohman74d6faf2008-05-12 23:51:09 +00003494
3495<h5>Semantics:</h5>
3496
3497<p>
3498The result is an aggregate of the same type as <tt>val</tt>. Its
3499value is that of <tt>val</tt> except that the value at the position
Dan Gohman6c6dea02008-05-13 18:16:06 +00003500specified by the indices is that of <tt>elt</tt>.
Dan Gohman74d6faf2008-05-12 23:51:09 +00003501</p>
3502
3503<h5>Example:</h5>
3504
3505<pre>
Dan Gohmanb1aab4e2008-06-23 15:26:37 +00003506 %result = insertvalue {i32, float} %agg, i32 1, 0 <i>; yields {i32, float}</i>
Dan Gohman74d6faf2008-05-12 23:51:09 +00003507</pre>
3508</div>
3509
3510
3511<!-- ======================================================================= -->
3512<div class="doc_subsection">
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003513 <a name="memoryops">Memory Access and Addressing Operations</a>
3514</div>
3515
3516<div class="doc_text">
3517
3518<p>A key design point of an SSA-based representation is how it
3519represents memory. In LLVM, no memory locations are in SSA form, which
3520makes things very simple. This section describes how to read, write,
3521allocate, and free memory in LLVM.</p>
3522
3523</div>
3524
3525<!-- _______________________________________________________________________ -->
3526<div class="doc_subsubsection">
3527 <a name="i_malloc">'<tt>malloc</tt>' Instruction</a>
3528</div>
3529
3530<div class="doc_text">
3531
3532<h5>Syntax:</h5>
3533
3534<pre>
3535 &lt;result&gt; = malloc &lt;type&gt;[, i32 &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
3536</pre>
3537
3538<h5>Overview:</h5>
3539
3540<p>The '<tt>malloc</tt>' instruction allocates memory from the system
Christopher Lambcfe00962007-12-17 01:00:21 +00003541heap and returns a pointer to it. The object is always allocated in the generic
3542address space (address space zero).</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003543
3544<h5>Arguments:</h5>
3545
3546<p>The '<tt>malloc</tt>' instruction allocates
3547<tt>sizeof(&lt;type&gt;)*NumElements</tt>
3548bytes of memory from the operating system and returns a pointer of the
3549appropriate type to the program. If "NumElements" is specified, it is the
Gabor Greif5082cf42008-02-09 22:24:34 +00003550number of elements allocated, otherwise "NumElements" is defaulted to be one.
Duncan Sandsb38ce6f2009-06-20 13:26:06 +00003551If a constant alignment is specified, the value result of the allocation is
3552guaranteed to be aligned to at least that boundary. If not specified, or if
3553zero, the target can choose to align the allocation on any convenient boundary
3554compatible with the type.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003555
3556<p>'<tt>type</tt>' must be a sized type.</p>
3557
3558<h5>Semantics:</h5>
3559
3560<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
Nick Lewyckyff384472008-11-24 03:41:24 +00003561a pointer is returned. The result of a zero byte allocation is undefined. The
Chris Lattner8b094fc2008-04-19 21:01:16 +00003562result is null if there is insufficient memory available.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003563
3564<h5>Example:</h5>
3565
3566<pre>
Dan Gohmanf54f50a2009-01-04 23:49:44 +00003567 %array = malloc [4 x i8] <i>; yields {[%4 x i8]*}:array</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003568
3569 %size = <a href="#i_add">add</a> i32 2, 2 <i>; yields {i32}:size = i32 4</i>
3570 %array1 = malloc i8, i32 4 <i>; yields {i8*}:array1</i>
3571 %array2 = malloc [12 x i8], i32 %size <i>; yields {[12 x i8]*}:array2</i>
3572 %array3 = malloc i32, i32 4, align 1024 <i>; yields {i32*}:array3</i>
3573 %array4 = malloc i32, align 1024 <i>; yields {i32*}:array4</i>
3574</pre>
Dan Gohman60967192009-01-12 23:12:39 +00003575
3576<p>Note that the code generator does not yet respect the
3577 alignment value.</p>
3578
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003579</div>
3580
3581<!-- _______________________________________________________________________ -->
3582<div class="doc_subsubsection">
3583 <a name="i_free">'<tt>free</tt>' Instruction</a>
3584</div>
3585
3586<div class="doc_text">
3587
3588<h5>Syntax:</h5>
3589
3590<pre>
Dan Gohmanf54f50a2009-01-04 23:49:44 +00003591 free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003592</pre>
3593
3594<h5>Overview:</h5>
3595
3596<p>The '<tt>free</tt>' instruction returns memory back to the unused
3597memory heap to be reallocated in the future.</p>
3598
3599<h5>Arguments:</h5>
3600
3601<p>'<tt>value</tt>' shall be a pointer value that points to a value
3602that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
3603instruction.</p>
3604
3605<h5>Semantics:</h5>
3606
3607<p>Access to the memory pointed to by the pointer is no longer defined
Chris Lattner329d6532008-04-19 22:41:32 +00003608after this instruction executes. If the pointer is null, the operation
3609is a noop.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003610
3611<h5>Example:</h5>
3612
3613<pre>
Dan Gohmanf54f50a2009-01-04 23:49:44 +00003614 %array = <a href="#i_malloc">malloc</a> [4 x i8] <i>; yields {[4 x i8]*}:array</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003615 free [4 x i8]* %array
3616</pre>
3617</div>
3618
3619<!-- _______________________________________________________________________ -->
3620<div class="doc_subsubsection">
3621 <a name="i_alloca">'<tt>alloca</tt>' Instruction</a>
3622</div>
3623
3624<div class="doc_text">
3625
3626<h5>Syntax:</h5>
3627
3628<pre>
3629 &lt;result&gt; = alloca &lt;type&gt;[, i32 &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
3630</pre>
3631
3632<h5>Overview:</h5>
3633
3634<p>The '<tt>alloca</tt>' instruction allocates memory on the stack frame of the
3635currently executing function, to be automatically released when this function
Christopher Lambcfe00962007-12-17 01:00:21 +00003636returns to its caller. The object is always allocated in the generic address
3637space (address space zero).</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003638
3639<h5>Arguments:</h5>
3640
3641<p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
3642bytes of memory on the runtime stack, returning a pointer of the
Gabor Greif5082cf42008-02-09 22:24:34 +00003643appropriate type to the program. If "NumElements" is specified, it is the
3644number of elements allocated, otherwise "NumElements" is defaulted to be one.
Duncan Sandsb38ce6f2009-06-20 13:26:06 +00003645If a constant alignment is specified, the value result of the allocation is
3646guaranteed to be aligned to at least that boundary. If not specified, or if
3647zero, the target can choose to align the allocation on any convenient boundary
3648compatible with the type.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003649
3650<p>'<tt>type</tt>' may be any sized type.</p>
3651
3652<h5>Semantics:</h5>
3653
Bill Wendling2a454572009-05-08 20:49:29 +00003654<p>Memory is allocated; a pointer is returned. The operation is undefined if
Chris Lattner8b094fc2008-04-19 21:01:16 +00003655there is insufficient stack space for the allocation. '<tt>alloca</tt>'d
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003656memory is automatically released when the function returns. The '<tt>alloca</tt>'
3657instruction is commonly used to represent automatic variables that must
3658have an address available. When the function returns (either with the <tt><a
3659 href="#i_ret">ret</a></tt> or <tt><a href="#i_unwind">unwind</a></tt>
Chris Lattner10368b62008-04-02 00:38:26 +00003660instructions), the memory is reclaimed. Allocating zero bytes
3661is legal, but the result is undefined.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003662
3663<h5>Example:</h5>
3664
3665<pre>
Dan Gohmanf54f50a2009-01-04 23:49:44 +00003666 %ptr = alloca i32 <i>; yields {i32*}:ptr</i>
3667 %ptr = alloca i32, i32 4 <i>; yields {i32*}:ptr</i>
3668 %ptr = alloca i32, i32 4, align 1024 <i>; yields {i32*}:ptr</i>
3669 %ptr = alloca i32, align 1024 <i>; yields {i32*}:ptr</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003670</pre>
3671</div>
3672
3673<!-- _______________________________________________________________________ -->
3674<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
3675Instruction</a> </div>
3676<div class="doc_text">
3677<h5>Syntax:</h5>
3678<pre> &lt;result&gt; = load &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;]<br> &lt;result&gt; = volatile load &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;]<br></pre>
3679<h5>Overview:</h5>
3680<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
3681<h5>Arguments:</h5>
3682<p>The argument to the '<tt>load</tt>' instruction specifies the memory
3683address from which to load. The pointer must point to a <a
3684 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
3685marked as <tt>volatile</tt>, then the optimizer is not allowed to modify
3686the number or order of execution of this <tt>load</tt> with other
3687volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
3688instructions. </p>
Chris Lattner21003c82008-01-06 21:04:43 +00003689<p>
Chris Lattner10368b62008-04-02 00:38:26 +00003690The optional constant "align" argument specifies the alignment of the operation
Chris Lattner21003c82008-01-06 21:04:43 +00003691(that is, the alignment of the memory address). A value of 0 or an
3692omitted "align" argument means that the operation has the preferential
3693alignment for the target. It is the responsibility of the code emitter
3694to ensure that the alignment information is correct. Overestimating
3695the alignment results in an undefined behavior. Underestimating the
3696alignment may produce less efficient code. An alignment of 1 is always
3697safe.
3698</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003699<h5>Semantics:</h5>
Duncan Sandsfe87fff2009-03-22 11:33:16 +00003700<p>The location of memory pointed to is loaded. If the value being loaded
3701is of scalar type then the number of bytes read does not exceed the minimum
3702number of bytes needed to hold all bits of the type. For example, loading an
3703<tt>i24</tt> reads at most three bytes. When loading a value of a type like
3704<tt>i20</tt> with a size that is not an integral number of bytes, the result
3705is undefined if the value was not originally written using a store of the
3706same type.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003707<h5>Examples:</h5>
3708<pre> %ptr = <a href="#i_alloca">alloca</a> i32 <i>; yields {i32*}:ptr</i>
3709 <a
3710 href="#i_store">store</a> i32 3, i32* %ptr <i>; yields {void}</i>
3711 %val = load i32* %ptr <i>; yields {i32}:val = i32 3</i>
3712</pre>
3713</div>
3714<!-- _______________________________________________________________________ -->
3715<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
3716Instruction</a> </div>
3717<div class="doc_text">
3718<h5>Syntax:</h5>
3719<pre> store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;] <i>; yields {void}</i>
3720 volatile store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;] <i>; yields {void}</i>
3721</pre>
3722<h5>Overview:</h5>
3723<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
3724<h5>Arguments:</h5>
3725<p>There are two arguments to the '<tt>store</tt>' instruction: a value
3726to store and an address at which to store it. The type of the '<tt>&lt;pointer&gt;</tt>'
Chris Lattner10368b62008-04-02 00:38:26 +00003727operand must be a pointer to the <a href="#t_firstclass">first class</a> type
3728of the '<tt>&lt;value&gt;</tt>'
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003729operand. If the <tt>store</tt> is marked as <tt>volatile</tt>, then the
3730optimizer is not allowed to modify the number or order of execution of
3731this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
3732 href="#i_store">store</a></tt> instructions.</p>
Chris Lattner21003c82008-01-06 21:04:43 +00003733<p>
Chris Lattner10368b62008-04-02 00:38:26 +00003734The optional constant "align" argument specifies the alignment of the operation
Chris Lattner21003c82008-01-06 21:04:43 +00003735(that is, the alignment of the memory address). A value of 0 or an
3736omitted "align" argument means that the operation has the preferential
3737alignment for the target. It is the responsibility of the code emitter
3738to ensure that the alignment information is correct. Overestimating
3739the alignment results in an undefined behavior. Underestimating the
3740alignment may produce less efficient code. An alignment of 1 is always
3741safe.
3742</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003743<h5>Semantics:</h5>
3744<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
Duncan Sandsfe87fff2009-03-22 11:33:16 +00003745at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.
3746If '<tt>&lt;value&gt;</tt>' is of scalar type then the number of bytes
3747written does not exceed the minimum number of bytes needed to hold all
3748bits of the type. For example, storing an <tt>i24</tt> writes at most
3749three bytes. When writing a value of a type like <tt>i20</tt> with a
3750size that is not an integral number of bytes, it is unspecified what
3751happens to the extra bits that do not belong to the type, but they will
3752typically be overwritten.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003753<h5>Example:</h5>
3754<pre> %ptr = <a href="#i_alloca">alloca</a> i32 <i>; yields {i32*}:ptr</i>
Bill Wendling63ffa142007-10-22 05:10:05 +00003755 store i32 3, i32* %ptr <i>; yields {void}</i>
3756 %val = <a href="#i_load">load</a> i32* %ptr <i>; yields {i32}:val = i32 3</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003757</pre>
3758</div>
3759
3760<!-- _______________________________________________________________________ -->
3761<div class="doc_subsubsection">
3762 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
3763</div>
3764
3765<div class="doc_text">
3766<h5>Syntax:</h5>
3767<pre>
Matthijs Kooijman32a080e2008-10-13 13:44:15 +00003768 &lt;result&gt; = getelementptr &lt;pty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003769</pre>
3770
3771<h5>Overview:</h5>
3772
3773<p>
3774The '<tt>getelementptr</tt>' instruction is used to get the address of a
Matthijs Kooijman32a080e2008-10-13 13:44:15 +00003775subelement of an aggregate data structure. It performs address calculation only
3776and does not access memory.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003777
3778<h5>Arguments:</h5>
3779
Matthijs Kooijman32a080e2008-10-13 13:44:15 +00003780<p>The first argument is always a pointer, and forms the basis of the
3781calculation. The remaining arguments are indices, that indicate which of the
3782elements of the aggregate object are indexed. The interpretation of each index
3783is dependent on the type being indexed into. The first index always indexes the
3784pointer value given as the first argument, the second index indexes a value of
3785the type pointed to (not necessarily the value directly pointed to, since the
3786first index can be non-zero), etc. The first type indexed into must be a pointer
3787value, subsequent types can be arrays, vectors and structs. Note that subsequent
3788types being indexed into can never be pointers, since that would require loading
3789the pointer before continuing calculation.</p>
3790
3791<p>The type of each index argument depends on the type it is indexing into.
3792When indexing into a (packed) structure, only <tt>i32</tt> integer
3793<b>constants</b> are allowed. When indexing into an array, pointer or vector,
Sanjiv Guptaa2e72d92009-04-27 03:21:00 +00003794integers of any width are allowed (also non-constants).</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003795
3796<p>For example, let's consider a C code fragment and how it gets
3797compiled to LLVM:</p>
3798
3799<div class="doc_code">
3800<pre>
3801struct RT {
3802 char A;
3803 int B[10][20];
3804 char C;
3805};
3806struct ST {
3807 int X;
3808 double Y;
3809 struct RT Z;
3810};
3811
3812int *foo(struct ST *s) {
3813 return &amp;s[1].Z.B[5][13];
3814}
3815</pre>
3816</div>
3817
3818<p>The LLVM code generated by the GCC frontend is:</p>
3819
3820<div class="doc_code">
3821<pre>
Chris Lattner5b6dc6e2009-01-11 20:53:49 +00003822%RT = <a href="#namedtypes">type</a> { i8 , [10 x [20 x i32]], i8 }
3823%ST = <a href="#namedtypes">type</a> { i32, double, %RT }
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003824
3825define i32* %foo(%ST* %s) {
3826entry:
3827 %reg = getelementptr %ST* %s, i32 1, i32 2, i32 1, i32 5, i32 13
3828 ret i32* %reg
3829}
3830</pre>
3831</div>
3832
3833<h5>Semantics:</h5>
3834
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003835<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
3836type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ i32, double, %RT
3837}</tt>' type, a structure. The second index indexes into the third element of
3838the structure, yielding a '<tt>%RT</tt>' = '<tt>{ i8 , [10 x [20 x i32]],
3839i8 }</tt>' type, another structure. The third index indexes into the second
3840element of the structure, yielding a '<tt>[10 x [20 x i32]]</tt>' type, an
3841array. The two dimensions of the array are subscripted into, yielding an
3842'<tt>i32</tt>' type. The '<tt>getelementptr</tt>' instruction returns a pointer
3843to this element, thus computing a value of '<tt>i32*</tt>' type.</p>
3844
3845<p>Note that it is perfectly legal to index partially through a
3846structure, returning a pointer to an inner element. Because of this,
3847the LLVM code for the given testcase is equivalent to:</p>
3848
3849<pre>
3850 define i32* %foo(%ST* %s) {
3851 %t1 = getelementptr %ST* %s, i32 1 <i>; yields %ST*:%t1</i>
3852 %t2 = getelementptr %ST* %t1, i32 0, i32 2 <i>; yields %RT*:%t2</i>
3853 %t3 = getelementptr %RT* %t2, i32 0, i32 1 <i>; yields [10 x [20 x i32]]*:%t3</i>
3854 %t4 = getelementptr [10 x [20 x i32]]* %t3, i32 0, i32 5 <i>; yields [20 x i32]*:%t4</i>
3855 %t5 = getelementptr [20 x i32]* %t4, i32 0, i32 13 <i>; yields i32*:%t5</i>
3856 ret i32* %t5
3857 }
3858</pre>
3859
Chris Lattner50609942009-03-09 20:55:18 +00003860<p>Note that it is undefined to access an array out of bounds: array
3861and pointer indexes must always be within the defined bounds of the
3862array type when accessed with an instruction that dereferences the
3863pointer (e.g. a load or store instruction). The one exception for
3864this rule is zero length arrays. These arrays are defined to be
3865accessible as variable length arrays, which requires access beyond the
3866zero'th element.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003867
3868<p>The getelementptr instruction is often confusing. For some more insight
3869into how it works, see <a href="GetElementPtr.html">the getelementptr
3870FAQ</a>.</p>
3871
3872<h5>Example:</h5>
3873
3874<pre>
3875 <i>; yields [12 x i8]*:aptr</i>
Matthijs Kooijman32a080e2008-10-13 13:44:15 +00003876 %aptr = getelementptr {i32, [12 x i8]}* %saptr, i64 0, i32 1
3877 <i>; yields i8*:vptr</i>
Dan Gohman2672f3e2008-10-14 16:51:45 +00003878 %vptr = getelementptr {i32, &lt;2 x i8&gt;}* %svptr, i64 0, i32 1, i32 1
Matthijs Kooijman32a080e2008-10-13 13:44:15 +00003879 <i>; yields i8*:eptr</i>
3880 %eptr = getelementptr [12 x i8]* %aptr, i64 0, i32 1
Sanjiv Gupta4f9a0dc2009-04-25 07:27:44 +00003881 <i>; yields i32*:iptr</i>
Sanjiv Gupta1e46c582009-04-24 16:38:13 +00003882 %iptr = getelementptr [10 x i32]* @arr, i16 0, i16 0
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003883</pre>
3884</div>
3885
3886<!-- ======================================================================= -->
3887<div class="doc_subsection"> <a name="convertops">Conversion Operations</a>
3888</div>
3889<div class="doc_text">
3890<p>The instructions in this category are the conversion instructions (casting)
3891which all take a single operand and a type. They perform various bit conversions
3892on the operand.</p>
3893</div>
3894
3895<!-- _______________________________________________________________________ -->
3896<div class="doc_subsubsection">
3897 <a name="i_trunc">'<tt>trunc .. to</tt>' Instruction</a>
3898</div>
3899<div class="doc_text">
3900
3901<h5>Syntax:</h5>
3902<pre>
3903 &lt;result&gt; = trunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3904</pre>
3905
3906<h5>Overview:</h5>
3907<p>
3908The '<tt>trunc</tt>' instruction truncates its operand to the type <tt>ty2</tt>.
3909</p>
3910
3911<h5>Arguments:</h5>
3912<p>
3913The '<tt>trunc</tt>' instruction takes a <tt>value</tt> to trunc, which must
3914be an <a href="#t_integer">integer</a> type, and a type that specifies the size
3915and type of the result, which must be an <a href="#t_integer">integer</a>
3916type. The bit size of <tt>value</tt> must be larger than the bit size of
3917<tt>ty2</tt>. Equal sized types are not allowed.</p>
3918
3919<h5>Semantics:</h5>
3920<p>
3921The '<tt>trunc</tt>' instruction truncates the high order bits in <tt>value</tt>
3922and converts the remaining bits to <tt>ty2</tt>. Since the source size must be
3923larger than the destination size, <tt>trunc</tt> cannot be a <i>no-op cast</i>.
3924It will always truncate bits.</p>
3925
3926<h5>Example:</h5>
3927<pre>
3928 %X = trunc i32 257 to i8 <i>; yields i8:1</i>
3929 %Y = trunc i32 123 to i1 <i>; yields i1:true</i>
3930 %Y = trunc i32 122 to i1 <i>; yields i1:false</i>
3931</pre>
3932</div>
3933
3934<!-- _______________________________________________________________________ -->
3935<div class="doc_subsubsection">
3936 <a name="i_zext">'<tt>zext .. to</tt>' Instruction</a>
3937</div>
3938<div class="doc_text">
3939
3940<h5>Syntax:</h5>
3941<pre>
3942 &lt;result&gt; = zext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3943</pre>
3944
3945<h5>Overview:</h5>
3946<p>The '<tt>zext</tt>' instruction zero extends its operand to type
3947<tt>ty2</tt>.</p>
3948
3949
3950<h5>Arguments:</h5>
3951<p>The '<tt>zext</tt>' instruction takes a value to cast, which must be of
3952<a href="#t_integer">integer</a> type, and a type to cast it to, which must
3953also be of <a href="#t_integer">integer</a> type. The bit size of the
3954<tt>value</tt> must be smaller than the bit size of the destination type,
3955<tt>ty2</tt>.</p>
3956
3957<h5>Semantics:</h5>
3958<p>The <tt>zext</tt> fills the high order bits of the <tt>value</tt> with zero
3959bits until it reaches the size of the destination type, <tt>ty2</tt>.</p>
3960
3961<p>When zero extending from i1, the result will always be either 0 or 1.</p>
3962
3963<h5>Example:</h5>
3964<pre>
3965 %X = zext i32 257 to i64 <i>; yields i64:257</i>
3966 %Y = zext i1 true to i32 <i>; yields i32:1</i>
3967</pre>
3968</div>
3969
3970<!-- _______________________________________________________________________ -->
3971<div class="doc_subsubsection">
3972 <a name="i_sext">'<tt>sext .. to</tt>' Instruction</a>
3973</div>
3974<div class="doc_text">
3975
3976<h5>Syntax:</h5>
3977<pre>
3978 &lt;result&gt; = sext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3979</pre>
3980
3981<h5>Overview:</h5>
3982<p>The '<tt>sext</tt>' sign extends <tt>value</tt> to the type <tt>ty2</tt>.</p>
3983
3984<h5>Arguments:</h5>
3985<p>
3986The '<tt>sext</tt>' instruction takes a value to cast, which must be of
3987<a href="#t_integer">integer</a> type, and a type to cast it to, which must
3988also be of <a href="#t_integer">integer</a> type. The bit size of the
3989<tt>value</tt> must be smaller than the bit size of the destination type,
3990<tt>ty2</tt>.</p>
3991
3992<h5>Semantics:</h5>
3993<p>
3994The '<tt>sext</tt>' instruction performs a sign extension by copying the sign
3995bit (highest order bit) of the <tt>value</tt> until it reaches the bit size of
3996the type <tt>ty2</tt>.</p>
3997
3998<p>When sign extending from i1, the extension always results in -1 or 0.</p>
3999
4000<h5>Example:</h5>
4001<pre>
4002 %X = sext i8 -1 to i16 <i>; yields i16 :65535</i>
4003 %Y = sext i1 true to i32 <i>; yields i32:-1</i>
4004</pre>
4005</div>
4006
4007<!-- _______________________________________________________________________ -->
4008<div class="doc_subsubsection">
4009 <a name="i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a>
4010</div>
4011
4012<div class="doc_text">
4013
4014<h5>Syntax:</h5>
4015
4016<pre>
4017 &lt;result&gt; = fptrunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4018</pre>
4019
4020<h5>Overview:</h5>
4021<p>The '<tt>fptrunc</tt>' instruction truncates <tt>value</tt> to type
4022<tt>ty2</tt>.</p>
4023
4024
4025<h5>Arguments:</h5>
4026<p>The '<tt>fptrunc</tt>' instruction takes a <a href="#t_floating">floating
4027 point</a> value to cast and a <a href="#t_floating">floating point</a> type to
4028cast it to. The size of <tt>value</tt> must be larger than the size of
4029<tt>ty2</tt>. This implies that <tt>fptrunc</tt> cannot be used to make a
4030<i>no-op cast</i>.</p>
4031
4032<h5>Semantics:</h5>
4033<p> The '<tt>fptrunc</tt>' instruction truncates a <tt>value</tt> from a larger
4034<a href="#t_floating">floating point</a> type to a smaller
4035<a href="#t_floating">floating point</a> type. If the value cannot fit within
4036the destination type, <tt>ty2</tt>, then the results are undefined.</p>
4037
4038<h5>Example:</h5>
4039<pre>
4040 %X = fptrunc double 123.0 to float <i>; yields float:123.0</i>
4041 %Y = fptrunc double 1.0E+300 to float <i>; yields undefined</i>
4042</pre>
4043</div>
4044
4045<!-- _______________________________________________________________________ -->
4046<div class="doc_subsubsection">
4047 <a name="i_fpext">'<tt>fpext .. to</tt>' Instruction</a>
4048</div>
4049<div class="doc_text">
4050
4051<h5>Syntax:</h5>
4052<pre>
4053 &lt;result&gt; = fpext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4054</pre>
4055
4056<h5>Overview:</h5>
4057<p>The '<tt>fpext</tt>' extends a floating point <tt>value</tt> to a larger
4058floating point value.</p>
4059
4060<h5>Arguments:</h5>
4061<p>The '<tt>fpext</tt>' instruction takes a
4062<a href="#t_floating">floating point</a> <tt>value</tt> to cast,
4063and a <a href="#t_floating">floating point</a> type to cast it to. The source
4064type must be smaller than the destination type.</p>
4065
4066<h5>Semantics:</h5>
4067<p>The '<tt>fpext</tt>' instruction extends the <tt>value</tt> from a smaller
4068<a href="#t_floating">floating point</a> type to a larger
4069<a href="#t_floating">floating point</a> type. The <tt>fpext</tt> cannot be
4070used to make a <i>no-op cast</i> because it always changes bits. Use
4071<tt>bitcast</tt> to make a <i>no-op cast</i> for a floating point cast.</p>
4072
4073<h5>Example:</h5>
4074<pre>
4075 %X = fpext float 3.1415 to double <i>; yields double:3.1415</i>
4076 %Y = fpext float 1.0 to float <i>; yields float:1.0 (no-op)</i>
4077</pre>
4078</div>
4079
4080<!-- _______________________________________________________________________ -->
4081<div class="doc_subsubsection">
4082 <a name="i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a>
4083</div>
4084<div class="doc_text">
4085
4086<h5>Syntax:</h5>
4087<pre>
Reid Spencere6adee82007-07-31 14:40:14 +00004088 &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 +00004089</pre>
4090
4091<h5>Overview:</h5>
Reid Spencere6adee82007-07-31 14:40:14 +00004092<p>The '<tt>fptoui</tt>' converts a floating point <tt>value</tt> to its
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004093unsigned integer equivalent of type <tt>ty2</tt>.
4094</p>
4095
4096<h5>Arguments:</h5>
Reid Spencere6adee82007-07-31 14:40:14 +00004097<p>The '<tt>fptoui</tt>' instruction takes a value to cast, which must be a
Nate Begeman78246ca2007-11-17 03:58:34 +00004098scalar or vector <a href="#t_floating">floating point</a> value, and a type
4099to cast it to <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a>
4100type. If <tt>ty</tt> is a vector floating point type, <tt>ty2</tt> must be a
4101vector integer type with the same number of elements as <tt>ty</tt></p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004102
4103<h5>Semantics:</h5>
Reid Spencere6adee82007-07-31 14:40:14 +00004104<p> The '<tt>fptoui</tt>' instruction converts its
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004105<a href="#t_floating">floating point</a> operand into the nearest (rounding
4106towards zero) unsigned integer value. If the value cannot fit in <tt>ty2</tt>,
4107the results are undefined.</p>
4108
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004109<h5>Example:</h5>
4110<pre>
Reid Spencere6adee82007-07-31 14:40:14 +00004111 %X = fptoui double 123.0 to i32 <i>; yields i32:123</i>
Chris Lattner681f1e82007-09-22 03:17:52 +00004112 %Y = fptoui float 1.0E+300 to i1 <i>; yields undefined:1</i>
Reid Spencere6adee82007-07-31 14:40:14 +00004113 %X = fptoui float 1.04E+17 to i8 <i>; yields undefined:1</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004114</pre>
4115</div>
4116
4117<!-- _______________________________________________________________________ -->
4118<div class="doc_subsubsection">
4119 <a name="i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a>
4120</div>
4121<div class="doc_text">
4122
4123<h5>Syntax:</h5>
4124<pre>
4125 &lt;result&gt; = fptosi &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4126</pre>
4127
4128<h5>Overview:</h5>
4129<p>The '<tt>fptosi</tt>' instruction converts
4130<a href="#t_floating">floating point</a> <tt>value</tt> to type <tt>ty2</tt>.
4131</p>
4132
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004133<h5>Arguments:</h5>
4134<p> The '<tt>fptosi</tt>' instruction takes a value to cast, which must be a
Nate Begeman78246ca2007-11-17 03:58:34 +00004135scalar or vector <a href="#t_floating">floating point</a> value, and a type
4136to cast it to <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a>
4137type. If <tt>ty</tt> is a vector floating point type, <tt>ty2</tt> must be a
4138vector integer type with the same number of elements as <tt>ty</tt></p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004139
4140<h5>Semantics:</h5>
4141<p>The '<tt>fptosi</tt>' instruction converts its
4142<a href="#t_floating">floating point</a> operand into the nearest (rounding
4143towards zero) signed integer value. If the value cannot fit in <tt>ty2</tt>,
4144the results are undefined.</p>
4145
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004146<h5>Example:</h5>
4147<pre>
4148 %X = fptosi double -123.0 to i32 <i>; yields i32:-123</i>
Chris Lattner681f1e82007-09-22 03:17:52 +00004149 %Y = fptosi float 1.0E-247 to i1 <i>; yields undefined:1</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004150 %X = fptosi float 1.04E+17 to i8 <i>; yields undefined:1</i>
4151</pre>
4152</div>
4153
4154<!-- _______________________________________________________________________ -->
4155<div class="doc_subsubsection">
4156 <a name="i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a>
4157</div>
4158<div class="doc_text">
4159
4160<h5>Syntax:</h5>
4161<pre>
4162 &lt;result&gt; = uitofp &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4163</pre>
4164
4165<h5>Overview:</h5>
4166<p>The '<tt>uitofp</tt>' instruction regards <tt>value</tt> as an unsigned
4167integer and converts that value to the <tt>ty2</tt> type.</p>
4168
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004169<h5>Arguments:</h5>
Nate Begeman78246ca2007-11-17 03:58:34 +00004170<p>The '<tt>uitofp</tt>' instruction takes a value to cast, which must be a
4171scalar or vector <a href="#t_integer">integer</a> value, and a type to cast it
4172to <tt>ty2</tt>, which must be an <a href="#t_floating">floating point</a>
4173type. If <tt>ty</tt> is a vector integer type, <tt>ty2</tt> must be a vector
4174floating point type with the same number of elements as <tt>ty</tt></p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004175
4176<h5>Semantics:</h5>
4177<p>The '<tt>uitofp</tt>' instruction interprets its operand as an unsigned
4178integer quantity and converts it to the corresponding floating point value. If
4179the value cannot fit in the floating point value, the results are undefined.</p>
4180
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004181<h5>Example:</h5>
4182<pre>
4183 %X = uitofp i32 257 to float <i>; yields float:257.0</i>
Dan Gohman2672f3e2008-10-14 16:51:45 +00004184 %Y = uitofp i8 -1 to double <i>; yields double:255.0</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004185</pre>
4186</div>
4187
4188<!-- _______________________________________________________________________ -->
4189<div class="doc_subsubsection">
4190 <a name="i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a>
4191</div>
4192<div class="doc_text">
4193
4194<h5>Syntax:</h5>
4195<pre>
4196 &lt;result&gt; = sitofp &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4197</pre>
4198
4199<h5>Overview:</h5>
4200<p>The '<tt>sitofp</tt>' instruction regards <tt>value</tt> as a signed
4201integer and converts that value to the <tt>ty2</tt> type.</p>
4202
4203<h5>Arguments:</h5>
Nate Begeman78246ca2007-11-17 03:58:34 +00004204<p>The '<tt>sitofp</tt>' instruction takes a value to cast, which must be a
4205scalar or vector <a href="#t_integer">integer</a> value, and a type to cast it
4206to <tt>ty2</tt>, which must be an <a href="#t_floating">floating point</a>
4207type. If <tt>ty</tt> is a vector integer type, <tt>ty2</tt> must be a vector
4208floating point type with the same number of elements as <tt>ty</tt></p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004209
4210<h5>Semantics:</h5>
4211<p>The '<tt>sitofp</tt>' instruction interprets its operand as a signed
4212integer quantity and converts it to the corresponding floating point value. If
4213the value cannot fit in the floating point value, the results are undefined.</p>
4214
4215<h5>Example:</h5>
4216<pre>
4217 %X = sitofp i32 257 to float <i>; yields float:257.0</i>
Dan Gohman2672f3e2008-10-14 16:51:45 +00004218 %Y = sitofp i8 -1 to double <i>; yields double:-1.0</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004219</pre>
4220</div>
4221
4222<!-- _______________________________________________________________________ -->
4223<div class="doc_subsubsection">
4224 <a name="i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a>
4225</div>
4226<div class="doc_text">
4227
4228<h5>Syntax:</h5>
4229<pre>
4230 &lt;result&gt; = ptrtoint &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4231</pre>
4232
4233<h5>Overview:</h5>
4234<p>The '<tt>ptrtoint</tt>' instruction converts the pointer <tt>value</tt> to
4235the integer type <tt>ty2</tt>.</p>
4236
4237<h5>Arguments:</h5>
4238<p>The '<tt>ptrtoint</tt>' instruction takes a <tt>value</tt> to cast, which
4239must be a <a href="#t_pointer">pointer</a> value, and a type to cast it to
Dan Gohman2672f3e2008-10-14 16:51:45 +00004240<tt>ty2</tt>, which must be an <a href="#t_integer">integer</a> type.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004241
4242<h5>Semantics:</h5>
4243<p>The '<tt>ptrtoint</tt>' instruction converts <tt>value</tt> to integer type
4244<tt>ty2</tt> by interpreting the pointer value as an integer and either
4245truncating or zero extending that value to the size of the integer type. If
4246<tt>value</tt> is smaller than <tt>ty2</tt> then a zero extension is done. If
4247<tt>value</tt> is larger than <tt>ty2</tt> then a truncation is done. If they
4248are the same size, then nothing is done (<i>no-op cast</i>) other than a type
4249change.</p>
4250
4251<h5>Example:</h5>
4252<pre>
4253 %X = ptrtoint i32* %X to i8 <i>; yields truncation on 32-bit architecture</i>
4254 %Y = ptrtoint i32* %x to i64 <i>; yields zero extension on 32-bit architecture</i>
4255</pre>
4256</div>
4257
4258<!-- _______________________________________________________________________ -->
4259<div class="doc_subsubsection">
4260 <a name="i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a>
4261</div>
4262<div class="doc_text">
4263
4264<h5>Syntax:</h5>
4265<pre>
4266 &lt;result&gt; = inttoptr &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4267</pre>
4268
4269<h5>Overview:</h5>
4270<p>The '<tt>inttoptr</tt>' instruction converts an integer <tt>value</tt> to
4271a pointer type, <tt>ty2</tt>.</p>
4272
4273<h5>Arguments:</h5>
4274<p>The '<tt>inttoptr</tt>' instruction takes an <a href="#t_integer">integer</a>
4275value to cast, and a type to cast it to, which must be a
Dan Gohman2672f3e2008-10-14 16:51:45 +00004276<a href="#t_pointer">pointer</a> type.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004277
4278<h5>Semantics:</h5>
4279<p>The '<tt>inttoptr</tt>' instruction converts <tt>value</tt> to type
4280<tt>ty2</tt> by applying either a zero extension or a truncation depending on
4281the size of the integer <tt>value</tt>. If <tt>value</tt> is larger than the
4282size of a pointer then a truncation is done. If <tt>value</tt> is smaller than
4283the size of a pointer then a zero extension is done. If they are the same size,
4284nothing is done (<i>no-op cast</i>).</p>
4285
4286<h5>Example:</h5>
4287<pre>
4288 %X = inttoptr i32 255 to i32* <i>; yields zero extension on 64-bit architecture</i>
4289 %X = inttoptr i32 255 to i32* <i>; yields no-op on 32-bit architecture</i>
4290 %Y = inttoptr i64 0 to i32* <i>; yields truncation on 32-bit architecture</i>
4291</pre>
4292</div>
4293
4294<!-- _______________________________________________________________________ -->
4295<div class="doc_subsubsection">
4296 <a name="i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a>
4297</div>
4298<div class="doc_text">
4299
4300<h5>Syntax:</h5>
4301<pre>
4302 &lt;result&gt; = bitcast &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4303</pre>
4304
4305<h5>Overview:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00004306
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004307<p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
4308<tt>ty2</tt> without changing any bits.</p>
4309
4310<h5>Arguments:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00004311
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004312<p>The '<tt>bitcast</tt>' instruction takes a value to cast, which must be
Dan Gohman7305fa02008-09-08 16:45:59 +00004313a non-aggregate first class value, and a type to cast it to, which must also be
4314a non-aggregate <a href="#t_firstclass">first class</a> type. The bit sizes of
4315<tt>value</tt>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004316and the destination type, <tt>ty2</tt>, must be identical. If the source
Chris Lattner6704c212008-05-20 20:48:21 +00004317type is a pointer, the destination type must also be a pointer. This
4318instruction supports bitwise conversion of vectors to integers and to vectors
4319of other types (as long as they have the same size).</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004320
4321<h5>Semantics:</h5>
4322<p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
4323<tt>ty2</tt>. It is always a <i>no-op cast</i> because no bits change with
4324this conversion. The conversion is done as if the <tt>value</tt> had been
4325stored to memory and read back as type <tt>ty2</tt>. Pointer types may only be
4326converted to other pointer types with this instruction. To convert pointers to
4327other types, use the <a href="#i_inttoptr">inttoptr</a> or
4328<a href="#i_ptrtoint">ptrtoint</a> instructions first.</p>
4329
4330<h5>Example:</h5>
4331<pre>
4332 %X = bitcast i8 255 to i8 <i>; yields i8 :-1</i>
4333 %Y = bitcast i32* %x to sint* <i>; yields sint*:%x</i>
Dan Gohman2672f3e2008-10-14 16:51:45 +00004334 %Z = bitcast &lt;2 x int&gt; %V to i64; <i>; yields i64: %V</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004335</pre>
4336</div>
4337
4338<!-- ======================================================================= -->
4339<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
4340<div class="doc_text">
4341<p>The instructions in this category are the "miscellaneous"
4342instructions, which defy better classification.</p>
4343</div>
4344
4345<!-- _______________________________________________________________________ -->
4346<div class="doc_subsubsection"><a name="i_icmp">'<tt>icmp</tt>' Instruction</a>
4347</div>
4348<div class="doc_text">
4349<h5>Syntax:</h5>
Dan Gohman2672f3e2008-10-14 16:51:45 +00004350<pre> &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 +00004351</pre>
4352<h5>Overview:</h5>
Dan Gohmanb60ca3c2008-09-09 01:02:47 +00004353<p>The '<tt>icmp</tt>' instruction returns a boolean value or
4354a vector of boolean values based on comparison
4355of its two integer, integer vector, or pointer operands.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004356<h5>Arguments:</h5>
4357<p>The '<tt>icmp</tt>' instruction takes three operands. The first operand is
4358the condition code indicating the kind of comparison to perform. It is not
4359a value, just a keyword. The possible condition code are:
Dan Gohman2672f3e2008-10-14 16:51:45 +00004360</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004361<ol>
4362 <li><tt>eq</tt>: equal</li>
4363 <li><tt>ne</tt>: not equal </li>
4364 <li><tt>ugt</tt>: unsigned greater than</li>
4365 <li><tt>uge</tt>: unsigned greater or equal</li>
4366 <li><tt>ult</tt>: unsigned less than</li>
4367 <li><tt>ule</tt>: unsigned less or equal</li>
4368 <li><tt>sgt</tt>: signed greater than</li>
4369 <li><tt>sge</tt>: signed greater or equal</li>
4370 <li><tt>slt</tt>: signed less than</li>
4371 <li><tt>sle</tt>: signed less or equal</li>
4372</ol>
4373<p>The remaining two arguments must be <a href="#t_integer">integer</a> or
Dan Gohmanb60ca3c2008-09-09 01:02:47 +00004374<a href="#t_pointer">pointer</a>
4375or integer <a href="#t_vector">vector</a> typed.
4376They must also be identical types.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004377<h5>Semantics:</h5>
Gabor Greifd9068fe2008-08-07 21:46:00 +00004378<p>The '<tt>icmp</tt>' compares <tt>op1</tt> and <tt>op2</tt> according to
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004379the condition code given as <tt>cond</tt>. The comparison performed always
Dan Gohmanb60ca3c2008-09-09 01:02:47 +00004380yields either an <a href="#t_primitive"><tt>i1</tt></a> or vector of <tt>i1</tt> result, as follows:
Dan Gohman2672f3e2008-10-14 16:51:45 +00004381</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004382<ol>
4383 <li><tt>eq</tt>: yields <tt>true</tt> if the operands are equal,
4384 <tt>false</tt> otherwise. No sign interpretation is necessary or performed.
4385 </li>
4386 <li><tt>ne</tt>: yields <tt>true</tt> if the operands are unequal,
Dan Gohman2672f3e2008-10-14 16:51:45 +00004387 <tt>false</tt> otherwise. No sign interpretation is necessary or performed.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004388 <li><tt>ugt</tt>: interprets the operands as unsigned values and yields
Gabor Greifd9068fe2008-08-07 21:46:00 +00004389 <tt>true</tt> if <tt>op1</tt> is greater than <tt>op2</tt>.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004390 <li><tt>uge</tt>: interprets the operands as unsigned values and yields
Gabor Greifd9068fe2008-08-07 21:46:00 +00004391 <tt>true</tt> if <tt>op1</tt> is greater than or equal to <tt>op2</tt>.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004392 <li><tt>ult</tt>: interprets the operands as unsigned values and yields
Gabor Greifd9068fe2008-08-07 21:46:00 +00004393 <tt>true</tt> if <tt>op1</tt> is less than <tt>op2</tt>.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004394 <li><tt>ule</tt>: interprets the operands as unsigned values and yields
Gabor Greifd9068fe2008-08-07 21:46:00 +00004395 <tt>true</tt> if <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004396 <li><tt>sgt</tt>: interprets the operands as signed values and yields
Gabor Greifd9068fe2008-08-07 21:46:00 +00004397 <tt>true</tt> if <tt>op1</tt> is greater than <tt>op2</tt>.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004398 <li><tt>sge</tt>: interprets the operands as signed values and yields
Gabor Greifd9068fe2008-08-07 21:46:00 +00004399 <tt>true</tt> if <tt>op1</tt> is greater than or equal to <tt>op2</tt>.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004400 <li><tt>slt</tt>: interprets the operands as signed values and yields
Gabor Greifd9068fe2008-08-07 21:46:00 +00004401 <tt>true</tt> if <tt>op1</tt> is less than <tt>op2</tt>.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004402 <li><tt>sle</tt>: interprets the operands as signed values and yields
Gabor Greifd9068fe2008-08-07 21:46:00 +00004403 <tt>true</tt> if <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004404</ol>
4405<p>If the operands are <a href="#t_pointer">pointer</a> typed, the pointer
4406values are compared as if they were integers.</p>
Dan Gohmanb60ca3c2008-09-09 01:02:47 +00004407<p>If the operands are integer vectors, then they are compared
4408element by element. The result is an <tt>i1</tt> vector with
4409the same number of elements as the values being compared.
4410Otherwise, the result is an <tt>i1</tt>.
4411</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004412
4413<h5>Example:</h5>
4414<pre> &lt;result&gt; = icmp eq i32 4, 5 <i>; yields: result=false</i>
4415 &lt;result&gt; = icmp ne float* %X, %X <i>; yields: result=false</i>
4416 &lt;result&gt; = icmp ult i16 4, 5 <i>; yields: result=true</i>
4417 &lt;result&gt; = icmp sgt i16 4, 5 <i>; yields: result=false</i>
4418 &lt;result&gt; = icmp ule i16 -4, 5 <i>; yields: result=false</i>
4419 &lt;result&gt; = icmp sge i16 4, 5 <i>; yields: result=false</i>
4420</pre>
Dan Gohmana53eb382009-01-22 01:39:38 +00004421
4422<p>Note that the code generator does not yet support vector types with
4423 the <tt>icmp</tt> instruction.</p>
4424
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004425</div>
4426
4427<!-- _______________________________________________________________________ -->
4428<div class="doc_subsubsection"><a name="i_fcmp">'<tt>fcmp</tt>' Instruction</a>
4429</div>
4430<div class="doc_text">
4431<h5>Syntax:</h5>
Dan Gohman2672f3e2008-10-14 16:51:45 +00004432<pre> &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 +00004433</pre>
4434<h5>Overview:</h5>
Dan Gohmanb60ca3c2008-09-09 01:02:47 +00004435<p>The '<tt>fcmp</tt>' instruction returns a boolean value
4436or vector of boolean values based on comparison
Dan Gohman2672f3e2008-10-14 16:51:45 +00004437of its operands.</p>
Dan Gohmanb60ca3c2008-09-09 01:02:47 +00004438<p>
4439If the operands are floating point scalars, then the result
4440type is a boolean (<a href="#t_primitive"><tt>i1</tt></a>).
4441</p>
4442<p>If the operands are floating point vectors, then the result type
4443is a vector of boolean with the same number of elements as the
4444operands being compared.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004445<h5>Arguments:</h5>
4446<p>The '<tt>fcmp</tt>' instruction takes three operands. The first operand is
4447the condition code indicating the kind of comparison to perform. It is not
Dan Gohman2672f3e2008-10-14 16:51:45 +00004448a value, just a keyword. The possible condition code are:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004449<ol>
4450 <li><tt>false</tt>: no comparison, always returns false</li>
4451 <li><tt>oeq</tt>: ordered and equal</li>
4452 <li><tt>ogt</tt>: ordered and greater than </li>
4453 <li><tt>oge</tt>: ordered and greater than or equal</li>
4454 <li><tt>olt</tt>: ordered and less than </li>
4455 <li><tt>ole</tt>: ordered and less than or equal</li>
4456 <li><tt>one</tt>: ordered and not equal</li>
4457 <li><tt>ord</tt>: ordered (no nans)</li>
4458 <li><tt>ueq</tt>: unordered or equal</li>
4459 <li><tt>ugt</tt>: unordered or greater than </li>
4460 <li><tt>uge</tt>: unordered or greater than or equal</li>
4461 <li><tt>ult</tt>: unordered or less than </li>
4462 <li><tt>ule</tt>: unordered or less than or equal</li>
4463 <li><tt>une</tt>: unordered or not equal</li>
4464 <li><tt>uno</tt>: unordered (either nans)</li>
4465 <li><tt>true</tt>: no comparison, always returns true</li>
4466</ol>
4467<p><i>Ordered</i> means that neither operand is a QNAN while
4468<i>unordered</i> means that either operand may be a QNAN.</p>
Dan Gohmanb60ca3c2008-09-09 01:02:47 +00004469<p>Each of <tt>val1</tt> and <tt>val2</tt> arguments must be
4470either a <a href="#t_floating">floating point</a> type
4471or a <a href="#t_vector">vector</a> of floating point type.
4472They must have identical types.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004473<h5>Semantics:</h5>
Gabor Greifd9068fe2008-08-07 21:46:00 +00004474<p>The '<tt>fcmp</tt>' instruction compares <tt>op1</tt> and <tt>op2</tt>
Dan Gohmanb60ca3c2008-09-09 01:02:47 +00004475according to the condition code given as <tt>cond</tt>.
4476If the operands are vectors, then the vectors are compared
4477element by element.
4478Each comparison performed
Dan Gohman2672f3e2008-10-14 16:51:45 +00004479always yields an <a href="#t_primitive">i1</a> result, as follows:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004480<ol>
4481 <li><tt>false</tt>: always yields <tt>false</tt>, regardless of operands.</li>
4482 <li><tt>oeq</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Gabor Greifd9068fe2008-08-07 21:46:00 +00004483 <tt>op1</tt> is equal to <tt>op2</tt>.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004484 <li><tt>ogt</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Gabor Greifd9068fe2008-08-07 21:46:00 +00004485 <tt>op1</tt> is greather than <tt>op2</tt>.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004486 <li><tt>oge</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Gabor Greifd9068fe2008-08-07 21:46:00 +00004487 <tt>op1</tt> is greater than or equal to <tt>op2</tt>.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004488 <li><tt>olt</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Gabor Greifd9068fe2008-08-07 21:46:00 +00004489 <tt>op1</tt> is less than <tt>op2</tt>.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004490 <li><tt>ole</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Gabor Greifd9068fe2008-08-07 21:46:00 +00004491 <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004492 <li><tt>one</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Gabor Greifd9068fe2008-08-07 21:46:00 +00004493 <tt>op1</tt> is not equal to <tt>op2</tt>.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004494 <li><tt>ord</tt>: yields <tt>true</tt> if both operands are not a QNAN.</li>
4495 <li><tt>ueq</tt>: yields <tt>true</tt> if either operand is a QNAN or
Gabor Greifd9068fe2008-08-07 21:46:00 +00004496 <tt>op1</tt> is equal to <tt>op2</tt>.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004497 <li><tt>ugt</tt>: yields <tt>true</tt> if either operand is a QNAN or
Gabor Greifd9068fe2008-08-07 21:46:00 +00004498 <tt>op1</tt> is greater than <tt>op2</tt>.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004499 <li><tt>uge</tt>: yields <tt>true</tt> if either operand is a QNAN or
Gabor Greifd9068fe2008-08-07 21:46:00 +00004500 <tt>op1</tt> is greater than or equal to <tt>op2</tt>.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004501 <li><tt>ult</tt>: yields <tt>true</tt> if either operand is a QNAN or
Gabor Greifd9068fe2008-08-07 21:46:00 +00004502 <tt>op1</tt> is less than <tt>op2</tt>.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004503 <li><tt>ule</tt>: yields <tt>true</tt> if either operand is a QNAN or
Gabor Greifd9068fe2008-08-07 21:46:00 +00004504 <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004505 <li><tt>une</tt>: yields <tt>true</tt> if either operand is a QNAN or
Gabor Greifd9068fe2008-08-07 21:46:00 +00004506 <tt>op1</tt> is not equal to <tt>op2</tt>.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004507 <li><tt>uno</tt>: yields <tt>true</tt> if either operand is a QNAN.</li>
4508 <li><tt>true</tt>: always yields <tt>true</tt>, regardless of operands.</li>
4509</ol>
4510
4511<h5>Example:</h5>
4512<pre> &lt;result&gt; = fcmp oeq float 4.0, 5.0 <i>; yields: result=false</i>
Dan Gohmanb60ca3c2008-09-09 01:02:47 +00004513 &lt;result&gt; = fcmp one float 4.0, 5.0 <i>; yields: result=true</i>
4514 &lt;result&gt; = fcmp olt float 4.0, 5.0 <i>; yields: result=true</i>
4515 &lt;result&gt; = fcmp ueq double 1.0, 2.0 <i>; yields: result=false</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004516</pre>
Dan Gohmana53eb382009-01-22 01:39:38 +00004517
4518<p>Note that the code generator does not yet support vector types with
4519 the <tt>fcmp</tt> instruction.</p>
4520
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004521</div>
4522
4523<!-- _______________________________________________________________________ -->
Nate Begeman646fa482008-05-12 19:01:56 +00004524<div class="doc_subsubsection">
Chris Lattner6704c212008-05-20 20:48:21 +00004525 <a name="i_phi">'<tt>phi</tt>' Instruction</a>
4526</div>
4527
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004528<div class="doc_text">
Chris Lattner6704c212008-05-20 20:48:21 +00004529
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004530<h5>Syntax:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00004531
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004532<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
4533<h5>Overview:</h5>
4534<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
4535the SSA graph representing the function.</p>
4536<h5>Arguments:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00004537
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004538<p>The type of the incoming values is specified with the first type
4539field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
4540as arguments, with one pair for each predecessor basic block of the
4541current block. Only values of <a href="#t_firstclass">first class</a>
4542type may be used as the value arguments to the PHI node. Only labels
4543may be used as the label arguments.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00004544
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004545<p>There must be no non-phi instructions between the start of a basic
4546block and the PHI instructions: i.e. PHI instructions must be first in
4547a basic block.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00004548
Jay Foad8e2fd2c2009-06-03 10:20:10 +00004549<p>For the purposes of the SSA form, the use of each incoming value is
4550deemed to occur on the edge from the corresponding predecessor block
4551to the current block (but after any definition of an '<tt>invoke</tt>'
4552instruction's return value on the same edge).</p>
4553
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004554<h5>Semantics:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00004555
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004556<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the value
4557specified by the pair corresponding to the predecessor basic block that executed
4558just prior to the current block.</p>
Chris Lattner6704c212008-05-20 20:48:21 +00004559
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004560<h5>Example:</h5>
Chris Lattner6704c212008-05-20 20:48:21 +00004561<pre>
4562Loop: ; Infinite loop that counts from 0 on up...
4563 %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]
4564 %nextindvar = add i32 %indvar, 1
4565 br label %Loop
4566</pre>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004567</div>
4568
4569<!-- _______________________________________________________________________ -->
4570<div class="doc_subsubsection">
4571 <a name="i_select">'<tt>select</tt>' Instruction</a>
4572</div>
4573
4574<div class="doc_text">
4575
4576<h5>Syntax:</h5>
4577
4578<pre>
Dan Gohmanb60ca3c2008-09-09 01:02:47 +00004579 &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>
4580
Dan Gohman2672f3e2008-10-14 16:51:45 +00004581 <i>selty</i> is either i1 or {&lt;N x i1&gt;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004582</pre>
4583
4584<h5>Overview:</h5>
4585
4586<p>
4587The '<tt>select</tt>' instruction is used to choose one value based on a
4588condition, without branching.
4589</p>
4590
4591
4592<h5>Arguments:</h5>
4593
4594<p>
Dan Gohmanb60ca3c2008-09-09 01:02:47 +00004595The '<tt>select</tt>' instruction requires an 'i1' value or
4596a vector of 'i1' values indicating the
Chris Lattner6704c212008-05-20 20:48:21 +00004597condition, and two values of the same <a href="#t_firstclass">first class</a>
Dan Gohmanb60ca3c2008-09-09 01:02:47 +00004598type. If the val1/val2 are vectors and
4599the condition is a scalar, then entire vectors are selected, not
Chris Lattner6704c212008-05-20 20:48:21 +00004600individual elements.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004601</p>
4602
4603<h5>Semantics:</h5>
4604
4605<p>
Dan Gohmanb60ca3c2008-09-09 01:02:47 +00004606If the condition is an i1 and it evaluates to 1, the instruction returns the first
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004607value argument; otherwise, it returns the second value argument.
4608</p>
Dan Gohmanb60ca3c2008-09-09 01:02:47 +00004609<p>
4610If the condition is a vector of i1, then the value arguments must
4611be vectors of the same size, and the selection is done element
4612by element.
4613</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004614
4615<h5>Example:</h5>
4616
4617<pre>
4618 %X = select i1 true, i8 17, i8 42 <i>; yields i8:17</i>
4619</pre>
Dan Gohmana53eb382009-01-22 01:39:38 +00004620
4621<p>Note that the code generator does not yet support conditions
4622 with vector type.</p>
4623
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004624</div>
4625
4626
4627<!-- _______________________________________________________________________ -->
4628<div class="doc_subsubsection">
4629 <a name="i_call">'<tt>call</tt>' Instruction</a>
4630</div>
4631
4632<div class="doc_text">
4633
4634<h5>Syntax:</h5>
4635<pre>
Devang Pateld0bfcc72008-10-07 17:48:33 +00004636 &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 +00004637</pre>
4638
4639<h5>Overview:</h5>
4640
4641<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
4642
4643<h5>Arguments:</h5>
4644
4645<p>This instruction requires several arguments:</p>
4646
4647<ol>
4648 <li>
4649 <p>The optional "tail" marker indicates whether the callee function accesses
4650 any allocas or varargs in the caller. If the "tail" marker is present, the
4651 function call is eligible for tail call optimization. Note that calls may
4652 be marked "tail" even if they do not occur before a <a
Dan Gohman2672f3e2008-10-14 16:51:45 +00004653 href="#i_ret"><tt>ret</tt></a> instruction.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004654 </li>
4655 <li>
4656 <p>The optional "cconv" marker indicates which <a href="#callingconv">calling
4657 convention</a> the call should use. If none is specified, the call defaults
Dan Gohman2672f3e2008-10-14 16:51:45 +00004658 to using C calling conventions.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004659 </li>
Devang Patelac2fc272008-10-06 18:50:38 +00004660
4661 <li>
4662 <p>The optional <a href="#paramattrs">Parameter Attributes</a> list for
4663 return values. Only '<tt>zeroext</tt>', '<tt>signext</tt>',
4664 and '<tt>inreg</tt>' attributes are valid here.</p>
4665 </li>
4666
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004667 <li>
Nick Lewycky93082fc2007-09-08 13:57:50 +00004668 <p>'<tt>ty</tt>': the type of the call instruction itself which is also
4669 the type of the return value. Functions that return no value are marked
4670 <tt><a href="#t_void">void</a></tt>.</p>
4671 </li>
4672 <li>
4673 <p>'<tt>fnty</tt>': shall be the signature of the pointer to function
4674 value being invoked. The argument types must match the types implied by
4675 this signature. This type can be omitted if the function is not varargs
4676 and if the function type does not return a pointer to a function.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004677 </li>
4678 <li>
4679 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to
4680 be invoked. In most cases, this is a direct function invocation, but
4681 indirect <tt>call</tt>s are just as possible, calling an arbitrary pointer
4682 to function value.</p>
4683 </li>
4684 <li>
4685 <p>'<tt>function args</tt>': argument list whose types match the
4686 function signature argument types. All arguments must be of
4687 <a href="#t_firstclass">first class</a> type. If the function signature
4688 indicates the function accepts a variable number of arguments, the extra
4689 arguments can be specified.</p>
4690 </li>
Devang Patelac2fc272008-10-06 18:50:38 +00004691 <li>
Devang Pateld0bfcc72008-10-07 17:48:33 +00004692 <p>The optional <a href="#fnattrs">function attributes</a> list. Only
Devang Patelac2fc272008-10-06 18:50:38 +00004693 '<tt>noreturn</tt>', '<tt>nounwind</tt>', '<tt>readonly</tt>' and
4694 '<tt>readnone</tt>' attributes are valid here.</p>
4695 </li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004696</ol>
4697
4698<h5>Semantics:</h5>
4699
4700<p>The '<tt>call</tt>' instruction is used to cause control flow to
4701transfer to a specified function, with its incoming arguments bound to
4702the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
4703instruction in the called function, control flow continues with the
4704instruction after the function call, and the return value of the
Dan Gohman2672f3e2008-10-14 16:51:45 +00004705function is bound to the result argument.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004706
4707<h5>Example:</h5>
4708
4709<pre>
Nick Lewycky93082fc2007-09-08 13:57:50 +00004710 %retval = call i32 @test(i32 %argc)
Chris Lattner5e893ef2008-03-21 17:24:17 +00004711 call i32 (i8 *, ...)* @printf(i8 * %msg, i32 12, i8 42) <i>; yields i32</i>
4712 %X = tail call i32 @foo() <i>; yields i32</i>
4713 %Y = tail call <a href="#callingconv">fastcc</a> i32 @foo() <i>; yields i32</i>
4714 call void %foo(i8 97 signext)
Devang Patela3cc5372008-03-10 20:49:15 +00004715
4716 %struct.A = type { i32, i8 }
Devang Patelac2fc272008-10-06 18:50:38 +00004717 %r = call %struct.A @foo() <i>; yields { 32, i8 }</i>
Dan Gohman3e700032008-10-04 19:00:07 +00004718 %gr = extractvalue %struct.A %r, 0 <i>; yields i32</i>
4719 %gr1 = extractvalue %struct.A %r, 1 <i>; yields i8</i>
Chris Lattnerac454b32008-10-08 06:26:11 +00004720 %Z = call void @foo() noreturn <i>; indicates that %foo never returns normally</i>
Matthijs Kooijman2c4e05a2008-10-07 10:03:45 +00004721 %ZZ = call zeroext i32 @bar() <i>; Return value is %zero extended</i>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004722</pre>
4723
4724</div>
4725
4726<!-- _______________________________________________________________________ -->
4727<div class="doc_subsubsection">
4728 <a name="i_va_arg">'<tt>va_arg</tt>' Instruction</a>
4729</div>
4730
4731<div class="doc_text">
4732
4733<h5>Syntax:</h5>
4734
4735<pre>
4736 &lt;resultval&gt; = va_arg &lt;va_list*&gt; &lt;arglist&gt;, &lt;argty&gt;
4737</pre>
4738
4739<h5>Overview:</h5>
4740
4741<p>The '<tt>va_arg</tt>' instruction is used to access arguments passed through
4742the "variable argument" area of a function call. It is used to implement the
4743<tt>va_arg</tt> macro in C.</p>
4744
4745<h5>Arguments:</h5>
4746
4747<p>This instruction takes a <tt>va_list*</tt> value and the type of
4748the argument. It returns a value of the specified argument type and
4749increments the <tt>va_list</tt> to point to the next argument. The
4750actual type of <tt>va_list</tt> is target specific.</p>
4751
4752<h5>Semantics:</h5>
4753
4754<p>The '<tt>va_arg</tt>' instruction loads an argument of the specified
4755type from the specified <tt>va_list</tt> and causes the
4756<tt>va_list</tt> to point to the next argument. For more information,
4757see the variable argument handling <a href="#int_varargs">Intrinsic
4758Functions</a>.</p>
4759
4760<p>It is legal for this instruction to be called in a function which does not
4761take a variable number of arguments, for example, the <tt>vfprintf</tt>
4762function.</p>
4763
4764<p><tt>va_arg</tt> is an LLVM instruction instead of an <a
4765href="#intrinsics">intrinsic function</a> because it takes a type as an
4766argument.</p>
4767
4768<h5>Example:</h5>
4769
4770<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
4771
Dan Gohman60967192009-01-12 23:12:39 +00004772<p>Note that the code generator does not yet fully support va_arg
4773 on many targets. Also, it does not currently support va_arg with
4774 aggregate types on any target.</p>
4775
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004776</div>
4777
4778<!-- *********************************************************************** -->
4779<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
4780<!-- *********************************************************************** -->
4781
4782<div class="doc_text">
4783
4784<p>LLVM supports the notion of an "intrinsic function". These functions have
4785well known names and semantics and are required to follow certain restrictions.
4786Overall, these intrinsics represent an extension mechanism for the LLVM
4787language that does not require changing all of the transformations in LLVM when
4788adding to the language (or the bitcode reader/writer, the parser, etc...).</p>
4789
4790<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix. This
4791prefix is reserved in LLVM for intrinsic names; thus, function names may not
4792begin with this prefix. Intrinsic functions must always be external functions:
4793you cannot define the body of intrinsic functions. Intrinsic functions may
4794only be used in call or invoke instructions: it is illegal to take the address
4795of an intrinsic function. Additionally, because intrinsic functions are part
4796of the LLVM language, it is required if any are added that they be documented
4797here.</p>
4798
Chandler Carrutha228e392007-08-04 01:51:18 +00004799<p>Some intrinsic functions can be overloaded, i.e., the intrinsic represents
4800a family of functions that perform the same operation but on different data
4801types. Because LLVM can represent over 8 million different integer types,
4802overloading is used commonly to allow an intrinsic function to operate on any
4803integer type. One or more of the argument types or the result type can be
4804overloaded to accept any integer type. Argument types may also be defined as
4805exactly matching a previous argument's type or the result type. This allows an
4806intrinsic function which accepts multiple arguments, but needs all of them to
4807be of the same type, to only be overloaded with respect to a single argument or
4808the result.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004809
Chandler Carrutha228e392007-08-04 01:51:18 +00004810<p>Overloaded intrinsics will have the names of its overloaded argument types
4811encoded into its function name, each preceded by a period. Only those types
4812which are overloaded result in a name suffix. Arguments whose type is matched
4813against another type do not. For example, the <tt>llvm.ctpop</tt> function can
4814take an integer of any width and returns an integer of exactly the same integer
4815width. This leads to a family of functions such as
4816<tt>i8 @llvm.ctpop.i8(i8 %val)</tt> and <tt>i29 @llvm.ctpop.i29(i29 %val)</tt>.
4817Only one type, the return type, is overloaded, and only one type suffix is
4818required. Because the argument's type is matched against the return type, it
4819does not require its own name suffix.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004820
4821<p>To learn how to add an intrinsic function, please see the
4822<a href="ExtendingLLVM.html">Extending LLVM Guide</a>.
4823</p>
4824
4825</div>
4826
4827<!-- ======================================================================= -->
4828<div class="doc_subsection">
4829 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
4830</div>
4831
4832<div class="doc_text">
4833
4834<p>Variable argument support is defined in LLVM with the <a
4835 href="#i_va_arg"><tt>va_arg</tt></a> instruction and these three
4836intrinsic functions. These functions are related to the similarly
4837named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
4838
4839<p>All of these functions operate on arguments that use a
4840target-specific value type "<tt>va_list</tt>". The LLVM assembly
4841language reference manual does not define what this type is, so all
4842transformations should be prepared to handle these functions regardless of
4843the type used.</p>
4844
4845<p>This example shows how the <a href="#i_va_arg"><tt>va_arg</tt></a>
4846instruction and the variable argument handling intrinsic functions are
4847used.</p>
4848
4849<div class="doc_code">
4850<pre>
4851define i32 @test(i32 %X, ...) {
4852 ; Initialize variable argument processing
4853 %ap = alloca i8*
4854 %ap2 = bitcast i8** %ap to i8*
4855 call void @llvm.va_start(i8* %ap2)
4856
4857 ; Read a single integer argument
4858 %tmp = va_arg i8** %ap, i32
4859
4860 ; Demonstrate usage of llvm.va_copy and llvm.va_end
4861 %aq = alloca i8*
4862 %aq2 = bitcast i8** %aq to i8*
4863 call void @llvm.va_copy(i8* %aq2, i8* %ap2)
4864 call void @llvm.va_end(i8* %aq2)
4865
4866 ; Stop processing of arguments.
4867 call void @llvm.va_end(i8* %ap2)
4868 ret i32 %tmp
4869}
4870
4871declare void @llvm.va_start(i8*)
4872declare void @llvm.va_copy(i8*, i8*)
4873declare void @llvm.va_end(i8*)
4874</pre>
4875</div>
4876
4877</div>
4878
4879<!-- _______________________________________________________________________ -->
4880<div class="doc_subsubsection">
4881 <a name="int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
4882</div>
4883
4884
4885<div class="doc_text">
4886<h5>Syntax:</h5>
4887<pre> declare void %llvm.va_start(i8* &lt;arglist&gt;)<br></pre>
4888<h5>Overview:</h5>
Dan Gohman2672f3e2008-10-14 16:51:45 +00004889<p>The '<tt>llvm.va_start</tt>' intrinsic initializes
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004890<tt>*&lt;arglist&gt;</tt> for subsequent use by <tt><a
4891href="#i_va_arg">va_arg</a></tt>.</p>
4892
4893<h5>Arguments:</h5>
4894
Dan Gohman2672f3e2008-10-14 16:51:45 +00004895<p>The argument is a pointer to a <tt>va_list</tt> element to initialize.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004896
4897<h5>Semantics:</h5>
4898
Dan Gohman2672f3e2008-10-14 16:51:45 +00004899<p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004900macro available in C. In a target-dependent way, it initializes the
4901<tt>va_list</tt> element to which the argument points, so that the next call to
4902<tt>va_arg</tt> will produce the first variable argument passed to the function.
4903Unlike the C <tt>va_start</tt> macro, this intrinsic does not need to know the
4904last argument of the function as the compiler can figure that out.</p>
4905
4906</div>
4907
4908<!-- _______________________________________________________________________ -->
4909<div class="doc_subsubsection">
4910 <a name="int_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
4911</div>
4912
4913<div class="doc_text">
4914<h5>Syntax:</h5>
4915<pre> declare void @llvm.va_end(i8* &lt;arglist&gt;)<br></pre>
4916<h5>Overview:</h5>
4917
4918<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>*&lt;arglist&gt;</tt>,
4919which has been initialized previously with <tt><a href="#int_va_start">llvm.va_start</a></tt>
4920or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
4921
4922<h5>Arguments:</h5>
4923
4924<p>The argument is a pointer to a <tt>va_list</tt> to destroy.</p>
4925
4926<h5>Semantics:</h5>
4927
4928<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
4929macro available in C. In a target-dependent way, it destroys the
4930<tt>va_list</tt> element to which the argument points. Calls to <a
4931href="#int_va_start"><tt>llvm.va_start</tt></a> and <a href="#int_va_copy">
4932<tt>llvm.va_copy</tt></a> must be matched exactly with calls to
4933<tt>llvm.va_end</tt>.</p>
4934
4935</div>
4936
4937<!-- _______________________________________________________________________ -->
4938<div class="doc_subsubsection">
4939 <a name="int_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
4940</div>
4941
4942<div class="doc_text">
4943
4944<h5>Syntax:</h5>
4945
4946<pre>
4947 declare void @llvm.va_copy(i8* &lt;destarglist&gt;, i8* &lt;srcarglist&gt;)
4948</pre>
4949
4950<h5>Overview:</h5>
4951
4952<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position
4953from the source argument list to the destination argument list.</p>
4954
4955<h5>Arguments:</h5>
4956
4957<p>The first argument is a pointer to a <tt>va_list</tt> element to initialize.
4958The second argument is a pointer to a <tt>va_list</tt> element to copy from.</p>
4959
4960
4961<h5>Semantics:</h5>
4962
4963<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
4964macro available in C. In a target-dependent way, it copies the source
4965<tt>va_list</tt> element into the destination <tt>va_list</tt> element. This
4966intrinsic is necessary because the <tt><a href="#int_va_start">
4967llvm.va_start</a></tt> intrinsic may be arbitrarily complex and require, for
4968example, memory allocation.</p>
4969
4970</div>
4971
4972<!-- ======================================================================= -->
4973<div class="doc_subsection">
4974 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
4975</div>
4976
4977<div class="doc_text">
4978
4979<p>
4980LLVM support for <a href="GarbageCollection.html">Accurate Garbage
Chris Lattner96451482008-08-05 18:29:16 +00004981Collection</a> (GC) requires the implementation and generation of these
4982intrinsics.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004983These intrinsics allow identification of <a href="#int_gcroot">GC roots on the
4984stack</a>, as well as garbage collector implementations that require <a
4985href="#int_gcread">read</a> and <a href="#int_gcwrite">write</a> barriers.
4986Front-ends for type-safe garbage collected languages should generate these
4987intrinsics to make use of the LLVM garbage collectors. For more details, see <a
4988href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
4989</p>
Christopher Lambcfe00962007-12-17 01:00:21 +00004990
4991<p>The garbage collection intrinsics only operate on objects in the generic
4992 address space (address space zero).</p>
4993
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004994</div>
4995
4996<!-- _______________________________________________________________________ -->
4997<div class="doc_subsubsection">
4998 <a name="int_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
4999</div>
5000
5001<div class="doc_text">
5002
5003<h5>Syntax:</h5>
5004
5005<pre>
Chris Lattner38bd5dd2007-09-21 17:30:40 +00005006 declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005007</pre>
5008
5009<h5>Overview:</h5>
5010
5011<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
5012the code generator, and allows some metadata to be associated with it.</p>
5013
5014<h5>Arguments:</h5>
5015
5016<p>The first argument specifies the address of a stack object that contains the
5017root pointer. The second pointer (which must be either a constant or a global
5018value address) contains the meta-data to be associated with the root.</p>
5019
5020<h5>Semantics:</h5>
5021
Chris Lattnera7d94ba2008-04-24 05:59:56 +00005022<p>At runtime, a call to this intrinsic stores a null pointer into the "ptrloc"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005023location. At compile-time, the code generator generates information to allow
Gordon Henriksen40393542007-12-25 02:31:26 +00005024the runtime to find the pointer at GC safe points. The '<tt>llvm.gcroot</tt>'
5025intrinsic may only be used in a function which <a href="#gc">specifies a GC
5026algorithm</a>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005027
5028</div>
5029
5030
5031<!-- _______________________________________________________________________ -->
5032<div class="doc_subsubsection">
5033 <a name="int_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
5034</div>
5035
5036<div class="doc_text">
5037
5038<h5>Syntax:</h5>
5039
5040<pre>
Chris Lattner38bd5dd2007-09-21 17:30:40 +00005041 declare i8* @llvm.gcread(i8* %ObjPtr, i8** %Ptr)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005042</pre>
5043
5044<h5>Overview:</h5>
5045
5046<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
5047locations, allowing garbage collector implementations that require read
5048barriers.</p>
5049
5050<h5>Arguments:</h5>
5051
5052<p>The second argument is the address to read from, which should be an address
5053allocated from the garbage collector. The first object is a pointer to the
5054start of the referenced object, if needed by the language runtime (otherwise
5055null).</p>
5056
5057<h5>Semantics:</h5>
5058
5059<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
5060instruction, but may be replaced with substantially more complex code by the
Gordon Henriksen40393542007-12-25 02:31:26 +00005061garbage collector runtime, as needed. The '<tt>llvm.gcread</tt>' intrinsic
5062may only be used in a function which <a href="#gc">specifies a GC
5063algorithm</a>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005064
5065</div>
5066
5067
5068<!-- _______________________________________________________________________ -->
5069<div class="doc_subsubsection">
5070 <a name="int_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
5071</div>
5072
5073<div class="doc_text">
5074
5075<h5>Syntax:</h5>
5076
5077<pre>
Chris Lattner38bd5dd2007-09-21 17:30:40 +00005078 declare void @llvm.gcwrite(i8* %P1, i8* %Obj, i8** %P2)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005079</pre>
5080
5081<h5>Overview:</h5>
5082
5083<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
5084locations, allowing garbage collector implementations that require write
5085barriers (such as generational or reference counting collectors).</p>
5086
5087<h5>Arguments:</h5>
5088
5089<p>The first argument is the reference to store, the second is the start of the
5090object to store it to, and the third is the address of the field of Obj to
5091store to. If the runtime does not require a pointer to the object, Obj may be
5092null.</p>
5093
5094<h5>Semantics:</h5>
5095
5096<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
5097instruction, but may be replaced with substantially more complex code by the
Gordon Henriksen40393542007-12-25 02:31:26 +00005098garbage collector runtime, as needed. The '<tt>llvm.gcwrite</tt>' intrinsic
5099may only be used in a function which <a href="#gc">specifies a GC
5100algorithm</a>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005101
5102</div>
5103
5104
5105
5106<!-- ======================================================================= -->
5107<div class="doc_subsection">
5108 <a name="int_codegen">Code Generator Intrinsics</a>
5109</div>
5110
5111<div class="doc_text">
5112<p>
5113These intrinsics are provided by LLVM to expose special features that may only
5114be implemented with code generator support.
5115</p>
5116
5117</div>
5118
5119<!-- _______________________________________________________________________ -->
5120<div class="doc_subsubsection">
5121 <a name="int_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
5122</div>
5123
5124<div class="doc_text">
5125
5126<h5>Syntax:</h5>
5127<pre>
5128 declare i8 *@llvm.returnaddress(i32 &lt;level&gt;)
5129</pre>
5130
5131<h5>Overview:</h5>
5132
5133<p>
5134The '<tt>llvm.returnaddress</tt>' intrinsic attempts to compute a
5135target-specific value indicating the return address of the current function
5136or one of its callers.
5137</p>
5138
5139<h5>Arguments:</h5>
5140
5141<p>
5142The argument to this intrinsic indicates which function to return the address
5143for. Zero indicates the calling function, one indicates its caller, etc. The
5144argument is <b>required</b> to be a constant integer value.
5145</p>
5146
5147<h5>Semantics:</h5>
5148
5149<p>
5150The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
5151the return address of the specified call frame, or zero if it cannot be
5152identified. The value returned by this intrinsic is likely to be incorrect or 0
5153for arguments other than zero, so it should only be used for debugging purposes.
5154</p>
5155
5156<p>
5157Note that calling this intrinsic does not prevent function inlining or other
5158aggressive transformations, so the value returned may not be that of the obvious
5159source-language caller.
5160</p>
5161</div>
5162
5163
5164<!-- _______________________________________________________________________ -->
5165<div class="doc_subsubsection">
5166 <a name="int_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
5167</div>
5168
5169<div class="doc_text">
5170
5171<h5>Syntax:</h5>
5172<pre>
Chris Lattner38bd5dd2007-09-21 17:30:40 +00005173 declare i8 *@llvm.frameaddress(i32 &lt;level&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005174</pre>
5175
5176<h5>Overview:</h5>
5177
5178<p>
5179The '<tt>llvm.frameaddress</tt>' intrinsic attempts to return the
5180target-specific frame pointer value for the specified stack frame.
5181</p>
5182
5183<h5>Arguments:</h5>
5184
5185<p>
5186The argument to this intrinsic indicates which function to return the frame
5187pointer for. Zero indicates the calling function, one indicates its caller,
5188etc. The argument is <b>required</b> to be a constant integer value.
5189</p>
5190
5191<h5>Semantics:</h5>
5192
5193<p>
5194The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
5195the frame address of the specified call frame, or zero if it cannot be
5196identified. The value returned by this intrinsic is likely to be incorrect or 0
5197for arguments other than zero, so it should only be used for debugging purposes.
5198</p>
5199
5200<p>
5201Note that calling this intrinsic does not prevent function inlining or other
5202aggressive transformations, so the value returned may not be that of the obvious
5203source-language caller.
5204</p>
5205</div>
5206
5207<!-- _______________________________________________________________________ -->
5208<div class="doc_subsubsection">
5209 <a name="int_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a>
5210</div>
5211
5212<div class="doc_text">
5213
5214<h5>Syntax:</h5>
5215<pre>
Chris Lattner38bd5dd2007-09-21 17:30:40 +00005216 declare i8 *@llvm.stacksave()
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005217</pre>
5218
5219<h5>Overview:</h5>
5220
5221<p>
5222The '<tt>llvm.stacksave</tt>' intrinsic is used to remember the current state of
5223the function stack, for use with <a href="#int_stackrestore">
5224<tt>llvm.stackrestore</tt></a>. This is useful for implementing language
5225features like scoped automatic variable sized arrays in C99.
5226</p>
5227
5228<h5>Semantics:</h5>
5229
5230<p>
5231This intrinsic returns a opaque pointer value that can be passed to <a
5232href="#int_stackrestore"><tt>llvm.stackrestore</tt></a>. When an
5233<tt>llvm.stackrestore</tt> intrinsic is executed with a value saved from
5234<tt>llvm.stacksave</tt>, it effectively restores the state of the stack to the
5235state it was in when the <tt>llvm.stacksave</tt> intrinsic executed. In
5236practice, this pops any <a href="#i_alloca">alloca</a> blocks from the stack
5237that were allocated after the <tt>llvm.stacksave</tt> was executed.
5238</p>
5239
5240</div>
5241
5242<!-- _______________________________________________________________________ -->
5243<div class="doc_subsubsection">
5244 <a name="int_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a>
5245</div>
5246
5247<div class="doc_text">
5248
5249<h5>Syntax:</h5>
5250<pre>
5251 declare void @llvm.stackrestore(i8 * %ptr)
5252</pre>
5253
5254<h5>Overview:</h5>
5255
5256<p>
5257The '<tt>llvm.stackrestore</tt>' intrinsic is used to restore the state of
5258the function stack to the state it was in when the corresponding <a
5259href="#int_stacksave"><tt>llvm.stacksave</tt></a> intrinsic executed. This is
5260useful for implementing language features like scoped automatic variable sized
5261arrays in C99.
5262</p>
5263
5264<h5>Semantics:</h5>
5265
5266<p>
5267See the description for <a href="#int_stacksave"><tt>llvm.stacksave</tt></a>.
5268</p>
5269
5270</div>
5271
5272
5273<!-- _______________________________________________________________________ -->
5274<div class="doc_subsubsection">
5275 <a name="int_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a>
5276</div>
5277
5278<div class="doc_text">
5279
5280<h5>Syntax:</h5>
5281<pre>
Chris Lattner38bd5dd2007-09-21 17:30:40 +00005282 declare void @llvm.prefetch(i8* &lt;address&gt;, i32 &lt;rw&gt;, i32 &lt;locality&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005283</pre>
5284
5285<h5>Overview:</h5>
5286
5287
5288<p>
5289The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to insert
5290a prefetch instruction if supported; otherwise, it is a noop. Prefetches have
5291no
5292effect on the behavior of the program but can change its performance
5293characteristics.
5294</p>
5295
5296<h5>Arguments:</h5>
5297
5298<p>
5299<tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier
5300determining if the fetch should be for a read (0) or write (1), and
5301<tt>locality</tt> is a temporal locality specifier ranging from (0) - no
5302locality, to (3) - extremely local keep in cache. The <tt>rw</tt> and
5303<tt>locality</tt> arguments must be constant integers.
5304</p>
5305
5306<h5>Semantics:</h5>
5307
5308<p>
5309This intrinsic does not modify the behavior of the program. In particular,
5310prefetches cannot trap and do not produce a value. On targets that support this
5311intrinsic, the prefetch can provide hints to the processor cache for better
5312performance.
5313</p>
5314
5315</div>
5316
5317<!-- _______________________________________________________________________ -->
5318<div class="doc_subsubsection">
5319 <a name="int_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a>
5320</div>
5321
5322<div class="doc_text">
5323
5324<h5>Syntax:</h5>
5325<pre>
Chris Lattner38bd5dd2007-09-21 17:30:40 +00005326 declare void @llvm.pcmarker(i32 &lt;id&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005327</pre>
5328
5329<h5>Overview:</h5>
5330
5331
5332<p>
5333The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a Program Counter
Chris Lattner96451482008-08-05 18:29:16 +00005334(PC) in a region of
5335code to simulators and other tools. The method is target specific, but it is
5336expected that the marker will use exported symbols to transmit the PC of the
5337marker.
5338The marker makes no guarantees that it will remain with any specific instruction
5339after optimizations. It is possible that the presence of a marker will inhibit
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005340optimizations. The intended use is to be inserted after optimizations to allow
5341correlations of simulation runs.
5342</p>
5343
5344<h5>Arguments:</h5>
5345
5346<p>
5347<tt>id</tt> is a numerical id identifying the marker.
5348</p>
5349
5350<h5>Semantics:</h5>
5351
5352<p>
5353This intrinsic does not modify the behavior of the program. Backends that do not
5354support this intrinisic may ignore it.
5355</p>
5356
5357</div>
5358
5359<!-- _______________________________________________________________________ -->
5360<div class="doc_subsubsection">
5361 <a name="int_readcyclecounter">'<tt>llvm.readcyclecounter</tt>' Intrinsic</a>
5362</div>
5363
5364<div class="doc_text">
5365
5366<h5>Syntax:</h5>
5367<pre>
5368 declare i64 @llvm.readcyclecounter( )
5369</pre>
5370
5371<h5>Overview:</h5>
5372
5373
5374<p>
5375The '<tt>llvm.readcyclecounter</tt>' intrinsic provides access to the cycle
5376counter register (or similar low latency, high accuracy clocks) on those targets
5377that support it. On X86, it should map to RDTSC. On Alpha, it should map to RPCC.
5378As the backing counters overflow quickly (on the order of 9 seconds on alpha), this
5379should only be used for small timings.
5380</p>
5381
5382<h5>Semantics:</h5>
5383
5384<p>
5385When directly supported, reading the cycle counter should not modify any memory.
5386Implementations are allowed to either return a application specific value or a
5387system wide value. On backends without support, this is lowered to a constant 0.
5388</p>
5389
5390</div>
5391
5392<!-- ======================================================================= -->
5393<div class="doc_subsection">
5394 <a name="int_libc">Standard C Library Intrinsics</a>
5395</div>
5396
5397<div class="doc_text">
5398<p>
5399LLVM provides intrinsics for a few important standard C library functions.
5400These intrinsics allow source-language front-ends to pass information about the
5401alignment of the pointer arguments to the code generator, providing opportunity
5402for more efficient code generation.
5403</p>
5404
5405</div>
5406
5407<!-- _______________________________________________________________________ -->
5408<div class="doc_subsubsection">
5409 <a name="int_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
5410</div>
5411
5412<div class="doc_text">
5413
5414<h5>Syntax:</h5>
Chris Lattner82c2e432008-11-21 16:42:48 +00005415<p>This is an overloaded intrinsic. You can use llvm.memcpy on any integer bit
5416width. Not all targets support all bit widths however.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005417<pre>
Chris Lattner82c2e432008-11-21 16:42:48 +00005418 declare void @llvm.memcpy.i8(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5419 i8 &lt;len&gt;, i32 &lt;align&gt;)
5420 declare void @llvm.memcpy.i16(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5421 i16 &lt;len&gt;, i32 &lt;align&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005422 declare void @llvm.memcpy.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5423 i32 &lt;len&gt;, i32 &lt;align&gt;)
5424 declare void @llvm.memcpy.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5425 i64 &lt;len&gt;, i32 &lt;align&gt;)
5426</pre>
5427
5428<h5>Overview:</h5>
5429
5430<p>
5431The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source
5432location to the destination location.
5433</p>
5434
5435<p>
5436Note that, unlike the standard libc function, the <tt>llvm.memcpy.*</tt>
5437intrinsics do not return a value, and takes an extra alignment argument.
5438</p>
5439
5440<h5>Arguments:</h5>
5441
5442<p>
5443The first argument is a pointer to the destination, the second is a pointer to
5444the source. The third argument is an integer argument
5445specifying the number of bytes to copy, and the fourth argument is the alignment
5446of the source and destination locations.
5447</p>
5448
5449<p>
5450If the call to this intrinisic has an alignment value that is not 0 or 1, then
5451the caller guarantees that both the source and destination pointers are aligned
5452to that boundary.
5453</p>
5454
5455<h5>Semantics:</h5>
5456
5457<p>
5458The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source
5459location to the destination location, which are not allowed to overlap. It
5460copies "len" bytes of memory over. If the argument is known to be aligned to
5461some boundary, this can be specified as the fourth argument, otherwise it should
5462be set to 0 or 1.
5463</p>
5464</div>
5465
5466
5467<!-- _______________________________________________________________________ -->
5468<div class="doc_subsubsection">
5469 <a name="int_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
5470</div>
5471
5472<div class="doc_text">
5473
5474<h5>Syntax:</h5>
Chris Lattner82c2e432008-11-21 16:42:48 +00005475<p>This is an overloaded intrinsic. You can use llvm.memmove on any integer bit
5476width. Not all targets support all bit widths however.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005477<pre>
Chris Lattner82c2e432008-11-21 16:42:48 +00005478 declare void @llvm.memmove.i8(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5479 i8 &lt;len&gt;, i32 &lt;align&gt;)
5480 declare void @llvm.memmove.i16(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5481 i16 &lt;len&gt;, i32 &lt;align&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005482 declare void @llvm.memmove.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5483 i32 &lt;len&gt;, i32 &lt;align&gt;)
5484 declare void @llvm.memmove.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5485 i64 &lt;len&gt;, i32 &lt;align&gt;)
5486</pre>
5487
5488<h5>Overview:</h5>
5489
5490<p>
5491The '<tt>llvm.memmove.*</tt>' intrinsics move a block of memory from the source
5492location to the destination location. It is similar to the
Chris Lattnerdba16ea2008-01-06 19:51:52 +00005493'<tt>llvm.memcpy</tt>' intrinsic but allows the two memory locations to overlap.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005494</p>
5495
5496<p>
5497Note that, unlike the standard libc function, the <tt>llvm.memmove.*</tt>
5498intrinsics do not return a value, and takes an extra alignment argument.
5499</p>
5500
5501<h5>Arguments:</h5>
5502
5503<p>
5504The first argument is a pointer to the destination, the second is a pointer to
5505the source. The third argument is an integer argument
5506specifying the number of bytes to copy, and the fourth argument is the alignment
5507of the source and destination locations.
5508</p>
5509
5510<p>
5511If the call to this intrinisic has an alignment value that is not 0 or 1, then
5512the caller guarantees that the source and destination pointers are aligned to
5513that boundary.
5514</p>
5515
5516<h5>Semantics:</h5>
5517
5518<p>
5519The '<tt>llvm.memmove.*</tt>' intrinsics copy a block of memory from the source
5520location to the destination location, which may overlap. It
5521copies "len" bytes of memory over. If the argument is known to be aligned to
5522some boundary, this can be specified as the fourth argument, otherwise it should
5523be set to 0 or 1.
5524</p>
5525</div>
5526
5527
5528<!-- _______________________________________________________________________ -->
5529<div class="doc_subsubsection">
5530 <a name="int_memset">'<tt>llvm.memset.*</tt>' Intrinsics</a>
5531</div>
5532
5533<div class="doc_text">
5534
5535<h5>Syntax:</h5>
Chris Lattner82c2e432008-11-21 16:42:48 +00005536<p>This is an overloaded intrinsic. You can use llvm.memset on any integer bit
5537width. Not all targets support all bit widths however.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005538<pre>
Chris Lattner82c2e432008-11-21 16:42:48 +00005539 declare void @llvm.memset.i8(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
5540 i8 &lt;len&gt;, i32 &lt;align&gt;)
5541 declare void @llvm.memset.i16(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
5542 i16 &lt;len&gt;, i32 &lt;align&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005543 declare void @llvm.memset.i32(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
5544 i32 &lt;len&gt;, i32 &lt;align&gt;)
5545 declare void @llvm.memset.i64(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
5546 i64 &lt;len&gt;, i32 &lt;align&gt;)
5547</pre>
5548
5549<h5>Overview:</h5>
5550
5551<p>
5552The '<tt>llvm.memset.*</tt>' intrinsics fill a block of memory with a particular
5553byte value.
5554</p>
5555
5556<p>
5557Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
5558does not return a value, and takes an extra alignment argument.
5559</p>
5560
5561<h5>Arguments:</h5>
5562
5563<p>
5564The first argument is a pointer to the destination to fill, the second is the
5565byte value to fill it with, the third argument is an integer
5566argument specifying the number of bytes to fill, and the fourth argument is the
5567known alignment of destination location.
5568</p>
5569
5570<p>
5571If the call to this intrinisic has an alignment value that is not 0 or 1, then
5572the caller guarantees that the destination pointer is aligned to that boundary.
5573</p>
5574
5575<h5>Semantics:</h5>
5576
5577<p>
5578The '<tt>llvm.memset.*</tt>' intrinsics fill "len" bytes of memory starting at
5579the
5580destination location. If the argument is known to be aligned to some boundary,
5581this can be specified as the fourth argument, otherwise it should be set to 0 or
55821.
5583</p>
5584</div>
5585
5586
5587<!-- _______________________________________________________________________ -->
5588<div class="doc_subsubsection">
5589 <a name="int_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a>
5590</div>
5591
5592<div class="doc_text">
5593
5594<h5>Syntax:</h5>
Dale Johannesenf9adbb62007-10-02 17:47:38 +00005595<p>This is an overloaded intrinsic. You can use <tt>llvm.sqrt</tt> on any
Dan Gohman361079c2007-10-15 20:30:11 +00005596floating point or vector of floating point type. Not all targets support all
Dan Gohman2672f3e2008-10-14 16:51:45 +00005597types however.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005598<pre>
Dale Johannesenf9adbb62007-10-02 17:47:38 +00005599 declare float @llvm.sqrt.f32(float %Val)
5600 declare double @llvm.sqrt.f64(double %Val)
5601 declare x86_fp80 @llvm.sqrt.f80(x86_fp80 %Val)
5602 declare fp128 @llvm.sqrt.f128(fp128 %Val)
5603 declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005604</pre>
5605
5606<h5>Overview:</h5>
5607
5608<p>
5609The '<tt>llvm.sqrt</tt>' intrinsics return the sqrt of the specified operand,
Dan Gohman361079c2007-10-15 20:30:11 +00005610returning the same value as the libm '<tt>sqrt</tt>' functions would. Unlike
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005611<tt>sqrt</tt> in libm, however, <tt>llvm.sqrt</tt> has undefined behavior for
Chris Lattnerf914a002008-01-29 07:00:44 +00005612negative numbers other than -0.0 (which allows for better optimization, because
5613there is no need to worry about errno being set). <tt>llvm.sqrt(-0.0)</tt> is
5614defined to return -0.0 like IEEE sqrt.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005615</p>
5616
5617<h5>Arguments:</h5>
5618
5619<p>
5620The argument and return value are floating point numbers of the same type.
5621</p>
5622
5623<h5>Semantics:</h5>
5624
5625<p>
5626This function returns the sqrt of the specified operand if it is a nonnegative
5627floating point number.
5628</p>
5629</div>
5630
5631<!-- _______________________________________________________________________ -->
5632<div class="doc_subsubsection">
5633 <a name="int_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a>
5634</div>
5635
5636<div class="doc_text">
5637
5638<h5>Syntax:</h5>
Dale Johannesenf9adbb62007-10-02 17:47:38 +00005639<p>This is an overloaded intrinsic. You can use <tt>llvm.powi</tt> on any
Dan Gohman361079c2007-10-15 20:30:11 +00005640floating point or vector of floating point type. Not all targets support all
Dan Gohman2672f3e2008-10-14 16:51:45 +00005641types however.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005642<pre>
Dale Johannesenf9adbb62007-10-02 17:47:38 +00005643 declare float @llvm.powi.f32(float %Val, i32 %power)
5644 declare double @llvm.powi.f64(double %Val, i32 %power)
5645 declare x86_fp80 @llvm.powi.f80(x86_fp80 %Val, i32 %power)
5646 declare fp128 @llvm.powi.f128(fp128 %Val, i32 %power)
5647 declare ppc_fp128 @llvm.powi.ppcf128(ppc_fp128 %Val, i32 %power)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005648</pre>
5649
5650<h5>Overview:</h5>
5651
5652<p>
5653The '<tt>llvm.powi.*</tt>' intrinsics return the first operand raised to the
5654specified (positive or negative) power. The order of evaluation of
Dan Gohman361079c2007-10-15 20:30:11 +00005655multiplications is not defined. When a vector of floating point type is
5656used, the second argument remains a scalar integer value.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005657</p>
5658
5659<h5>Arguments:</h5>
5660
5661<p>
5662The second argument is an integer power, and the first is a value to raise to
5663that power.
5664</p>
5665
5666<h5>Semantics:</h5>
5667
5668<p>
5669This function returns the first value raised to the second power with an
5670unspecified sequence of rounding operations.</p>
5671</div>
5672
Dan Gohman361079c2007-10-15 20:30:11 +00005673<!-- _______________________________________________________________________ -->
5674<div class="doc_subsubsection">
5675 <a name="int_sin">'<tt>llvm.sin.*</tt>' Intrinsic</a>
5676</div>
5677
5678<div class="doc_text">
5679
5680<h5>Syntax:</h5>
5681<p>This is an overloaded intrinsic. You can use <tt>llvm.sin</tt> on any
5682floating point or vector of floating point type. Not all targets support all
Dan Gohman2672f3e2008-10-14 16:51:45 +00005683types however.</p>
Dan Gohman361079c2007-10-15 20:30:11 +00005684<pre>
5685 declare float @llvm.sin.f32(float %Val)
5686 declare double @llvm.sin.f64(double %Val)
5687 declare x86_fp80 @llvm.sin.f80(x86_fp80 %Val)
5688 declare fp128 @llvm.sin.f128(fp128 %Val)
5689 declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128 %Val)
5690</pre>
5691
5692<h5>Overview:</h5>
5693
5694<p>
5695The '<tt>llvm.sin.*</tt>' intrinsics return the sine of the operand.
5696</p>
5697
5698<h5>Arguments:</h5>
5699
5700<p>
5701The argument and return value are floating point numbers of the same type.
5702</p>
5703
5704<h5>Semantics:</h5>
5705
5706<p>
5707This function returns the sine of the specified operand, returning the
5708same values as the libm <tt>sin</tt> functions would, and handles error
Dan Gohmaneaba92e2007-10-17 18:05:13 +00005709conditions in the same way.</p>
Dan Gohman361079c2007-10-15 20:30:11 +00005710</div>
5711
5712<!-- _______________________________________________________________________ -->
5713<div class="doc_subsubsection">
5714 <a name="int_cos">'<tt>llvm.cos.*</tt>' Intrinsic</a>
5715</div>
5716
5717<div class="doc_text">
5718
5719<h5>Syntax:</h5>
5720<p>This is an overloaded intrinsic. You can use <tt>llvm.cos</tt> on any
5721floating point or vector of floating point type. Not all targets support all
Dan Gohman2672f3e2008-10-14 16:51:45 +00005722types however.</p>
Dan Gohman361079c2007-10-15 20:30:11 +00005723<pre>
5724 declare float @llvm.cos.f32(float %Val)
5725 declare double @llvm.cos.f64(double %Val)
5726 declare x86_fp80 @llvm.cos.f80(x86_fp80 %Val)
5727 declare fp128 @llvm.cos.f128(fp128 %Val)
5728 declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128 %Val)
5729</pre>
5730
5731<h5>Overview:</h5>
5732
5733<p>
5734The '<tt>llvm.cos.*</tt>' intrinsics return the cosine of the operand.
5735</p>
5736
5737<h5>Arguments:</h5>
5738
5739<p>
5740The argument and return value are floating point numbers of the same type.
5741</p>
5742
5743<h5>Semantics:</h5>
5744
5745<p>
5746This function returns the cosine of the specified operand, returning the
5747same values as the libm <tt>cos</tt> functions would, and handles error
Dan Gohmaneaba92e2007-10-17 18:05:13 +00005748conditions in the same way.</p>
Dan Gohman361079c2007-10-15 20:30:11 +00005749</div>
5750
5751<!-- _______________________________________________________________________ -->
5752<div class="doc_subsubsection">
5753 <a name="int_pow">'<tt>llvm.pow.*</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 <tt>llvm.pow</tt> on any
5760floating point or vector of floating point type. Not all targets support all
Dan Gohman2672f3e2008-10-14 16:51:45 +00005761types however.</p>
Dan Gohman361079c2007-10-15 20:30:11 +00005762<pre>
5763 declare float @llvm.pow.f32(float %Val, float %Power)
5764 declare double @llvm.pow.f64(double %Val, double %Power)
5765 declare x86_fp80 @llvm.pow.f80(x86_fp80 %Val, x86_fp80 %Power)
5766 declare fp128 @llvm.pow.f128(fp128 %Val, fp128 %Power)
5767 declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128 %Val, ppc_fp128 Power)
5768</pre>
5769
5770<h5>Overview:</h5>
5771
5772<p>
5773The '<tt>llvm.pow.*</tt>' intrinsics return the first operand raised to the
5774specified (positive or negative) power.
5775</p>
5776
5777<h5>Arguments:</h5>
5778
5779<p>
5780The second argument is a floating point power, and the first is a value to
5781raise to that power.
5782</p>
5783
5784<h5>Semantics:</h5>
5785
5786<p>
5787This function returns the first value raised to the second power,
5788returning the
5789same values as the libm <tt>pow</tt> functions would, and handles error
Dan Gohmaneaba92e2007-10-17 18:05:13 +00005790conditions in the same way.</p>
Dan Gohman361079c2007-10-15 20:30:11 +00005791</div>
5792
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005793
5794<!-- ======================================================================= -->
5795<div class="doc_subsection">
5796 <a name="int_manip">Bit Manipulation Intrinsics</a>
5797</div>
5798
5799<div class="doc_text">
5800<p>
5801LLVM provides intrinsics for a few important bit manipulation operations.
5802These allow efficient code generation for some algorithms.
5803</p>
5804
5805</div>
5806
5807<!-- _______________________________________________________________________ -->
5808<div class="doc_subsubsection">
5809 <a name="int_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a>
5810</div>
5811
5812<div class="doc_text">
5813
5814<h5>Syntax:</h5>
5815<p>This is an overloaded intrinsic function. You can use bswap on any integer
Dan Gohman2672f3e2008-10-14 16:51:45 +00005816type that is an even number of bytes (i.e. BitWidth % 16 == 0).</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005817<pre>
Chandler Carrutha228e392007-08-04 01:51:18 +00005818 declare i16 @llvm.bswap.i16(i16 &lt;id&gt;)
5819 declare i32 @llvm.bswap.i32(i32 &lt;id&gt;)
5820 declare i64 @llvm.bswap.i64(i64 &lt;id&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005821</pre>
5822
5823<h5>Overview:</h5>
5824
5825<p>
5826The '<tt>llvm.bswap</tt>' family of intrinsics is used to byte swap integer
5827values with an even number of bytes (positive multiple of 16 bits). These are
5828useful for performing operations on data that is not in the target's native
5829byte order.
5830</p>
5831
5832<h5>Semantics:</h5>
5833
5834<p>
Chandler Carrutha228e392007-08-04 01:51:18 +00005835The <tt>llvm.bswap.i16</tt> intrinsic returns an i16 value that has the high
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005836and low byte of the input i16 swapped. Similarly, the <tt>llvm.bswap.i32</tt>
5837intrinsic returns an i32 value that has the four bytes of the input i32
5838swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the returned
Chandler Carrutha228e392007-08-04 01:51:18 +00005839i32 will have its bytes in 3, 2, 1, 0 order. The <tt>llvm.bswap.i48</tt>,
5840<tt>llvm.bswap.i64</tt> and other intrinsics extend this concept to
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005841additional even-byte lengths (6 bytes, 8 bytes and more, respectively).
5842</p>
5843
5844</div>
5845
5846<!-- _______________________________________________________________________ -->
5847<div class="doc_subsubsection">
5848 <a name="int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic</a>
5849</div>
5850
5851<div class="doc_text">
5852
5853<h5>Syntax:</h5>
5854<p>This is an overloaded intrinsic. You can use llvm.ctpop on any integer bit
Dan Gohman2672f3e2008-10-14 16:51:45 +00005855width. Not all targets support all bit widths however.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005856<pre>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005857 declare i8 @llvm.ctpop.i8(i8 &lt;src&gt;)
Chandler Carrutha228e392007-08-04 01:51:18 +00005858 declare i16 @llvm.ctpop.i16(i16 &lt;src&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005859 declare i32 @llvm.ctpop.i32(i32 &lt;src&gt;)
Chandler Carrutha228e392007-08-04 01:51:18 +00005860 declare i64 @llvm.ctpop.i64(i64 &lt;src&gt;)
5861 declare i256 @llvm.ctpop.i256(i256 &lt;src&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005862</pre>
5863
5864<h5>Overview:</h5>
5865
5866<p>
5867The '<tt>llvm.ctpop</tt>' family of intrinsics counts the number of bits set in a
5868value.
5869</p>
5870
5871<h5>Arguments:</h5>
5872
5873<p>
5874The only argument is the value to be counted. The argument may be of any
5875integer type. The return type must match the argument type.
5876</p>
5877
5878<h5>Semantics:</h5>
5879
5880<p>
5881The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable.
5882</p>
5883</div>
5884
5885<!-- _______________________________________________________________________ -->
5886<div class="doc_subsubsection">
5887 <a name="int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic</a>
5888</div>
5889
5890<div class="doc_text">
5891
5892<h5>Syntax:</h5>
5893<p>This is an overloaded intrinsic. You can use <tt>llvm.ctlz</tt> on any
Dan Gohman2672f3e2008-10-14 16:51:45 +00005894integer bit width. Not all targets support all bit widths however.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005895<pre>
Chandler Carrutha228e392007-08-04 01:51:18 +00005896 declare i8 @llvm.ctlz.i8 (i8 &lt;src&gt;)
5897 declare i16 @llvm.ctlz.i16(i16 &lt;src&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005898 declare i32 @llvm.ctlz.i32(i32 &lt;src&gt;)
Chandler Carrutha228e392007-08-04 01:51:18 +00005899 declare i64 @llvm.ctlz.i64(i64 &lt;src&gt;)
5900 declare i256 @llvm.ctlz.i256(i256 &lt;src&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005901</pre>
5902
5903<h5>Overview:</h5>
5904
5905<p>
5906The '<tt>llvm.ctlz</tt>' family of intrinsic functions counts the number of
5907leading zeros in a variable.
5908</p>
5909
5910<h5>Arguments:</h5>
5911
5912<p>
5913The only argument is the value to be counted. The argument may be of any
5914integer type. The return type must match the argument type.
5915</p>
5916
5917<h5>Semantics:</h5>
5918
5919<p>
5920The '<tt>llvm.ctlz</tt>' intrinsic counts the leading (most significant) zeros
5921in a variable. If the src == 0 then the result is the size in bits of the type
5922of src. For example, <tt>llvm.ctlz(i32 2) = 30</tt>.
5923</p>
5924</div>
5925
5926
5927
5928<!-- _______________________________________________________________________ -->
5929<div class="doc_subsubsection">
5930 <a name="int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic</a>
5931</div>
5932
5933<div class="doc_text">
5934
5935<h5>Syntax:</h5>
5936<p>This is an overloaded intrinsic. You can use <tt>llvm.cttz</tt> on any
Dan Gohman2672f3e2008-10-14 16:51:45 +00005937integer bit width. Not all targets support all bit widths however.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005938<pre>
Chandler Carrutha228e392007-08-04 01:51:18 +00005939 declare i8 @llvm.cttz.i8 (i8 &lt;src&gt;)
5940 declare i16 @llvm.cttz.i16(i16 &lt;src&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005941 declare i32 @llvm.cttz.i32(i32 &lt;src&gt;)
Chandler Carrutha228e392007-08-04 01:51:18 +00005942 declare i64 @llvm.cttz.i64(i64 &lt;src&gt;)
5943 declare i256 @llvm.cttz.i256(i256 &lt;src&gt;)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005944</pre>
5945
5946<h5>Overview:</h5>
5947
5948<p>
5949The '<tt>llvm.cttz</tt>' family of intrinsic functions counts the number of
5950trailing zeros.
5951</p>
5952
5953<h5>Arguments:</h5>
5954
5955<p>
5956The only argument is the value to be counted. The argument may be of any
5957integer type. The return type must match the argument type.
5958</p>
5959
5960<h5>Semantics:</h5>
5961
5962<p>
5963The '<tt>llvm.cttz</tt>' intrinsic counts the trailing (least significant) zeros
5964in a variable. If the src == 0 then the result is the size in bits of the type
5965of src. For example, <tt>llvm.cttz(2) = 1</tt>.
5966</p>
5967</div>
5968
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005969
Bill Wendling3e1258b2009-02-08 04:04:40 +00005970<!-- ======================================================================= -->
5971<div class="doc_subsection">
5972 <a name="int_overflow">Arithmetic with Overflow Intrinsics</a>
5973</div>
5974
5975<div class="doc_text">
5976<p>
5977LLVM provides intrinsics for some arithmetic with overflow operations.
5978</p>
5979
5980</div>
5981
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005982<!-- _______________________________________________________________________ -->
5983<div class="doc_subsubsection">
Bill Wendling3e1258b2009-02-08 04:04:40 +00005984 <a name="int_sadd_overflow">'<tt>llvm.sadd.with.overflow.*</tt>' Intrinsics</a>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005985</div>
5986
5987<div class="doc_text">
5988
5989<h5>Syntax:</h5>
5990
5991<p>This is an overloaded intrinsic. You can use <tt>llvm.sadd.with.overflow</tt>
Bill Wendling3e1258b2009-02-08 04:04:40 +00005992on any integer bit width.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00005993
5994<pre>
5995 declare {i16, i1} @llvm.sadd.with.overflow.i16(i16 %a, i16 %b)
5996 declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
5997 declare {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 %b)
5998</pre>
5999
6000<h5>Overview:</h5>
6001
6002<p>The '<tt>llvm.sadd.with.overflow</tt>' family of intrinsic functions perform
6003a signed addition of the two arguments, and indicate whether an overflow
6004occurred during the signed summation.</p>
6005
6006<h5>Arguments:</h5>
6007
6008<p>The arguments (%a and %b) and the first element of the result structure may
6009be of integer types of any bit width, but they must have the same bit width. The
6010second element of the result structure must be of type <tt>i1</tt>. <tt>%a</tt>
6011and <tt>%b</tt> are the two values that will undergo signed addition.</p>
6012
6013<h5>Semantics:</h5>
6014
6015<p>The '<tt>llvm.sadd.with.overflow</tt>' family of intrinsic functions perform
6016a signed addition of the two variables. They return a structure &mdash; the
6017first element of which is the signed summation, and the second element of which
6018is a bit specifying if the signed summation resulted in an overflow.</p>
6019
6020<h5>Examples:</h5>
6021<pre>
6022 %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
6023 %sum = extractvalue {i32, i1} %res, 0
6024 %obit = extractvalue {i32, i1} %res, 1
6025 br i1 %obit, label %overflow, label %normal
6026</pre>
6027
6028</div>
6029
6030<!-- _______________________________________________________________________ -->
6031<div class="doc_subsubsection">
Bill Wendling3e1258b2009-02-08 04:04:40 +00006032 <a name="int_uadd_overflow">'<tt>llvm.uadd.with.overflow.*</tt>' Intrinsics</a>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006033</div>
6034
6035<div class="doc_text">
6036
6037<h5>Syntax:</h5>
6038
6039<p>This is an overloaded intrinsic. You can use <tt>llvm.uadd.with.overflow</tt>
Bill Wendling3e1258b2009-02-08 04:04:40 +00006040on any integer bit width.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006041
6042<pre>
6043 declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b)
6044 declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
6045 declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b)
6046</pre>
6047
6048<h5>Overview:</h5>
6049
6050<p>The '<tt>llvm.uadd.with.overflow</tt>' family of intrinsic functions perform
6051an unsigned addition of the two arguments, and indicate whether a carry occurred
6052during the unsigned summation.</p>
6053
6054<h5>Arguments:</h5>
6055
6056<p>The arguments (%a and %b) and the first element of the result structure may
6057be of integer types of any bit width, but they must have the same bit width. The
6058second element of the result structure must be of type <tt>i1</tt>. <tt>%a</tt>
6059and <tt>%b</tt> are the two values that will undergo unsigned addition.</p>
6060
6061<h5>Semantics:</h5>
6062
6063<p>The '<tt>llvm.uadd.with.overflow</tt>' family of intrinsic functions perform
6064an unsigned addition of the two arguments. They return a structure &mdash; the
6065first element of which is the sum, and the second element of which is a bit
6066specifying if the unsigned summation resulted in a carry.</p>
6067
6068<h5>Examples:</h5>
6069<pre>
6070 %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
6071 %sum = extractvalue {i32, i1} %res, 0
6072 %obit = extractvalue {i32, i1} %res, 1
6073 br i1 %obit, label %carry, label %normal
6074</pre>
6075
6076</div>
6077
6078<!-- _______________________________________________________________________ -->
6079<div class="doc_subsubsection">
Bill Wendling3e1258b2009-02-08 04:04:40 +00006080 <a name="int_ssub_overflow">'<tt>llvm.ssub.with.overflow.*</tt>' Intrinsics</a>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006081</div>
6082
6083<div class="doc_text">
6084
6085<h5>Syntax:</h5>
6086
6087<p>This is an overloaded intrinsic. You can use <tt>llvm.ssub.with.overflow</tt>
Bill Wendling3e1258b2009-02-08 04:04:40 +00006088on any integer bit width.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006089
6090<pre>
6091 declare {i16, i1} @llvm.ssub.with.overflow.i16(i16 %a, i16 %b)
6092 declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
6093 declare {i64, i1} @llvm.ssub.with.overflow.i64(i64 %a, i64 %b)
6094</pre>
6095
6096<h5>Overview:</h5>
6097
6098<p>The '<tt>llvm.ssub.with.overflow</tt>' family of intrinsic functions perform
6099a signed subtraction of the two arguments, and indicate whether an overflow
6100occurred during the signed subtraction.</p>
6101
6102<h5>Arguments:</h5>
6103
6104<p>The arguments (%a and %b) and the first element of the result structure may
6105be of integer types of any bit width, but they must have the same bit width. The
6106second element of the result structure must be of type <tt>i1</tt>. <tt>%a</tt>
6107and <tt>%b</tt> are the two values that will undergo signed subtraction.</p>
6108
6109<h5>Semantics:</h5>
6110
6111<p>The '<tt>llvm.ssub.with.overflow</tt>' family of intrinsic functions perform
6112a signed subtraction of the two arguments. They return a structure &mdash; the
6113first element of which is the subtraction, and the second element of which is a bit
6114specifying if the signed subtraction resulted in an overflow.</p>
6115
6116<h5>Examples:</h5>
6117<pre>
6118 %res = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
6119 %sum = extractvalue {i32, i1} %res, 0
6120 %obit = extractvalue {i32, i1} %res, 1
6121 br i1 %obit, label %overflow, label %normal
6122</pre>
6123
6124</div>
6125
6126<!-- _______________________________________________________________________ -->
6127<div class="doc_subsubsection">
Bill Wendling3e1258b2009-02-08 04:04:40 +00006128 <a name="int_usub_overflow">'<tt>llvm.usub.with.overflow.*</tt>' Intrinsics</a>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006129</div>
6130
6131<div class="doc_text">
6132
6133<h5>Syntax:</h5>
6134
6135<p>This is an overloaded intrinsic. You can use <tt>llvm.usub.with.overflow</tt>
Bill Wendling3e1258b2009-02-08 04:04:40 +00006136on any integer bit width.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006137
6138<pre>
6139 declare {i16, i1} @llvm.usub.with.overflow.i16(i16 %a, i16 %b)
6140 declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
6141 declare {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b)
6142</pre>
6143
6144<h5>Overview:</h5>
6145
6146<p>The '<tt>llvm.usub.with.overflow</tt>' family of intrinsic functions perform
6147an unsigned subtraction of the two arguments, and indicate whether an overflow
6148occurred during the unsigned subtraction.</p>
6149
6150<h5>Arguments:</h5>
6151
6152<p>The arguments (%a and %b) and the first element of the result structure may
6153be of integer types of any bit width, but they must have the same bit width. The
6154second element of the result structure must be of type <tt>i1</tt>. <tt>%a</tt>
6155and <tt>%b</tt> are the two values that will undergo unsigned subtraction.</p>
6156
6157<h5>Semantics:</h5>
6158
6159<p>The '<tt>llvm.usub.with.overflow</tt>' family of intrinsic functions perform
6160an unsigned subtraction of the two arguments. They return a structure &mdash; the
6161first element of which is the subtraction, and the second element of which is a bit
6162specifying if the unsigned subtraction resulted in an overflow.</p>
6163
6164<h5>Examples:</h5>
6165<pre>
6166 %res = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
6167 %sum = extractvalue {i32, i1} %res, 0
6168 %obit = extractvalue {i32, i1} %res, 1
6169 br i1 %obit, label %overflow, label %normal
6170</pre>
6171
6172</div>
6173
6174<!-- _______________________________________________________________________ -->
6175<div class="doc_subsubsection">
Bill Wendling3e1258b2009-02-08 04:04:40 +00006176 <a name="int_smul_overflow">'<tt>llvm.smul.with.overflow.*</tt>' Intrinsics</a>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006177</div>
6178
6179<div class="doc_text">
6180
6181<h5>Syntax:</h5>
6182
6183<p>This is an overloaded intrinsic. You can use <tt>llvm.smul.with.overflow</tt>
Bill Wendling3e1258b2009-02-08 04:04:40 +00006184on any integer bit width.</p>
Bill Wendling3f8cebe2009-02-08 01:40:31 +00006185
6186<pre>
6187 declare {i16, i1} @llvm.smul.with.overflow.i16(i16 %a, i16 %b)
6188 declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
6189 declare {i64, i1} @llvm.smul.with.overflow.i64(i64 %a, i64 %b)
6190</pre>
6191
6192<h5>Overview:</h5>
6193
6194<p>The '<tt>llvm.smul.with.overflow</tt>' family of intrinsic functions perform
6195a signed multiplication of the two arguments, and indicate whether an overflow
6196occurred during the signed multiplication.</p>
6197
6198<h5>Arguments:</h5>
6199
6200<p>The arguments (%a and %b) and the first element of the result structure may
6201be of integer types of any bit width, but they must have the same bit width. The
6202second element of the result structure must be of type <tt>i1</tt>. <tt>%a</tt>
6203and <tt>%b</tt> are the two values that will undergo signed multiplication.</p>
6204
6205<h5>Semantics:</h5>
6206
6207<p>The '<tt>llvm.smul.with.overflow</tt>' family of intrinsic functions perform
6208a signed multiplication of the two arguments. They return a structure &mdash;
6209the first element of which is the multiplication, and the second element of
6210which is a bit specifying if the signed multiplication resulted in an
6211overflow.</p>
6212
6213<h5>Examples:</h5>
6214<pre>
6215 %res = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
6216 %sum = extractvalue {i32, i1} %res, 0
6217 %obit = extractvalue {i32, i1} %res, 1
6218 br i1 %obit, label %overflow, label %normal
6219</pre>
6220
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006221</div>
6222
Bill Wendlingbda98b62009-02-08 23:00:09 +00006223<!-- _______________________________________________________________________ -->
6224<div class="doc_subsubsection">
6225 <a name="int_umul_overflow">'<tt>llvm.umul.with.overflow.*</tt>' Intrinsics</a>
6226</div>
6227
6228<div class="doc_text">
6229
6230<h5>Syntax:</h5>
6231
6232<p>This is an overloaded intrinsic. You can use <tt>llvm.umul.with.overflow</tt>
6233on any integer bit width.</p>
6234
6235<pre>
6236 declare {i16, i1} @llvm.umul.with.overflow.i16(i16 %a, i16 %b)
6237 declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
6238 declare {i64, i1} @llvm.umul.with.overflow.i64(i64 %a, i64 %b)
6239</pre>
6240
6241<h5>Overview:</h5>
6242
Bill Wendlingbda98b62009-02-08 23:00:09 +00006243<p>The '<tt>llvm.umul.with.overflow</tt>' family of intrinsic functions perform
6244a unsigned multiplication of the two arguments, and indicate whether an overflow
6245occurred during the unsigned multiplication.</p>
6246
6247<h5>Arguments:</h5>
6248
6249<p>The arguments (%a and %b) and the first element of the result structure may
6250be of integer types of any bit width, but they must have the same bit width. The
6251second element of the result structure must be of type <tt>i1</tt>. <tt>%a</tt>
6252and <tt>%b</tt> are the two values that will undergo unsigned
6253multiplication.</p>
6254
6255<h5>Semantics:</h5>
6256
6257<p>The '<tt>llvm.umul.with.overflow</tt>' family of intrinsic functions perform
6258an unsigned multiplication of the two arguments. They return a structure &mdash;
6259the first element of which is the multiplication, and the second element of
6260which is a bit specifying if the unsigned multiplication resulted in an
6261overflow.</p>
6262
6263<h5>Examples:</h5>
6264<pre>
6265 %res = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
6266 %sum = extractvalue {i32, i1} %res, 0
6267 %obit = extractvalue {i32, i1} %res, 1
6268 br i1 %obit, label %overflow, label %normal
6269</pre>
6270
6271</div>
6272
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006273<!-- ======================================================================= -->
6274<div class="doc_subsection">
6275 <a name="int_debugger">Debugger Intrinsics</a>
6276</div>
6277
6278<div class="doc_text">
6279<p>
6280The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
6281are described in the <a
6282href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
6283Debugging</a> document.
6284</p>
6285</div>
6286
6287
6288<!-- ======================================================================= -->
6289<div class="doc_subsection">
6290 <a name="int_eh">Exception Handling Intrinsics</a>
6291</div>
6292
6293<div class="doc_text">
6294<p> The LLVM exception handling intrinsics (which all start with
6295<tt>llvm.eh.</tt> prefix), are described in the <a
6296href="ExceptionHandling.html#format_common_intrinsics">LLVM Exception
6297Handling</a> document. </p>
6298</div>
6299
6300<!-- ======================================================================= -->
6301<div class="doc_subsection">
Duncan Sands7407a9f2007-09-11 14:10:23 +00006302 <a name="int_trampoline">Trampoline Intrinsic</a>
Duncan Sands38947cd2007-07-27 12:58:54 +00006303</div>
6304
6305<div class="doc_text">
6306<p>
Duncan Sands7407a9f2007-09-11 14:10:23 +00006307 This intrinsic makes it possible to excise one parameter, marked with
Duncan Sands38947cd2007-07-27 12:58:54 +00006308 the <tt>nest</tt> attribute, from a function. The result is a callable
6309 function pointer lacking the nest parameter - the caller does not need
6310 to provide a value for it. Instead, the value to use is stored in
6311 advance in a "trampoline", a block of memory usually allocated
6312 on the stack, which also contains code to splice the nest value into the
6313 argument list. This is used to implement the GCC nested function address
6314 extension.
6315</p>
6316<p>
6317 For example, if the function is
6318 <tt>i32 f(i8* nest %c, i32 %x, i32 %y)</tt> then the resulting function
Bill Wendlinge262b4c2007-09-22 09:23:55 +00006319 pointer has signature <tt>i32 (i32, i32)*</tt>. It can be created as follows:</p>
Duncan Sands38947cd2007-07-27 12:58:54 +00006320<pre>
Duncan Sands7407a9f2007-09-11 14:10:23 +00006321 %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86
6322 %tramp1 = getelementptr [10 x i8]* %tramp, i32 0, i32 0
6323 %p = call i8* @llvm.init.trampoline( i8* %tramp1, i8* bitcast (i32 (i8* nest , i32, i32)* @f to i8*), i8* %nval )
6324 %fp = bitcast i8* %p to i32 (i32, i32)*
Duncan Sands38947cd2007-07-27 12:58:54 +00006325</pre>
Bill Wendlinge262b4c2007-09-22 09:23:55 +00006326 <p>The call <tt>%val = call i32 %fp( i32 %x, i32 %y )</tt> is then equivalent
6327 to <tt>%val = call i32 %f( i8* %nval, i32 %x, i32 %y )</tt>.</p>
Duncan Sands38947cd2007-07-27 12:58:54 +00006328</div>
6329
6330<!-- _______________________________________________________________________ -->
6331<div class="doc_subsubsection">
6332 <a name="int_it">'<tt>llvm.init.trampoline</tt>' Intrinsic</a>
6333</div>
6334<div class="doc_text">
6335<h5>Syntax:</h5>
6336<pre>
Duncan Sands7407a9f2007-09-11 14:10:23 +00006337declare i8* @llvm.init.trampoline(i8* &lt;tramp&gt;, i8* &lt;func&gt;, i8* &lt;nval&gt;)
Duncan Sands38947cd2007-07-27 12:58:54 +00006338</pre>
6339<h5>Overview:</h5>
6340<p>
Duncan Sands7407a9f2007-09-11 14:10:23 +00006341 This fills the memory pointed to by <tt>tramp</tt> with code
6342 and returns a function pointer suitable for executing it.
Duncan Sands38947cd2007-07-27 12:58:54 +00006343</p>
6344<h5>Arguments:</h5>
6345<p>
6346 The <tt>llvm.init.trampoline</tt> intrinsic takes three arguments, all
6347 pointers. The <tt>tramp</tt> argument must point to a sufficiently large
6348 and sufficiently aligned block of memory; this memory is written to by the
Duncan Sands35012212007-08-22 23:39:54 +00006349 intrinsic. Note that the size and the alignment are target-specific - LLVM
6350 currently provides no portable way of determining them, so a front-end that
6351 generates this intrinsic needs to have some target-specific knowledge.
6352 The <tt>func</tt> argument must hold a function bitcast to an <tt>i8*</tt>.
Duncan Sands38947cd2007-07-27 12:58:54 +00006353</p>
6354<h5>Semantics:</h5>
6355<p>
6356 The block of memory pointed to by <tt>tramp</tt> is filled with target
Duncan Sands7407a9f2007-09-11 14:10:23 +00006357 dependent code, turning it into a function. A pointer to this function is
6358 returned, but needs to be bitcast to an
Duncan Sands38947cd2007-07-27 12:58:54 +00006359 <a href="#int_trampoline">appropriate function pointer type</a>
Duncan Sands7407a9f2007-09-11 14:10:23 +00006360 before being called. The new function's signature is the same as that of
6361 <tt>func</tt> with any arguments marked with the <tt>nest</tt> attribute
6362 removed. At most one such <tt>nest</tt> argument is allowed, and it must be
6363 of pointer type. Calling the new function is equivalent to calling
6364 <tt>func</tt> with the same argument list, but with <tt>nval</tt> used for the
6365 missing <tt>nest</tt> argument. If, after calling
6366 <tt>llvm.init.trampoline</tt>, the memory pointed to by <tt>tramp</tt> is
6367 modified, then the effect of any later call to the returned function pointer is
6368 undefined.
Duncan Sands38947cd2007-07-27 12:58:54 +00006369</p>
6370</div>
6371
6372<!-- ======================================================================= -->
6373<div class="doc_subsection">
Andrew Lenharth785610d2008-02-16 01:24:58 +00006374 <a name="int_atomics">Atomic Operations and Synchronization Intrinsics</a>
6375</div>
6376
6377<div class="doc_text">
6378<p>
6379 These intrinsic functions expand the "universal IR" of LLVM to represent
6380 hardware constructs for atomic operations and memory synchronization. This
6381 provides an interface to the hardware, not an interface to the programmer. It
Chris Lattner96451482008-08-05 18:29:16 +00006382 is aimed at a low enough level to allow any programming models or APIs
6383 (Application Programming Interfaces) which
Andrew Lenharth785610d2008-02-16 01:24:58 +00006384 need atomic behaviors to map cleanly onto it. It is also modeled primarily on
6385 hardware behavior. Just as hardware provides a "universal IR" for source
6386 languages, it also provides a starting point for developing a "universal"
6387 atomic operation and synchronization IR.
6388</p>
6389<p>
6390 These do <em>not</em> form an API such as high-level threading libraries,
6391 software transaction memory systems, atomic primitives, and intrinsic
6392 functions as found in BSD, GNU libc, atomic_ops, APR, and other system and
6393 application libraries. The hardware interface provided by LLVM should allow
6394 a clean implementation of all of these APIs and parallel programming models.
6395 No one model or paradigm should be selected above others unless the hardware
6396 itself ubiquitously does so.
6397
6398</p>
6399</div>
6400
6401<!-- _______________________________________________________________________ -->
6402<div class="doc_subsubsection">
6403 <a name="int_memory_barrier">'<tt>llvm.memory.barrier</tt>' Intrinsic</a>
6404</div>
6405<div class="doc_text">
6406<h5>Syntax:</h5>
6407<pre>
6408declare void @llvm.memory.barrier( i1 &lt;ll&gt;, i1 &lt;ls&gt;, i1 &lt;sl&gt;, i1 &lt;ss&gt;,
6409i1 &lt;device&gt; )
6410
6411</pre>
6412<h5>Overview:</h5>
6413<p>
6414 The <tt>llvm.memory.barrier</tt> intrinsic guarantees ordering between
6415 specific pairs of memory access types.
6416</p>
6417<h5>Arguments:</h5>
6418<p>
6419 The <tt>llvm.memory.barrier</tt> intrinsic requires five boolean arguments.
6420 The first four arguments enables a specific barrier as listed below. The fith
6421 argument specifies that the barrier applies to io or device or uncached memory.
6422
6423</p>
6424 <ul>
6425 <li><tt>ll</tt>: load-load barrier</li>
6426 <li><tt>ls</tt>: load-store barrier</li>
6427 <li><tt>sl</tt>: store-load barrier</li>
6428 <li><tt>ss</tt>: store-store barrier</li>
Dan Gohman2672f3e2008-10-14 16:51:45 +00006429 <li><tt>device</tt>: barrier applies to device and uncached memory also.</li>
Andrew Lenharth785610d2008-02-16 01:24:58 +00006430 </ul>
6431<h5>Semantics:</h5>
6432<p>
6433 This intrinsic causes the system to enforce some ordering constraints upon
6434 the loads and stores of the program. This barrier does not indicate
6435 <em>when</em> any events will occur, it only enforces an <em>order</em> in
6436 which they occur. For any of the specified pairs of load and store operations
6437 (f.ex. load-load, or store-load), all of the first operations preceding the
6438 barrier will complete before any of the second operations succeeding the
6439 barrier begin. Specifically the semantics for each pairing is as follows:
6440</p>
6441 <ul>
6442 <li><tt>ll</tt>: All loads before the barrier must complete before any load
6443 after the barrier begins.</li>
6444
6445 <li><tt>ls</tt>: All loads before the barrier must complete before any
6446 store after the barrier begins.</li>
6447 <li><tt>ss</tt>: All stores before the barrier must complete before any
6448 store after the barrier begins.</li>
6449 <li><tt>sl</tt>: All stores before the barrier must complete before any
6450 load after the barrier begins.</li>
6451 </ul>
6452<p>
6453 These semantics are applied with a logical "and" behavior when more than one
6454 is enabled in a single memory barrier intrinsic.
6455</p>
6456<p>
6457 Backends may implement stronger barriers than those requested when they do not
6458 support as fine grained a barrier as requested. Some architectures do not
6459 need all types of barriers and on such architectures, these become noops.
6460</p>
6461<h5>Example:</h5>
6462<pre>
6463%ptr = malloc i32
6464 store i32 4, %ptr
6465
6466%result1 = load i32* %ptr <i>; yields {i32}:result1 = 4</i>
6467 call void @llvm.memory.barrier( i1 false, i1 true, i1 false, i1 false )
6468 <i>; guarantee the above finishes</i>
6469 store i32 8, %ptr <i>; before this begins</i>
6470</pre>
6471</div>
6472
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006473<!-- _______________________________________________________________________ -->
6474<div class="doc_subsubsection">
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006475 <a name="int_atomic_cmp_swap">'<tt>llvm.atomic.cmp.swap.*</tt>' Intrinsic</a>
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006476</div>
6477<div class="doc_text">
6478<h5>Syntax:</h5>
6479<p>
Mon P Wangce3ac892008-07-30 04:36:53 +00006480 This is an overloaded intrinsic. You can use <tt>llvm.atomic.cmp.swap</tt> on
6481 any integer bit width and for different address spaces. Not all targets
6482 support all bit widths however.</p>
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006483
6484<pre>
Mon P Wangce3ac892008-07-30 04:36:53 +00006485declare i8 @llvm.atomic.cmp.swap.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;cmp&gt;, i8 &lt;val&gt; )
6486declare i16 @llvm.atomic.cmp.swap.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;cmp&gt;, i16 &lt;val&gt; )
6487declare i32 @llvm.atomic.cmp.swap.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;cmp&gt;, i32 &lt;val&gt; )
6488declare 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 +00006489
6490</pre>
6491<h5>Overview:</h5>
6492<p>
6493 This loads a value in memory and compares it to a given value. If they are
6494 equal, it stores a new value into the memory.
6495</p>
6496<h5>Arguments:</h5>
6497<p>
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006498 The <tt>llvm.atomic.cmp.swap</tt> intrinsic takes three arguments. The result as
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006499 well as both <tt>cmp</tt> and <tt>val</tt> must be integer values with the
6500 same bit width. The <tt>ptr</tt> argument must be a pointer to a value of
6501 this integer type. While any bit width integer may be used, targets may only
6502 lower representations they support in hardware.
6503
6504</p>
6505<h5>Semantics:</h5>
6506<p>
6507 This entire intrinsic must be executed atomically. It first loads the value
6508 in memory pointed to by <tt>ptr</tt> and compares it with the value
6509 <tt>cmp</tt>. If they are equal, <tt>val</tt> is stored into the memory. The
6510 loaded value is yielded in all cases. This provides the equivalent of an
6511 atomic compare-and-swap operation within the SSA framework.
6512</p>
6513<h5>Examples:</h5>
6514
6515<pre>
6516%ptr = malloc i32
6517 store i32 4, %ptr
6518
6519%val1 = add i32 4, 4
Mon P Wangce3ac892008-07-30 04:36:53 +00006520%result1 = call i32 @llvm.atomic.cmp.swap.i32.p0i32( i32* %ptr, i32 4, %val1 )
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006521 <i>; yields {i32}:result1 = 4</i>
6522%stored1 = icmp eq i32 %result1, 4 <i>; yields {i1}:stored1 = true</i>
6523%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 8</i>
6524
6525%val2 = add i32 1, 1
Mon P Wangce3ac892008-07-30 04:36:53 +00006526%result2 = call i32 @llvm.atomic.cmp.swap.i32.p0i32( i32* %ptr, i32 5, %val2 )
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006527 <i>; yields {i32}:result2 = 8</i>
6528%stored2 = icmp eq i32 %result2, 5 <i>; yields {i1}:stored2 = false</i>
6529
6530%memval2 = load i32* %ptr <i>; yields {i32}:memval2 = 8</i>
6531</pre>
6532</div>
6533
6534<!-- _______________________________________________________________________ -->
6535<div class="doc_subsubsection">
6536 <a name="int_atomic_swap">'<tt>llvm.atomic.swap.*</tt>' Intrinsic</a>
6537</div>
6538<div class="doc_text">
6539<h5>Syntax:</h5>
6540
6541<p>
6542 This is an overloaded intrinsic. You can use <tt>llvm.atomic.swap</tt> on any
6543 integer bit width. Not all targets support all bit widths however.</p>
6544<pre>
Mon P Wangce3ac892008-07-30 04:36:53 +00006545declare i8 @llvm.atomic.swap.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;val&gt; )
6546declare i16 @llvm.atomic.swap.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;val&gt; )
6547declare i32 @llvm.atomic.swap.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;val&gt; )
6548declare i64 @llvm.atomic.swap.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;val&gt; )
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006549
6550</pre>
6551<h5>Overview:</h5>
6552<p>
6553 This intrinsic loads the value stored in memory at <tt>ptr</tt> and yields
6554 the value from memory. It then stores the value in <tt>val</tt> in the memory
6555 at <tt>ptr</tt>.
6556</p>
6557<h5>Arguments:</h5>
6558
6559<p>
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006560 The <tt>llvm.atomic.swap</tt> intrinsic takes two arguments. Both the
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006561 <tt>val</tt> argument and the result must be integers of the same bit width.
6562 The first argument, <tt>ptr</tt>, must be a pointer to a value of this
6563 integer type. The targets may only lower integer representations they
6564 support.
6565</p>
6566<h5>Semantics:</h5>
6567<p>
6568 This intrinsic loads the value pointed to by <tt>ptr</tt>, yields it, and
6569 stores <tt>val</tt> back into <tt>ptr</tt> atomically. This provides the
6570 equivalent of an atomic swap operation within the SSA framework.
6571
6572</p>
6573<h5>Examples:</h5>
6574<pre>
6575%ptr = malloc i32
6576 store i32 4, %ptr
6577
6578%val1 = add i32 4, 4
Mon P Wangce3ac892008-07-30 04:36:53 +00006579%result1 = call i32 @llvm.atomic.swap.i32.p0i32( i32* %ptr, i32 %val1 )
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006580 <i>; yields {i32}:result1 = 4</i>
6581%stored1 = icmp eq i32 %result1, 4 <i>; yields {i1}:stored1 = true</i>
6582%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 8</i>
6583
6584%val2 = add i32 1, 1
Mon P Wangce3ac892008-07-30 04:36:53 +00006585%result2 = call i32 @llvm.atomic.swap.i32.p0i32( i32* %ptr, i32 %val2 )
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006586 <i>; yields {i32}:result2 = 8</i>
6587
6588%stored2 = icmp eq i32 %result2, 8 <i>; yields {i1}:stored2 = true</i>
6589%memval2 = load i32* %ptr <i>; yields {i32}:memval2 = 2</i>
6590</pre>
6591</div>
6592
6593<!-- _______________________________________________________________________ -->
6594<div class="doc_subsubsection">
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006595 <a name="int_atomic_load_add">'<tt>llvm.atomic.load.add.*</tt>' Intrinsic</a>
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006596
6597</div>
6598<div class="doc_text">
6599<h5>Syntax:</h5>
6600<p>
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006601 This is an overloaded intrinsic. You can use <tt>llvm.atomic.load.add</tt> on any
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006602 integer bit width. Not all targets support all bit widths however.</p>
6603<pre>
Mon P Wangce3ac892008-07-30 04:36:53 +00006604declare i8 @llvm.atomic.load.add.i8..p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6605declare i16 @llvm.atomic.load.add.i16..p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6606declare i32 @llvm.atomic.load.add.i32..p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6607declare i64 @llvm.atomic.load.add.i64..p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006608
6609</pre>
6610<h5>Overview:</h5>
6611<p>
6612 This intrinsic adds <tt>delta</tt> to the value stored in memory at
6613 <tt>ptr</tt>. It yields the original value at <tt>ptr</tt>.
6614</p>
6615<h5>Arguments:</h5>
6616<p>
6617
6618 The intrinsic takes two arguments, the first a pointer to an integer value
6619 and the second an integer value. The result is also an integer value. These
6620 integer types can have any bit width, but they must all have the same bit
6621 width. The targets may only lower integer representations they support.
6622</p>
6623<h5>Semantics:</h5>
6624<p>
6625 This intrinsic does a series of operations atomically. It first loads the
6626 value stored at <tt>ptr</tt>. It then adds <tt>delta</tt>, stores the result
6627 to <tt>ptr</tt>. It yields the original value stored at <tt>ptr</tt>.
6628</p>
6629
6630<h5>Examples:</h5>
6631<pre>
6632%ptr = malloc i32
6633 store i32 4, %ptr
Mon P Wangce3ac892008-07-30 04:36:53 +00006634%result1 = call i32 @llvm.atomic.load.add.i32.p0i32( i32* %ptr, i32 4 )
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006635 <i>; yields {i32}:result1 = 4</i>
Mon P Wangce3ac892008-07-30 04:36:53 +00006636%result2 = call i32 @llvm.atomic.load.add.i32.p0i32( i32* %ptr, i32 2 )
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006637 <i>; yields {i32}:result2 = 8</i>
Mon P Wangce3ac892008-07-30 04:36:53 +00006638%result3 = call i32 @llvm.atomic.load.add.i32.p0i32( i32* %ptr, i32 5 )
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006639 <i>; yields {i32}:result3 = 10</i>
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006640%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 15</i>
Andrew Lenharthe44f3902008-02-21 06:45:13 +00006641</pre>
6642</div>
6643
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006644<!-- _______________________________________________________________________ -->
6645<div class="doc_subsubsection">
6646 <a name="int_atomic_load_sub">'<tt>llvm.atomic.load.sub.*</tt>' Intrinsic</a>
6647
6648</div>
6649<div class="doc_text">
6650<h5>Syntax:</h5>
6651<p>
6652 This is an overloaded intrinsic. You can use <tt>llvm.atomic.load.sub</tt> on
Mon P Wangce3ac892008-07-30 04:36:53 +00006653 any integer bit width and for different address spaces. Not all targets
6654 support all bit widths however.</p>
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006655<pre>
Mon P Wangce3ac892008-07-30 04:36:53 +00006656declare i8 @llvm.atomic.load.sub.i8.p0i32( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6657declare i16 @llvm.atomic.load.sub.i16.p0i32( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6658declare i32 @llvm.atomic.load.sub.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6659declare i64 @llvm.atomic.load.sub.i64.p0i32( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006660
6661</pre>
6662<h5>Overview:</h5>
6663<p>
6664 This intrinsic subtracts <tt>delta</tt> to the value stored in memory at
6665 <tt>ptr</tt>. It yields the original value at <tt>ptr</tt>.
6666</p>
6667<h5>Arguments:</h5>
6668<p>
6669
6670 The intrinsic takes two arguments, the first a pointer to an integer value
6671 and the second an integer value. The result is also an integer value. These
6672 integer types can have any bit width, but they must all have the same bit
6673 width. The targets may only lower integer representations they support.
6674</p>
6675<h5>Semantics:</h5>
6676<p>
6677 This intrinsic does a series of operations atomically. It first loads the
6678 value stored at <tt>ptr</tt>. It then subtracts <tt>delta</tt>, stores the
6679 result to <tt>ptr</tt>. It yields the original value stored at <tt>ptr</tt>.
6680</p>
6681
6682<h5>Examples:</h5>
6683<pre>
6684%ptr = malloc i32
6685 store i32 8, %ptr
Mon P Wangce3ac892008-07-30 04:36:53 +00006686%result1 = call i32 @llvm.atomic.load.sub.i32.p0i32( i32* %ptr, i32 4 )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006687 <i>; yields {i32}:result1 = 8</i>
Mon P Wangce3ac892008-07-30 04:36:53 +00006688%result2 = call i32 @llvm.atomic.load.sub.i32.p0i32( i32* %ptr, i32 2 )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006689 <i>; yields {i32}:result2 = 4</i>
Mon P Wangce3ac892008-07-30 04:36:53 +00006690%result3 = call i32 @llvm.atomic.load.sub.i32.p0i32( i32* %ptr, i32 5 )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006691 <i>; yields {i32}:result3 = 2</i>
6692%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = -3</i>
6693</pre>
6694</div>
6695
6696<!-- _______________________________________________________________________ -->
6697<div class="doc_subsubsection">
6698 <a name="int_atomic_load_and">'<tt>llvm.atomic.load.and.*</tt>' Intrinsic</a><br>
6699 <a name="int_atomic_load_nand">'<tt>llvm.atomic.load.nand.*</tt>' Intrinsic</a><br>
6700 <a name="int_atomic_load_or">'<tt>llvm.atomic.load.or.*</tt>' Intrinsic</a><br>
6701 <a name="int_atomic_load_xor">'<tt>llvm.atomic.load.xor.*</tt>' Intrinsic</a><br>
6702
6703</div>
6704<div class="doc_text">
6705<h5>Syntax:</h5>
6706<p>
6707 These are overloaded intrinsics. You can use <tt>llvm.atomic.load_and</tt>,
6708 <tt>llvm.atomic.load_nand</tt>, <tt>llvm.atomic.load_or</tt>, and
Mon P Wangce3ac892008-07-30 04:36:53 +00006709 <tt>llvm.atomic.load_xor</tt> on any integer bit width and for different
6710 address spaces. Not all targets support all bit widths however.</p>
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006711<pre>
Mon P Wangce3ac892008-07-30 04:36:53 +00006712declare i8 @llvm.atomic.load.and.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6713declare i16 @llvm.atomic.load.and.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6714declare i32 @llvm.atomic.load.and.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6715declare i64 @llvm.atomic.load.and.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006716
6717</pre>
6718
6719<pre>
Mon P Wangce3ac892008-07-30 04:36:53 +00006720declare i8 @llvm.atomic.load.or.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6721declare i16 @llvm.atomic.load.or.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6722declare i32 @llvm.atomic.load.or.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6723declare i64 @llvm.atomic.load.or.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006724
6725</pre>
6726
6727<pre>
Mon P Wangce3ac892008-07-30 04:36:53 +00006728declare i8 @llvm.atomic.load.nand.i8.p0i32( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6729declare i16 @llvm.atomic.load.nand.i16.p0i32( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6730declare i32 @llvm.atomic.load.nand.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6731declare i64 @llvm.atomic.load.nand.i64.p0i32( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006732
6733</pre>
6734
6735<pre>
Mon P Wangce3ac892008-07-30 04:36:53 +00006736declare i8 @llvm.atomic.load.xor.i8.p0i32( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6737declare i16 @llvm.atomic.load.xor.i16.p0i32( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6738declare i32 @llvm.atomic.load.xor.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6739declare i64 @llvm.atomic.load.xor.i64.p0i32( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006740
6741</pre>
6742<h5>Overview:</h5>
6743<p>
6744 These intrinsics bitwise the operation (and, nand, or, xor) <tt>delta</tt> to
6745 the value stored in memory at <tt>ptr</tt>. It yields the original value
6746 at <tt>ptr</tt>.
6747</p>
6748<h5>Arguments:</h5>
6749<p>
6750
6751 These intrinsics take two arguments, the first a pointer to an integer value
6752 and the second an integer value. The result is also an integer value. These
6753 integer types can have any bit width, but they must all have the same bit
6754 width. The targets may only lower integer representations they support.
6755</p>
6756<h5>Semantics:</h5>
6757<p>
6758 These intrinsics does a series of operations atomically. They first load the
6759 value stored at <tt>ptr</tt>. They then do the bitwise operation
6760 <tt>delta</tt>, store the result to <tt>ptr</tt>. They yield the original
6761 value stored at <tt>ptr</tt>.
6762</p>
6763
6764<h5>Examples:</h5>
6765<pre>
6766%ptr = malloc i32
6767 store i32 0x0F0F, %ptr
Mon P Wangce3ac892008-07-30 04:36:53 +00006768%result0 = call i32 @llvm.atomic.load.nand.i32.p0i32( i32* %ptr, i32 0xFF )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006769 <i>; yields {i32}:result0 = 0x0F0F</i>
Mon P Wangce3ac892008-07-30 04:36:53 +00006770%result1 = call i32 @llvm.atomic.load.and.i32.p0i32( i32* %ptr, i32 0xFF )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006771 <i>; yields {i32}:result1 = 0xFFFFFFF0</i>
Mon P Wangce3ac892008-07-30 04:36:53 +00006772%result2 = call i32 @llvm.atomic.load.or.i32.p0i32( i32* %ptr, i32 0F )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006773 <i>; yields {i32}:result2 = 0xF0</i>
Mon P Wangce3ac892008-07-30 04:36:53 +00006774%result3 = call i32 @llvm.atomic.load.xor.i32.p0i32( i32* %ptr, i32 0F )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006775 <i>; yields {i32}:result3 = FF</i>
6776%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = F0</i>
6777</pre>
6778</div>
6779
6780
6781<!-- _______________________________________________________________________ -->
6782<div class="doc_subsubsection">
6783 <a name="int_atomic_load_max">'<tt>llvm.atomic.load.max.*</tt>' Intrinsic</a><br>
6784 <a name="int_atomic_load_min">'<tt>llvm.atomic.load.min.*</tt>' Intrinsic</a><br>
6785 <a name="int_atomic_load_umax">'<tt>llvm.atomic.load.umax.*</tt>' Intrinsic</a><br>
6786 <a name="int_atomic_load_umin">'<tt>llvm.atomic.load.umin.*</tt>' Intrinsic</a><br>
6787
6788</div>
6789<div class="doc_text">
6790<h5>Syntax:</h5>
6791<p>
6792 These are overloaded intrinsics. You can use <tt>llvm.atomic.load_max</tt>,
6793 <tt>llvm.atomic.load_min</tt>, <tt>llvm.atomic.load_umax</tt>, and
Mon P Wangce3ac892008-07-30 04:36:53 +00006794 <tt>llvm.atomic.load_umin</tt> on any integer bit width and for different
6795 address spaces. Not all targets
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006796 support all bit widths however.</p>
6797<pre>
Mon P Wangce3ac892008-07-30 04:36:53 +00006798declare i8 @llvm.atomic.load.max.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6799declare i16 @llvm.atomic.load.max.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6800declare i32 @llvm.atomic.load.max.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6801declare i64 @llvm.atomic.load.max.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006802
6803</pre>
6804
6805<pre>
Mon P Wangce3ac892008-07-30 04:36:53 +00006806declare i8 @llvm.atomic.load.min.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6807declare i16 @llvm.atomic.load.min.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6808declare i32 @llvm.atomic.load.min.i32..p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6809declare i64 @llvm.atomic.load.min.i64..p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006810
6811</pre>
6812
6813<pre>
Mon P Wangce3ac892008-07-30 04:36:53 +00006814declare i8 @llvm.atomic.load.umax.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6815declare i16 @llvm.atomic.load.umax.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6816declare i32 @llvm.atomic.load.umax.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6817declare i64 @llvm.atomic.load.umax.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006818
6819</pre>
6820
6821<pre>
Mon P Wangce3ac892008-07-30 04:36:53 +00006822declare i8 @llvm.atomic.load.umin.i8..p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6823declare i16 @llvm.atomic.load.umin.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6824declare i32 @llvm.atomic.load.umin.i32..p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6825declare i64 @llvm.atomic.load.umin.i64..p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006826
6827</pre>
6828<h5>Overview:</h5>
6829<p>
6830 These intrinsics takes the signed or unsigned minimum or maximum of
6831 <tt>delta</tt> and the value stored in memory at <tt>ptr</tt>. It yields the
6832 original value at <tt>ptr</tt>.
6833</p>
6834<h5>Arguments:</h5>
6835<p>
6836
6837 These intrinsics take two arguments, the first a pointer to an integer value
6838 and the second an integer value. The result is also an integer value. These
6839 integer types can have any bit width, but they must all have the same bit
6840 width. The targets may only lower integer representations they support.
6841</p>
6842<h5>Semantics:</h5>
6843<p>
6844 These intrinsics does a series of operations atomically. They first load the
6845 value stored at <tt>ptr</tt>. They then do the signed or unsigned min or max
6846 <tt>delta</tt> and the value, store the result to <tt>ptr</tt>. They yield
6847 the original value stored at <tt>ptr</tt>.
6848</p>
6849
6850<h5>Examples:</h5>
6851<pre>
6852%ptr = malloc i32
6853 store i32 7, %ptr
Mon P Wangce3ac892008-07-30 04:36:53 +00006854%result0 = call i32 @llvm.atomic.load.min.i32.p0i32( i32* %ptr, i32 -2 )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006855 <i>; yields {i32}:result0 = 7</i>
Mon P Wangce3ac892008-07-30 04:36:53 +00006856%result1 = call i32 @llvm.atomic.load.max.i32.p0i32( i32* %ptr, i32 8 )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006857 <i>; yields {i32}:result1 = -2</i>
Mon P Wangce3ac892008-07-30 04:36:53 +00006858%result2 = call i32 @llvm.atomic.load.umin.i32.p0i32( i32* %ptr, i32 10 )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006859 <i>; yields {i32}:result2 = 8</i>
Mon P Wangce3ac892008-07-30 04:36:53 +00006860%result3 = call i32 @llvm.atomic.load.umax.i32.p0i32( i32* %ptr, i32 30 )
Mon P Wang6bde9ec2008-06-25 08:15:39 +00006861 <i>; yields {i32}:result3 = 8</i>
6862%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 30</i>
6863</pre>
6864</div>
Andrew Lenharth785610d2008-02-16 01:24:58 +00006865
6866<!-- ======================================================================= -->
6867<div class="doc_subsection">
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006868 <a name="int_general">General Intrinsics</a>
6869</div>
6870
6871<div class="doc_text">
6872<p> This class of intrinsics is designed to be generic and has
6873no specific purpose. </p>
6874</div>
6875
6876<!-- _______________________________________________________________________ -->
6877<div class="doc_subsubsection">
6878 <a name="int_var_annotation">'<tt>llvm.var.annotation</tt>' Intrinsic</a>
6879</div>
6880
6881<div class="doc_text">
6882
6883<h5>Syntax:</h5>
6884<pre>
6885 declare void @llvm.var.annotation(i8* &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
6886</pre>
6887
6888<h5>Overview:</h5>
6889
6890<p>
6891The '<tt>llvm.var.annotation</tt>' intrinsic
6892</p>
6893
6894<h5>Arguments:</h5>
6895
6896<p>
6897The first argument is a pointer to a value, the second is a pointer to a
6898global string, the third is a pointer to a global string which is the source
6899file name, and the last argument is the line number.
6900</p>
6901
6902<h5>Semantics:</h5>
6903
6904<p>
Anton Korobeynikove6e764f2008-01-15 22:31:34 +00006905This intrinsic allows annotation of local variables with arbitrary strings.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006906This can be useful for special purpose optimizations that want to look for these
Anton Korobeynikove6e764f2008-01-15 22:31:34 +00006907annotations. These have no other defined use, they are ignored by code
6908generation and optimization.
6909</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006910</div>
6911
Tanya Lattnerb306a9e2007-09-21 22:59:12 +00006912<!-- _______________________________________________________________________ -->
6913<div class="doc_subsubsection">
Tanya Lattnerc9869b12007-09-21 23:57:59 +00006914 <a name="int_annotation">'<tt>llvm.annotation.*</tt>' Intrinsic</a>
Tanya Lattnerb306a9e2007-09-21 22:59:12 +00006915</div>
6916
6917<div class="doc_text">
6918
6919<h5>Syntax:</h5>
Tanya Lattnere545be72007-09-21 23:56:27 +00006920<p>This is an overloaded intrinsic. You can use '<tt>llvm.annotation</tt>' on
6921any integer bit width.
6922</p>
Tanya Lattnerb306a9e2007-09-21 22:59:12 +00006923<pre>
Tanya Lattner09161fe2007-09-22 00:03:01 +00006924 declare i8 @llvm.annotation.i8(i8 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
6925 declare i16 @llvm.annotation.i16(i16 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
6926 declare i32 @llvm.annotation.i32(i32 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
6927 declare i64 @llvm.annotation.i64(i64 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
6928 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 +00006929</pre>
6930
6931<h5>Overview:</h5>
Tanya Lattnere545be72007-09-21 23:56:27 +00006932
6933<p>
6934The '<tt>llvm.annotation</tt>' intrinsic.
Tanya Lattnerb306a9e2007-09-21 22:59:12 +00006935</p>
6936
6937<h5>Arguments:</h5>
6938
6939<p>
6940The first argument is an integer value (result of some expression),
6941the second is a pointer to a global string, the third is a pointer to a global
6942string which is the source file name, and the last argument is the line number.
Tanya Lattnere545be72007-09-21 23:56:27 +00006943It returns the value of the first argument.
Tanya Lattnerb306a9e2007-09-21 22:59:12 +00006944</p>
6945
6946<h5>Semantics:</h5>
6947
6948<p>
6949This intrinsic allows annotations to be put on arbitrary expressions
6950with arbitrary strings. This can be useful for special purpose optimizations
6951that want to look for these annotations. These have no other defined use, they
6952are ignored by code generation and optimization.
Dan Gohman2672f3e2008-10-14 16:51:45 +00006953</p>
Tanya Lattnerb306a9e2007-09-21 22:59:12 +00006954</div>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006955
Anton Korobeynikove6e764f2008-01-15 22:31:34 +00006956<!-- _______________________________________________________________________ -->
6957<div class="doc_subsubsection">
6958 <a name="int_trap">'<tt>llvm.trap</tt>' Intrinsic</a>
6959</div>
6960
6961<div class="doc_text">
6962
6963<h5>Syntax:</h5>
6964<pre>
6965 declare void @llvm.trap()
6966</pre>
6967
6968<h5>Overview:</h5>
6969
6970<p>
6971The '<tt>llvm.trap</tt>' intrinsic
6972</p>
6973
6974<h5>Arguments:</h5>
6975
6976<p>
6977None
6978</p>
6979
6980<h5>Semantics:</h5>
6981
6982<p>
6983This intrinsics is lowered to the target dependent trap instruction. If the
6984target does not have a trap instruction, this intrinsic will be lowered to the
6985call of the abort() function.
6986</p>
6987</div>
6988
Bill Wendlinge4164592008-11-19 05:56:17 +00006989<!-- _______________________________________________________________________ -->
6990<div class="doc_subsubsection">
Misha Brukman5dd7f4d2008-11-22 23:55:29 +00006991 <a name="int_stackprotector">'<tt>llvm.stackprotector</tt>' Intrinsic</a>
Bill Wendlinge4164592008-11-19 05:56:17 +00006992</div>
6993<div class="doc_text">
6994<h5>Syntax:</h5>
6995<pre>
6996declare void @llvm.stackprotector( i8* &lt;guard&gt;, i8** &lt;slot&gt; )
6997
6998</pre>
6999<h5>Overview:</h5>
7000<p>
7001 The <tt>llvm.stackprotector</tt> intrinsic takes the <tt>guard</tt> and stores
7002 it onto the stack at <tt>slot</tt>. The stack slot is adjusted to ensure that
7003 it is placed on the stack before local variables.
7004</p>
7005<h5>Arguments:</h5>
7006<p>
7007 The <tt>llvm.stackprotector</tt> intrinsic requires two pointer arguments. The
7008 first argument is the value loaded from the stack guard
7009 <tt>@__stack_chk_guard</tt>. The second variable is an <tt>alloca</tt> that
7010 has enough space to hold the value of the guard.
7011</p>
7012<h5>Semantics:</h5>
7013<p>
7014 This intrinsic causes the prologue/epilogue inserter to force the position of
7015 the <tt>AllocaInst</tt> stack slot to be before local variables on the
7016 stack. This is to ensure that if a local variable on the stack is overwritten,
7017 it will destroy the value of the guard. When the function exits, the guard on
7018 the stack is checked against the original guard. If they're different, then
7019 the program aborts by calling the <tt>__stack_chk_fail()</tt> function.
7020</p>
7021</div>
7022
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007023<!-- *********************************************************************** -->
7024<hr>
7025<address>
7026 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
Misha Brukman947321d2008-12-11 17:34:48 +00007027 src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007028 <a href="http://validator.w3.org/check/referer"><img
Misha Brukman947321d2008-12-11 17:34:48 +00007029 src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007030
7031 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
7032 <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
7033 Last modified: $Date$
7034</address>
Chris Lattner08497ce2008-01-04 04:33:49 +00007035
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007036</body>
7037</html>