122fddaa82850da438de0cf6c65fbac2e55d3730
[oota-llvm.git] / docs / LangRef.html
1 <!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>
23       <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>
41       <li><a href="#callingconv">Calling Conventions</a></li>
42       <li><a href="#namedtypes">Named Types</a></li>
43       <li><a href="#globalvars">Global Variables</a></li>
44       <li><a href="#functionstructure">Functions</a></li>
45       <li><a href="#aliasstructure">Aliases</a></li>
46       <li><a href="#paramattrs">Parameter Attributes</a></li>
47       <li><a href="#fnattrs">Function Attributes</a></li>
48       <li><a href="#gc">Garbage Collector Names</a></li>
49       <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>
55       <li><a href="#t_classifications">Type Classifications</a></li>
56       <li><a href="#t_primitive">Primitive Types</a>    
57         <ol>
58           <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>
61           <li><a href="#t_metadata">Metadata Type</a></li>
62         </ol>
63       </li>
64       <li><a href="#t_derived">Derived Types</a>
65         <ol>
66           <li><a href="#t_integer">Integer Type</a></li>
67           <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>
76       <li><a href="#t_uprefs">Type Up-references</a></li>
77     </ol>
78   </li>
79   <li><a href="#constants">Constants</a>
80     <ol>
81       <li><a href="#simpleconstants">Simple Constants</a></li>
82       <li><a href="#complexconstants">Complex Constants</a></li>
83       <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>
86       <li><a href="#metadata">Embedded Metadata</a></li>
87     </ol>
88   </li>
89   <li><a href="#othervalues">Other Values</a>
90     <ol>
91       <li><a href="#inlineasm">Inline Assembler Expressions</a></li>
92     </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>
109           <li><a href="#i_fadd">'<tt>fadd</tt>' Instruction</a></li>
110           <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
111           <li><a href="#i_fsub">'<tt>fsub</tt>' Instruction</a></li>
112           <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
113           <li><a href="#i_fmul">'<tt>fmul</tt>' Instruction</a></li>
114           <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>
139       <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>
145       <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>
170       </li>
171       <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>
217           <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>
220         </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>
228         </ol>
229       </li>
230       <li><a href="#int_overflow">Arithmetic with Overflow Intrinsics</a>
231         <ol>
232           <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>
237           <li><a href="#int_umul_overflow">'<tt>llvm.umul.with.overflow.*</tt> Intrinsics</a></li>
238         </ol>
239       </li>
240       <li><a href="#int_debugger">Debugger intrinsics</a></li>
241       <li><a href="#int_eh">Exception Handling intrinsics</a></li>
242       <li><a href="#int_trampoline">Trampoline Intrinsic</a>
243         <ol>
244           <li><a href="#int_it">'<tt>llvm.init.trampoline</tt>' Intrinsic</a></li>
245         </ol>
246       </li>
247       <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>
264       <li><a href="#int_general">General intrinsics</a>
265         <ol>
266           <li><a href="#int_var_annotation">
267             '<tt>llvm.var.annotation</tt>' Intrinsic</a></li>
268           <li><a href="#int_annotation">
269             '<tt>llvm.annotation.*</tt>' Intrinsic</a></li>
270           <li><a href="#int_trap">
271             '<tt>llvm.trap</tt>' Intrinsic</a></li>
272           <li><a href="#int_stackprotector">
273             '<tt>llvm.stackprotector</tt>' Intrinsic</a></li>
274         </ol>
275       </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
291 <p>This document is a reference manual for the LLVM assembly language. LLVM is
292    a Static Single Assignment (SSA) based representation that provides type
293    safety, low-level operations, flexibility, and the capability of representing
294    'all' high-level languages cleanly.  It is the common code representation
295    used throughout all phases of the LLVM compilation strategy.</p>
296
297 </div>
298
299 <!-- *********************************************************************** -->
300 <div class="doc_section"> <a name="introduction">Introduction</a> </div>
301 <!-- *********************************************************************** -->
302
303 <div class="doc_text">
304
305 <p>The LLVM code representation is designed to be used in three different forms:
306    as an in-memory compiler IR, as an on-disk bitcode representation (suitable
307    for fast loading by a Just-In-Time compiler), and as a human readable
308    assembly language representation.  This allows LLVM to provide a powerful
309    intermediate representation for efficient compiler transformations and
310    analysis, while providing a natural means to debug and visualize the
311    transformations.  The three different forms of LLVM are all equivalent.  This
312    document describes the human readable representation and notation.</p>
313
314 <p>The LLVM representation aims to be light-weight and low-level while being
315    expressive, typed, and extensible at the same time.  It aims to be a
316    "universal IR" of sorts, by being at a low enough level that high-level ideas
317    may be cleanly mapped to it (similar to how microprocessors are "universal
318    IR's", allowing many source languages to be mapped to them).  By providing
319    type information, LLVM can be used as the target of optimizations: for
320    example, through pointer analysis, it can be proven that a C automatic
321    variable is never accessed outside of the current function... allowing it to
322    be promoted to a simple SSA value instead of a memory location.</p>
323
324 </div>
325
326 <!-- _______________________________________________________________________ -->
327 <div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
328
329 <div class="doc_text">
330
331 <p>It is important to note that this document describes 'well formed' LLVM
332    assembly language.  There is a difference between what the parser accepts and
333    what is considered 'well formed'.  For example, the following instruction is
334    syntactically okay, but not well formed:</p>
335
336 <div class="doc_code">
337 <pre>
338 %x = <a href="#i_add">add</a> i32 1, %x
339 </pre>
340 </div>
341
342 <p>...because the definition of <tt>%x</tt> does not dominate all of its
343    uses. The LLVM infrastructure provides a verification pass that may be used
344    to verify that an LLVM module is well formed.  This pass is automatically run
345    by the parser after parsing input assembly and by the optimizer before it
346    outputs bitcode.  The violations pointed out by the verifier pass indicate
347    bugs in transformation passes or input to the parser.</p>
348
349 </div>
350
351 <!-- Describe the typesetting conventions here. -->
352
353 <!-- *********************************************************************** -->
354 <div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
355 <!-- *********************************************************************** -->
356
357 <div class="doc_text">
358
359 <p>LLVM identifiers come in two basic types: global and local. Global
360    identifiers (functions, global variables) begin with the <tt>'@'</tt>
361    character. Local identifiers (register names, types) begin with
362    the <tt>'%'</tt> character. Additionally, there are three different formats
363    for identifiers, for different purposes:</p>
364
365 <ol>
366   <li>Named values are represented as a string of characters with their prefix.
367       For example, <tt>%foo</tt>, <tt>@DivisionByZero</tt>,
368       <tt>%a.really.long.identifier</tt>. The actual regular expression used is
369       '<tt>[%@][a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.  Identifiers which require
370       other characters in their names can be surrounded with quotes. Special
371       characters may be escaped using <tt>"\xx"</tt> where <tt>xx</tt> is the
372       ASCII code for the character in hexadecimal.  In this way, any character
373       can be used in a name value, even quotes themselves.</li>
374
375   <li>Unnamed values are represented as an unsigned numeric value with their
376       prefix.  For example, <tt>%12</tt>, <tt>@2</tt>, <tt>%44</tt>.</li>
377
378   <li>Constants, which are described in a <a href="#constants">section about
379       constants</a>, below.</li>
380 </ol>
381
382 <p>LLVM requires that values start with a prefix for two reasons: Compilers
383    don't need to worry about name clashes with reserved words, and the set of
384    reserved words may be expanded in the future without penalty.  Additionally,
385    unnamed identifiers allow a compiler to quickly come up with a temporary
386    variable without having to avoid symbol table conflicts.</p>
387
388 <p>Reserved words in LLVM are very similar to reserved words in other
389    languages. There are keywords for different opcodes
390    ('<tt><a href="#i_add">add</a></tt>',
391    '<tt><a href="#i_bitcast">bitcast</a></tt>',
392    '<tt><a href="#i_ret">ret</a></tt>', etc...), for primitive type names
393    ('<tt><a href="#t_void">void</a></tt>',
394    '<tt><a href="#t_primitive">i32</a></tt>', etc...), and others.  These
395    reserved words cannot conflict with variable names, because none of them
396    start with a prefix character (<tt>'%'</tt> or <tt>'@'</tt>).</p>
397
398 <p>Here is an example of LLVM code to multiply the integer variable
399    '<tt>%X</tt>' by 8:</p>
400
401 <p>The easy way:</p>
402
403 <div class="doc_code">
404 <pre>
405 %result = <a href="#i_mul">mul</a> i32 %X, 8
406 </pre>
407 </div>
408
409 <p>After strength reduction:</p>
410
411 <div class="doc_code">
412 <pre>
413 %result = <a href="#i_shl">shl</a> i32 %X, i8 3
414 </pre>
415 </div>
416
417 <p>And the hard way:</p>
418
419 <div class="doc_code">
420 <pre>
421 <a href="#i_add">add</a> i32 %X, %X           <i>; yields {i32}:%0</i>
422 <a href="#i_add">add</a> i32 %0, %0           <i>; yields {i32}:%1</i>
423 %result = <a href="#i_add">add</a> i32 %1, %1
424 </pre>
425 </div>
426
427 <p>This last way of multiplying <tt>%X</tt> by 8 illustrates several important
428    lexical features of LLVM:</p>
429
430 <ol>
431   <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
432       line.</li>
433
434   <li>Unnamed temporaries are created when the result of a computation is not
435       assigned to a named value.</li>
436
437   <li>Unnamed temporaries are numbered sequentially</li>
438 </ol>
439
440 <p>...and it also shows a convention that we follow in this document.  When
441    demonstrating instructions, we will follow an instruction with a comment that
442    defines the type and name of value produced.  Comments are shown in italic
443    text.</p>
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 translation unit
458    of the input programs.  Each module consists of functions, global variables,
459    and symbol table entries.  Modules may be combined together with the LLVM
460    linker, which merges function (and global variable) definitions, resolves
461    forward declarations, and merges symbol table entries. Here is an example of
462    the "hello world" module:</p>
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>
473 define i32 @main() {                                              <i>; i32()* </i>
474         <i>; Convert [13 x i8]* to i8  *...</i>
475         %cast210 = <a
476  href="#i_getelementptr">getelementptr</a> [13 x i8]* @.LC0, i64 0, i64 0   <i>; i8 *</i>
477
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> named
487    "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>" function, and
488    a <a href="#functionstructure">function definition</a> for
489    "<tt>main</tt>".</p>
490
491 <p>In general, a module is made up of a list of global values, where both
492    functions and global variables are global values.  Global values are
493    represented by a pointer to a memory location (in this case, a pointer to an
494    array of char, and a pointer to a function), and have one of the
495    following <a href="#linkage">linkage types</a>.</p>
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>All Global Variables and Functions have one of the following types of
507    linkage:</p>
508
509 <dl>
510   <dt><tt><b><a name="linkage_private">private</a></b></tt>: </dt>
511
512   <dd>Global values with private linkage are only directly accessible by objects
513       in the current module.  In particular, linking code into a module with an
514       private global value may cause the private to be renamed as necessary to
515       avoid collisions.  Because the symbol is private to the module, all
516       references can be updated. This doesn't show up in any symbol table in the
517       object file.</dd>
518
519   <dt><tt><b><a name="linkage_linker_private">linker_private</a></b></tt>: </dt>
520
521   <dd>Similar to private, but the symbol is passed through the assembler and
522       removed by the linker after evaluation.</dd>
523
524   <dt><tt><b><a name="linkage_internal">internal</a></b></tt>: </dt>
525
526   <dd>Similar to private, but the value shows as a local symbol
527       (<tt>STB_LOCAL</tt> in the case of ELF) in the object file. This
528       corresponds to the notion of the '<tt>static</tt>' keyword in C.</dd>
529
530   <dt><tt><b><a name="linkage_available_externally">available_externally</a></b></tt>: </dt>
531
532   <dd>Globals with "<tt>available_externally</tt>" linkage are never emitted
533       into the object file corresponding to the LLVM module.  They exist to
534       allow inlining and other optimizations to take place given knowledge of
535       the definition of the global, which is known to be somewhere outside the
536       module.  Globals with <tt>available_externally</tt> linkage are allowed to
537       be discarded at will, and are otherwise the same as <tt>linkonce_odr</tt>.
538       This linkage type is only allowed on definitions, not declarations.</dd>
539
540   <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
541
542   <dd>Globals with "<tt>linkonce</tt>" linkage are merged with other globals of
543       the same name when linkage occurs.  This is typically used to implement
544       inline functions, templates, or other code which must be generated in each
545       translation unit that uses it.  Unreferenced <tt>linkonce</tt> globals are
546       allowed to be discarded.</dd>
547
548   <dt><tt><b><a name="linkage_common">common</a></b></tt>: </dt>
549
550   <dd>"<tt>common</tt>" linkage is exactly the same as <tt>linkonce</tt>
551      linkage, except that unreferenced <tt>common</tt> globals may not be
552      discarded.  This is used for globals that may be emitted in multiple
553      translation units, but that are not guaranteed to be emitted into every
554      translation unit that uses them.  One example of this is tentative
555      definitions in C, such as "<tt>int X;</tt>" at global scope.</dd>
556
557   <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
558
559   <dd>"<tt>weak</tt>" linkage is the same as <tt>common</tt> linkage, except
560       that some targets may choose to emit different assembly sequences for them
561       for target-dependent reasons.  This is used for globals that are declared
562       "weak" in C source code.</dd>
563
564   <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
565
566   <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
567       pointer to array type.  When two global variables with appending linkage
568       are linked together, the two global arrays are appended together.  This is
569       the LLVM, typesafe, equivalent of having the system linker append together
570       "sections" with identical names when .o files are linked.</dd>
571
572   <dt><tt><b><a name="linkage_externweak">extern_weak</a></b></tt>: </dt>
573
574   <dd>The semantics of this linkage follow the ELF object file model: the symbol
575       is weak until linked, if not linked, the symbol becomes null instead of
576       being an undefined reference.</dd>
577
578   <dt><tt><b><a name="linkage_linkonce">linkonce_odr</a></b></tt>: </dt>
579   <dt><tt><b><a name="linkage_weak">weak_odr</a></b></tt>: </dt>
580
581   <dd>Some languages allow differing globals to be merged, such as two functions
582       with different semantics.  Other languages, such as <tt>C++</tt>, ensure
583       that only equivalent globals are ever merged (the "one definition rule" -
584       "ODR").  Such languages can use the <tt>linkonce_odr</tt>
585       and <tt>weak_odr</tt> linkage types to indicate that the global will only
586       be merged with equivalent globals.  These linkage types are otherwise the
587       same as their non-<tt>odr</tt> versions.</dd>
588
589   <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
590
591   <dd>If none of the above identifiers are used, the global is externally
592       visible, meaning that it participates in linkage and can be used to
593       resolve external symbol references.</dd>
594 </dl>
595
596 <p>The next two types of linkage are targeted for Microsoft Windows platform
597    only. They are designed to support importing (exporting) symbols from (to)
598    DLLs (Dynamic Link Libraries).</p>
599
600 <dl>
601   <dt><tt><b><a name="linkage_dllimport">dllimport</a></b></tt>: </dt>
602
603   <dd>"<tt>dllimport</tt>" linkage causes the compiler to reference a function
604       or variable via a global pointer to a pointer that is set up by the DLL
605       exporting the symbol. On Microsoft Windows targets, the pointer name is
606       formed by combining <code>__imp_</code> and the function or variable
607       name.</dd>
608
609   <dt><tt><b><a name="linkage_dllexport">dllexport</a></b></tt>: </dt>
610
611   <dd>"<tt>dllexport</tt>" linkage causes the compiler to provide a global
612       pointer to a pointer in a DLL, so that it can be referenced with the
613       <tt>dllimport</tt> attribute. On Microsoft Windows targets, the pointer
614       name is formed by combining <code>__imp_</code> and the function or
615       variable name.</dd>
616 </dl>
617
618 <p>For example, since the "<tt>.LC0</tt>" variable is defined to be internal, if
619    another module defined a "<tt>.LC0</tt>" variable and was linked with this
620    one, one of the two would be renamed, preventing a collision.  Since
621    "<tt>main</tt>" and "<tt>puts</tt>" are external (i.e., lacking any linkage
622    declarations), they are accessible outside of the current module.</p>
623
624 <p>It is illegal for a function <i>declaration</i> to have any linkage type
625    other than "externally visible", <tt>dllimport</tt>
626    or <tt>extern_weak</tt>.</p>
627
628 <p>Aliases can have only <tt>external</tt>, <tt>internal</tt>, <tt>weak</tt>
629    or <tt>weak_odr</tt> linkages.</p>
630
631 </div>
632
633 <!-- ======================================================================= -->
634 <div class="doc_subsection">
635   <a name="callingconv">Calling Conventions</a>
636 </div>
637
638 <div class="doc_text">
639
640 <p>LLVM <a href="#functionstructure">functions</a>, <a href="#i_call">calls</a>
641    and <a href="#i_invoke">invokes</a> can all have an optional calling
642    convention specified for the call.  The calling convention of any pair of
643    dynamic caller/callee must match, or the behavior of the program is
644    undefined.  The following calling conventions are supported by LLVM, and more
645    may be added in the future:</p>
646
647 <dl>
648   <dt><b>"<tt>ccc</tt>" - The C calling convention</b>:</dt>
649
650   <dd>This calling convention (the default if no other calling convention is
651       specified) matches the target C calling conventions.  This calling
652       convention supports varargs function calls and tolerates some mismatch in
653       the declared prototype and implemented declaration of the function (as
654       does normal C).</dd>
655
656   <dt><b>"<tt>fastcc</tt>" - The fast calling convention</b>:</dt>
657
658   <dd>This calling convention attempts to make calls as fast as possible
659       (e.g. by passing things in registers).  This calling convention allows the
660       target to use whatever tricks it wants to produce fast code for the
661       target, without having to conform to an externally specified ABI
662       (Application Binary Interface).  Implementations of this convention should
663       allow arbitrary <a href="CodeGenerator.html#tailcallopt">tail call
664       optimization</a> to be supported.  This calling convention does not
665       support varargs and requires the prototype of all callees to exactly match
666       the prototype of the function definition.</dd>
667
668   <dt><b>"<tt>coldcc</tt>" - The cold calling convention</b>:</dt>
669
670   <dd>This calling convention attempts to make code in the caller as efficient
671       as possible under the assumption that the call is not commonly executed.
672       As such, these calls often preserve all registers so that the call does
673       not break any live ranges in the caller side.  This calling convention
674       does not support varargs and requires the prototype of all callees to
675       exactly match the prototype of the function definition.</dd>
676
677   <dt><b>"<tt>cc &lt;<em>n</em>&gt;</tt>" - Numbered convention</b>:</dt>
678
679   <dd>Any calling convention may be specified by number, allowing
680       target-specific calling conventions to be used.  Target specific calling
681       conventions start at 64.</dd>
682 </dl>
683
684 <p>More calling conventions can be added/defined on an as-needed basis, to
685    support Pascal conventions or any other well-known target-independent
686    convention.</p>
687
688 </div>
689
690 <!-- ======================================================================= -->
691 <div class="doc_subsection">
692   <a name="visibility">Visibility Styles</a>
693 </div>
694
695 <div class="doc_text">
696
697 <p>All Global Variables and Functions have one of the following visibility
698    styles:</p>
699
700 <dl>
701   <dt><b>"<tt>default</tt>" - Default style</b>:</dt>
702
703   <dd>On targets that use the ELF object file format, default visibility means
704       that the declaration is visible to other modules and, in shared libraries,
705       means that the declared entity may be overridden. On Darwin, default
706       visibility means that the declaration is visible to other modules. Default
707       visibility corresponds to "external linkage" in the language.</dd>
708
709   <dt><b>"<tt>hidden</tt>" - Hidden style</b>:</dt>
710
711   <dd>Two declarations of an object with hidden visibility refer to the same
712       object if they are in the same shared object. Usually, hidden visibility
713       indicates that the symbol will not be placed into the dynamic symbol
714       table, so no other module (executable or shared library) can reference it
715       directly.</dd>
716
717   <dt><b>"<tt>protected</tt>" - Protected style</b>:</dt>
718
719   <dd>On ELF, protected visibility indicates that the symbol will be placed in
720       the dynamic symbol table, but that references within the defining module
721       will bind to the local symbol. That is, the symbol cannot be overridden by
722       another module.</dd>
723 </dl>
724
725 </div>
726
727 <!-- ======================================================================= -->
728 <div class="doc_subsection">
729   <a name="namedtypes">Named Types</a>
730 </div>
731
732 <div class="doc_text">
733
734 <p>LLVM IR allows you to specify name aliases for certain types.  This can make
735    it easier to read the IR and make the IR more condensed (particularly when
736    recursive types are involved).  An example of a name specification is:</p>
737
738 <div class="doc_code">
739 <pre>
740 %mytype = type { %mytype*, i32 }
741 </pre>
742 </div>
743
744 <p>You may give a name to any <a href="#typesystem">type</a> except
745    "<a href="t_void">void</a>".  Type name aliases may be used anywhere a type
746    is expected with the syntax "%mytype".</p>
747
748 <p>Note that type names are aliases for the structural type that they indicate,
749    and that you can therefore specify multiple names for the same type.  This
750    often leads to confusing behavior when dumping out a .ll file.  Since LLVM IR
751    uses structural typing, the name is not part of the type.  When printing out
752    LLVM IR, the printer will pick <em>one name</em> to render all types of a
753    particular shape.  This means that if you have code where two different
754    source types end up having the same LLVM type, that the dumper will sometimes
755    print the "wrong" or unexpected type.  This is an important design point and
756    isn't going to change.</p>
757
758 </div>
759
760 <!-- ======================================================================= -->
761 <div class="doc_subsection">
762   <a name="globalvars">Global Variables</a>
763 </div>
764
765 <div class="doc_text">
766
767 <p>Global variables define regions of memory allocated at compilation time
768    instead of run-time.  Global variables may optionally be initialized, may
769    have an explicit section to be placed in, and may have an optional explicit
770    alignment specified.  A variable may be defined as "thread_local", which
771    means that it will not be shared by threads (each thread will have a
772    separated copy of the variable).  A variable may be defined as a global
773    "constant," which indicates that the contents of the variable
774    will <b>never</b> be modified (enabling better optimization, allowing the
775    global data to be placed in the read-only section of an executable, etc).
776    Note that variables that need runtime initialization cannot be marked
777    "constant" as there is a store to the variable.</p>
778
779 <p>LLVM explicitly allows <em>declarations</em> of global variables to be marked
780    constant, even if the final definition of the global is not.  This capability
781    can be used to enable slightly better optimization of the program, but
782    requires the language definition to guarantee that optimizations based on the
783    'constantness' are valid for the translation units that do not include the
784    definition.</p>
785
786 <p>As SSA values, global variables define pointer values that are in scope
787    (i.e. they dominate) all basic blocks in the program.  Global variables
788    always define a pointer to their "content" type because they describe a
789    region of memory, and all memory objects in LLVM are accessed through
790    pointers.</p>
791
792 <p>A global variable may be declared to reside in a target-specific numbered
793    address space. For targets that support them, address spaces may affect how
794    optimizations are performed and/or what target instructions are used to
795    access the variable. The default address space is zero. The address space
796    qualifier must precede any other attributes.</p>
797
798 <p>LLVM allows an explicit section to be specified for globals.  If the target
799    supports it, it will emit globals to the section specified.</p>
800
801 <p>An explicit alignment may be specified for a global.  If not present, or if
802    the alignment is set to zero, the alignment of the global is set by the
803    target to whatever it feels convenient.  If an explicit alignment is
804    specified, the global is forced to have at least that much alignment.  All
805    alignments must be a power of 2.</p>
806
807 <p>For example, the following defines a global in a numbered address space with
808    an initializer, section, and alignment:</p>
809
810 <div class="doc_code">
811 <pre>
812 @G = addrspace(5) constant float 1.0, section "foo", align 4
813 </pre>
814 </div>
815
816 </div>
817
818
819 <!-- ======================================================================= -->
820 <div class="doc_subsection">
821   <a name="functionstructure">Functions</a>
822 </div>
823
824 <div class="doc_text">
825
826 <p>LLVM function definitions consist of the "<tt>define</tt>" keyord, an
827    optional <a href="#linkage">linkage type</a>, an optional
828    <a href="#visibility">visibility style</a>, an optional
829    <a href="#callingconv">calling convention</a>, a return type, an optional
830    <a href="#paramattrs">parameter attribute</a> for the return type, a function
831    name, a (possibly empty) argument list (each with optional
832    <a href="#paramattrs">parameter attributes</a>), optional
833    <a href="#fnattrs">function attributes</a>, an optional section, an optional
834    alignment, an optional <a href="#gc">garbage collector name</a>, an opening
835    curly brace, a list of basic blocks, and a closing curly brace.</p>
836
837 <p>LLVM function declarations consist of the "<tt>declare</tt>" keyword, an
838    optional <a href="#linkage">linkage type</a>, an optional
839    <a href="#visibility">visibility style</a>, an optional 
840    <a href="#callingconv">calling convention</a>, a return type, an optional
841    <a href="#paramattrs">parameter attribute</a> for the return type, a function
842    name, a possibly empty list of arguments, an optional alignment, and an
843    optional <a href="#gc">garbage collector name</a>.</p>
844
845 <p>A function definition contains a list of basic blocks, forming the CFG
846    (Control Flow Graph) for the function.  Each basic block may optionally start
847    with a label (giving the basic block a symbol table entry), contains a list
848    of instructions, and ends with a <a href="#terminators">terminator</a>
849    instruction (such as a branch or function return).</p>
850
851 <p>The first basic block in a function is special in two ways: it is immediately
852    executed on entrance to the function, and it is not allowed to have
853    predecessor basic blocks (i.e. there can not be any branches to the entry
854    block of a function).  Because the block can have no predecessors, it also
855    cannot have any <a href="#i_phi">PHI nodes</a>.</p>
856
857 <p>LLVM allows an explicit section to be specified for functions.  If the target
858    supports it, it will emit functions to the section specified.</p>
859
860 <p>An explicit alignment may be specified for a function.  If not present, or if
861    the alignment is set to zero, the alignment of the function is set by the
862    target to whatever it feels convenient.  If an explicit alignment is
863    specified, the function is forced to have at least that much alignment.  All
864    alignments must be a power of 2.</p>
865
866   <h5>Syntax:</h5>
867
868 <div class="doc_code">
869 <pre>
870 define [<a href="#linkage">linkage</a>] [<a href="#visibility">visibility</a>]
871        [<a href="#callingconv">cconv</a>] [<a href="#paramattrs">ret attrs</a>]
872        &lt;ResultType&gt; @&lt;FunctionName&gt; ([argument list])
873        [<a href="#fnattrs">fn Attrs</a>] [section "name"] [align N]
874        [<a href="#gc">gc</a>] { ... }
875 </pre>
876 </div>
877
878 </div>
879
880 <!-- ======================================================================= -->
881 <div class="doc_subsection">
882   <a name="aliasstructure">Aliases</a>
883 </div>
884
885 <div class="doc_text">
886
887 <p>Aliases act as "second name" for the aliasee value (which can be either
888    function, global variable, another alias or bitcast of global value). Aliases
889    may have an optional <a href="#linkage">linkage type</a>, and an
890    optional <a href="#visibility">visibility style</a>.</p>
891
892   <h5>Syntax:</h5>
893
894 <div class="doc_code">
895 <pre>
896 @&lt;Name&gt; = alias [Linkage] [Visibility] &lt;AliaseeTy&gt; @&lt;Aliasee&gt;
897 </pre>
898 </div>
899
900 </div>
901
902 <!-- ======================================================================= -->
903 <div class="doc_subsection"><a name="paramattrs">Parameter Attributes</a></div>
904
905 <div class="doc_text">
906
907 <p>The return type and each parameter of a function type may have a set of
908    <i>parameter attributes</i> associated with them. Parameter attributes are
909    used to communicate additional information about the result or parameters of
910    a function. Parameter attributes are considered to be part of the function,
911    not of the function type, so functions with different parameter attributes
912    can have the same function type.</p>
913
914 <p>Parameter attributes are simple keywords that follow the type specified. If
915    multiple parameter attributes are needed, they are space separated. For
916    example:</p>
917
918 <div class="doc_code">
919 <pre>
920 declare i32 @printf(i8* noalias nocapture, ...)
921 declare i32 @atoi(i8 zeroext)
922 declare signext i8 @returns_signed_char()
923 </pre>
924 </div>
925
926 <p>Note that any attributes for the function result (<tt>nounwind</tt>,
927    <tt>readonly</tt>) come immediately after the argument list.</p>
928
929 <p>Currently, only the following parameter attributes are defined:</p>
930
931 <dl>
932   <dt><tt>zeroext</tt></dt>
933
934   <dd>This indicates to the code generator that the parameter or return value
935       should be zero-extended to a 32-bit value by the caller (for a parameter)
936       or the callee (for a return value).</dd>
937
938   <dt><tt>signext</tt></dt>
939
940   <dd>This indicates to the code generator that the parameter or return value
941       should be sign-extended to a 32-bit value by the caller (for a parameter)
942       or the callee (for a return value).</dd>
943
944   <dt><tt>inreg</tt></dt>
945
946   <dd>This indicates that this parameter or return value should be treated in a
947       special target-dependent fashion during while emitting code for a function
948       call or return (usually, by putting it in a register as opposed to memory,
949       though some targets use it to distinguish between two different kinds of
950       registers).  Use of this attribute is target-specific.</dd>
951
952   <dt><tt><a name="byval">byval</a></tt></dt>
953
954   <dd>This indicates that the pointer parameter should really be passed by value
955       to the function.  The attribute implies that a hidden copy of the pointee
956       is made between the caller and the callee, so the callee is unable to
957       modify the value in the callee.  This attribute is only valid on LLVM
958       pointer arguments.  It is generally used to pass structs and arrays by
959       value, but is also valid on pointers to scalars.  The copy is considered
960       to belong to the caller not the callee (for example,
961       <tt><a href="#readonly">readonly</a></tt> functions should not write to
962       <tt>byval</tt> parameters). This is not a valid attribute for return
963       values.  The byval attribute also supports specifying an alignment with
964       the align attribute.  This has a target-specific effect on the code
965       generator that usually indicates a desired alignment for the synthesized
966       stack slot.</dd>
967
968   <dt><tt>sret</tt></dt>
969
970   <dd>This indicates that the pointer parameter specifies the address of a
971       structure that is the return value of the function in the source program.
972       This pointer must be guaranteed by the caller to be valid: loads and
973       stores to the structure may be assumed by the callee to not to trap.  This
974       may only be applied to the first parameter. This is not a valid attribute
975       for return values. </dd>
976
977   <dt><tt>noalias</tt></dt>
978
979   <dd>This indicates that the pointer does not alias any global or any other
980       parameter.  The caller is responsible for ensuring that this is the
981       case. On a function return value, <tt>noalias</tt> additionally indicates
982       that the pointer does not alias any other pointers visible to the
983       caller. For further details, please see the discussion of the NoAlias
984       response in
985       <a href="http://llvm.org/docs/AliasAnalysis.html#MustMayNo">alias
986       analysis</a>.</dd>
987
988   <dt><tt>nocapture</tt></dt>
989
990   <dd>This indicates that the callee does not make any copies of the pointer
991       that outlive the callee itself. This is not a valid attribute for return
992       values.</dd>
993
994   <dt><tt>nest</tt></dt>
995
996   <dd>This indicates that the pointer parameter can be excised using the
997       <a href="#int_trampoline">trampoline intrinsics</a>. This is not a valid
998       attribute for return values.</dd>
999 </dl>
1000
1001 </div>
1002
1003 <!-- ======================================================================= -->
1004 <div class="doc_subsection">
1005   <a name="gc">Garbage Collector Names</a>
1006 </div>
1007
1008 <div class="doc_text">
1009
1010 <p>Each function may specify a garbage collector name, which is simply a
1011    string:</p>
1012
1013 <div class="doc_code">
1014 <pre>
1015 define void @f() gc "name" { ...
1016 </pre>
1017 </div>
1018
1019 <p>The compiler declares the supported values of <i>name</i>. Specifying a
1020    collector which will cause the compiler to alter its output in order to
1021    support the named garbage collection algorithm.</p>
1022
1023 </div>
1024
1025 <!-- ======================================================================= -->
1026 <div class="doc_subsection">
1027   <a name="fnattrs">Function Attributes</a>
1028 </div>
1029
1030 <div class="doc_text">
1031
1032 <p>Function attributes are set to communicate additional information about a
1033    function. Function attributes are considered to be part of the function, not
1034    of the function type, so functions with different parameter attributes can
1035    have the same function type.</p>
1036
1037 <p>Function attributes are simple keywords that follow the type specified. If
1038    multiple attributes are needed, they are space separated. For example:</p>
1039
1040 <div class="doc_code">
1041 <pre>
1042 define void @f() noinline { ... }
1043 define void @f() alwaysinline { ... }
1044 define void @f() alwaysinline optsize { ... }
1045 define void @f() optsize
1046 </pre>
1047 </div>
1048
1049 <dl>
1050   <dt><tt>alwaysinline</tt></dt>
1051
1052   <dd>This attribute indicates that the inliner should attempt to inline this
1053       function into callers whenever possible, ignoring any active inlining size
1054       threshold for this caller.</dd>
1055
1056   <dt><tt>noinline</tt></dt>
1057
1058   <dd>This attribute indicates that the inliner should never inline this
1059       function in any situation. This attribute may not be used together with
1060       the <tt>alwaysinline</tt> attribute.</dd>
1061
1062   <dt><tt>optsize</tt></dt>
1063
1064   <dd>This attribute suggests that optimization passes and code generator passes
1065       make choices that keep the code size of this function low, and otherwise
1066       do optimizations specifically to reduce code size.</dd>
1067
1068   <dt><tt>noreturn</tt></dt>
1069
1070   <dd>This function attribute indicates that the function never returns
1071       normally.  This produces undefined behavior at runtime if the function
1072       ever does dynamically return.</dd>
1073
1074   <dt><tt>nounwind</tt></dt>
1075
1076   <dd>This function attribute indicates that the function never returns with an
1077       unwind or exceptional control flow.  If the function does unwind, its
1078       runtime behavior is undefined.</dd>
1079
1080   <dt><tt>readnone</tt></dt>
1081
1082   <dd>This attribute indicates that the function computes its result (or decides
1083       to unwind an exception) based strictly on its arguments, without
1084       dereferencing any pointer arguments or otherwise accessing any mutable
1085       state (e.g. memory, control registers, etc) visible to caller functions.
1086       It does not write through any pointer arguments
1087       (including <tt><a href="#byval">byval</a></tt> arguments) and never
1088       changes any state visible to callers.  This means that it cannot unwind
1089       exceptions by calling the <tt>C++</tt> exception throwing methods, but
1090       could use the <tt>unwind</tt> instruction.</dd>
1091
1092   <dt><tt><a name="readonly">readonly</a></tt></dt>
1093
1094   <dd>This attribute indicates that the function does not write through any
1095       pointer arguments (including <tt><a href="#byval">byval</a></tt>
1096       arguments) or otherwise modify any state (e.g. memory, control registers,
1097       etc) visible to caller functions.  It may dereference pointer arguments
1098       and read state that may be set in the caller.  A readonly function always
1099       returns the same value (or unwinds an exception identically) when called
1100       with the same set of arguments and global state.  It cannot unwind an
1101       exception by calling the <tt>C++</tt> exception throwing methods, but may
1102       use the <tt>unwind</tt> instruction.</dd>
1103
1104   <dt><tt><a name="ssp">ssp</a></tt></dt>
1105
1106   <dd>This attribute indicates that the function should emit a stack smashing
1107       protector. It is in the form of a "canary"&mdash;a random value placed on
1108       the stack before the local variables that's checked upon return from the
1109       function to see if it has been overwritten. A heuristic is used to
1110       determine if a function needs stack protectors or not.<br>
1111 <br>
1112       If a function that has an <tt>ssp</tt> attribute is inlined into a
1113       function that doesn't have an <tt>ssp</tt> attribute, then the resulting
1114       function will have an <tt>ssp</tt> attribute.</dd>
1115
1116   <dt><tt>sspreq</tt></dt>
1117
1118   <dd>This attribute indicates that the function should <em>always</em> emit a
1119       stack smashing protector. This overrides
1120       the <tt><a href="#ssp">ssp</a></tt> function attribute.
1121
1122      If a function that has an <tt>sspreq</tt> attribute is inlined into a
1123      function that doesn't have an <tt>sspreq</tt> attribute or which has
1124      an <tt>ssp</tt> attribute, then the resulting function will have
1125      an <tt>sspreq</tt> attribute.</dd>
1126
1127   <dt><tt>noredzone</tt></dt>
1128
1129   <dd>This attribute indicates that the code generator should not use a red
1130       zone, even if the target-specific ABI normally permits it.</dd>
1131
1132   <dt><tt>noimplicitfloat</tt></dt>
1133
1134   <dd>This attributes disables implicit floating point instructions.</dd>
1135
1136   <dt><tt>naked</tt></dt>
1137
1138   <dd>This attribute disables prologue / epilogue emission for the function.
1139       This can have very system-specific consequences.</dd>
1140 </dl>
1141
1142 </div>
1143
1144 <!-- ======================================================================= -->
1145 <div class="doc_subsection">
1146   <a name="moduleasm">Module-Level Inline Assembly</a>
1147 </div>
1148
1149 <div class="doc_text">
1150
1151 <p>Modules may contain "module-level inline asm" blocks, which corresponds to
1152    the GCC "file scope inline asm" blocks.  These blocks are internally
1153    concatenated by LLVM and treated as a single unit, but may be separated in
1154    the <tt>.ll</tt> file if desired.  The syntax is very simple:</p>
1155
1156 <div class="doc_code">
1157 <pre>
1158 module asm "inline asm code goes here"
1159 module asm "more can go here"
1160 </pre>
1161 </div>
1162
1163 <p>The strings can contain any character by escaping non-printable characters.
1164    The escape sequence used is simply "\xx" where "xx" is the two digit hex code
1165    for the number.</p>
1166
1167 <p>The inline asm code is simply printed to the machine code .s file when
1168    assembly code is generated.</p>
1169
1170 </div>
1171
1172 <!-- ======================================================================= -->
1173 <div class="doc_subsection">
1174   <a name="datalayout">Data Layout</a>
1175 </div>
1176
1177 <div class="doc_text">
1178
1179 <p>A module may specify a target specific data layout string that specifies how
1180    data is to be laid out in memory. The syntax for the data layout is
1181    simply:</p>
1182
1183 <div class="doc_code">
1184 <pre>
1185 target datalayout = "<i>layout specification</i>"
1186 </pre>
1187 </div>
1188
1189 <p>The <i>layout specification</i> consists of a list of specifications
1190    separated by the minus sign character ('-').  Each specification starts with
1191    a letter and may include other information after the letter to define some
1192    aspect of the data layout.  The specifications accepted are as follows:</p>
1193
1194 <dl>
1195   <dt><tt>E</tt></dt>
1196
1197   <dd>Specifies that the target lays out data in big-endian form. That is, the
1198       bits with the most significance have the lowest address location.</dd>
1199
1200   <dt><tt>e</tt></dt>
1201
1202   <dd>Specifies that the target lays out data in little-endian form. That is,
1203       the bits with the least significance have the lowest address
1204       location.</dd>
1205
1206   <dt><tt>p:<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1207
1208   <dd>This specifies the <i>size</i> of a pointer and its <i>abi</i> and 
1209       <i>preferred</i> alignments. All sizes are in bits. Specifying
1210       the <i>pref</i> alignment is optional. If omitted, the
1211       preceding <tt>:</tt> should be omitted too.</dd>
1212
1213   <dt><tt>i<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1214
1215   <dd>This specifies the alignment for an integer type of a given bit
1216       <i>size</i>. The value of <i>size</i> must be in the range [1,2^23).</dd>
1217
1218   <dt><tt>v<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1219
1220   <dd>This specifies the alignment for a vector type of a given bit 
1221       <i>size</i>.</dd>
1222
1223   <dt><tt>f<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1224
1225   <dd>This specifies the alignment for a floating point type of a given bit 
1226       <i>size</i>. The value of <i>size</i> must be either 32 (float) or 64
1227       (double).</dd>
1228
1229   <dt><tt>a<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1230
1231   <dd>This specifies the alignment for an aggregate type of a given bit
1232       <i>size</i>.</dd>
1233
1234   <dt><tt>s<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1235
1236   <dd>This specifies the alignment for a stack object of a given bit
1237       <i>size</i>.</dd>
1238 </dl>
1239
1240 <p>When constructing the data layout for a given target, LLVM starts with a
1241    default set of specifications which are then (possibly) overriden by the
1242    specifications in the <tt>datalayout</tt> keyword. The default specifications
1243    are given in this list:</p>
1244
1245 <ul>
1246   <li><tt>E</tt> - big endian</li>
1247   <li><tt>p:32:64:64</tt> - 32-bit pointers with 64-bit alignment</li>
1248   <li><tt>i1:8:8</tt> - i1 is 8-bit (byte) aligned</li>
1249   <li><tt>i8:8:8</tt> - i8 is 8-bit (byte) aligned</li>
1250   <li><tt>i16:16:16</tt> - i16 is 16-bit aligned</li>
1251   <li><tt>i32:32:32</tt> - i32 is 32-bit aligned</li>
1252   <li><tt>i64:32:64</tt> - i64 has ABI alignment of 32-bits but preferred
1253   alignment of 64-bits</li>
1254   <li><tt>f32:32:32</tt> - float is 32-bit aligned</li>
1255   <li><tt>f64:64:64</tt> - double is 64-bit aligned</li>
1256   <li><tt>v64:64:64</tt> - 64-bit vector is 64-bit aligned</li>
1257   <li><tt>v128:128:128</tt> - 128-bit vector is 128-bit aligned</li>
1258   <li><tt>a0:0:1</tt> - aggregates are 8-bit aligned</li>
1259   <li><tt>s0:64:64</tt> - stack objects are 64-bit aligned</li>
1260 </ul>
1261
1262 <p>When LLVM is determining the alignment for a given type, it uses the
1263    following rules:</p>
1264
1265 <ol>
1266   <li>If the type sought is an exact match for one of the specifications, that
1267       specification is used.</li>
1268
1269   <li>If no match is found, and the type sought is an integer type, then the
1270       smallest integer type that is larger than the bitwidth of the sought type
1271       is used. If none of the specifications are larger than the bitwidth then
1272       the the largest integer type is used. For example, given the default
1273       specifications above, the i7 type will use the alignment of i8 (next
1274       largest) while both i65 and i256 will use the alignment of i64 (largest
1275       specified).</li>
1276
1277   <li>If no match is found, and the type sought is a vector type, then the
1278       largest vector type that is smaller than the sought vector type will be
1279       used as a fall back.  This happens because &lt;128 x double&gt; can be
1280       implemented in terms of 64 &lt;2 x double&gt;, for example.</li>
1281 </ol>
1282
1283 </div>
1284
1285 <!-- *********************************************************************** -->
1286 <div class="doc_section"> <a name="typesystem">Type System</a> </div>
1287 <!-- *********************************************************************** -->
1288
1289 <div class="doc_text">
1290
1291 <p>The LLVM type system is one of the most important features of the
1292    intermediate representation.  Being typed enables a number of optimizations
1293    to be performed on the intermediate representation directly, without having
1294    to do extra analyses on the side before the transformation.  A strong type
1295    system makes it easier to read the generated code and enables novel analyses
1296    and transformations that are not feasible to perform on normal three address
1297    code representations.</p>
1298
1299 </div>
1300
1301 <!-- ======================================================================= -->
1302 <div class="doc_subsection"> <a name="t_classifications">Type
1303 Classifications</a> </div>
1304
1305 <div class="doc_text">
1306
1307 <p>The types fall into a few useful classifications:</p>
1308
1309 <table border="1" cellspacing="0" cellpadding="4">
1310   <tbody>
1311     <tr><th>Classification</th><th>Types</th></tr>
1312     <tr>
1313       <td><a href="#t_integer">integer</a></td>
1314       <td><tt>i1, i2, i3, ... i8, ... i16, ... i32, ... i64, ... </tt></td>
1315     </tr>
1316     <tr>
1317       <td><a href="#t_floating">floating point</a></td>
1318       <td><tt>float, double, x86_fp80, fp128, ppc_fp128</tt></td>
1319     </tr>
1320     <tr>
1321       <td><a name="t_firstclass">first class</a></td>
1322       <td><a href="#t_integer">integer</a>,
1323           <a href="#t_floating">floating point</a>,
1324           <a href="#t_pointer">pointer</a>,
1325           <a href="#t_vector">vector</a>,
1326           <a href="#t_struct">structure</a>,
1327           <a href="#t_array">array</a>,
1328           <a href="#t_label">label</a>,
1329           <a href="#t_metadata">metadata</a>.
1330       </td>
1331     </tr>
1332     <tr>
1333       <td><a href="#t_primitive">primitive</a></td>
1334       <td><a href="#t_label">label</a>,
1335           <a href="#t_void">void</a>,
1336           <a href="#t_floating">floating point</a>,
1337           <a href="#t_metadata">metadata</a>.</td>
1338     </tr>
1339     <tr>
1340       <td><a href="#t_derived">derived</a></td>
1341       <td><a href="#t_integer">integer</a>,
1342           <a href="#t_array">array</a>,
1343           <a href="#t_function">function</a>,
1344           <a href="#t_pointer">pointer</a>,
1345           <a href="#t_struct">structure</a>,
1346           <a href="#t_pstruct">packed structure</a>,
1347           <a href="#t_vector">vector</a>,
1348           <a href="#t_opaque">opaque</a>.
1349       </td>
1350     </tr>
1351   </tbody>
1352 </table>
1353
1354 <p>The <a href="#t_firstclass">first class</a> types are perhaps the most
1355    important.  Values of these types are the only ones which can be produced by
1356    instructions, passed as arguments, or used as operands to instructions.</p>
1357
1358 </div>
1359
1360 <!-- ======================================================================= -->
1361 <div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
1362
1363 <div class="doc_text">
1364
1365 <p>The primitive types are the fundamental building blocks of the LLVM
1366    system.</p>
1367
1368 </div>
1369
1370 <!-- _______________________________________________________________________ -->
1371 <div class="doc_subsubsection"> <a name="t_floating">Floating Point Types</a> </div>
1372
1373 <div class="doc_text">
1374
1375 <table>
1376   <tbody>
1377     <tr><th>Type</th><th>Description</th></tr>
1378     <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr>
1379     <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr>
1380     <tr><td><tt>fp128</tt></td><td>128-bit floating point value (112-bit mantissa)</td></tr>
1381     <tr><td><tt>x86_fp80</tt></td><td>80-bit floating point value (X87)</td></tr>
1382     <tr><td><tt>ppc_fp128</tt></td><td>128-bit floating point value (two 64-bits)</td></tr>
1383   </tbody>
1384 </table>
1385
1386 </div>
1387
1388 <!-- _______________________________________________________________________ -->
1389 <div class="doc_subsubsection"> <a name="t_void">Void Type</a> </div>
1390
1391 <div class="doc_text">
1392 <h5>Overview:</h5>
1393 <p>The void type does not represent any value and has no size.</p>
1394
1395 <h5>Syntax:</h5>
1396
1397 <pre>
1398   void
1399 </pre>
1400 </div>
1401
1402 <!-- _______________________________________________________________________ -->
1403 <div class="doc_subsubsection"> <a name="t_label">Label Type</a> </div>
1404
1405 <div class="doc_text">
1406 <h5>Overview:</h5>
1407 <p>The label type represents code labels.</p>
1408
1409 <h5>Syntax:</h5>
1410
1411 <pre>
1412   label
1413 </pre>
1414 </div>
1415
1416 <!-- _______________________________________________________________________ -->
1417 <div class="doc_subsubsection"> <a name="t_metadata">Metadata Type</a> </div>
1418
1419 <div class="doc_text">
1420 <h5>Overview:</h5>
1421 <p>The metadata type represents embedded metadata. The only derived type that
1422    may contain metadata is <tt>metadata*</tt> or a function type that returns or
1423    takes metadata typed parameters, but not pointer to metadata types.</p>
1424
1425 <h5>Syntax:</h5>
1426
1427 <pre>
1428   metadata
1429 </pre>
1430 </div>
1431
1432
1433 <!-- ======================================================================= -->
1434 <div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
1435
1436 <div class="doc_text">
1437
1438 <p>The real power in LLVM comes from the derived types in the system.  This is
1439    what allows a programmer to represent arrays, functions, pointers, and other
1440    useful types.  Note that these derived types may be recursive: For example,
1441    it is possible to have a two dimensional array.</p>
1442
1443 </div>
1444
1445 <!-- _______________________________________________________________________ -->
1446 <div class="doc_subsubsection"> <a name="t_integer">Integer Type</a> </div>
1447
1448 <div class="doc_text">
1449
1450 <h5>Overview:</h5>
1451 <p>The integer type is a very simple derived type that simply specifies an
1452    arbitrary bit width for the integer type desired. Any bit width from 1 bit to
1453    2^23-1 (about 8 million) can be specified.</p>
1454
1455 <h5>Syntax:</h5>
1456
1457 <pre>
1458   iN
1459 </pre>
1460
1461 <p>The number of bits the integer will occupy is specified by the <tt>N</tt>
1462    value.</p>
1463
1464 <h5>Examples:</h5>
1465 <table class="layout">
1466   <tr class="layout">
1467     <td class="left"><tt>i1</tt></td>
1468     <td class="left">a single-bit integer.</td>
1469   </tr>
1470   <tr class="layout">
1471     <td class="left"><tt>i32</tt></td>
1472     <td class="left">a 32-bit integer.</td>
1473   </tr>
1474   <tr class="layout">
1475     <td class="left"><tt>i1942652</tt></td>
1476     <td class="left">a really big integer of over 1 million bits.</td>
1477   </tr>
1478 </table>
1479
1480 <p>Note that the code generator does not yet support large integer types to be
1481    used as function return types. The specific limit on how large a return type
1482    the code generator can currently handle is target-dependent; currently it's
1483    often 64 bits for 32-bit targets and 128 bits for 64-bit targets.</p>
1484
1485 </div>
1486
1487 <!-- _______________________________________________________________________ -->
1488 <div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
1489
1490 <div class="doc_text">
1491
1492 <h5>Overview:</h5>
1493 <p>The array type is a very simple derived type that arranges elements
1494    sequentially in memory.  The array type requires a size (number of elements)
1495    and an underlying data type.</p>
1496
1497 <h5>Syntax:</h5>
1498
1499 <pre>
1500   [&lt;# elements&gt; x &lt;elementtype&gt;]
1501 </pre>
1502
1503 <p>The number of elements is a constant integer value; <tt>elementtype</tt> may
1504    be any type with a size.</p>
1505
1506 <h5>Examples:</h5>
1507 <table class="layout">
1508   <tr class="layout">
1509     <td class="left"><tt>[40 x i32]</tt></td>
1510     <td class="left">Array of 40 32-bit integer values.</td>
1511   </tr>
1512   <tr class="layout">
1513     <td class="left"><tt>[41 x i32]</tt></td>
1514     <td class="left">Array of 41 32-bit integer values.</td>
1515   </tr>
1516   <tr class="layout">
1517     <td class="left"><tt>[4 x i8]</tt></td>
1518     <td class="left">Array of 4 8-bit integer values.</td>
1519   </tr>
1520 </table>
1521 <p>Here are some examples of multidimensional arrays:</p>
1522 <table class="layout">
1523   <tr class="layout">
1524     <td class="left"><tt>[3 x [4 x i32]]</tt></td>
1525     <td class="left">3x4 array of 32-bit integer values.</td>
1526   </tr>
1527   <tr class="layout">
1528     <td class="left"><tt>[12 x [10 x float]]</tt></td>
1529     <td class="left">12x10 array of single precision floating point values.</td>
1530   </tr>
1531   <tr class="layout">
1532     <td class="left"><tt>[2 x [3 x [4 x i16]]]</tt></td>
1533     <td class="left">2x3x4 array of 16-bit integer  values.</td>
1534   </tr>
1535 </table>
1536
1537 <p>Note that 'variable sized arrays' can be implemented in LLVM with a zero
1538    length array.  Normally, accesses past the end of an array are undefined in
1539    LLVM (e.g. it is illegal to access the 5th element of a 3 element array).  As
1540    a special case, however, zero length arrays are recognized to be variable
1541    length.  This allows implementation of 'pascal style arrays' with the LLVM
1542    type "<tt>{ i32, [0 x float]}</tt>", for example.</p>
1543
1544 <p>Note that the code generator does not yet support large aggregate types to be
1545    used as function return types. The specific limit on how large an aggregate
1546    return type the code generator can currently handle is target-dependent, and
1547    also dependent on the aggregate element types.</p>
1548
1549 </div>
1550
1551 <!-- _______________________________________________________________________ -->
1552 <div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
1553
1554 <div class="doc_text">
1555
1556 <h5>Overview:</h5>
1557 <p>The function type can be thought of as a function signature.  It consists of
1558    a return type and a list of formal parameter types. The return type of a
1559    function type is a scalar type, a void type, or a struct type.  If the return
1560    type is a struct type then all struct elements must be of first class types,
1561    and the struct must have at least one element.</p>
1562
1563 <h5>Syntax:</h5>
1564
1565 <pre>
1566   &lt;returntype list&gt; (&lt;parameter list&gt;)
1567 </pre>
1568
1569 <p>...where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
1570    specifiers.  Optionally, the parameter list may include a type <tt>...</tt>,
1571    which indicates that the function takes a variable number of arguments.
1572    Variable argument functions can access their arguments with
1573    the <a href="#int_varargs">variable argument handling intrinsic</a>
1574    functions.  '<tt>&lt;returntype list&gt;</tt>' is a comma-separated list of
1575    <a href="#t_firstclass">first class</a> type specifiers.</p>
1576
1577 <h5>Examples:</h5>
1578 <table class="layout">
1579   <tr class="layout">
1580     <td class="left"><tt>i32 (i32)</tt></td>
1581     <td class="left">function taking an <tt>i32</tt>, returning an <tt>i32</tt>
1582     </td>
1583   </tr><tr class="layout">
1584     <td class="left"><tt>float&nbsp;(i16&nbsp;signext,&nbsp;i32&nbsp;*)&nbsp;*
1585     </tt></td>
1586     <td class="left"><a href="#t_pointer">Pointer</a> to a function that takes 
1587       an <tt>i16</tt> that should be sign extended and a 
1588       <a href="#t_pointer">pointer</a> to <tt>i32</tt>, returning 
1589       <tt>float</tt>.
1590     </td>
1591   </tr><tr class="layout">
1592     <td class="left"><tt>i32 (i8*, ...)</tt></td>
1593     <td class="left">A vararg function that takes at least one 
1594       <a href="#t_pointer">pointer</a> to <tt>i8 </tt> (char in C), 
1595       which returns an integer.  This is the signature for <tt>printf</tt> in 
1596       LLVM.
1597     </td>
1598   </tr><tr class="layout">
1599     <td class="left"><tt>{i32, i32} (i32)</tt></td>
1600     <td class="left">A function taking an <tt>i32</tt>, returning two 
1601         <tt>i32</tt> values as an aggregate of type <tt>{ i32, i32 }</tt>
1602     </td>
1603   </tr>
1604 </table>
1605
1606 </div>
1607
1608 <!-- _______________________________________________________________________ -->
1609 <div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
1610
1611 <div class="doc_text">
1612
1613 <h5>Overview:</h5>
1614 <p>The structure type is used to represent a collection of data members together
1615    in memory.  The packing of the field types is defined to match the ABI of the
1616    underlying processor.  The elements of a structure may be any type that has a
1617    size.</p>
1618
1619 <p>Structures are accessed using '<tt><a href="#i_load">load</a></tt> and
1620    '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a field with
1621    the '<tt><a href="#i_getelementptr">getelementptr</a></tt>' instruction.</p>
1622
1623 <h5>Syntax:</h5>
1624
1625 <pre>  { &lt;type list&gt; }<br></pre>
1626
1627 <h5>Examples:</h5>
1628 <table class="layout">
1629   <tr class="layout">
1630     <td class="left"><tt>{ i32, i32, i32 }</tt></td>
1631     <td class="left">A triple of three <tt>i32</tt> values</td>
1632   </tr><tr class="layout">
1633     <td class="left"><tt>{&nbsp;float,&nbsp;i32&nbsp;(i32)&nbsp;*&nbsp;}</tt></td>
1634     <td class="left">A pair, where the first element is a <tt>float</tt> and the
1635       second element is a <a href="#t_pointer">pointer</a> to a
1636       <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning
1637       an <tt>i32</tt>.</td>
1638   </tr>
1639 </table>
1640
1641 <p>Note that the code generator does not yet support large aggregate types to be
1642    used as function return types. The specific limit on how large an aggregate
1643    return type the code generator can currently handle is target-dependent, and
1644    also dependent on the aggregate element types.</p>
1645
1646 </div>
1647
1648 <!-- _______________________________________________________________________ -->
1649 <div class="doc_subsubsection"> <a name="t_pstruct">Packed Structure Type</a>
1650 </div>
1651
1652 <div class="doc_text">
1653
1654 <h5>Overview:</h5>
1655 <p>The packed structure type is used to represent a collection of data members
1656    together in memory.  There is no padding between fields.  Further, the
1657    alignment of a packed structure is 1 byte.  The elements of a packed
1658    structure may be any type that has a size.</p>
1659
1660 <p>Structures are accessed using '<tt><a href="#i_load">load</a></tt> and
1661    '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a field with
1662    the '<tt><a href="#i_getelementptr">getelementptr</a></tt>' instruction.</p>
1663
1664 <h5>Syntax:</h5>
1665
1666 <pre>  &lt; { &lt;type list&gt; } &gt; <br></pre>
1667
1668 <h5>Examples:</h5>
1669 <table class="layout">
1670   <tr class="layout">
1671     <td class="left"><tt>&lt; { i32, i32, i32 } &gt;</tt></td>
1672     <td class="left">A triple of three <tt>i32</tt> values</td>
1673   </tr><tr class="layout">
1674   <td class="left">
1675 <tt>&lt;&nbsp;{&nbsp;float,&nbsp;i32&nbsp;(i32)*&nbsp;}&nbsp;&gt;</tt></td>
1676     <td class="left">A pair, where the first element is a <tt>float</tt> and the
1677       second element is a <a href="#t_pointer">pointer</a> to a
1678       <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning
1679       an <tt>i32</tt>.</td>
1680   </tr>
1681 </table>
1682
1683 </div>
1684
1685 <!-- _______________________________________________________________________ -->
1686 <div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
1687
1688 <div class="doc_text">
1689
1690 <h5>Overview:</h5>
1691 <p>As in many languages, the pointer type represents a pointer or reference to
1692    another object, which must live in memory. Pointer types may have an optional
1693    address space attribute defining the target-specific numbered address space
1694    where the pointed-to object resides. The default address space is zero.</p>
1695
1696 <p>Note that LLVM does not permit pointers to void (<tt>void*</tt>) nor does it
1697    permit pointers to labels (<tt>label*</tt>).  Use <tt>i8*</tt> instead.</p>
1698
1699 <h5>Syntax:</h5>
1700
1701 <pre>  &lt;type&gt; *<br></pre>
1702
1703 <h5>Examples:</h5>
1704 <table class="layout">
1705   <tr class="layout">
1706     <td class="left"><tt>[4 x i32]*</tt></td>
1707     <td class="left">A <a href="#t_pointer">pointer</a> to <a
1708                     href="#t_array">array</a> of four <tt>i32</tt> values.</td>
1709   </tr>
1710   <tr class="layout">
1711     <td class="left"><tt>i32 (i32 *) *</tt></td>
1712     <td class="left"> A <a href="#t_pointer">pointer</a> to a <a
1713       href="#t_function">function</a> that takes an <tt>i32*</tt>, returning an
1714       <tt>i32</tt>.</td>
1715   </tr>
1716   <tr class="layout">
1717     <td class="left"><tt>i32 addrspace(5)*</tt></td>
1718     <td class="left">A <a href="#t_pointer">pointer</a> to an <tt>i32</tt> value
1719      that resides in address space #5.</td>
1720   </tr>
1721 </table>
1722
1723 </div>
1724
1725 <!-- _______________________________________________________________________ -->
1726 <div class="doc_subsubsection"> <a name="t_vector">Vector Type</a> </div>
1727
1728 <div class="doc_text">
1729
1730 <h5>Overview:</h5>
1731 <p>A vector type is a simple derived type that represents a vector of elements.
1732    Vector types are used when multiple primitive data are operated in parallel
1733    using a single instruction (SIMD).  A vector type requires a size (number of
1734    elements) and an underlying primitive data type.  Vectors must have a power
1735    of two length (1, 2, 4, 8, 16 ...).  Vector types are considered
1736    <a href="#t_firstclass">first class</a>.</p>
1737
1738 <h5>Syntax:</h5>
1739
1740 <pre>
1741   &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;
1742 </pre>
1743
1744 <p>The number of elements is a constant integer value; elementtype may be any
1745    integer or floating point type.</p>
1746
1747 <h5>Examples:</h5>
1748
1749 <table class="layout">
1750   <tr class="layout">
1751     <td class="left"><tt>&lt;4 x i32&gt;</tt></td>
1752     <td class="left">Vector of 4 32-bit integer values.</td>
1753   </tr>
1754   <tr class="layout">
1755     <td class="left"><tt>&lt;8 x float&gt;</tt></td>
1756     <td class="left">Vector of 8 32-bit floating-point values.</td>
1757   </tr>
1758   <tr class="layout">
1759     <td class="left"><tt>&lt;2 x i64&gt;</tt></td>
1760     <td class="left">Vector of 2 64-bit integer values.</td>
1761   </tr>
1762 </table>
1763
1764 <p>Note that the code generator does not yet support large vector types to be
1765    used as function return types. The specific limit on how large a vector
1766    return type codegen can currently handle is target-dependent; currently it's
1767    often a few times longer than a hardware vector register.</p>
1768
1769 </div>
1770
1771 <!-- _______________________________________________________________________ -->
1772 <div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div>
1773 <div class="doc_text">
1774
1775 <h5>Overview:</h5>
1776 <p>Opaque types are used to represent unknown types in the system.  This
1777    corresponds (for example) to the C notion of a forward declared structure
1778    type.  In LLVM, opaque types can eventually be resolved to any type (not just
1779    a structure type).</p>
1780
1781 <h5>Syntax:</h5>
1782
1783 <pre>
1784   opaque
1785 </pre>
1786
1787 <h5>Examples:</h5>
1788
1789 <table class="layout">
1790   <tr class="layout">
1791     <td class="left"><tt>opaque</tt></td>
1792     <td class="left">An opaque type.</td>
1793   </tr>
1794 </table>
1795
1796 </div>
1797
1798 <!-- ======================================================================= -->
1799 <div class="doc_subsection">
1800   <a name="t_uprefs">Type Up-references</a>
1801 </div>
1802
1803 <div class="doc_text">
1804
1805 <h5>Overview:</h5>
1806 <p>An "up reference" allows you to refer to a lexically enclosing type without
1807    requiring it to have a name. For instance, a structure declaration may
1808    contain a pointer to any of the types it is lexically a member of.  Example
1809    of up references (with their equivalent as named type declarations)
1810    include:</p>
1811
1812 <pre>
1813    { \2 * }                %x = type { %x* }
1814    { \2 }*                 %y = type { %y }*
1815    \1*                     %z = type %z*
1816 </pre>
1817
1818 <p>An up reference is needed by the asmprinter for printing out cyclic types
1819    when there is no declared name for a type in the cycle.  Because the
1820    asmprinter does not want to print out an infinite type string, it needs a
1821    syntax to handle recursive types that have no names (all names are optional
1822    in llvm IR).</p>
1823
1824 <h5>Syntax:</h5>
1825
1826 <pre>
1827    \&lt;level&gt;
1828 </pre>
1829
1830 <p>The level is the count of the lexical type that is being referred to.</p>
1831
1832 <h5>Examples:</h5>
1833
1834 <table class="layout">
1835   <tr class="layout">
1836     <td class="left"><tt>\1*</tt></td>
1837     <td class="left">Self-referential pointer.</td>
1838   </tr>
1839   <tr class="layout">
1840     <td class="left"><tt>{ { \3*, i8 }, i32 }</tt></td>
1841     <td class="left">Recursive structure where the upref refers to the out-most
1842                      structure.</td>
1843   </tr>
1844 </table>
1845
1846 </div>
1847
1848 <!-- *********************************************************************** -->
1849 <div class="doc_section"> <a name="constants">Constants</a> </div>
1850 <!-- *********************************************************************** -->
1851
1852 <div class="doc_text">
1853
1854 <p>LLVM has several different basic types of constants.  This section describes
1855    them all and their syntax.</p>
1856
1857 </div>
1858
1859 <!-- ======================================================================= -->
1860 <div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
1861
1862 <div class="doc_text">
1863
1864 <dl>
1865   <dt><b>Boolean constants</b></dt>
1866
1867   <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
1868       constants of the <tt><a href="#t_primitive">i1</a></tt> type.</dd>
1869
1870   <dt><b>Integer constants</b></dt>
1871
1872   <dd>Standard integers (such as '4') are constants of
1873       the <a href="#t_integer">integer</a> type.  Negative numbers may be used
1874       with integer types.</dd>
1875
1876   <dt><b>Floating point constants</b></dt>
1877
1878   <dd>Floating point constants use standard decimal notation (e.g. 123.421),
1879       exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
1880       notation (see below).  The assembler requires the exact decimal value of a
1881       floating-point constant.  For example, the assembler accepts 1.25 but
1882       rejects 1.3 because 1.3 is a repeating decimal in binary.  Floating point
1883       constants must have a <a href="#t_floating">floating point</a> type. </dd>
1884
1885   <dt><b>Null pointer constants</b></dt>
1886
1887   <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
1888       and must be of <a href="#t_pointer">pointer type</a>.</dd>
1889 </dl>
1890
1891 <p>The one non-intuitive notation for constants is the hexadecimal form of
1892    floating point constants.  For example, the form '<tt>double
1893    0x432ff973cafa8000</tt>' is equivalent to (but harder to read than)
1894    '<tt>double 4.5e+15</tt>'.  The only time hexadecimal floating point
1895    constants are required (and the only time that they are generated by the
1896    disassembler) is when a floating point constant must be emitted but it cannot
1897    be represented as a decimal floating point number in a reasonable number of
1898    digits.  For example, NaN's, infinities, and other special values are
1899    represented in their IEEE hexadecimal format so that assembly and disassembly
1900    do not cause any bits to change in the constants.</p>
1901
1902 <p>When using the hexadecimal form, constants of types float and double are
1903    represented using the 16-digit form shown above (which matches the IEEE754
1904    representation for double); float values must, however, be exactly
1905    representable as IEE754 single precision.  Hexadecimal format is always used
1906    for long double, and there are three forms of long double.  The 80-bit format
1907    used by x86 is represented as <tt>0xK</tt> followed by 20 hexadecimal digits.
1908    The 128-bit format used by PowerPC (two adjacent doubles) is represented
1909    by <tt>0xM</tt> followed by 32 hexadecimal digits.  The IEEE 128-bit format
1910    is represented by <tt>0xL</tt> followed by 32 hexadecimal digits; no
1911    currently supported target uses this format.  Long doubles will only work if
1912    they match the long double format on your target.  All hexadecimal formats
1913    are big-endian (sign bit at the left).</p>
1914
1915 </div>
1916
1917 <!-- ======================================================================= -->
1918 <div class="doc_subsection">
1919 <a name="aggregateconstants"></a> <!-- old anchor -->
1920 <a name="complexconstants">Complex Constants</a>
1921 </div>
1922
1923 <div class="doc_text">
1924
1925 <p>Complex constants are a (potentially recursive) combination of simple
1926    constants and smaller complex constants.</p>
1927
1928 <dl>
1929   <dt><b>Structure constants</b></dt>
1930
1931   <dd>Structure constants are represented with notation similar to structure
1932       type definitions (a comma separated list of elements, surrounded by braces
1933       (<tt>{}</tt>)).  For example: "<tt>{ i32 4, float 17.0, i32* @G }</tt>",
1934       where "<tt>@G</tt>" is declared as "<tt>@G = external global i32</tt>".
1935       Structure constants must have <a href="#t_struct">structure type</a>, and
1936       the number and types of elements must match those specified by the
1937       type.</dd>
1938
1939   <dt><b>Array constants</b></dt>
1940
1941   <dd>Array constants are represented with notation similar to array type
1942      definitions (a comma separated list of elements, surrounded by square
1943      brackets (<tt>[]</tt>)).  For example: "<tt>[ i32 42, i32 11, i32 74
1944      ]</tt>".  Array constants must have <a href="#t_array">array type</a>, and
1945      the number and types of elements must match those specified by the
1946      type.</dd>
1947
1948   <dt><b>Vector constants</b></dt>
1949
1950   <dd>Vector constants are represented with notation similar to vector type
1951       definitions (a comma separated list of elements, surrounded by
1952       less-than/greater-than's (<tt>&lt;&gt;</tt>)).  For example: "<tt>&lt; i32
1953       42, i32 11, i32 74, i32 100 &gt;</tt>".  Vector constants must
1954       have <a href="#t_vector">vector type</a>, and the number and types of
1955       elements must match those specified by the type.</dd>
1956
1957   <dt><b>Zero initialization</b></dt>
1958
1959   <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
1960       value to zero of <em>any</em> type, including scalar and aggregate types.
1961       This is often used to avoid having to print large zero initializers
1962       (e.g. for large arrays) and is always exactly equivalent to using explicit
1963       zero initializers.</dd>
1964
1965   <dt><b>Metadata node</b></dt>
1966
1967   <dd>A metadata node is a structure-like constant with
1968       <a href="#t_metadata">metadata type</a>.  For example: "<tt>metadata !{
1969       i32 0, metadata !"test" }</tt>".  Unlike other constants that are meant to
1970       be interpreted as part of the instruction stream, metadata is a place to
1971       attach additional information such as debug info.</dd>
1972 </dl>
1973
1974 </div>
1975
1976 <!-- ======================================================================= -->
1977 <div class="doc_subsection">
1978   <a name="globalconstants">Global Variable and Function Addresses</a>
1979 </div>
1980
1981 <div class="doc_text">
1982
1983 <p>The addresses of <a href="#globalvars">global variables</a>
1984    and <a href="#functionstructure">functions</a> are always implicitly valid
1985    (link-time) constants.  These constants are explicitly referenced when
1986    the <a href="#identifiers">identifier for the global</a> is used and always
1987    have <a href="#t_pointer">pointer</a> type. For example, the following is a
1988    legal LLVM file:</p>
1989
1990 <div class="doc_code">
1991 <pre>
1992 @X = global i32 17
1993 @Y = global i32 42
1994 @Z = global [2 x i32*] [ i32* @X, i32* @Y ]
1995 </pre>
1996 </div>
1997
1998 </div>
1999
2000 <!-- ======================================================================= -->
2001 <div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
2002 <div class="doc_text">
2003
2004 <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has no
2005    specific value.  Undefined values may be of any type and be used anywhere a
2006    constant is permitted.</p>
2007
2008 <p>Undefined values indicate to the compiler that the program is well defined no
2009    matter what value is used, giving the compiler more freedom to optimize.</p>
2010
2011 </div>
2012
2013 <!-- ======================================================================= -->
2014 <div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
2015 </div>
2016
2017 <div class="doc_text">
2018
2019 <p>Constant expressions are used to allow expressions involving other constants
2020    to be used as constants.  Constant expressions may be of
2021    any <a href="#t_firstclass">first class</a> type and may involve any LLVM
2022    operation that does not have side effects (e.g. load and call are not
2023    supported).  The following is the syntax for constant expressions:</p>
2024
2025 <dl>
2026   <dt><b><tt>trunc ( CST to TYPE )</tt></b></dt>
2027
2028   <dd>Truncate a constant to another type. The bit size of CST must be larger
2029       than the bit size of TYPE. Both types must be integers.</dd>
2030
2031   <dt><b><tt>zext ( CST to TYPE )</tt></b></dt>
2032
2033   <dd>Zero extend a constant to another type. The bit size of CST must be
2034       smaller or equal to the bit size of TYPE.  Both types must be
2035       integers.</dd>
2036
2037   <dt><b><tt>sext ( CST to TYPE )</tt></b></dt>
2038
2039   <dd>Sign extend a constant to another type. The bit size of CST must be
2040       smaller or equal to the bit size of TYPE.  Both types must be
2041       integers.</dd>
2042
2043   <dt><b><tt>fptrunc ( CST to TYPE )</tt></b></dt>
2044
2045   <dd>Truncate a floating point constant to another floating point type. The
2046       size of CST must be larger than the size of TYPE. Both types must be
2047       floating point.</dd>
2048
2049   <dt><b><tt>fpext ( CST to TYPE )</tt></b></dt>
2050
2051   <dd>Floating point extend a constant to another type. The size of CST must be
2052       smaller or equal to the size of TYPE. Both types must be floating
2053       point.</dd>
2054
2055   <dt><b><tt>fptoui ( CST to TYPE )</tt></b></dt>
2056
2057   <dd>Convert a floating point constant to the corresponding unsigned integer
2058       constant. TYPE must be a scalar or vector integer type. CST must be of
2059       scalar or vector floating point type. Both CST and TYPE must be scalars,
2060       or vectors of the same number of elements. If the value won't fit in the
2061       integer type, the results are undefined.</dd>
2062
2063   <dt><b><tt>fptosi ( CST to TYPE )</tt></b></dt>
2064
2065   <dd>Convert a floating point constant to the corresponding signed integer
2066       constant.  TYPE must be a scalar or vector integer type. CST must be of
2067       scalar or vector floating point type. Both CST and TYPE must be scalars,
2068       or vectors of the same number of elements. If the value won't fit in the
2069       integer type, the results are undefined.</dd>
2070
2071   <dt><b><tt>uitofp ( CST to TYPE )</tt></b></dt>
2072
2073   <dd>Convert an unsigned integer constant to the corresponding floating point
2074       constant. TYPE must be a scalar or vector floating point type. CST must be
2075       of scalar or vector integer type. Both CST and TYPE must be scalars, or
2076       vectors of the same number of elements. If the value won't fit in the
2077       floating point type, the results are undefined.</dd>
2078
2079   <dt><b><tt>sitofp ( CST to TYPE )</tt></b></dt>
2080
2081   <dd>Convert a signed integer constant to the corresponding floating point
2082       constant. TYPE must be a scalar or vector floating point type. CST must be
2083       of scalar or vector integer type. Both CST and TYPE must be scalars, or
2084       vectors of the same number of elements. If the value won't fit in the
2085       floating point type, the results are undefined.</dd>
2086
2087   <dt><b><tt>ptrtoint ( CST to TYPE )</tt></b></dt>
2088
2089   <dd>Convert a pointer typed constant to the corresponding integer constant
2090       <tt>TYPE</tt> must be an integer type. <tt>CST</tt> must be of pointer
2091       type. The <tt>CST</tt> value is zero extended, truncated, or unchanged to
2092       make it fit in <tt>TYPE</tt>.</dd>
2093
2094   <dt><b><tt>inttoptr ( CST to TYPE )</tt></b></dt>
2095
2096   <dd>Convert a integer constant to a pointer constant.  TYPE must be a pointer
2097       type.  CST must be of integer type. The CST value is zero extended,
2098       truncated, or unchanged to make it fit in a pointer size. This one is
2099       <i>really</i> dangerous!</dd>
2100
2101   <dt><b><tt>bitcast ( CST to TYPE )</tt></b></dt>
2102
2103   <dd>Convert a constant, CST, to another TYPE. The constraints of the operands
2104       are the same as those for the <a href="#i_bitcast">bitcast
2105       instruction</a>.</dd>
2106
2107   <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
2108
2109   <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
2110       constants.  As with the <a href="#i_getelementptr">getelementptr</a>
2111       instruction, the index list may have zero or more indexes, which are
2112       required to make sense for the type of "CSTPTR".</dd>
2113
2114   <dt><b><tt>select ( COND, VAL1, VAL2 )</tt></b></dt>
2115
2116   <dd>Perform the <a href="#i_select">select operation</a> on constants.</dd>
2117
2118   <dt><b><tt>icmp COND ( VAL1, VAL2 )</tt></b></dt>
2119
2120   <dd>Performs the <a href="#i_icmp">icmp operation</a> on constants.</dd>
2121
2122   <dt><b><tt>fcmp COND ( VAL1, VAL2 )</tt></b></dt>
2123
2124   <dd>Performs the <a href="#i_fcmp">fcmp operation</a> on constants.</dd>
2125
2126   <dt><b><tt>extractelement ( VAL, IDX )</tt></b></dt>
2127
2128   <dd>Perform the <a href="#i_extractelement">extractelement operation</a> on
2129       constants.</dd>
2130
2131   <dt><b><tt>insertelement ( VAL, ELT, IDX )</tt></b></dt>
2132
2133   <dd>Perform the <a href="#i_insertelement">insertelement operation</a> on
2134     constants.</dd>
2135
2136   <dt><b><tt>shufflevector ( VEC1, VEC2, IDXMASK )</tt></b></dt>
2137
2138   <dd>Perform the <a href="#i_shufflevector">shufflevector operation</a> on
2139       constants.</dd>
2140
2141   <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
2142
2143   <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
2144       be any of the <a href="#binaryops">binary</a>
2145       or <a href="#bitwiseops">bitwise binary</a> operations.  The constraints
2146       on operands are the same as those for the corresponding instruction
2147       (e.g. no bitwise operations on floating point values are allowed).</dd>
2148 </dl>
2149
2150 </div>
2151
2152 <!-- ======================================================================= -->
2153 <div class="doc_subsection"><a name="metadata">Embedded Metadata</a>
2154 </div>
2155
2156 <div class="doc_text">
2157
2158 <p>Embedded metadata provides a way to attach arbitrary data to the instruction
2159    stream without affecting the behaviour of the program.  There are two
2160    metadata primitives, strings and nodes. All metadata has the
2161    <tt>metadata</tt> type and is identified in syntax by a preceding exclamation
2162    point ('<tt>!</tt>').</p>
2163
2164 <p>A metadata string is a string surrounded by double quotes.  It can contain
2165    any character by escaping non-printable characters with "\xx" where "xx" is
2166    the two digit hex code.  For example: "<tt>!"test\00"</tt>".</p>
2167
2168 <p>Metadata nodes are represented with notation similar to structure constants
2169    (a comma separated list of elements, surrounded by braces and preceeded by an
2170    exclamation point).  For example: "<tt>!{ metadata !"test\00", i32
2171    10}</tt>".</p>
2172
2173 <p>A metadata node will attempt to track changes to the values it holds. In the
2174    event that a value is deleted, it will be replaced with a typeless
2175    "<tt>null</tt>", such as "<tt>metadata !{null, i32 10}</tt>".</p>
2176
2177 <p>Optimizations may rely on metadata to provide additional information about
2178    the program that isn't available in the instructions, or that isn't easily
2179    computable. Similarly, the code generator may expect a certain metadata
2180    format to be used to express debugging information.</p>
2181
2182 </div>
2183
2184 <!-- *********************************************************************** -->
2185 <div class="doc_section"> <a name="othervalues">Other Values</a> </div>
2186 <!-- *********************************************************************** -->
2187
2188 <!-- ======================================================================= -->
2189 <div class="doc_subsection">
2190 <a name="inlineasm">Inline Assembler Expressions</a>
2191 </div>
2192
2193 <div class="doc_text">
2194
2195 <p>LLVM supports inline assembler expressions (as opposed
2196    to <a href="#moduleasm"> Module-Level Inline Assembly</a>) through the use of
2197    a special value.  This value represents the inline assembler as a string
2198    (containing the instructions to emit), a list of operand constraints (stored
2199    as a string), and a flag that indicates whether or not the inline asm
2200    expression has side effects.  An example inline assembler expression is:</p>
2201
2202 <div class="doc_code">
2203 <pre>
2204 i32 (i32) asm "bswap $0", "=r,r"
2205 </pre>
2206 </div>
2207
2208 <p>Inline assembler expressions may <b>only</b> be used as the callee operand of
2209    a <a href="#i_call"><tt>call</tt> instruction</a>.  Thus, typically we
2210    have:</p>
2211
2212 <div class="doc_code">
2213 <pre>
2214 %X = call i32 asm "<a href="#int_bswap">bswap</a> $0", "=r,r"(i32 %Y)
2215 </pre>
2216 </div>
2217
2218 <p>Inline asms with side effects not visible in the constraint list must be
2219    marked as having side effects.  This is done through the use of the
2220    '<tt>sideeffect</tt>' keyword, like so:</p>
2221
2222 <div class="doc_code">
2223 <pre>
2224 call void asm sideeffect "eieio", ""()
2225 </pre>
2226 </div>
2227
2228 <p>TODO: The format of the asm and constraints string still need to be
2229    documented here.  Constraints on what can be done (e.g. duplication, moving,
2230    etc need to be documented).  This is probably best done by reference to
2231    another document that covers inline asm from a holistic perspective.</p>
2232
2233 </div>
2234
2235 <!-- *********************************************************************** -->
2236 <div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
2237 <!-- *********************************************************************** -->
2238
2239 <div class="doc_text">
2240
2241 <p>The LLVM instruction set consists of several different classifications of
2242    instructions: <a href="#terminators">terminator
2243    instructions</a>, <a href="#binaryops">binary instructions</a>,
2244    <a href="#bitwiseops">bitwise binary instructions</a>,
2245    <a href="#memoryops">memory instructions</a>, and
2246    <a href="#otherops">other instructions</a>.</p>
2247
2248 </div>
2249
2250 <!-- ======================================================================= -->
2251 <div class="doc_subsection"> <a name="terminators">Terminator
2252 Instructions</a> </div>
2253
2254 <div class="doc_text">
2255
2256 <p>As mentioned <a href="#functionstructure">previously</a>, every basic block
2257    in a program ends with a "Terminator" instruction, which indicates which
2258    block should be executed after the current block is finished. These
2259    terminator instructions typically yield a '<tt>void</tt>' value: they produce
2260    control flow, not values (the one exception being the
2261    '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
2262
2263 <p>There are six different terminator instructions: the
2264    '<a href="#i_ret"><tt>ret</tt></a>' instruction, the
2265    '<a href="#i_br"><tt>br</tt></a>' instruction, the
2266    '<a href="#i_switch"><tt>switch</tt></a>' instruction, the
2267    '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the
2268    '<a href="#i_unwind"><tt>unwind</tt></a>' instruction, and the
2269    '<a href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
2270
2271 </div>
2272
2273 <!-- _______________________________________________________________________ -->
2274 <div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
2275 Instruction</a> </div>
2276
2277 <div class="doc_text">
2278
2279 <h5>Syntax:</h5>
2280 <pre>
2281   ret &lt;type&gt; &lt;value&gt;       <i>; Return a value from a non-void function</i>
2282   ret void                 <i>; Return from void function</i>
2283 </pre>
2284
2285 <h5>Overview:</h5>
2286
2287 <p>The '<tt>ret</tt>' instruction is used to return control flow (and optionally
2288    a value) from a function back to the caller.</p>
2289
2290 <p>There are two forms of the '<tt>ret</tt>' instruction: one that returns a
2291    value and then causes control flow, and one that just causes control flow to
2292    occur.</p>
2293
2294 <h5>Arguments:</h5>
2295
2296 <p>The '<tt>ret</tt>' instruction optionally accepts a single argument, the
2297    return value. The type of the return value must be a
2298    '<a href="#t_firstclass">first class</a>' type.</p>
2299
2300 <p>A function is not <a href="#wellformed">well formed</a> if it it has a
2301    non-void return type and contains a '<tt>ret</tt>' instruction with no return
2302    value or a return value with a type that does not match its type, or if it
2303    has a void return type and contains a '<tt>ret</tt>' instruction with a
2304    return value.</p>
2305
2306 <h5>Semantics:</h5>
2307
2308 <p>When the '<tt>ret</tt>' instruction is executed, control flow returns back to
2309    the calling function's context.  If the caller is a
2310    "<a href="#i_call"><tt>call</tt></a>" instruction, execution continues at the
2311    instruction after the call.  If the caller was an
2312    "<a href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues at
2313    the beginning of the "normal" destination block.  If the instruction returns
2314    a value, that value shall set the call or invoke instruction's return
2315    value.</p>
2316
2317 <h5>Example:</h5>
2318
2319 <pre>
2320   ret i32 5                       <i>; Return an integer value of 5</i>
2321   ret void                        <i>; Return from a void function</i>
2322   ret { i32, i8 } { i32 4, i8 2 } <i>; Return a struct of values 4 and 2</i>
2323 </pre>
2324
2325 <p>Note that the code generator does not yet fully support large
2326    return values. The specific sizes that are currently supported are
2327    dependent on the target. For integers, on 32-bit targets the limit
2328    is often 64 bits, and on 64-bit targets the limit is often 128 bits.
2329    For aggregate types, the current limits are dependent on the element
2330    types; for example targets are often limited to 2 total integer
2331    elements and 2 total floating-point elements.</p>
2332
2333 </div>
2334 <!-- _______________________________________________________________________ -->
2335 <div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
2336
2337 <div class="doc_text">
2338
2339 <h5>Syntax:</h5>
2340 <pre>
2341   br i1 &lt;cond&gt;, label &lt;iftrue&gt;, label &lt;iffalse&gt;<br>  br label &lt;dest&gt;          <i>; Unconditional branch</i>
2342 </pre>
2343
2344 <h5>Overview:</h5>
2345 <p>The '<tt>br</tt>' instruction is used to cause control flow to transfer to a
2346    different basic block in the current function.  There are two forms of this
2347    instruction, corresponding to a conditional branch and an unconditional
2348    branch.</p>
2349
2350 <h5>Arguments:</h5>
2351 <p>The conditional branch form of the '<tt>br</tt>' instruction takes a single
2352    '<tt>i1</tt>' value and two '<tt>label</tt>' values.  The unconditional form
2353    of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>' value as a
2354    target.</p>
2355
2356 <h5>Semantics:</h5>
2357 <p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>i1</tt>'
2358    argument is evaluated.  If the value is <tt>true</tt>, control flows to the
2359    '<tt>iftrue</tt>' <tt>label</tt> argument.  If "cond" is <tt>false</tt>,
2360    control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
2361
2362 <h5>Example:</h5>
2363 <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
2364  href="#i_ret">ret</a> i32 1<br>IfUnequal:<br>  <a href="#i_ret">ret</a> i32 0<br></pre>
2365 </div>
2366
2367 <!-- _______________________________________________________________________ -->
2368 <div class="doc_subsubsection">
2369    <a name="i_switch">'<tt>switch</tt>' Instruction</a>
2370 </div>
2371
2372 <div class="doc_text">
2373
2374 <h5>Syntax:</h5>
2375 <pre>
2376   switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
2377 </pre>
2378
2379 <h5>Overview:</h5>
2380 <p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
2381    several different places.  It is a generalization of the '<tt>br</tt>'
2382    instruction, allowing a branch to occur to one of many possible
2383    destinations.</p>
2384
2385 <h5>Arguments:</h5>
2386 <p>The '<tt>switch</tt>' instruction uses three parameters: an integer
2387    comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination,
2388    and an array of pairs of comparison value constants and '<tt>label</tt>'s.
2389    The table is not allowed to contain duplicate constant entries.</p>
2390
2391 <h5>Semantics:</h5>
2392 <p>The <tt>switch</tt> instruction specifies a table of values and
2393    destinations. When the '<tt>switch</tt>' instruction is executed, this table
2394    is searched for the given value.  If the value is found, control flow is
2395    transfered to the corresponding destination; otherwise, control flow is
2396    transfered to the default destination.</p>
2397
2398 <h5>Implementation:</h5>
2399 <p>Depending on properties of the target machine and the particular
2400    <tt>switch</tt> instruction, this instruction may be code generated in
2401    different ways.  For example, it could be generated as a series of chained
2402    conditional branches or with a lookup table.</p>
2403
2404 <h5>Example:</h5>
2405 <pre>
2406  <i>; Emulate a conditional br instruction</i>
2407  %Val = <a href="#i_zext">zext</a> i1 %value to i32
2408  switch i32 %Val, label %truedest [ i32 0, label %falsedest ]
2409
2410  <i>; Emulate an unconditional br instruction</i>
2411  switch i32 0, label %dest [ ]
2412
2413  <i>; Implement a jump table:</i>
2414  switch i32 %val, label %otherwise [ i32 0, label %onzero
2415                                      i32 1, label %onone
2416                                      i32 2, label %ontwo ]
2417 </pre>
2418
2419 </div>
2420
2421 <!-- _______________________________________________________________________ -->
2422 <div class="doc_subsubsection">
2423   <a name="i_invoke">'<tt>invoke</tt>' Instruction</a>
2424 </div>
2425
2426 <div class="doc_text">
2427
2428 <h5>Syntax:</h5>
2429 <pre>
2430   &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>]
2431                 to label &lt;normal label&gt; unwind label &lt;exception label&gt;
2432 </pre>
2433
2434 <h5>Overview:</h5>
2435 <p>The '<tt>invoke</tt>' instruction causes control to transfer to a specified
2436    function, with the possibility of control flow transfer to either the
2437    '<tt>normal</tt>' label or the '<tt>exception</tt>' label.  If the callee
2438    function returns with the "<tt><a href="#i_ret">ret</a></tt>" instruction,
2439    control flow will return to the "normal" label.  If the callee (or any
2440    indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
2441    instruction, control is interrupted and continued at the dynamically nearest
2442    "exception" label.</p>
2443
2444 <h5>Arguments:</h5>
2445 <p>This instruction requires several arguments:</p>
2446
2447 <ol>
2448   <li>The optional "cconv" marker indicates which <a href="#callingconv">calling
2449       convention</a> the call should use.  If none is specified, the call
2450       defaults to using C calling conventions.</li>
2451
2452   <li>The optional <a href="#paramattrs">Parameter Attributes</a> list for
2453       return values. Only '<tt>zeroext</tt>', '<tt>signext</tt>', and
2454       '<tt>inreg</tt>' attributes are valid here.</li>
2455
2456   <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to
2457       function value being invoked.  In most cases, this is a direct function
2458       invocation, but indirect <tt>invoke</tt>s are just as possible, branching
2459       off an arbitrary pointer to function value.</li>
2460
2461   <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a
2462       function to be invoked. </li>
2463
2464   <li>'<tt>function args</tt>': argument list whose types match the function
2465       signature argument types.  If the function signature indicates the
2466       function accepts a variable number of arguments, the extra arguments can
2467       be specified.</li>
2468
2469   <li>'<tt>normal label</tt>': the label reached when the called function
2470       executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
2471
2472   <li>'<tt>exception label</tt>': the label reached when a callee returns with
2473       the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
2474
2475   <li>The optional <a href="#fnattrs">function attributes</a> list. Only
2476       '<tt>noreturn</tt>', '<tt>nounwind</tt>', '<tt>readonly</tt>' and
2477       '<tt>readnone</tt>' attributes are valid here.</li>
2478 </ol>
2479
2480 <h5>Semantics:</h5>
2481 <p>This instruction is designed to operate as a standard
2482    '<tt><a href="#i_call">call</a></tt>' instruction in most regards.  The
2483    primary difference is that it establishes an association with a label, which
2484    is used by the runtime library to unwind the stack.</p>
2485
2486 <p>This instruction is used in languages with destructors to ensure that proper
2487    cleanup is performed in the case of either a <tt>longjmp</tt> or a thrown
2488    exception.  Additionally, this is important for implementation of
2489    '<tt>catch</tt>' clauses in high-level languages that support them.</p>
2490
2491 <p>For the purposes of the SSA form, the definition of the value returned by the
2492    '<tt>invoke</tt>' instruction is deemed to occur on the edge from the current
2493    block to the "normal" label. If the callee unwinds then no return value is
2494    available.</p>
2495
2496 <h5>Example:</h5>
2497 <pre>
2498   %retval = invoke i32 @Test(i32 15) to label %Continue
2499               unwind label %TestCleanup              <i>; {i32}:retval set</i>
2500   %retval = invoke <a href="#callingconv">coldcc</a> i32 %Testfnptr(i32 15) to label %Continue
2501               unwind label %TestCleanup              <i>; {i32}:retval set</i>
2502 </pre>
2503
2504 </div>
2505
2506 <!-- _______________________________________________________________________ -->
2507
2508 <div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
2509 Instruction</a> </div>
2510
2511 <div class="doc_text">
2512
2513 <h5>Syntax:</h5>
2514 <pre>
2515   unwind
2516 </pre>
2517
2518 <h5>Overview:</h5>
2519 <p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
2520    at the first callee in the dynamic call stack which used
2521    an <a href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call.
2522    This is primarily used to implement exception handling.</p>
2523
2524 <h5>Semantics:</h5>
2525 <p>The '<tt>unwind</tt>' instruction causes execution of the current function to
2526    immediately halt.  The dynamic call stack is then searched for the
2527    first <a href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack.
2528    Once found, execution continues at the "exceptional" destination block
2529    specified by the <tt>invoke</tt> instruction.  If there is no <tt>invoke</tt>
2530    instruction in the dynamic call chain, undefined behavior results.</p>
2531
2532 </div>
2533
2534 <!-- _______________________________________________________________________ -->
2535
2536 <div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
2537 Instruction</a> </div>
2538
2539 <div class="doc_text">
2540
2541 <h5>Syntax:</h5>
2542 <pre>
2543   unreachable
2544 </pre>
2545
2546 <h5>Overview:</h5>
2547 <p>The '<tt>unreachable</tt>' instruction has no defined semantics.  This
2548    instruction is used to inform the optimizer that a particular portion of the
2549    code is not reachable.  This can be used to indicate that the code after a
2550    no-return function cannot be reached, and other facts.</p>
2551
2552 <h5>Semantics:</h5>
2553 <p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
2554
2555 </div>
2556
2557 <!-- ======================================================================= -->
2558 <div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
2559
2560 <div class="doc_text">
2561
2562 <p>Binary operators are used to do most of the computation in a program.  They
2563    require two operands of the same type, execute an operation on them, and
2564    produce a single value.  The operands might represent multiple data, as is
2565    the case with the <a href="#t_vector">vector</a> data type.  The result value
2566    has the same type as its operands.</p>
2567
2568 <p>There are several different binary operators:</p>
2569
2570 </div>
2571
2572 <!-- _______________________________________________________________________ -->
2573 <div class="doc_subsubsection">
2574   <a name="i_add">'<tt>add</tt>' Instruction</a>
2575 </div>
2576
2577 <div class="doc_text">
2578
2579 <h5>Syntax:</h5>
2580 <pre>
2581   &lt;result&gt; = add &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt;   <i>; yields {ty}:result</i>
2582 </pre>
2583
2584 <h5>Overview:</h5>
2585 <p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
2586
2587 <h5>Arguments:</h5>
2588
2589 <p>The two arguments to the '<tt>add</tt>' instruction must
2590    be <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of
2591    integer values. Both arguments must have identical types.</p>
2592
2593 <h5>Semantics:</h5>
2594 <p>The value produced is the integer sum of the two operands.</p>
2595
2596 <p>If the sum has unsigned overflow, the result returned is the mathematical
2597    result modulo 2<sup>n</sup>, where n is the bit width of the result.</p>
2598
2599 <p>Because LLVM integers use a two's complement representation, this instruction
2600    is appropriate for both signed and unsigned integers.</p>
2601
2602 <h5>Example:</h5>
2603 <pre>
2604   &lt;result&gt; = add i32 4, %var          <i>; yields {i32}:result = 4 + %var</i>
2605 </pre>
2606
2607 </div>
2608
2609 <!-- _______________________________________________________________________ -->
2610 <div class="doc_subsubsection">
2611   <a name="i_fadd">'<tt>fadd</tt>' Instruction</a>
2612 </div>
2613
2614 <div class="doc_text">
2615
2616 <h5>Syntax:</h5>
2617 <pre>
2618   &lt;result&gt; = fadd &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt;   <i>; yields {ty}:result</i>
2619 </pre>
2620
2621 <h5>Overview:</h5>
2622 <p>The '<tt>fadd</tt>' instruction returns the sum of its two operands.</p>
2623
2624 <h5>Arguments:</h5>
2625 <p>The two arguments to the '<tt>fadd</tt>' instruction must be
2626    <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> of
2627    floating point values. Both arguments must have identical types.</p>
2628
2629 <h5>Semantics:</h5>
2630 <p>The value produced is the floating point sum of the two operands.</p>
2631
2632 <h5>Example:</h5>
2633 <pre>
2634   &lt;result&gt; = fadd float 4.0, %var          <i>; yields {float}:result = 4.0 + %var</i>
2635 </pre>
2636
2637 </div>
2638
2639 <!-- _______________________________________________________________________ -->
2640 <div class="doc_subsubsection">
2641    <a name="i_sub">'<tt>sub</tt>' Instruction</a>
2642 </div>
2643
2644 <div class="doc_text">
2645
2646 <h5>Syntax:</h5>
2647 <pre>
2648   &lt;result&gt; = sub &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt;   <i>; yields {ty}:result</i>
2649 </pre>
2650
2651 <h5>Overview:</h5>
2652 <p>The '<tt>sub</tt>' instruction returns the difference of its two
2653    operands.</p>
2654
2655 <p>Note that the '<tt>sub</tt>' instruction is used to represent the
2656    '<tt>neg</tt>' instruction present in most other intermediate
2657    representations.</p>
2658
2659 <h5>Arguments:</h5>
2660 <p>The two arguments to the '<tt>sub</tt>' instruction must
2661    be <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of
2662    integer values.  Both arguments must have identical types.</p>
2663
2664 <h5>Semantics:</h5>
2665 <p>The value produced is the integer difference of the two operands.</p>
2666
2667 <p>If the difference has unsigned overflow, the result returned is the
2668    mathematical result modulo 2<sup>n</sup>, where n is the bit width of the
2669    result.</p>
2670
2671 <p>Because LLVM integers use a two's complement representation, this instruction
2672    is appropriate for both signed and unsigned integers.</p>
2673
2674 <h5>Example:</h5>
2675 <pre>
2676   &lt;result&gt; = sub i32 4, %var          <i>; yields {i32}:result = 4 - %var</i>
2677   &lt;result&gt; = sub i32 0, %val          <i>; yields {i32}:result = -%var</i>
2678 </pre>
2679
2680 </div>
2681
2682 <!-- _______________________________________________________________________ -->
2683 <div class="doc_subsubsection">
2684    <a name="i_fsub">'<tt>fsub</tt>' Instruction</a>
2685 </div>
2686
2687 <div class="doc_text">
2688
2689 <h5>Syntax:</h5>
2690 <pre>
2691   &lt;result&gt; = fsub &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt;   <i>; yields {ty}:result</i>
2692 </pre>
2693
2694 <h5>Overview:</h5>
2695 <p>The '<tt>fsub</tt>' instruction returns the difference of its two
2696    operands.</p>
2697
2698 <p>Note that the '<tt>fsub</tt>' instruction is used to represent the
2699    '<tt>fneg</tt>' instruction present in most other intermediate
2700    representations.</p>
2701
2702 <h5>Arguments:</h5>
2703 <p>The two arguments to the '<tt>fsub</tt>' instruction must be
2704    <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> of
2705    floating point values.  Both arguments must have identical types.</p>
2706
2707 <h5>Semantics:</h5>
2708 <p>The value produced is the floating point difference of the two operands.</p>
2709
2710 <h5>Example:</h5>
2711 <pre>
2712   &lt;result&gt; = fsub float 4.0, %var           <i>; yields {float}:result = 4.0 - %var</i>
2713   &lt;result&gt; = fsub float -0.0, %val          <i>; yields {float}:result = -%var</i>
2714 </pre>
2715
2716 </div>
2717
2718 <!-- _______________________________________________________________________ -->
2719 <div class="doc_subsubsection">
2720   <a name="i_mul">'<tt>mul</tt>' Instruction</a>
2721 </div>
2722
2723 <div class="doc_text">
2724
2725 <h5>Syntax:</h5>
2726 <pre>
2727   &lt;result&gt; = mul &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt;   <i>; yields {ty}:result</i>
2728 </pre>
2729
2730 <h5>Overview:</h5>
2731 <p>The '<tt>mul</tt>' instruction returns the product of its two operands.</p>
2732
2733 <h5>Arguments:</h5>
2734 <p>The two arguments to the '<tt>mul</tt>' instruction must
2735    be <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of
2736    integer values.  Both arguments must have identical types.</p>
2737  
2738 <h5>Semantics:</h5>
2739 <p>The value produced is the integer product of the two operands.</p>
2740
2741 <p>If the result of the multiplication has unsigned overflow, the result
2742    returned is the mathematical result modulo 2<sup>n</sup>, where n is the bit
2743    width of the result.</p>
2744
2745 <p>Because LLVM integers use a two's complement representation, and the result
2746    is the same width as the operands, this instruction returns the correct
2747    result for both signed and unsigned integers.  If a full product
2748    (e.g. <tt>i32</tt>x<tt>i32</tt>-><tt>i64</tt>) is needed, the operands should
2749    be sign-extended or zero-extended as appropriate to the width of the full
2750    product.</p>
2751
2752 <h5>Example:</h5>
2753 <pre>
2754   &lt;result&gt; = mul i32 4, %var          <i>; yields {i32}:result = 4 * %var</i>
2755 </pre>
2756
2757 </div>
2758
2759 <!-- _______________________________________________________________________ -->
2760 <div class="doc_subsubsection">
2761   <a name="i_fmul">'<tt>fmul</tt>' Instruction</a>
2762 </div>
2763
2764 <div class="doc_text">
2765
2766 <h5>Syntax:</h5>
2767 <pre>
2768   &lt;result&gt; = fmul &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt;   <i>; yields {ty}:result</i>
2769 </pre>
2770
2771 <h5>Overview:</h5>
2772 <p>The '<tt>fmul</tt>' instruction returns the product of its two operands.</p>
2773
2774 <h5>Arguments:</h5>
2775 <p>The two arguments to the '<tt>fmul</tt>' instruction must be
2776    <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> of
2777    floating point values.  Both arguments must have identical types.</p>
2778
2779 <h5>Semantics:</h5>
2780 <p>The value produced is the floating point product of the two operands.</p>
2781
2782 <h5>Example:</h5>
2783 <pre>
2784   &lt;result&gt; = fmul float 4.0, %var          <i>; yields {float}:result = 4.0 * %var</i>
2785 </pre>
2786
2787 </div>
2788
2789 <!-- _______________________________________________________________________ -->
2790 <div class="doc_subsubsection"> <a name="i_udiv">'<tt>udiv</tt>' Instruction
2791 </a></div>
2792
2793 <div class="doc_text">
2794
2795 <h5>Syntax:</h5>
2796 <pre>
2797   &lt;result&gt; = udiv &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt;   <i>; yields {ty}:result</i>
2798 </pre>
2799
2800 <h5>Overview:</h5>
2801 <p>The '<tt>udiv</tt>' instruction returns the quotient of its two operands.</p>
2802
2803 <h5>Arguments:</h5>
2804 <p>The two arguments to the '<tt>udiv</tt>' instruction must be 
2805    <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
2806    values.  Both arguments must have identical types.</p>
2807
2808 <h5>Semantics:</h5>
2809 <p>The value produced is the unsigned integer quotient of the two operands.</p>
2810
2811 <p>Note that unsigned integer division and signed integer division are distinct
2812    operations; for signed integer division, use '<tt>sdiv</tt>'.</p>
2813
2814 <p>Division by zero leads to undefined behavior.</p>
2815
2816 <h5>Example:</h5>
2817 <pre>
2818   &lt;result&gt; = udiv i32 4, %var          <i>; yields {i32}:result = 4 / %var</i>
2819 </pre>
2820
2821 </div>
2822
2823 <!-- _______________________________________________________________________ -->
2824 <div class="doc_subsubsection"> <a name="i_sdiv">'<tt>sdiv</tt>' Instruction
2825 </a> </div>
2826
2827 <div class="doc_text">
2828
2829 <h5>Syntax:</h5>
2830 <pre>
2831   &lt;result&gt; = sdiv &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt;   <i>; yields {ty}:result</i>
2832 </pre>
2833
2834 <h5>Overview:</h5>
2835 <p>The '<tt>sdiv</tt>' instruction returns the quotient of its two operands.</p>
2836
2837 <h5>Arguments:</h5>
2838 <p>The two arguments to the '<tt>sdiv</tt>' instruction must be 
2839    <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
2840    values.  Both arguments must have identical types.</p>
2841
2842 <h5>Semantics:</h5>
2843 <p>The value produced is the signed integer quotient of the two operands rounded
2844    towards zero.</p>
2845
2846 <p>Note that signed integer division and unsigned integer division are distinct
2847    operations; for unsigned integer division, use '<tt>udiv</tt>'.</p>
2848
2849 <p>Division by zero leads to undefined behavior. Overflow also leads to
2850    undefined behavior; this is a rare case, but can occur, for example, by doing
2851    a 32-bit division of -2147483648 by -1.</p>
2852
2853 <h5>Example:</h5>
2854 <pre>
2855   &lt;result&gt; = sdiv i32 4, %var          <i>; yields {i32}:result = 4 / %var</i>
2856 </pre>
2857
2858 </div>
2859
2860 <!-- _______________________________________________________________________ -->
2861 <div class="doc_subsubsection"> <a name="i_fdiv">'<tt>fdiv</tt>'
2862 Instruction</a> </div>
2863
2864 <div class="doc_text">
2865
2866 <h5>Syntax:</h5>
2867 <pre>
2868   &lt;result&gt; = fdiv &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt;   <i>; yields {ty}:result</i>
2869 </pre>
2870
2871 <h5>Overview:</h5>
2872 <p>The '<tt>fdiv</tt>' instruction returns the quotient of its two operands.</p>
2873
2874 <h5>Arguments:</h5>
2875 <p>The two arguments to the '<tt>fdiv</tt>' instruction must be
2876    <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> of
2877    floating point values.  Both arguments must have identical types.</p>
2878
2879 <h5>Semantics:</h5>
2880 <p>The value produced is the floating point quotient of the two operands.</p>
2881
2882 <h5>Example:</h5>
2883 <pre>
2884   &lt;result&gt; = fdiv float 4.0, %var          <i>; yields {float}:result = 4.0 / %var</i>
2885 </pre>
2886
2887 </div>
2888
2889 <!-- _______________________________________________________________________ -->
2890 <div class="doc_subsubsection"> <a name="i_urem">'<tt>urem</tt>' Instruction</a>
2891 </div>
2892
2893 <div class="doc_text">
2894
2895 <h5>Syntax:</h5>
2896 <pre>
2897   &lt;result&gt; = urem &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt;   <i>; yields {ty}:result</i>
2898 </pre>
2899
2900 <h5>Overview:</h5>
2901 <p>The '<tt>urem</tt>' instruction returns the remainder from the unsigned
2902    division of its two arguments.</p>
2903
2904 <h5>Arguments:</h5>
2905 <p>The two arguments to the '<tt>urem</tt>' instruction must be 
2906    <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
2907    values.  Both arguments must have identical types.</p>
2908
2909 <h5>Semantics:</h5>
2910 <p>This instruction returns the unsigned integer <i>remainder</i> of a division.
2911    This instruction always performs an unsigned division to get the
2912    remainder.</p>
2913
2914 <p>Note that unsigned integer remainder and signed integer remainder are
2915    distinct operations; for signed integer remainder, use '<tt>srem</tt>'.</p>
2916
2917 <p>Taking the remainder of a division by zero leads to undefined behavior.</p>
2918
2919 <h5>Example:</h5>
2920 <pre>
2921   &lt;result&gt; = urem i32 4, %var          <i>; yields {i32}:result = 4 % %var</i>
2922 </pre>
2923
2924 </div>
2925
2926 <!-- _______________________________________________________________________ -->
2927 <div class="doc_subsubsection">
2928   <a name="i_srem">'<tt>srem</tt>' Instruction</a>
2929 </div>
2930
2931 <div class="doc_text">
2932
2933 <h5>Syntax:</h5>
2934 <pre>
2935   &lt;result&gt; = srem &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt;   <i>; yields {ty}:result</i>
2936 </pre>
2937
2938 <h5>Overview:</h5>
2939 <p>The '<tt>srem</tt>' instruction returns the remainder from the signed
2940    division of its two operands. This instruction can also take
2941    <a href="#t_vector">vector</a> versions of the values in which case the
2942    elements must be integers.</p>
2943
2944 <h5>Arguments:</h5>
2945 <p>The two arguments to the '<tt>srem</tt>' instruction must be 
2946    <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
2947    values.  Both arguments must have identical types.</p>
2948
2949 <h5>Semantics:</h5>
2950 <p>This instruction returns the <i>remainder</i> of a division (where the result
2951    has the same sign as the dividend, <tt>op1</tt>), not the <i>modulo</i>
2952    operator (where the result has the same sign as the divisor, <tt>op2</tt>) of
2953    a value.  For more information about the difference,
2954    see <a href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
2955    Math Forum</a>. For a table of how this is implemented in various languages,
2956    please see <a href="http://en.wikipedia.org/wiki/Modulo_operation">
2957    Wikipedia: modulo operation</a>.</p>
2958
2959 <p>Note that signed integer remainder and unsigned integer remainder are
2960    distinct operations; for unsigned integer remainder, use '<tt>urem</tt>'.</p>
2961
2962 <p>Taking the remainder of a division by zero leads to undefined behavior.
2963    Overflow also leads to undefined behavior; this is a rare case, but can
2964    occur, for example, by taking the remainder of a 32-bit division of
2965    -2147483648 by -1.  (The remainder doesn't actually overflow, but this rule
2966    lets srem be implemented using instructions that return both the result of
2967    the division and the remainder.)</p>
2968
2969 <h5>Example:</h5>
2970 <pre>
2971   &lt;result&gt; = srem i32 4, %var          <i>; yields {i32}:result = 4 % %var</i>
2972 </pre>
2973
2974 </div>
2975
2976 <!-- _______________________________________________________________________ -->
2977 <div class="doc_subsubsection">
2978   <a name="i_frem">'<tt>frem</tt>' Instruction</a> </div>
2979
2980 <div class="doc_text">
2981
2982 <h5>Syntax:</h5>
2983 <pre>
2984   &lt;result&gt; = frem &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt;   <i>; yields {ty}:result</i>
2985 </pre>
2986
2987 <h5>Overview:</h5>
2988 <p>The '<tt>frem</tt>' instruction returns the remainder from the division of
2989    its two operands.</p>
2990
2991 <h5>Arguments:</h5>
2992 <p>The two arguments to the '<tt>frem</tt>' instruction must be
2993    <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> of
2994    floating point values.  Both arguments must have identical types.</p>
2995
2996 <h5>Semantics:</h5>
2997 <p>This instruction returns the <i>remainder</i> of a division.  The remainder
2998    has the same sign as the dividend.</p>
2999
3000 <h5>Example:</h5>
3001 <pre>
3002   &lt;result&gt; = frem float 4.0, %var          <i>; yields {float}:result = 4.0 % %var</i>
3003 </pre>
3004
3005 </div>
3006
3007 <!-- ======================================================================= -->
3008 <div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
3009 Operations</a> </div>
3010
3011 <div class="doc_text">
3012
3013 <p>Bitwise binary operators are used to do various forms of bit-twiddling in a
3014    program.  They are generally very efficient instructions and can commonly be
3015    strength reduced from other instructions.  They require two operands of the
3016    same type, execute an operation on them, and produce a single value.  The
3017    resulting value is the same type as its operands.</p>
3018
3019 </div>
3020
3021 <!-- _______________________________________________________________________ -->
3022 <div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
3023 Instruction</a> </div>
3024
3025 <div class="doc_text">
3026
3027 <h5>Syntax:</h5>
3028 <pre>
3029   &lt;result&gt; = shl &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt;   <i>; yields {ty}:result</i>
3030 </pre>
3031
3032 <h5>Overview:</h5>
3033 <p>The '<tt>shl</tt>' instruction returns the first operand shifted to the left
3034    a specified number of bits.</p>
3035
3036 <h5>Arguments:</h5>
3037 <p>Both arguments to the '<tt>shl</tt>' instruction must be the
3038     same <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of
3039     integer type.  '<tt>op2</tt>' is treated as an unsigned value.</p>
3040  
3041 <h5>Semantics:</h5>
3042 <p>The value produced is <tt>op1</tt> * 2<sup><tt>op2</tt></sup> mod
3043    2<sup>n</sup>, where <tt>n</tt> is the width of the result.  If <tt>op2</tt>
3044    is (statically or dynamically) negative or equal to or larger than the number
3045    of bits in <tt>op1</tt>, the result is undefined.  If the arguments are
3046    vectors, each vector element of <tt>op1</tt> is shifted by the corresponding
3047    shift amount in <tt>op2</tt>.</p>
3048
3049 <h5>Example:</h5>
3050 <pre>
3051   &lt;result&gt; = shl i32 4, %var   <i>; yields {i32}: 4 &lt;&lt; %var</i>
3052   &lt;result&gt; = shl i32 4, 2      <i>; yields {i32}: 16</i>
3053   &lt;result&gt; = shl i32 1, 10     <i>; yields {i32}: 1024</i>
3054   &lt;result&gt; = shl i32 1, 32     <i>; undefined</i>
3055   &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>
3056 </pre>
3057
3058 </div>
3059
3060 <!-- _______________________________________________________________________ -->
3061 <div class="doc_subsubsection"> <a name="i_lshr">'<tt>lshr</tt>'
3062 Instruction</a> </div>
3063
3064 <div class="doc_text">
3065
3066 <h5>Syntax:</h5>
3067 <pre>
3068   &lt;result&gt; = lshr &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt;   <i>; yields {ty}:result</i>
3069 </pre>
3070
3071 <h5>Overview:</h5>
3072 <p>The '<tt>lshr</tt>' instruction (logical shift right) returns the first
3073    operand shifted to the right a specified number of bits with zero fill.</p>
3074
3075 <h5>Arguments:</h5>
3076 <p>Both arguments to the '<tt>lshr</tt>' instruction must be the same 
3077    <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
3078    type. '<tt>op2</tt>' is treated as an unsigned value.</p>
3079
3080 <h5>Semantics:</h5>
3081 <p>This instruction always performs a logical shift right operation. The most
3082    significant bits of the result will be filled with zero bits after the shift.
3083    If <tt>op2</tt> is (statically or dynamically) equal to or larger than the
3084    number of bits in <tt>op1</tt>, the result is undefined. If the arguments are
3085    vectors, each vector element of <tt>op1</tt> is shifted by the corresponding
3086    shift amount in <tt>op2</tt>.</p>
3087
3088 <h5>Example:</h5>
3089 <pre>
3090   &lt;result&gt; = lshr i32 4, 1   <i>; yields {i32}:result = 2</i>
3091   &lt;result&gt; = lshr i32 4, 2   <i>; yields {i32}:result = 1</i>
3092   &lt;result&gt; = lshr i8  4, 3   <i>; yields {i8}:result = 0</i>
3093   &lt;result&gt; = lshr i8 -2, 1   <i>; yields {i8}:result = 0x7FFFFFFF </i>
3094   &lt;result&gt; = lshr i32 1, 32  <i>; undefined</i>
3095   &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>
3096 </pre>
3097
3098 </div>
3099
3100 <!-- _______________________________________________________________________ -->
3101 <div class="doc_subsubsection"> <a name="i_ashr">'<tt>ashr</tt>'
3102 Instruction</a> </div>
3103 <div class="doc_text">
3104
3105 <h5>Syntax:</h5>
3106 <pre>
3107   &lt;result&gt; = ashr &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt;   <i>; yields {ty}:result</i>
3108 </pre>
3109
3110 <h5>Overview:</h5>
3111 <p>The '<tt>ashr</tt>' instruction (arithmetic shift right) returns the first
3112    operand shifted to the right a specified number of bits with sign
3113    extension.</p>
3114
3115 <h5>Arguments:</h5>
3116 <p>Both arguments to the '<tt>ashr</tt>' instruction must be the same 
3117    <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
3118    type.  '<tt>op2</tt>' is treated as an unsigned value.</p>
3119
3120 <h5>Semantics:</h5>
3121 <p>This instruction always performs an arithmetic shift right operation, The
3122    most significant bits of the result will be filled with the sign bit
3123    of <tt>op1</tt>.  If <tt>op2</tt> is (statically or dynamically) equal to or
3124    larger than the number of bits in <tt>op1</tt>, the result is undefined. If
3125    the arguments are vectors, each vector element of <tt>op1</tt> is shifted by
3126    the corresponding shift amount in <tt>op2</tt>.</p>
3127
3128 <h5>Example:</h5>
3129 <pre>
3130   &lt;result&gt; = ashr i32 4, 1   <i>; yields {i32}:result = 2</i>
3131   &lt;result&gt; = ashr i32 4, 2   <i>; yields {i32}:result = 1</i>
3132   &lt;result&gt; = ashr i8  4, 3   <i>; yields {i8}:result = 0</i>
3133   &lt;result&gt; = ashr i8 -2, 1   <i>; yields {i8}:result = -1</i>
3134   &lt;result&gt; = ashr i32 1, 32  <i>; undefined</i>
3135   &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>
3136 </pre>
3137
3138 </div>
3139
3140 <!-- _______________________________________________________________________ -->
3141 <div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
3142 Instruction</a> </div>
3143
3144 <div class="doc_text">
3145
3146 <h5>Syntax:</h5>
3147 <pre>
3148   &lt;result&gt; = and &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt;   <i>; yields {ty}:result</i>
3149 </pre>
3150
3151 <h5>Overview:</h5>
3152 <p>The '<tt>and</tt>' instruction returns the bitwise logical and of its two
3153    operands.</p>
3154
3155 <h5>Arguments:</h5>
3156 <p>The two arguments to the '<tt>and</tt>' instruction must be 
3157    <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
3158    values.  Both arguments must have identical types.</p>
3159
3160 <h5>Semantics:</h5>
3161 <p>The truth table used for the '<tt>and</tt>' instruction is:</p>
3162
3163 <table border="1" cellspacing="0" cellpadding="4">
3164   <tbody>
3165     <tr>
3166       <td>In0</td>
3167       <td>In1</td>
3168       <td>Out</td>
3169     </tr>
3170     <tr>
3171       <td>0</td>
3172       <td>0</td>
3173       <td>0</td>
3174     </tr>
3175     <tr>
3176       <td>0</td>
3177       <td>1</td>
3178       <td>0</td>
3179     </tr>
3180     <tr>
3181       <td>1</td>
3182       <td>0</td>
3183       <td>0</td>
3184     </tr>
3185     <tr>
3186       <td>1</td>
3187       <td>1</td>
3188       <td>1</td>
3189     </tr>
3190   </tbody>
3191 </table>
3192
3193 <h5>Example:</h5>
3194 <pre>
3195   &lt;result&gt; = and i32 4, %var         <i>; yields {i32}:result = 4 &amp; %var</i>
3196   &lt;result&gt; = and i32 15, 40          <i>; yields {i32}:result = 8</i>
3197   &lt;result&gt; = and i32 4, 8            <i>; yields {i32}:result = 0</i>
3198 </pre>
3199 </div>
3200 <!-- _______________________________________________________________________ -->
3201 <div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
3202
3203 <div class="doc_text">
3204
3205 <h5>Syntax:</h5>
3206 <pre>
3207   &lt;result&gt; = or &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt;   <i>; yields {ty}:result</i>
3208 </pre>
3209
3210 <h5>Overview:</h5>
3211 <p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive or of its
3212    two operands.</p>
3213
3214 <h5>Arguments:</h5>
3215 <p>The two arguments to the '<tt>or</tt>' instruction must be 
3216    <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
3217    values.  Both arguments must have identical types.</p>
3218
3219 <h5>Semantics:</h5>
3220 <p>The truth table used for the '<tt>or</tt>' instruction is:</p>
3221
3222 <table border="1" cellspacing="0" cellpadding="4">
3223   <tbody>
3224     <tr>
3225       <td>In0</td>
3226       <td>In1</td>
3227       <td>Out</td>
3228     </tr>
3229     <tr>
3230       <td>0</td>
3231       <td>0</td>
3232       <td>0</td>
3233     </tr>
3234     <tr>
3235       <td>0</td>
3236       <td>1</td>
3237       <td>1</td>
3238     </tr>
3239     <tr>
3240       <td>1</td>
3241       <td>0</td>
3242       <td>1</td>
3243     </tr>
3244     <tr>
3245       <td>1</td>
3246       <td>1</td>
3247       <td>1</td>
3248     </tr>
3249   </tbody>
3250 </table>
3251
3252 <h5>Example:</h5>
3253 <pre>
3254   &lt;result&gt; = or i32 4, %var         <i>; yields {i32}:result = 4 | %var</i>
3255   &lt;result&gt; = or i32 15, 40          <i>; yields {i32}:result = 47</i>
3256   &lt;result&gt; = or i32 4, 8            <i>; yields {i32}:result = 12</i>
3257 </pre>
3258
3259 </div>
3260
3261 <!-- _______________________________________________________________________ -->
3262 <div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
3263 Instruction</a> </div>
3264
3265 <div class="doc_text">
3266
3267 <h5>Syntax:</h5>
3268 <pre>
3269   &lt;result&gt; = xor &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt;   <i>; yields {ty}:result</i>
3270 </pre>
3271
3272 <h5>Overview:</h5>
3273 <p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive or of
3274    its two operands.  The <tt>xor</tt> is used to implement the "one's
3275    complement" operation, which is the "~" operator in C.</p>
3276
3277 <h5>Arguments:</h5>
3278 <p>The two arguments to the '<tt>xor</tt>' instruction must be 
3279    <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
3280    values.  Both arguments must have identical types.</p>
3281
3282 <h5>Semantics:</h5>
3283 <p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
3284
3285 <table border="1" cellspacing="0" cellpadding="4">
3286   <tbody>
3287     <tr>
3288       <td>In0</td>
3289       <td>In1</td>
3290       <td>Out</td>
3291     </tr>
3292     <tr>
3293       <td>0</td>
3294       <td>0</td>
3295       <td>0</td>
3296     </tr>
3297     <tr>
3298       <td>0</td>
3299       <td>1</td>
3300       <td>1</td>
3301     </tr>
3302     <tr>
3303       <td>1</td>
3304       <td>0</td>
3305       <td>1</td>
3306     </tr>
3307     <tr>
3308       <td>1</td>
3309       <td>1</td>
3310       <td>0</td>
3311     </tr>
3312   </tbody>
3313 </table>
3314
3315 <h5>Example:</h5>
3316 <pre>
3317   &lt;result&gt; = xor i32 4, %var         <i>; yields {i32}:result = 4 ^ %var</i>
3318   &lt;result&gt; = xor i32 15, 40          <i>; yields {i32}:result = 39</i>
3319   &lt;result&gt; = xor i32 4, 8            <i>; yields {i32}:result = 12</i>
3320   &lt;result&gt; = xor i32 %V, -1          <i>; yields {i32}:result = ~%V</i>
3321 </pre>
3322
3323 </div>
3324
3325 <!-- ======================================================================= -->
3326 <div class="doc_subsection"> 
3327   <a name="vectorops">Vector Operations</a>
3328 </div>
3329
3330 <div class="doc_text">
3331
3332 <p>LLVM supports several instructions to represent vector operations in a
3333    target-independent manner.  These instructions cover the element-access and
3334    vector-specific operations needed to process vectors effectively.  While LLVM
3335    does directly support these vector operations, many sophisticated algorithms
3336    will want to use target-specific intrinsics to take full advantage of a
3337    specific target.</p>
3338
3339 </div>
3340
3341 <!-- _______________________________________________________________________ -->
3342 <div class="doc_subsubsection">
3343    <a name="i_extractelement">'<tt>extractelement</tt>' Instruction</a>
3344 </div>
3345
3346 <div class="doc_text">
3347
3348 <h5>Syntax:</h5>
3349 <pre>
3350   &lt;result&gt; = extractelement &lt;n x &lt;ty&gt;&gt; &lt;val&gt;, i32 &lt;idx&gt;    <i>; yields &lt;ty&gt;</i>
3351 </pre>
3352
3353 <h5>Overview:</h5>
3354 <p>The '<tt>extractelement</tt>' instruction extracts a single scalar element
3355    from a vector at a specified index.</p>
3356
3357
3358 <h5>Arguments:</h5>
3359 <p>The first operand of an '<tt>extractelement</tt>' instruction is a value
3360    of <a href="#t_vector">vector</a> type.  The second operand is an index
3361    indicating the position from which to extract the element.  The index may be
3362    a variable.</p>
3363
3364 <h5>Semantics:</h5>
3365 <p>The result is a scalar of the same type as the element type of
3366    <tt>val</tt>.  Its value is the value at position <tt>idx</tt> of
3367    <tt>val</tt>.  If <tt>idx</tt> exceeds the length of <tt>val</tt>, the
3368    results are undefined.</p>
3369
3370 <h5>Example:</h5>
3371 <pre>
3372   %result = extractelement &lt;4 x i32&gt; %vec, i32 0    <i>; yields i32</i>
3373 </pre>
3374
3375 </div>
3376
3377 <!-- _______________________________________________________________________ -->
3378 <div class="doc_subsubsection">
3379    <a name="i_insertelement">'<tt>insertelement</tt>' Instruction</a>
3380 </div>
3381
3382 <div class="doc_text">
3383
3384 <h5>Syntax:</h5>
3385 <pre>
3386   &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>
3387 </pre>
3388
3389 <h5>Overview:</h5>
3390 <p>The '<tt>insertelement</tt>' instruction inserts a scalar element into a
3391    vector at a specified index.</p>
3392
3393 <h5>Arguments:</h5>
3394 <p>The first operand of an '<tt>insertelement</tt>' instruction is a value
3395    of <a href="#t_vector">vector</a> type.  The second operand is a scalar value
3396    whose type must equal the element type of the first operand.  The third
3397    operand is an index indicating the position at which to insert the value.
3398    The index may be a variable.</p>
3399
3400 <h5>Semantics:</h5>
3401 <p>The result is a vector of the same type as <tt>val</tt>.  Its element values
3402    are those of <tt>val</tt> except at position <tt>idx</tt>, where it gets the
3403    value <tt>elt</tt>.  If <tt>idx</tt> exceeds the length of <tt>val</tt>, the
3404    results are undefined.</p>
3405
3406 <h5>Example:</h5>
3407 <pre>
3408   %result = insertelement &lt;4 x i32&gt; %vec, i32 1, i32 0    <i>; yields &lt;4 x i32&gt;</i>
3409 </pre>
3410
3411 </div>
3412
3413 <!-- _______________________________________________________________________ -->
3414 <div class="doc_subsubsection">
3415    <a name="i_shufflevector">'<tt>shufflevector</tt>' Instruction</a>
3416 </div>
3417
3418 <div class="doc_text">
3419
3420 <h5>Syntax:</h5>
3421 <pre>
3422   &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>
3423 </pre>
3424
3425 <h5>Overview:</h5>
3426 <p>The '<tt>shufflevector</tt>' instruction constructs a permutation of elements
3427    from two input vectors, returning a vector with the same element type as the
3428    input and length that is the same as the shuffle mask.</p>
3429
3430 <h5>Arguments:</h5>
3431 <p>The first two operands of a '<tt>shufflevector</tt>' instruction are vectors
3432    with types that match each other. The third argument is a shuffle mask whose
3433    element type is always 'i32'.  The result of the instruction is a vector
3434    whose length is the same as the shuffle mask and whose element type is the
3435    same as the element type of the first two operands.</p>
3436
3437 <p>The shuffle mask operand is required to be a constant vector with either
3438    constant integer or undef values.</p>
3439
3440 <h5>Semantics:</h5>
3441 <p>The elements of the two input vectors are numbered from left to right across
3442    both of the vectors.  The shuffle mask operand specifies, for each element of
3443    the result vector, which element of the two input vectors the result element
3444    gets.  The element selector may be undef (meaning "don't care") and the
3445    second operand may be undef if performing a shuffle from only one vector.</p>
3446
3447 <h5>Example:</h5>
3448 <pre>
3449   %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; %v2, 
3450                           &lt;4 x i32&gt; &lt;i32 0, i32 4, i32 1, i32 5&gt;  <i>; yields &lt;4 x i32&gt;</i>
3451   %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; undef, 
3452                           &lt;4 x i32&gt; &lt;i32 0, i32 1, i32 2, i32 3&gt;  <i>; yields &lt;4 x i32&gt;</i> - Identity shuffle.
3453   %result = shufflevector &lt;8 x i32&gt; %v1, &lt;8 x i32&gt; undef, 
3454                           &lt;4 x i32&gt; &lt;i32 0, i32 1, i32 2, i32 3&gt;  <i>; yields &lt;4 x i32&gt;</i>
3455   %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; %v2, 
3456                           &lt;8 x i32&gt; &lt;i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 &gt;  <i>; yields &lt;8 x i32&gt;</i>
3457 </pre>
3458
3459 </div>
3460
3461 <!-- ======================================================================= -->
3462 <div class="doc_subsection"> 
3463   <a name="aggregateops">Aggregate Operations</a>
3464 </div>
3465
3466 <div class="doc_text">
3467
3468 <p>LLVM supports several instructions for working with aggregate values.</p>
3469
3470 </div>
3471
3472 <!-- _______________________________________________________________________ -->
3473 <div class="doc_subsubsection">
3474    <a name="i_extractvalue">'<tt>extractvalue</tt>' Instruction</a>
3475 </div>
3476
3477 <div class="doc_text">
3478
3479 <h5>Syntax:</h5>
3480 <pre>
3481   &lt;result&gt; = extractvalue &lt;aggregate type&gt; &lt;val&gt;, &lt;idx&gt;{, &lt;idx&gt;}*
3482 </pre>
3483
3484 <h5>Overview:</h5>
3485 <p>The '<tt>extractvalue</tt>' instruction extracts the value of a struct field
3486    or array element from an aggregate value.</p>
3487
3488 <h5>Arguments:</h5>
3489 <p>The first operand of an '<tt>extractvalue</tt>' instruction is a value
3490    of <a href="#t_struct">struct</a> or <a href="#t_array">array</a> type.  The
3491    operands are constant indices to specify which value to extract in a similar
3492    manner as indices in a
3493    '<tt><a href="#i_getelementptr">getelementptr</a></tt>' instruction.</p>
3494
3495 <h5>Semantics:</h5>
3496 <p>The result is the value at the position in the aggregate specified by the
3497    index operands.</p>
3498
3499 <h5>Example:</h5>
3500 <pre>
3501   %result = extractvalue {i32, float} %agg, 0    <i>; yields i32</i>
3502 </pre>
3503
3504 </div>
3505
3506 <!-- _______________________________________________________________________ -->
3507 <div class="doc_subsubsection">
3508    <a name="i_insertvalue">'<tt>insertvalue</tt>' Instruction</a>
3509 </div>
3510
3511 <div class="doc_text">
3512
3513 <h5>Syntax:</h5>
3514 <pre>
3515   &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>
3516 </pre>
3517
3518 <h5>Overview:</h5>
3519 <p>The '<tt>insertvalue</tt>' instruction inserts a value into a struct field or
3520    array element in an aggregate.</p>
3521
3522
3523 <h5>Arguments:</h5>
3524 <p>The first operand of an '<tt>insertvalue</tt>' instruction is a value
3525    of <a href="#t_struct">struct</a> or <a href="#t_array">array</a> type.  The
3526    second operand is a first-class value to insert.  The following operands are
3527    constant indices indicating the position at which to insert the value in a
3528    similar manner as indices in a
3529    '<tt><a href="#i_getelementptr">getelementptr</a></tt>' instruction.  The
3530    value to insert must have the same type as the value identified by the
3531    indices.</p>
3532
3533 <h5>Semantics:</h5>
3534 <p>The result is an aggregate of the same type as <tt>val</tt>.  Its value is
3535    that of <tt>val</tt> except that the value at the position specified by the
3536    indices is that of <tt>elt</tt>.</p>
3537
3538 <h5>Example:</h5>
3539 <pre>
3540   %result = insertvalue {i32, float} %agg, i32 1, 0    <i>; yields {i32, float}</i>
3541 </pre>
3542
3543 </div>
3544
3545
3546 <!-- ======================================================================= -->
3547 <div class="doc_subsection"> 
3548   <a name="memoryops">Memory Access and Addressing Operations</a>
3549 </div>
3550
3551 <div class="doc_text">
3552
3553 <p>A key design point of an SSA-based representation is how it represents
3554    memory.  In LLVM, no memory locations are in SSA form, which makes things
3555    very simple.  This section describes how to read, write, allocate, and free
3556    memory in LLVM.</p>
3557
3558 </div>
3559
3560 <!-- _______________________________________________________________________ -->
3561 <div class="doc_subsubsection">
3562   <a name="i_malloc">'<tt>malloc</tt>' Instruction</a>
3563 </div>
3564
3565 <div class="doc_text">
3566
3567 <h5>Syntax:</h5>
3568 <pre>
3569   &lt;result&gt; = malloc &lt;type&gt;[, i32 &lt;NumElements&gt;][, align &lt;alignment&gt;]     <i>; yields {type*}:result</i>
3570 </pre>
3571
3572 <h5>Overview:</h5>
3573 <p>The '<tt>malloc</tt>' instruction allocates memory from the system heap and
3574    returns a pointer to it. The object is always allocated in the generic
3575    address space (address space zero).</p>
3576
3577 <h5>Arguments:</h5>
3578 <p>The '<tt>malloc</tt>' instruction allocates
3579    <tt>sizeof(&lt;type&gt;)*NumElements</tt> bytes of memory from the operating
3580    system and returns a pointer of the appropriate type to the program.  If
3581    "NumElements" is specified, it is the number of elements allocated, otherwise
3582    "NumElements" is defaulted to be one.  If a constant alignment is specified,
3583    the value result of the allocation is guaranteed to be aligned to at least
3584    that boundary.  If not specified, or if zero, the target can choose to align
3585    the allocation on any convenient boundary compatible with the type.</p>
3586
3587 <p>'<tt>type</tt>' must be a sized type.</p>
3588
3589 <h5>Semantics:</h5>
3590 <p>Memory is allocated using the system "<tt>malloc</tt>" function, and a
3591    pointer is returned.  The result of a zero byte allocation is undefined.  The
3592    result is null if there is insufficient memory available.</p>
3593
3594 <h5>Example:</h5>
3595 <pre>
3596   %array  = malloc [4 x i8]                     <i>; yields {[%4 x i8]*}:array</i>
3597
3598   %size   = <a href="#i_add">add</a> i32 2, 2                        <i>; yields {i32}:size = i32 4</i>
3599   %array1 = malloc i8, i32 4                    <i>; yields {i8*}:array1</i>
3600   %array2 = malloc [12 x i8], i32 %size         <i>; yields {[12 x i8]*}:array2</i>
3601   %array3 = malloc i32, i32 4, align 1024       <i>; yields {i32*}:array3</i>
3602   %array4 = malloc i32, align 1024              <i>; yields {i32*}:array4</i>
3603 </pre>
3604
3605 <p>Note that the code generator does not yet respect the alignment value.</p>
3606
3607 </div>
3608
3609 <!-- _______________________________________________________________________ -->
3610 <div class="doc_subsubsection">
3611   <a name="i_free">'<tt>free</tt>' Instruction</a>
3612 </div>
3613
3614 <div class="doc_text">
3615
3616 <h5>Syntax:</h5>
3617 <pre>
3618   free &lt;type&gt; &lt;value&gt;                           <i>; yields {void}</i>
3619 </pre>
3620
3621 <h5>Overview:</h5>
3622 <p>The '<tt>free</tt>' instruction returns memory back to the unused memory heap
3623    to be reallocated in the future.</p>
3624
3625 <h5>Arguments:</h5>
3626 <p>'<tt>value</tt>' shall be a pointer value that points to a value that was
3627    allocated with the '<tt><a href="#i_malloc">malloc</a></tt>' instruction.</p>
3628
3629 <h5>Semantics:</h5>
3630 <p>Access to the memory pointed to by the pointer is no longer defined after
3631    this instruction executes.  If the pointer is null, the operation is a
3632    noop.</p>
3633
3634 <h5>Example:</h5>
3635 <pre>
3636   %array  = <a href="#i_malloc">malloc</a> [4 x i8]                     <i>; yields {[4 x i8]*}:array</i>
3637             free   [4 x i8]* %array
3638 </pre>
3639
3640 </div>
3641
3642 <!-- _______________________________________________________________________ -->
3643 <div class="doc_subsubsection">
3644   <a name="i_alloca">'<tt>alloca</tt>' Instruction</a>
3645 </div>
3646
3647 <div class="doc_text">
3648
3649 <h5>Syntax:</h5>
3650 <pre>
3651   &lt;result&gt; = alloca &lt;type&gt;[, i32 &lt;NumElements&gt;][, align &lt;alignment&gt;]     <i>; yields {type*}:result</i>
3652 </pre>
3653
3654 <h5>Overview:</h5>
3655 <p>The '<tt>alloca</tt>' instruction allocates memory on the stack frame of the
3656    currently executing function, to be automatically released when this function
3657    returns to its caller. The object is always allocated in the generic address
3658    space (address space zero).</p>
3659
3660 <h5>Arguments:</h5>
3661 <p>The '<tt>alloca</tt>' instruction
3662    allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt> bytes of memory on the
3663    runtime stack, returning a pointer of the appropriate type to the program.
3664    If "NumElements" is specified, it is the number of elements allocated,
3665    otherwise "NumElements" is defaulted to be one.  If a constant alignment is
3666    specified, the value result of the allocation is guaranteed to be aligned to
3667    at least that boundary.  If not specified, or if zero, the target can choose
3668    to align the allocation on any convenient boundary compatible with the
3669    type.</p>
3670
3671 <p>'<tt>type</tt>' may be any sized type.</p>
3672
3673 <h5>Semantics:</h5>
3674 <p>Memory is allocated; a pointer is returned.  The operation is undefined if
3675    there is insufficient stack space for the allocation.  '<tt>alloca</tt>'d
3676    memory is automatically released when the function returns.  The
3677    '<tt>alloca</tt>' instruction is commonly used to represent automatic
3678    variables that must have an address available.  When the function returns
3679    (either with the <tt><a href="#i_ret">ret</a></tt>
3680    or <tt><a href="#i_unwind">unwind</a></tt> instructions), the memory is
3681    reclaimed.  Allocating zero bytes is legal, but the result is undefined.</p>
3682
3683 <h5>Example:</h5>
3684 <pre>
3685   %ptr = alloca i32                             <i>; yields {i32*}:ptr</i>
3686   %ptr = alloca i32, i32 4                      <i>; yields {i32*}:ptr</i>
3687   %ptr = alloca i32, i32 4, align 1024          <i>; yields {i32*}:ptr</i>
3688   %ptr = alloca i32, align 1024                 <i>; yields {i32*}:ptr</i>
3689 </pre>
3690
3691 </div>
3692
3693 <!-- _______________________________________________________________________ -->
3694 <div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
3695 Instruction</a> </div>
3696
3697 <div class="doc_text">
3698
3699 <h5>Syntax:</h5>
3700 <pre>
3701   &lt;result&gt; = load &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;]
3702   &lt;result&gt; = volatile load &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;]
3703 </pre>
3704
3705 <h5>Overview:</h5>
3706 <p>The '<tt>load</tt>' instruction is used to read from memory.</p>
3707
3708 <h5>Arguments:</h5>
3709 <p>The argument to the '<tt>load</tt>' instruction specifies the memory address
3710    from which to load.  The pointer must point to
3711    a <a href="#t_firstclass">first class</a> type.  If the <tt>load</tt> is
3712    marked as <tt>volatile</tt>, then the optimizer is not allowed to modify the
3713    number or order of execution of this <tt>load</tt> with other
3714    volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
3715    instructions. </p>
3716
3717 <p>The optional constant "align" argument specifies the alignment of the
3718    operation (that is, the alignment of the memory address). A value of 0 or an
3719    omitted "align" argument means that the operation has the preferential
3720    alignment for the target. It is the responsibility of the code emitter to
3721    ensure that the alignment information is correct. Overestimating the
3722    alignment results in an undefined behavior. Underestimating the alignment may
3723    produce less efficient code. An alignment of 1 is always safe.</p>
3724
3725 <h5>Semantics:</h5>
3726 <p>The location of memory pointed to is loaded.  If the value being loaded is of
3727    scalar type then the number of bytes read does not exceed the minimum number
3728    of bytes needed to hold all bits of the type.  For example, loading an
3729    <tt>i24</tt> reads at most three bytes.  When loading a value of a type like
3730    <tt>i20</tt> with a size that is not an integral number of bytes, the result
3731    is undefined if the value was not originally written using a store of the
3732    same type.</p>
3733
3734 <h5>Examples:</h5>
3735 <pre>
3736   %ptr = <a href="#i_alloca">alloca</a> i32                               <i>; yields {i32*}:ptr</i>
3737   <a href="#i_store">store</a> i32 3, i32* %ptr                          <i>; yields {void}</i>
3738   %val = load i32* %ptr                           <i>; yields {i32}:val = i32 3</i>
3739 </pre>
3740
3741 </div>
3742
3743 <!-- _______________________________________________________________________ -->
3744 <div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
3745 Instruction</a> </div>
3746
3747 <div class="doc_text">
3748
3749 <h5>Syntax:</h5>
3750 <pre>
3751   store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;]                   <i>; yields {void}</i>
3752   volatile store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;]          <i>; yields {void}</i>
3753 </pre>
3754
3755 <h5>Overview:</h5>
3756 <p>The '<tt>store</tt>' instruction is used to write to memory.</p>
3757
3758 <h5>Arguments:</h5>
3759 <p>There are two arguments to the '<tt>store</tt>' instruction: a value to store
3760    and an address at which to store it.  The type of the
3761    '<tt>&lt;pointer&gt;</tt>' operand must be a pointer to
3762    the <a href="#t_firstclass">first class</a> type of the
3763    '<tt>&lt;value&gt;</tt>' operand. If the <tt>store</tt> is marked
3764    as <tt>volatile</tt>, then the optimizer is not allowed to modify the number
3765    or order of execution of this <tt>store</tt> with other
3766    volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
3767    instructions.</p>
3768
3769 <p>The optional constant "align" argument specifies the alignment of the
3770    operation (that is, the alignment of the memory address). A value of 0 or an
3771    omitted "align" argument means that the operation has the preferential
3772    alignment for the target. It is the responsibility of the code emitter to
3773    ensure that the alignment information is correct. Overestimating the
3774    alignment results in an undefined behavior. Underestimating the alignment may
3775    produce less efficient code. An alignment of 1 is always safe.</p>
3776
3777 <h5>Semantics:</h5>
3778 <p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>' at the
3779    location specified by the '<tt>&lt;pointer&gt;</tt>' operand.  If
3780    '<tt>&lt;value&gt;</tt>' is of scalar type then the number of bytes written
3781    does not exceed the minimum number of bytes needed to hold all bits of the
3782    type.  For example, storing an <tt>i24</tt> writes at most three bytes.  When
3783    writing a value of a type like <tt>i20</tt> with a size that is not an
3784    integral number of bytes, it is unspecified what happens to the extra bits
3785    that do not belong to the type, but they will typically be overwritten.</p>
3786
3787 <h5>Example:</h5>
3788 <pre>
3789   %ptr = <a href="#i_alloca">alloca</a> i32                               <i>; yields {i32*}:ptr</i>
3790   store i32 3, i32* %ptr                          <i>; yields {void}</i>
3791   %val = <a href="#i_load">load</a> i32* %ptr                           <i>; yields {i32}:val = i32 3</i>
3792 </pre>
3793
3794 </div>
3795
3796 <!-- _______________________________________________________________________ -->
3797 <div class="doc_subsubsection">
3798    <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
3799 </div>
3800
3801 <div class="doc_text">
3802
3803 <h5>Syntax:</h5>
3804 <pre>
3805   &lt;result&gt; = getelementptr &lt;pty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
3806 </pre>
3807
3808 <h5>Overview:</h5>
3809 <p>The '<tt>getelementptr</tt>' instruction is used to get the address of a
3810    subelement of an aggregate data structure. It performs address calculation
3811    only and does not access memory.</p>
3812
3813 <h5>Arguments:</h5>
3814 <p>The first argument is always a pointer, and forms the basis of the
3815    calculation. The remaining arguments are indices, that indicate which of the
3816    elements of the aggregate object are indexed. The interpretation of each
3817    index is dependent on the type being indexed into. The first index always
3818    indexes the pointer value given as the first argument, the second index
3819    indexes a value of the type pointed to (not necessarily the value directly
3820    pointed to, since the first index can be non-zero), etc. The first type
3821    indexed into must be a pointer value, subsequent types can be arrays, vectors
3822    and structs. Note that subsequent types being indexed into can never be
3823    pointers, since that would require loading the pointer before continuing
3824    calculation.</p>
3825
3826 <p>The type of each index argument depends on the type it is indexing into.
3827    When indexing into a (packed) structure, only <tt>i32</tt> integer
3828    <b>constants</b> are allowed.  When indexing into an array, pointer or
3829    vector, integers of any width are allowed (also non-constants).</p>
3830
3831 <p>For example, let's consider a C code fragment and how it gets compiled to
3832    LLVM:</p>
3833
3834 <div class="doc_code">
3835 <pre>
3836 struct RT {
3837   char A;
3838   int B[10][20];
3839   char C;
3840 };
3841 struct ST {
3842   int X;
3843   double Y;
3844   struct RT Z;
3845 };
3846
3847 int *foo(struct ST *s) {
3848   return &amp;s[1].Z.B[5][13];
3849 }
3850 </pre>
3851 </div>
3852
3853 <p>The LLVM code generated by the GCC frontend is:</p>
3854
3855 <div class="doc_code">
3856 <pre>
3857 %RT = <a href="#namedtypes">type</a> { i8 , [10 x [20 x i32]], i8  }
3858 %ST = <a href="#namedtypes">type</a> { i32, double, %RT }
3859
3860 define i32* %foo(%ST* %s) {
3861 entry:
3862   %reg = getelementptr %ST* %s, i32 1, i32 2, i32 1, i32 5, i32 13
3863   ret i32* %reg
3864 }
3865 </pre>
3866 </div>
3867
3868 <h5>Semantics:</h5>
3869 <p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
3870    type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ i32, double, %RT
3871    }</tt>' type, a structure.  The second index indexes into the third element
3872    of the structure, yielding a '<tt>%RT</tt>' = '<tt>{ i8 , [10 x [20 x i32]],
3873    i8 }</tt>' type, another structure.  The third index indexes into the second
3874    element of the structure, yielding a '<tt>[10 x [20 x i32]]</tt>' type, an
3875    array.  The two dimensions of the array are subscripted into, yielding an
3876    '<tt>i32</tt>' type.  The '<tt>getelementptr</tt>' instruction returns a
3877    pointer to this element, thus computing a value of '<tt>i32*</tt>' type.</p>
3878
3879 <p>Note that it is perfectly legal to index partially through a structure,
3880    returning a pointer to an inner element.  Because of this, the LLVM code for
3881    the given testcase is equivalent to:</p>
3882
3883 <pre>
3884   define i32* %foo(%ST* %s) {
3885     %t1 = getelementptr %ST* %s, i32 1                        <i>; yields %ST*:%t1</i>
3886     %t2 = getelementptr %ST* %t1, i32 0, i32 2                <i>; yields %RT*:%t2</i>
3887     %t3 = getelementptr %RT* %t2, i32 0, i32 1                <i>; yields [10 x [20 x i32]]*:%t3</i>
3888     %t4 = getelementptr [10 x [20 x i32]]* %t3, i32 0, i32 5  <i>; yields [20 x i32]*:%t4</i>
3889     %t5 = getelementptr [20 x i32]* %t4, i32 0, i32 13        <i>; yields i32*:%t5</i>
3890     ret i32* %t5
3891   }
3892 </pre>
3893
3894 <p>Note that it is undefined to access an array out of bounds: array and pointer
3895    indexes must always be within the defined bounds of the array type when
3896    accessed with an instruction that dereferences the pointer (e.g. a load or
3897    store instruction).  The one exception for this rule is zero length arrays.
3898    These arrays are defined to be accessible as variable length arrays, which
3899    requires access beyond the zero'th element.</p>
3900
3901 <p>The getelementptr instruction is often confusing.  For some more insight into
3902    how it works, see <a href="GetElementPtr.html">the getelementptr FAQ</a>.</p>
3903
3904 <h5>Example:</h5>
3905 <pre>
3906     <i>; yields [12 x i8]*:aptr</i>
3907     %aptr = getelementptr {i32, [12 x i8]}* %saptr, i64 0, i32 1
3908     <i>; yields i8*:vptr</i>
3909     %vptr = getelementptr {i32, &lt;2 x i8&gt;}* %svptr, i64 0, i32 1, i32 1
3910     <i>; yields i8*:eptr</i>
3911     %eptr = getelementptr [12 x i8]* %aptr, i64 0, i32 1
3912     <i>; yields i32*:iptr</i>
3913     %iptr = getelementptr [10 x i32]* @arr, i16 0, i16 0
3914 </pre>
3915
3916 </div>
3917
3918 <!-- ======================================================================= -->
3919 <div class="doc_subsection"> <a name="convertops">Conversion Operations</a>
3920 </div>
3921
3922 <div class="doc_text">
3923
3924 <p>The instructions in this category are the conversion instructions (casting)
3925    which all take a single operand and a type. They perform various bit
3926    conversions on the operand.</p>
3927
3928 </div>
3929
3930 <!-- _______________________________________________________________________ -->
3931 <div class="doc_subsubsection">
3932    <a name="i_trunc">'<tt>trunc .. to</tt>' Instruction</a>
3933 </div>
3934 <div class="doc_text">
3935
3936 <h5>Syntax:</h5>
3937 <pre>
3938   &lt;result&gt; = trunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt;             <i>; yields ty2</i>
3939 </pre>
3940
3941 <h5>Overview:</h5>
3942 <p>The '<tt>trunc</tt>' instruction truncates its operand to the
3943    type <tt>ty2</tt>.</p>
3944
3945 <h5>Arguments:</h5>
3946 <p>The '<tt>trunc</tt>' instruction takes a <tt>value</tt> to trunc, which must
3947    be an <a href="#t_integer">integer</a> type, and a type that specifies the
3948    size and type of the result, which must be
3949    an <a href="#t_integer">integer</a> type. The bit size of <tt>value</tt> must
3950    be larger than the bit size of <tt>ty2</tt>. Equal sized types are not
3951    allowed.</p>
3952
3953 <h5>Semantics:</h5>
3954 <p>The '<tt>trunc</tt>' instruction truncates the high order bits
3955    in <tt>value</tt> and converts the remaining bits to <tt>ty2</tt>. Since the
3956    source size must be larger than the destination size, <tt>trunc</tt> cannot
3957    be a <i>no-op cast</i>.  It will always truncate bits.</p>
3958
3959 <h5>Example:</h5>
3960 <pre>
3961   %X = trunc i32 257 to i8              <i>; yields i8:1</i>
3962   %Y = trunc i32 123 to i1              <i>; yields i1:true</i>
3963   %Y = trunc i32 122 to i1              <i>; yields i1:false</i>
3964 </pre>
3965
3966 </div>
3967
3968 <!-- _______________________________________________________________________ -->
3969 <div class="doc_subsubsection">
3970    <a name="i_zext">'<tt>zext .. to</tt>' Instruction</a>
3971 </div>
3972 <div class="doc_text">
3973
3974 <h5>Syntax:</h5>
3975 <pre>
3976   &lt;result&gt; = zext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt;             <i>; yields ty2</i>
3977 </pre>
3978
3979 <h5>Overview:</h5>
3980 <p>The '<tt>zext</tt>' instruction zero extends its operand to type 
3981    <tt>ty2</tt>.</p>
3982
3983
3984 <h5>Arguments:</h5>
3985 <p>The '<tt>zext</tt>' instruction takes a value to cast, which must be of 
3986    <a href="#t_integer">integer</a> type, and a type to cast it to, which must
3987    also be of <a href="#t_integer">integer</a> type. The bit size of the
3988    <tt>value</tt> must be smaller than the bit size of the destination type, 
3989    <tt>ty2</tt>.</p>
3990
3991 <h5>Semantics:</h5>
3992 <p>The <tt>zext</tt> fills the high order bits of the <tt>value</tt> with zero
3993    bits until it reaches the size of the destination type, <tt>ty2</tt>.</p>
3994
3995 <p>When zero extending from i1, the result will always be either 0 or 1.</p>
3996
3997 <h5>Example:</h5>
3998 <pre>
3999   %X = zext i32 257 to i64              <i>; yields i64:257</i>
4000   %Y = zext i1 true to i32              <i>; yields i32:1</i>
4001 </pre>
4002
4003 </div>
4004
4005 <!-- _______________________________________________________________________ -->
4006 <div class="doc_subsubsection">
4007    <a name="i_sext">'<tt>sext .. to</tt>' Instruction</a>
4008 </div>
4009 <div class="doc_text">
4010
4011 <h5>Syntax:</h5>
4012 <pre>
4013   &lt;result&gt; = sext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt;             <i>; yields ty2</i>
4014 </pre>
4015
4016 <h5>Overview:</h5>
4017 <p>The '<tt>sext</tt>' sign extends <tt>value</tt> to the type <tt>ty2</tt>.</p>
4018
4019 <h5>Arguments:</h5>
4020 <p>The '<tt>sext</tt>' instruction takes a value to cast, which must be of 
4021    <a href="#t_integer">integer</a> type, and a type to cast it to, which must
4022    also be of <a href="#t_integer">integer</a> type.  The bit size of the
4023    <tt>value</tt> must be smaller than the bit size of the destination type, 
4024    <tt>ty2</tt>.</p>
4025
4026 <h5>Semantics:</h5>
4027 <p>The '<tt>sext</tt>' instruction performs a sign extension by copying the sign
4028    bit (highest order bit) of the <tt>value</tt> until it reaches the bit size
4029    of the type <tt>ty2</tt>.</p>
4030
4031 <p>When sign extending from i1, the extension always results in -1 or 0.</p>
4032
4033 <h5>Example:</h5>
4034 <pre>
4035   %X = sext i8  -1 to i16              <i>; yields i16   :65535</i>
4036   %Y = sext i1 true to i32             <i>; yields i32:-1</i>
4037 </pre>
4038
4039 </div>
4040
4041 <!-- _______________________________________________________________________ -->
4042 <div class="doc_subsubsection">
4043    <a name="i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a>
4044 </div>
4045
4046 <div class="doc_text">
4047
4048 <h5>Syntax:</h5>
4049 <pre>
4050   &lt;result&gt; = fptrunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt;             <i>; yields ty2</i>
4051 </pre>
4052
4053 <h5>Overview:</h5>
4054 <p>The '<tt>fptrunc</tt>' instruction truncates <tt>value</tt> to type
4055    <tt>ty2</tt>.</p>
4056
4057 <h5>Arguments:</h5>
4058 <p>The '<tt>fptrunc</tt>' instruction takes a <a href="#t_floating">floating
4059    point</a> value to cast and a <a href="#t_floating">floating point</a> type
4060    to cast it to. The size of <tt>value</tt> must be larger than the size of
4061    <tt>ty2</tt>. This implies that <tt>fptrunc</tt> cannot be used to make a 
4062    <i>no-op cast</i>.</p>
4063
4064 <h5>Semantics:</h5>
4065 <p>The '<tt>fptrunc</tt>' instruction truncates a <tt>value</tt> from a larger
4066    <a href="#t_floating">floating point</a> type to a smaller 
4067    <a href="#t_floating">floating point</a> type.  If the value cannot fit
4068    within the destination type, <tt>ty2</tt>, then the results are
4069    undefined.</p>
4070
4071 <h5>Example:</h5>
4072 <pre>
4073   %X = fptrunc double 123.0 to float         <i>; yields float:123.0</i>
4074   %Y = fptrunc double 1.0E+300 to float      <i>; yields undefined</i>
4075 </pre>
4076
4077 </div>
4078
4079 <!-- _______________________________________________________________________ -->
4080 <div class="doc_subsubsection">
4081    <a name="i_fpext">'<tt>fpext .. to</tt>' Instruction</a>
4082 </div>
4083 <div class="doc_text">
4084
4085 <h5>Syntax:</h5>
4086 <pre>
4087   &lt;result&gt; = fpext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt;             <i>; yields ty2</i>
4088 </pre>
4089
4090 <h5>Overview:</h5>
4091 <p>The '<tt>fpext</tt>' extends a floating point <tt>value</tt> to a larger
4092    floating point value.</p>
4093
4094 <h5>Arguments:</h5>
4095 <p>The '<tt>fpext</tt>' instruction takes a 
4096    <a href="#t_floating">floating point</a> <tt>value</tt> to cast, and
4097    a <a href="#t_floating">floating point</a> type to cast it to. The source
4098    type must be smaller than the destination type.</p>
4099
4100 <h5>Semantics:</h5>
4101 <p>The '<tt>fpext</tt>' instruction extends the <tt>value</tt> from a smaller
4102    <a href="#t_floating">floating point</a> type to a larger
4103    <a href="#t_floating">floating point</a> type. The <tt>fpext</tt> cannot be
4104    used to make a <i>no-op cast</i> because it always changes bits. Use
4105    <tt>bitcast</tt> to make a <i>no-op cast</i> for a floating point cast.</p>
4106
4107 <h5>Example:</h5>
4108 <pre>
4109   %X = fpext float 3.1415 to double        <i>; yields double:3.1415</i>
4110   %Y = fpext float 1.0 to float            <i>; yields float:1.0 (no-op)</i>
4111 </pre>
4112
4113 </div>
4114
4115 <!-- _______________________________________________________________________ -->
4116 <div class="doc_subsubsection">
4117    <a name="i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a>
4118 </div>
4119 <div class="doc_text">
4120
4121 <h5>Syntax:</h5>
4122 <pre>
4123   &lt;result&gt; = fptoui &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt;             <i>; yields ty2</i>
4124 </pre>
4125
4126 <h5>Overview:</h5>
4127 <p>The '<tt>fptoui</tt>' converts a floating point <tt>value</tt> to its
4128    unsigned integer equivalent of type <tt>ty2</tt>.</p>
4129
4130 <h5>Arguments:</h5>
4131 <p>The '<tt>fptoui</tt>' instruction takes a value to cast, which must be a
4132    scalar or vector <a href="#t_floating">floating point</a> value, and a type
4133    to cast it to <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a>
4134    type. If <tt>ty</tt> is a vector floating point type, <tt>ty2</tt> must be a
4135    vector integer type with the same number of elements as <tt>ty</tt></p>
4136
4137 <h5>Semantics:</h5>
4138 <p>The '<tt>fptoui</tt>' instruction converts its 
4139    <a href="#t_floating">floating point</a> operand into the nearest (rounding
4140    towards zero) unsigned integer value. If the value cannot fit
4141    in <tt>ty2</tt>, the results are undefined.</p>
4142
4143 <h5>Example:</h5>
4144 <pre>
4145   %X = fptoui double 123.0 to i32      <i>; yields i32:123</i>
4146   %Y = fptoui float 1.0E+300 to i1     <i>; yields undefined:1</i>
4147   %X = fptoui float 1.04E+17 to i8     <i>; yields undefined:1</i>
4148 </pre>
4149
4150 </div>
4151
4152 <!-- _______________________________________________________________________ -->
4153 <div class="doc_subsubsection">
4154    <a name="i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a>
4155 </div>
4156 <div class="doc_text">
4157
4158 <h5>Syntax:</h5>
4159 <pre>
4160   &lt;result&gt; = fptosi &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt;             <i>; yields ty2</i>
4161 </pre>
4162
4163 <h5>Overview:</h5>
4164 <p>The '<tt>fptosi</tt>' instruction converts 
4165    <a href="#t_floating">floating point</a> <tt>value</tt> to
4166    type <tt>ty2</tt>.</p>
4167
4168 <h5>Arguments:</h5>
4169 <p>The '<tt>fptosi</tt>' instruction takes a value to cast, which must be a
4170    scalar or vector <a href="#t_floating">floating point</a> value, and a type
4171    to cast it to <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a>
4172    type. If <tt>ty</tt> is a vector floating point type, <tt>ty2</tt> must be a
4173    vector integer type with the same number of elements as <tt>ty</tt></p>
4174
4175 <h5>Semantics:</h5>
4176 <p>The '<tt>fptosi</tt>' instruction converts its 
4177    <a href="#t_floating">floating point</a> operand into the nearest (rounding
4178    towards zero) signed integer value. If the value cannot fit in <tt>ty2</tt>,
4179    the results are undefined.</p>
4180
4181 <h5>Example:</h5>
4182 <pre>
4183   %X = fptosi double -123.0 to i32      <i>; yields i32:-123</i>
4184   %Y = fptosi float 1.0E-247 to i1      <i>; yields undefined:1</i>
4185   %X = fptosi float 1.04E+17 to i8      <i>; yields undefined:1</i>
4186 </pre>
4187
4188 </div>
4189
4190 <!-- _______________________________________________________________________ -->
4191 <div class="doc_subsubsection">
4192    <a name="i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a>
4193 </div>
4194 <div class="doc_text">
4195
4196 <h5>Syntax:</h5>
4197 <pre>
4198   &lt;result&gt; = uitofp &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt;             <i>; yields ty2</i>
4199 </pre>
4200
4201 <h5>Overview:</h5>
4202 <p>The '<tt>uitofp</tt>' instruction regards <tt>value</tt> as an unsigned
4203    integer and converts that value to the <tt>ty2</tt> type.</p>
4204
4205 <h5>Arguments:</h5>
4206 <p>The '<tt>uitofp</tt>' instruction takes a value to cast, which must be a
4207    scalar or vector <a href="#t_integer">integer</a> value, and a type to cast
4208    it to <tt>ty2</tt>, which must be an <a href="#t_floating">floating point</a>
4209    type. If <tt>ty</tt> is a vector integer type, <tt>ty2</tt> must be a vector
4210    floating point type with the same number of elements as <tt>ty</tt></p>
4211
4212 <h5>Semantics:</h5>
4213 <p>The '<tt>uitofp</tt>' instruction interprets its operand as an unsigned
4214    integer quantity and converts it to the corresponding floating point
4215    value. If the value cannot fit in the floating point value, the results are
4216    undefined.</p>
4217
4218 <h5>Example:</h5>
4219 <pre>
4220   %X = uitofp i32 257 to float         <i>; yields float:257.0</i>
4221   %Y = uitofp i8 -1 to double          <i>; yields double:255.0</i>
4222 </pre>
4223
4224 </div>
4225
4226 <!-- _______________________________________________________________________ -->
4227 <div class="doc_subsubsection">
4228    <a name="i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a>
4229 </div>
4230 <div class="doc_text">
4231
4232 <h5>Syntax:</h5>
4233 <pre>
4234   &lt;result&gt; = sitofp &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt;             <i>; yields ty2</i>
4235 </pre>
4236
4237 <h5>Overview:</h5>
4238 <p>The '<tt>sitofp</tt>' instruction regards <tt>value</tt> as a signed integer
4239    and converts that value to the <tt>ty2</tt> type.</p>
4240
4241 <h5>Arguments:</h5>
4242 <p>The '<tt>sitofp</tt>' instruction takes a value to cast, which must be a
4243    scalar or vector <a href="#t_integer">integer</a> value, and a type to cast
4244    it to <tt>ty2</tt>, which must be an <a href="#t_floating">floating point</a>
4245    type. If <tt>ty</tt> is a vector integer type, <tt>ty2</tt> must be a vector
4246    floating point type with the same number of elements as <tt>ty</tt></p>
4247
4248 <h5>Semantics:</h5>
4249 <p>The '<tt>sitofp</tt>' instruction interprets its operand as a signed integer
4250    quantity and converts it to the corresponding floating point value. If the
4251    value cannot fit in the floating point value, the results are undefined.</p>
4252
4253 <h5>Example:</h5>
4254 <pre>
4255   %X = sitofp i32 257 to float         <i>; yields float:257.0</i>
4256   %Y = sitofp i8 -1 to double          <i>; yields double:-1.0</i>
4257 </pre>
4258
4259 </div>
4260
4261 <!-- _______________________________________________________________________ -->
4262 <div class="doc_subsubsection">
4263    <a name="i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a>
4264 </div>
4265 <div class="doc_text">
4266
4267 <h5>Syntax:</h5>
4268 <pre>
4269   &lt;result&gt; = ptrtoint &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt;             <i>; yields ty2</i>
4270 </pre>
4271
4272 <h5>Overview:</h5>
4273 <p>The '<tt>ptrtoint</tt>' instruction converts the pointer <tt>value</tt> to
4274    the integer type <tt>ty2</tt>.</p>
4275
4276 <h5>Arguments:</h5>
4277 <p>The '<tt>ptrtoint</tt>' instruction takes a <tt>value</tt> to cast, which
4278    must be a <a href="#t_pointer">pointer</a> value, and a type to cast it to
4279    <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a> type.</p>
4280
4281 <h5>Semantics:</h5>
4282 <p>The '<tt>ptrtoint</tt>' instruction converts <tt>value</tt> to integer type
4283    <tt>ty2</tt> by interpreting the pointer value as an integer and either
4284    truncating or zero extending that value to the size of the integer type. If
4285    <tt>value</tt> is smaller than <tt>ty2</tt> then a zero extension is done. If
4286    <tt>value</tt> is larger than <tt>ty2</tt> then a truncation is done. If they
4287    are the same size, then nothing is done (<i>no-op cast</i>) other than a type
4288    change.</p>
4289
4290 <h5>Example:</h5>
4291 <pre>
4292   %X = ptrtoint i32* %X to i8           <i>; yields truncation on 32-bit architecture</i>
4293   %Y = ptrtoint i32* %x to i64          <i>; yields zero extension on 32-bit architecture</i>
4294 </pre>
4295
4296 </div>
4297
4298 <!-- _______________________________________________________________________ -->
4299 <div class="doc_subsubsection">
4300    <a name="i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a>
4301 </div>
4302 <div class="doc_text">
4303
4304 <h5>Syntax:</h5>
4305 <pre>
4306   &lt;result&gt; = inttoptr &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt;             <i>; yields ty2</i>
4307 </pre>
4308
4309 <h5>Overview:</h5>
4310 <p>The '<tt>inttoptr</tt>' instruction converts an integer <tt>value</tt> to a
4311    pointer type, <tt>ty2</tt>.</p>
4312
4313 <h5>Arguments:</h5>
4314 <p>The '<tt>inttoptr</tt>' instruction takes an <a href="#t_integer">integer</a>
4315    value to cast, and a type to cast it to, which must be a
4316    <a href="#t_pointer">pointer</a> type.</p>
4317
4318 <h5>Semantics:</h5>
4319 <p>The '<tt>inttoptr</tt>' instruction converts <tt>value</tt> to type
4320    <tt>ty2</tt> by applying either a zero extension or a truncation depending on
4321    the size of the integer <tt>value</tt>. If <tt>value</tt> is larger than the
4322    size of a pointer then a truncation is done. If <tt>value</tt> is smaller
4323    than the size of a pointer then a zero extension is done. If they are the
4324    same size, nothing is done (<i>no-op cast</i>).</p>
4325
4326 <h5>Example:</h5>
4327 <pre>
4328   %X = inttoptr i32 255 to i32*          <i>; yields zero extension on 64-bit architecture</i>
4329   %X = inttoptr i32 255 to i32*          <i>; yields no-op on 32-bit architecture</i>
4330   %Y = inttoptr i64 0 to i32*            <i>; yields truncation on 32-bit architecture</i>
4331 </pre>
4332
4333 </div>
4334
4335 <!-- _______________________________________________________________________ -->
4336 <div class="doc_subsubsection">
4337    <a name="i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a>
4338 </div>
4339 <div class="doc_text">
4340
4341 <h5>Syntax:</h5>
4342 <pre>
4343   &lt;result&gt; = bitcast &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt;             <i>; yields ty2</i>
4344 </pre>
4345
4346 <h5>Overview:</h5>
4347 <p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
4348    <tt>ty2</tt> without changing any bits.</p>
4349
4350 <h5>Arguments:</h5>
4351 <p>The '<tt>bitcast</tt>' instruction takes a value to cast, which must be a
4352    non-aggregate first class value, and a type to cast it to, which must also be
4353    a non-aggregate <a href="#t_firstclass">first class</a> type. The bit sizes
4354    of <tt>value</tt> and the destination type, <tt>ty2</tt>, must be
4355    identical. If the source type is a pointer, the destination type must also be
4356    a pointer.  This instruction supports bitwise conversion of vectors to
4357    integers and to vectors of other types (as long as they have the same
4358    size).</p>
4359
4360 <h5>Semantics:</h5>
4361 <p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
4362    <tt>ty2</tt>. It is always a <i>no-op cast</i> because no bits change with
4363    this conversion.  The conversion is done as if the <tt>value</tt> had been
4364    stored to memory and read back as type <tt>ty2</tt>. Pointer types may only
4365    be converted to other pointer types with this instruction. To convert
4366    pointers to other types, use the <a href="#i_inttoptr">inttoptr</a> or
4367    <a href="#i_ptrtoint">ptrtoint</a> instructions first.</p>
4368
4369 <h5>Example:</h5>
4370 <pre>
4371   %X = bitcast i8 255 to i8              <i>; yields i8 :-1</i>
4372   %Y = bitcast i32* %x to sint*          <i>; yields sint*:%x</i>
4373   %Z = bitcast &lt;2 x int&gt; %V to i64;      <i>; yields i64: %V</i>   
4374 </pre>
4375
4376 </div>
4377
4378 <!-- ======================================================================= -->
4379 <div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
4380
4381 <div class="doc_text">
4382
4383 <p>The instructions in this category are the "miscellaneous" instructions, which
4384    defy better classification.</p>
4385
4386 </div>
4387
4388 <!-- _______________________________________________________________________ -->
4389 <div class="doc_subsubsection"><a name="i_icmp">'<tt>icmp</tt>' Instruction</a>
4390 </div>
4391
4392 <div class="doc_text">
4393
4394 <h5>Syntax:</h5>
4395 <pre>
4396   &lt;result&gt; = icmp &lt;cond&gt; &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt;   <i>; yields {i1} or {&lt;N x i1&gt;}:result</i>
4397 </pre>
4398
4399 <h5>Overview:</h5>
4400 <p>The '<tt>icmp</tt>' instruction returns a boolean value or a vector of
4401    boolean values based on comparison of its two integer, integer vector, or
4402    pointer operands.</p>
4403
4404 <h5>Arguments:</h5>
4405 <p>The '<tt>icmp</tt>' instruction takes three operands. The first operand is
4406    the condition code indicating the kind of comparison to perform. It is not a
4407    value, just a keyword. The possible condition code are:</p>
4408
4409 <ol>
4410   <li><tt>eq</tt>: equal</li>
4411   <li><tt>ne</tt>: not equal </li>
4412   <li><tt>ugt</tt>: unsigned greater than</li>
4413   <li><tt>uge</tt>: unsigned greater or equal</li>
4414   <li><tt>ult</tt>: unsigned less than</li>
4415   <li><tt>ule</tt>: unsigned less or equal</li>
4416   <li><tt>sgt</tt>: signed greater than</li>
4417   <li><tt>sge</tt>: signed greater or equal</li>
4418   <li><tt>slt</tt>: signed less than</li>
4419   <li><tt>sle</tt>: signed less or equal</li>
4420 </ol>
4421
4422 <p>The remaining two arguments must be <a href="#t_integer">integer</a> or
4423    <a href="#t_pointer">pointer</a> or integer <a href="#t_vector">vector</a>
4424    typed.  They must also be identical types.</p>
4425
4426 <h5>Semantics:</h5>
4427 <p>The '<tt>icmp</tt>' compares <tt>op1</tt> and <tt>op2</tt> according to the
4428    condition code given as <tt>cond</tt>. The comparison performed always yields
4429    either an <a href="#t_primitive"><tt>i1</tt></a> or vector of <tt>i1</tt>
4430    result, as follows:</p>
4431
4432 <ol>
4433   <li><tt>eq</tt>: yields <tt>true</tt> if the operands are equal, 
4434       <tt>false</tt> otherwise. No sign interpretation is necessary or
4435       performed.</li>
4436
4437   <li><tt>ne</tt>: yields <tt>true</tt> if the operands are unequal, 
4438       <tt>false</tt> otherwise. No sign interpretation is necessary or
4439       performed.</li>
4440
4441   <li><tt>ugt</tt>: interprets the operands as unsigned values and yields
4442       <tt>true</tt> if <tt>op1</tt> is greater than <tt>op2</tt>.</li>
4443
4444   <li><tt>uge</tt>: interprets the operands as unsigned values and yields
4445       <tt>true</tt> if <tt>op1</tt> is greater than or equal
4446       to <tt>op2</tt>.</li>
4447
4448   <li><tt>ult</tt>: interprets the operands as unsigned values and yields
4449       <tt>true</tt> if <tt>op1</tt> is less than <tt>op2</tt>.</li>
4450
4451   <li><tt>ule</tt>: interprets the operands as unsigned values and yields
4452       <tt>true</tt> if <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li>
4453
4454   <li><tt>sgt</tt>: interprets the operands as signed values and yields
4455       <tt>true</tt> if <tt>op1</tt> is greater than <tt>op2</tt>.</li>
4456
4457   <li><tt>sge</tt>: interprets the operands as signed values and yields
4458       <tt>true</tt> if <tt>op1</tt> is greater than or equal
4459       to <tt>op2</tt>.</li>
4460
4461   <li><tt>slt</tt>: interprets the operands as signed values and yields
4462       <tt>true</tt> if <tt>op1</tt> is less than <tt>op2</tt>.</li>
4463
4464   <li><tt>sle</tt>: interprets the operands as signed values and yields
4465       <tt>true</tt> if <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li>
4466 </ol>
4467
4468 <p>If the operands are <a href="#t_pointer">pointer</a> typed, the pointer
4469    values are compared as if they were integers.</p>
4470
4471 <p>If the operands are integer vectors, then they are compared element by
4472    element. The result is an <tt>i1</tt> vector with the same number of elements
4473    as the values being compared.  Otherwise, the result is an <tt>i1</tt>.</p>
4474
4475 <h5>Example:</h5>
4476 <pre>
4477   &lt;result&gt; = icmp eq i32 4, 5          <i>; yields: result=false</i>
4478   &lt;result&gt; = icmp ne float* %X, %X     <i>; yields: result=false</i>
4479   &lt;result&gt; = icmp ult i16  4, 5        <i>; yields: result=true</i>
4480   &lt;result&gt; = icmp sgt i16  4, 5        <i>; yields: result=false</i>
4481   &lt;result&gt; = icmp ule i16 -4, 5        <i>; yields: result=false</i>
4482   &lt;result&gt; = icmp sge i16  4, 5        <i>; yields: result=false</i>
4483 </pre>
4484
4485 <p>Note that the code generator does not yet support vector types with
4486    the <tt>icmp</tt> instruction.</p>
4487
4488 </div>
4489
4490 <!-- _______________________________________________________________________ -->
4491 <div class="doc_subsubsection"><a name="i_fcmp">'<tt>fcmp</tt>' Instruction</a>
4492 </div>
4493
4494 <div class="doc_text">
4495
4496 <h5>Syntax:</h5>
4497 <pre>
4498   &lt;result&gt; = fcmp &lt;cond&gt; &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt;     <i>; yields {i1} or {&lt;N x i1&gt;}:result</i>
4499 </pre>
4500
4501 <h5>Overview:</h5>
4502 <p>The '<tt>fcmp</tt>' instruction returns a boolean value or vector of boolean
4503    values based on comparison of its operands.</p>
4504
4505 <p>If the operands are floating point scalars, then the result type is a boolean
4506 (<a href="#t_primitive"><tt>i1</tt></a>).</p>
4507
4508 <p>If the operands are floating point vectors, then the result type is a vector
4509    of boolean with the same number of elements as the operands being
4510    compared.</p>
4511
4512 <h5>Arguments:</h5>
4513 <p>The '<tt>fcmp</tt>' instruction takes three operands. The first operand is
4514    the condition code indicating the kind of comparison to perform. It is not a
4515    value, just a keyword. The possible condition code are:</p>
4516
4517 <ol>
4518   <li><tt>false</tt>: no comparison, always returns false</li>
4519   <li><tt>oeq</tt>: ordered and equal</li>
4520   <li><tt>ogt</tt>: ordered and greater than </li>
4521   <li><tt>oge</tt>: ordered and greater than or equal</li>
4522   <li><tt>olt</tt>: ordered and less than </li>
4523   <li><tt>ole</tt>: ordered and less than or equal</li>
4524   <li><tt>one</tt>: ordered and not equal</li>
4525   <li><tt>ord</tt>: ordered (no nans)</li>
4526   <li><tt>ueq</tt>: unordered or equal</li>
4527   <li><tt>ugt</tt>: unordered or greater than </li>
4528   <li><tt>uge</tt>: unordered or greater than or equal</li>
4529   <li><tt>ult</tt>: unordered or less than </li>
4530   <li><tt>ule</tt>: unordered or less than or equal</li>
4531   <li><tt>une</tt>: unordered or not equal</li>
4532   <li><tt>uno</tt>: unordered (either nans)</li>
4533   <li><tt>true</tt>: no comparison, always returns true</li>
4534 </ol>
4535
4536 <p><i>Ordered</i> means that neither operand is a QNAN while
4537    <i>unordered</i> means that either operand may be a QNAN.</p>
4538
4539 <p>Each of <tt>val1</tt> and <tt>val2</tt> arguments must be either
4540    a <a href="#t_floating">floating point</a> type or
4541    a <a href="#t_vector">vector</a> of floating point type.  They must have
4542    identical types.</p>
4543
4544 <h5>Semantics:</h5>
4545 <p>The '<tt>fcmp</tt>' instruction compares <tt>op1</tt> and <tt>op2</tt>
4546    according to the condition code given as <tt>cond</tt>.  If the operands are
4547    vectors, then the vectors are compared element by element.  Each comparison
4548    performed always yields an <a href="#t_primitive">i1</a> result, as
4549    follows:</p>
4550
4551 <ol>
4552   <li><tt>false</tt>: always yields <tt>false</tt>, regardless of operands.</li>
4553
4554   <li><tt>oeq</tt>: yields <tt>true</tt> if both operands are not a QNAN and 
4555       <tt>op1</tt> is equal to <tt>op2</tt>.</li>
4556
4557   <li><tt>ogt</tt>: yields <tt>true</tt> if both operands are not a QNAN and
4558       <tt>op1</tt> is greather than <tt>op2</tt>.</li>
4559
4560   <li><tt>oge</tt>: yields <tt>true</tt> if both operands are not a QNAN and 
4561       <tt>op1</tt> is greater than or equal to <tt>op2</tt>.</li>
4562
4563   <li><tt>olt</tt>: yields <tt>true</tt> if both operands are not a QNAN and 
4564       <tt>op1</tt> is less than <tt>op2</tt>.</li>
4565
4566   <li><tt>ole</tt>: yields <tt>true</tt> if both operands are not a QNAN and 
4567       <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li>
4568
4569   <li><tt>one</tt>: yields <tt>true</tt> if both operands are not a QNAN and 
4570       <tt>op1</tt> is not equal to <tt>op2</tt>.</li>
4571
4572   <li><tt>ord</tt>: yields <tt>true</tt> if both operands are not a QNAN.</li>
4573
4574   <li><tt>ueq</tt>: yields <tt>true</tt> if either operand is a QNAN or 
4575       <tt>op1</tt> is equal to <tt>op2</tt>.</li>
4576
4577   <li><tt>ugt</tt>: yields <tt>true</tt> if either operand is a QNAN or 
4578       <tt>op1</tt> is greater than <tt>op2</tt>.</li>
4579
4580   <li><tt>uge</tt>: yields <tt>true</tt> if either operand is a QNAN or 
4581       <tt>op1</tt> is greater than or equal to <tt>op2</tt>.</li>
4582
4583   <li><tt>ult</tt>: yields <tt>true</tt> if either operand is a QNAN or 
4584       <tt>op1</tt> is less than <tt>op2</tt>.</li>
4585
4586   <li><tt>ule</tt>: yields <tt>true</tt> if either operand is a QNAN or 
4587       <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li>
4588
4589   <li><tt>une</tt>: yields <tt>true</tt> if either operand is a QNAN or 
4590       <tt>op1</tt> is not equal to <tt>op2</tt>.</li>
4591
4592   <li><tt>uno</tt>: yields <tt>true</tt> if either operand is a QNAN.</li>
4593
4594   <li><tt>true</tt>: always yields <tt>true</tt>, regardless of operands.</li>
4595 </ol>
4596
4597 <h5>Example:</h5>
4598 <pre>
4599   &lt;result&gt; = fcmp oeq float 4.0, 5.0    <i>; yields: result=false</i>
4600   &lt;result&gt; = fcmp one float 4.0, 5.0    <i>; yields: result=true</i>
4601   &lt;result&gt; = fcmp olt float 4.0, 5.0    <i>; yields: result=true</i>
4602   &lt;result&gt; = fcmp ueq double 1.0, 2.0   <i>; yields: result=false</i>
4603 </pre>
4604
4605 <p>Note that the code generator does not yet support vector types with
4606    the <tt>fcmp</tt> instruction.</p>
4607
4608 </div>
4609
4610 <!-- _______________________________________________________________________ -->
4611 <div class="doc_subsubsection">
4612   <a name="i_phi">'<tt>phi</tt>' Instruction</a>
4613 </div>
4614
4615 <div class="doc_text">
4616
4617 <h5>Syntax:</h5>
4618 <pre>
4619   &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...
4620 </pre>
4621
4622 <h5>Overview:</h5>
4623 <p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in the
4624    SSA graph representing the function.</p>
4625
4626 <h5>Arguments:</h5>
4627 <p>The type of the incoming values is specified with the first type field. After
4628    this, the '<tt>phi</tt>' instruction takes a list of pairs as arguments, with
4629    one pair for each predecessor basic block of the current block.  Only values
4630    of <a href="#t_firstclass">first class</a> type may be used as the value
4631    arguments to the PHI node.  Only labels may be used as the label
4632    arguments.</p>
4633
4634 <p>There must be no non-phi instructions between the start of a basic block and
4635    the PHI instructions: i.e. PHI instructions must be first in a basic
4636    block.</p>
4637
4638 <p>For the purposes of the SSA form, the use of each incoming value is deemed to
4639    occur on the edge from the corresponding predecessor block to the current
4640    block (but after any definition of an '<tt>invoke</tt>' instruction's return
4641    value on the same edge).</p>
4642
4643 <h5>Semantics:</h5>
4644 <p>At runtime, the '<tt>phi</tt>' instruction logically takes on the value
4645    specified by the pair corresponding to the predecessor basic block that
4646    executed just prior to the current block.</p>
4647
4648 <h5>Example:</h5>
4649 <pre>
4650 Loop:       ; Infinite loop that counts from 0 on up...
4651   %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]
4652   %nextindvar = add i32 %indvar, 1
4653   br label %Loop
4654 </pre>
4655
4656 </div>
4657
4658 <!-- _______________________________________________________________________ -->
4659 <div class="doc_subsubsection">
4660    <a name="i_select">'<tt>select</tt>' Instruction</a>
4661 </div>
4662
4663 <div class="doc_text">
4664
4665 <h5>Syntax:</h5>
4666 <pre>
4667   &lt;result&gt; = select <i>selty</i> &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt;             <i>; yields ty</i>
4668
4669   <i>selty</i> is either i1 or {&lt;N x i1&gt;}
4670 </pre>
4671
4672 <h5>Overview:</h5>
4673 <p>The '<tt>select</tt>' instruction is used to choose one value based on a
4674    condition, without branching.</p>
4675
4676
4677 <h5>Arguments:</h5>
4678 <p>The '<tt>select</tt>' instruction requires an 'i1' value or a vector of 'i1'
4679    values indicating the condition, and two values of the
4680    same <a href="#t_firstclass">first class</a> type.  If the val1/val2 are
4681    vectors and the condition is a scalar, then entire vectors are selected, not
4682    individual elements.</p>
4683
4684 <h5>Semantics:</h5>
4685 <p>If the condition is an i1 and it evaluates to 1, the instruction returns the
4686    first value argument; otherwise, it returns the second value argument.</p>
4687
4688 <p>If the condition is a vector of i1, then the value arguments must be vectors
4689    of the same size, and the selection is done element by element.</p>
4690
4691 <h5>Example:</h5>
4692 <pre>
4693   %X = select i1 true, i8 17, i8 42          <i>; yields i8:17</i>
4694 </pre>
4695
4696 <p>Note that the code generator does not yet support conditions
4697    with vector type.</p>
4698
4699 </div>
4700
4701 <!-- _______________________________________________________________________ -->
4702 <div class="doc_subsubsection">
4703   <a name="i_call">'<tt>call</tt>' Instruction</a>
4704 </div>
4705
4706 <div class="doc_text">
4707
4708 <h5>Syntax:</h5>
4709 <pre>
4710   &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>]
4711 </pre>
4712
4713 <h5>Overview:</h5>
4714 <p>The '<tt>call</tt>' instruction represents a simple function call.</p>
4715
4716 <h5>Arguments:</h5>
4717 <p>This instruction requires several arguments:</p>
4718
4719 <ol>
4720   <li>The optional "tail" marker indicates whether the callee function accesses
4721       any allocas or varargs in the caller.  If the "tail" marker is present,
4722       the function call is eligible for tail call optimization.  Note that calls
4723       may be marked "tail" even if they do not occur before
4724       a <a href="#i_ret"><tt>ret</tt></a> instruction.</li>
4725
4726   <li>The optional "cconv" marker indicates which <a href="#callingconv">calling
4727       convention</a> the call should use.  If none is specified, the call
4728       defaults to using C calling conventions.</li>
4729
4730   <li>The optional <a href="#paramattrs">Parameter Attributes</a> list for
4731       return values. Only '<tt>zeroext</tt>', '<tt>signext</tt>', and
4732       '<tt>inreg</tt>' attributes are valid here.</li>
4733
4734   <li>'<tt>ty</tt>': the type of the call instruction itself which is also the
4735       type of the return value.  Functions that return no value are marked
4736       <tt><a href="#t_void">void</a></tt>.</li>
4737
4738   <li>'<tt>fnty</tt>': shall be the signature of the pointer to function value
4739       being invoked.  The argument types must match the types implied by this
4740       signature.  This type can be omitted if the function is not varargs and if
4741       the function type does not return a pointer to a function.</li>
4742
4743   <li>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to
4744       be invoked. In most cases, this is a direct function invocation, but
4745       indirect <tt>call</tt>s are just as possible, calling an arbitrary pointer
4746       to function value.</li>
4747
4748   <li>'<tt>function args</tt>': argument list whose types match the function
4749       signature argument types. All arguments must be of
4750       <a href="#t_firstclass">first class</a> type. If the function signature
4751       indicates the function accepts a variable number of arguments, the extra
4752       arguments can be specified.</li>
4753
4754   <li>The optional <a href="#fnattrs">function attributes</a> list. Only
4755       '<tt>noreturn</tt>', '<tt>nounwind</tt>', '<tt>readonly</tt>' and
4756       '<tt>readnone</tt>' attributes are valid here.</li>
4757 </ol>
4758
4759 <h5>Semantics:</h5>
4760 <p>The '<tt>call</tt>' instruction is used to cause control flow to transfer to
4761    a specified function, with its incoming arguments bound to the specified
4762    values. Upon a '<tt><a href="#i_ret">ret</a></tt>' instruction in the called
4763    function, control flow continues with the instruction after the function
4764    call, and the return value of the function is bound to the result
4765    argument.</p>
4766
4767 <h5>Example:</h5>
4768 <pre>
4769   %retval = call i32 @test(i32 %argc)
4770   call i32 (i8 *, ...)* @printf(i8 * %msg, i32 12, i8 42)      <i>; yields i32</i>
4771   %X = tail call i32 @foo()                                    <i>; yields i32</i>
4772   %Y = tail call <a href="#callingconv">fastcc</a> i32 @foo()  <i>; yields i32</i>
4773   call void %foo(i8 97 signext)
4774
4775   %struct.A = type { i32, i8 }
4776   %r = call %struct.A @foo()                        <i>; yields { 32, i8 }</i>
4777   %gr = extractvalue %struct.A %r, 0                <i>; yields i32</i>
4778   %gr1 = extractvalue %struct.A %r, 1               <i>; yields i8</i>
4779   %Z = call void @foo() noreturn                    <i>; indicates that %foo never returns normally</i>
4780   %ZZ = call zeroext i32 @bar()                     <i>; Return value is %zero extended</i>
4781 </pre>
4782
4783 </div>
4784
4785 <!-- _______________________________________________________________________ -->
4786 <div class="doc_subsubsection">
4787   <a name="i_va_arg">'<tt>va_arg</tt>' Instruction</a>
4788 </div>
4789
4790 <div class="doc_text">
4791
4792 <h5>Syntax:</h5>
4793 <pre>
4794   &lt;resultval&gt; = va_arg &lt;va_list*&gt; &lt;arglist&gt;, &lt;argty&gt;
4795 </pre>
4796
4797 <h5>Overview:</h5>
4798 <p>The '<tt>va_arg</tt>' instruction is used to access arguments passed through
4799    the "variable argument" area of a function call.  It is used to implement the
4800    <tt>va_arg</tt> macro in C.</p>
4801
4802 <h5>Arguments:</h5>
4803 <p>This instruction takes a <tt>va_list*</tt> value and the type of the
4804    argument. It returns a value of the specified argument type and increments
4805    the <tt>va_list</tt> to point to the next argument.  The actual type
4806    of <tt>va_list</tt> is target specific.</p>
4807
4808 <h5>Semantics:</h5>
4809 <p>The '<tt>va_arg</tt>' instruction loads an argument of the specified type
4810    from the specified <tt>va_list</tt> and causes the <tt>va_list</tt> to point
4811    to the next argument.  For more information, see the variable argument
4812    handling <a href="#int_varargs">Intrinsic Functions</a>.</p>
4813
4814 <p>It is legal for this instruction to be called in a function which does not
4815    take a variable number of arguments, for example, the <tt>vfprintf</tt>
4816    function.</p>
4817
4818 <p><tt>va_arg</tt> is an LLVM instruction instead of
4819    an <a href="#intrinsics">intrinsic function</a> because it takes a type as an
4820    argument.</p>
4821
4822 <h5>Example:</h5>
4823 <p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
4824
4825 <p>Note that the code generator does not yet fully support va_arg on many
4826    targets. Also, it does not currently support va_arg with aggregate types on
4827    any target.</p>
4828
4829 </div>
4830
4831 <!-- *********************************************************************** -->
4832 <div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
4833 <!-- *********************************************************************** -->
4834
4835 <div class="doc_text">
4836
4837 <p>LLVM supports the notion of an "intrinsic function".  These functions have
4838    well known names and semantics and are required to follow certain
4839    restrictions.  Overall, these intrinsics represent an extension mechanism for
4840    the LLVM language that does not require changing all of the transformations
4841    in LLVM when adding to the language (or the bitcode reader/writer, the
4842    parser, etc...).</p>
4843
4844 <p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix. This
4845    prefix is reserved in LLVM for intrinsic names; thus, function names may not
4846    begin with this prefix.  Intrinsic functions must always be external
4847    functions: you cannot define the body of intrinsic functions.  Intrinsic
4848    functions may only be used in call or invoke instructions: it is illegal to
4849    take the address of an intrinsic function.  Additionally, because intrinsic
4850    functions are part of the LLVM language, it is required if any are added that
4851    they be documented here.</p>
4852
4853 <p>Some intrinsic functions can be overloaded, i.e., the intrinsic represents a
4854    family of functions that perform the same operation but on different data
4855    types. Because LLVM can represent over 8 million different integer types,
4856    overloading is used commonly to allow an intrinsic function to operate on any
4857    integer type. One or more of the argument types or the result type can be
4858    overloaded to accept any integer type. Argument types may also be defined as
4859    exactly matching a previous argument's type or the result type. This allows
4860    an intrinsic function which accepts multiple arguments, but needs all of them
4861    to be of the same type, to only be overloaded with respect to a single
4862    argument or the result.</p>
4863
4864 <p>Overloaded intrinsics will have the names of its overloaded argument types
4865    encoded into its function name, each preceded by a period. Only those types
4866    which are overloaded result in a name suffix. Arguments whose type is matched
4867    against another type do not. For example, the <tt>llvm.ctpop</tt> function
4868    can take an integer of any width and returns an integer of exactly the same
4869    integer width. This leads to a family of functions such as
4870    <tt>i8 @llvm.ctpop.i8(i8 %val)</tt> and <tt>i29 @llvm.ctpop.i29(i29
4871    %val)</tt>.  Only one type, the return type, is overloaded, and only one type
4872    suffix is required. Because the argument's type is matched against the return
4873    type, it does not require its own name suffix.</p>
4874
4875 <p>To learn how to add an intrinsic function, please see the 
4876    <a href="ExtendingLLVM.html">Extending LLVM Guide</a>.</p>
4877
4878 </div>
4879
4880 <!-- ======================================================================= -->
4881 <div class="doc_subsection">
4882   <a name="int_varargs">Variable Argument Handling Intrinsics</a>
4883 </div>
4884
4885 <div class="doc_text">
4886
4887 <p>Variable argument support is defined in LLVM with
4888    the <a href="#i_va_arg"><tt>va_arg</tt></a> instruction and these three
4889    intrinsic functions.  These functions are related to the similarly named
4890    macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
4891
4892 <p>All of these functions operate on arguments that use a target-specific value
4893    type "<tt>va_list</tt>".  The LLVM assembly language reference manual does
4894    not define what this type is, so all transformations should be prepared to
4895    handle these functions regardless of the type used.</p>
4896
4897 <p>This example shows how the <a href="#i_va_arg"><tt>va_arg</tt></a>
4898    instruction and the variable argument handling intrinsic functions are
4899    used.</p>
4900
4901 <div class="doc_code">
4902 <pre>
4903 define i32 @test(i32 %X, ...) {
4904   ; Initialize variable argument processing
4905   %ap = alloca i8*
4906   %ap2 = bitcast i8** %ap to i8*
4907   call void @llvm.va_start(i8* %ap2)
4908
4909   ; Read a single integer argument
4910   %tmp = va_arg i8** %ap, i32
4911
4912   ; Demonstrate usage of llvm.va_copy and llvm.va_end
4913   %aq = alloca i8*
4914   %aq2 = bitcast i8** %aq to i8*
4915   call void @llvm.va_copy(i8* %aq2, i8* %ap2)
4916   call void @llvm.va_end(i8* %aq2)
4917
4918   ; Stop processing of arguments.
4919   call void @llvm.va_end(i8* %ap2)
4920   ret i32 %tmp
4921 }
4922
4923 declare void @llvm.va_start(i8*)
4924 declare void @llvm.va_copy(i8*, i8*)
4925 declare void @llvm.va_end(i8*)
4926 </pre>
4927 </div>
4928
4929 </div>
4930
4931 <!-- _______________________________________________________________________ -->
4932 <div class="doc_subsubsection">
4933   <a name="int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
4934 </div>
4935
4936
4937 <div class="doc_text">
4938
4939 <h5>Syntax:</h5>
4940 <pre>
4941   declare void %llvm.va_start(i8* &lt;arglist&gt;)
4942 </pre>
4943
4944 <h5>Overview:</h5>
4945 <p>The '<tt>llvm.va_start</tt>' intrinsic initializes <tt>*&lt;arglist&gt;</tt>
4946    for subsequent use by <tt><a href="#i_va_arg">va_arg</a></tt>.</p>
4947
4948 <h5>Arguments:</h5>
4949 <p>The argument is a pointer to a <tt>va_list</tt> element to initialize.</p>
4950
4951 <h5>Semantics:</h5>
4952 <p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
4953    macro available in C.  In a target-dependent way, it initializes
4954    the <tt>va_list</tt> element to which the argument points, so that the next
4955    call to <tt>va_arg</tt> will produce the first variable argument passed to
4956    the function.  Unlike the C <tt>va_start</tt> macro, this intrinsic does not
4957    need to know the last argument of the function as the compiler can figure
4958    that out.</p>
4959
4960 </div>
4961
4962 <!-- _______________________________________________________________________ -->
4963 <div class="doc_subsubsection">
4964  <a name="int_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
4965 </div>
4966
4967 <div class="doc_text">
4968
4969 <h5>Syntax:</h5>
4970 <pre>
4971   declare void @llvm.va_end(i8* &lt;arglist&gt;)
4972 </pre>
4973
4974 <h5>Overview:</h5>
4975 <p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>*&lt;arglist&gt;</tt>,
4976    which has been initialized previously
4977    with <tt><a href="#int_va_start">llvm.va_start</a></tt>
4978    or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
4979
4980 <h5>Arguments:</h5>
4981 <p>The argument is a pointer to a <tt>va_list</tt> to destroy.</p>
4982
4983 <h5>Semantics:</h5>
4984 <p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
4985    macro available in C.  In a target-dependent way, it destroys
4986    the <tt>va_list</tt> element to which the argument points.  Calls
4987    to <a href="#int_va_start"><tt>llvm.va_start</tt></a>
4988    and <a href="#int_va_copy"> <tt>llvm.va_copy</tt></a> must be matched exactly
4989    with calls to <tt>llvm.va_end</tt>.</p>
4990
4991 </div>
4992
4993 <!-- _______________________________________________________________________ -->
4994 <div class="doc_subsubsection">
4995   <a name="int_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
4996 </div>
4997
4998 <div class="doc_text">
4999
5000 <h5>Syntax:</h5>
5001 <pre>
5002   declare void @llvm.va_copy(i8* &lt;destarglist&gt;, i8* &lt;srcarglist&gt;)
5003 </pre>
5004
5005 <h5>Overview:</h5>
5006 <p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position
5007    from the source argument list to the destination argument list.</p>
5008
5009 <h5>Arguments:</h5>
5010 <p>The first argument is a pointer to a <tt>va_list</tt> element to initialize.
5011    The second argument is a pointer to a <tt>va_list</tt> element to copy
5012    from.</p>
5013
5014 <h5>Semantics:</h5>
5015 <p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
5016    macro available in C.  In a target-dependent way, it copies the
5017    source <tt>va_list</tt> element into the destination <tt>va_list</tt>
5018    element.  This intrinsic is necessary because
5019    the <tt><a href="#int_va_start"> llvm.va_start</a></tt> intrinsic may be
5020    arbitrarily complex and require, for example, memory allocation.</p>
5021
5022 </div>
5023
5024 <!-- ======================================================================= -->
5025 <div class="doc_subsection">
5026   <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
5027 </div>
5028
5029 <div class="doc_text">
5030
5031 <p>LLVM support for <a href="GarbageCollection.html">Accurate Garbage
5032 Collection</a> (GC) requires the implementation and generation of these
5033 intrinsics. These intrinsics allow identification of <a href="#int_gcroot">GC
5034 roots on the stack</a>, as well as garbage collector implementations that
5035 require <a href="#int_gcread">read</a> and <a href="#int_gcwrite">write</a>
5036 barriers.  Front-ends for type-safe garbage collected languages should generate
5037 these intrinsics to make use of the LLVM garbage collectors.  For more details,
5038 see <a href="GarbageCollection.html">Accurate Garbage Collection with
5039 LLVM</a>.</p>
5040
5041 <p>The garbage collection intrinsics only operate on objects in the generic
5042    address space (address space zero).</p>
5043
5044 </div>
5045
5046 <!-- _______________________________________________________________________ -->
5047 <div class="doc_subsubsection">
5048   <a name="int_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
5049 </div>
5050
5051 <div class="doc_text">
5052
5053 <h5>Syntax:</h5>
5054 <pre>
5055   declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata)
5056 </pre>
5057
5058 <h5>Overview:</h5>
5059 <p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
5060    the code generator, and allows some metadata to be associated with it.</p>
5061
5062 <h5>Arguments:</h5>
5063 <p>The first argument specifies the address of a stack object that contains the
5064    root pointer.  The second pointer (which must be either a constant or a
5065    global value address) contains the meta-data to be associated with the
5066    root.</p>
5067
5068 <h5>Semantics:</h5>
5069 <p>At runtime, a call to this intrinsic stores a null pointer into the "ptrloc"
5070    location.  At compile-time, the code generator generates information to allow
5071    the runtime to find the pointer at GC safe points. The '<tt>llvm.gcroot</tt>'
5072    intrinsic may only be used in a function which <a href="#gc">specifies a GC
5073    algorithm</a>.</p>
5074
5075 </div>
5076
5077 <!-- _______________________________________________________________________ -->
5078 <div class="doc_subsubsection">
5079   <a name="int_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
5080 </div>
5081
5082 <div class="doc_text">
5083
5084 <h5>Syntax:</h5>
5085 <pre>
5086   declare i8* @llvm.gcread(i8* %ObjPtr, i8** %Ptr)
5087 </pre>
5088
5089 <h5>Overview:</h5>
5090 <p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
5091    locations, allowing garbage collector implementations that require read
5092    barriers.</p>
5093
5094 <h5>Arguments:</h5>
5095 <p>The second argument is the address to read from, which should be an address
5096    allocated from the garbage collector.  The first object is a pointer to the
5097    start of the referenced object, if needed by the language runtime (otherwise
5098    null).</p>
5099
5100 <h5>Semantics:</h5>
5101 <p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
5102    instruction, but may be replaced with substantially more complex code by the
5103    garbage collector runtime, as needed. The '<tt>llvm.gcread</tt>' intrinsic
5104    may only be used in a function which <a href="#gc">specifies a GC
5105    algorithm</a>.</p>
5106
5107 </div>
5108
5109 <!-- _______________________________________________________________________ -->
5110 <div class="doc_subsubsection">
5111   <a name="int_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
5112 </div>
5113
5114 <div class="doc_text">
5115
5116 <h5>Syntax:</h5>
5117 <pre>
5118   declare void @llvm.gcwrite(i8* %P1, i8* %Obj, i8** %P2)
5119 </pre>
5120
5121 <h5>Overview:</h5>
5122 <p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
5123    locations, allowing garbage collector implementations that require write
5124    barriers (such as generational or reference counting collectors).</p>
5125
5126 <h5>Arguments:</h5>
5127 <p>The first argument is the reference to store, the second is the start of the
5128    object to store it to, and the third is the address of the field of Obj to
5129    store to.  If the runtime does not require a pointer to the object, Obj may
5130    be null.</p>
5131
5132 <h5>Semantics:</h5>
5133 <p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
5134    instruction, but may be replaced with substantially more complex code by the
5135    garbage collector runtime, as needed. The '<tt>llvm.gcwrite</tt>' intrinsic
5136    may only be used in a function which <a href="#gc">specifies a GC
5137    algorithm</a>.</p>
5138
5139 </div>
5140
5141 <!-- ======================================================================= -->
5142 <div class="doc_subsection">
5143   <a name="int_codegen">Code Generator Intrinsics</a>
5144 </div>
5145
5146 <div class="doc_text">
5147
5148 <p>These intrinsics are provided by LLVM to expose special features that may
5149    only be implemented with code generator support.</p>
5150
5151 </div>
5152
5153 <!-- _______________________________________________________________________ -->
5154 <div class="doc_subsubsection">
5155   <a name="int_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
5156 </div>
5157
5158 <div class="doc_text">
5159
5160 <h5>Syntax:</h5>
5161 <pre>
5162   declare i8  *@llvm.returnaddress(i32 &lt;level&gt;)
5163 </pre>
5164
5165 <h5>Overview:</h5>
5166 <p>The '<tt>llvm.returnaddress</tt>' intrinsic attempts to compute a
5167    target-specific value indicating the return address of the current function
5168    or one of its callers.</p>
5169
5170 <h5>Arguments:</h5>
5171 <p>The argument to this intrinsic indicates which function to return the address
5172    for.  Zero indicates the calling function, one indicates its caller, etc.
5173    The argument is <b>required</b> to be a constant integer value.</p>
5174
5175 <h5>Semantics:</h5>
5176 <p>The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer
5177    indicating the return address of the specified call frame, or zero if it
5178    cannot be identified.  The value returned by this intrinsic is likely to be
5179    incorrect or 0 for arguments other than zero, so it should only be used for
5180    debugging purposes.</p>
5181
5182 <p>Note that calling this intrinsic does not prevent function inlining or other
5183    aggressive transformations, so the value returned may not be that of the
5184    obvious source-language caller.</p>
5185
5186 </div>
5187
5188 <!-- _______________________________________________________________________ -->
5189 <div class="doc_subsubsection">
5190   <a name="int_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
5191 </div>
5192
5193 <div class="doc_text">
5194
5195 <h5>Syntax:</h5>
5196 <pre>
5197   declare i8 *@llvm.frameaddress(i32 &lt;level&gt;)
5198 </pre>
5199
5200 <h5>Overview:</h5>
5201 <p>The '<tt>llvm.frameaddress</tt>' intrinsic attempts to return the
5202    target-specific frame pointer value for the specified stack frame.</p>
5203
5204 <h5>Arguments:</h5>
5205 <p>The argument to this intrinsic indicates which function to return the frame
5206    pointer for.  Zero indicates the calling function, one indicates its caller,
5207    etc.  The argument is <b>required</b> to be a constant integer value.</p>
5208
5209 <h5>Semantics:</h5>
5210 <p>The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer
5211    indicating the frame address of the specified call frame, or zero if it
5212    cannot be identified.  The value returned by this intrinsic is likely to be
5213    incorrect or 0 for arguments other than zero, so it should only be used for
5214    debugging purposes.</p>
5215
5216 <p>Note that calling this intrinsic does not prevent function inlining or other
5217    aggressive transformations, so the value returned may not be that of the
5218    obvious source-language caller.</p>
5219
5220 </div>
5221
5222 <!-- _______________________________________________________________________ -->
5223 <div class="doc_subsubsection">
5224   <a name="int_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a>
5225 </div>
5226
5227 <div class="doc_text">
5228
5229 <h5>Syntax:</h5>
5230 <pre>
5231   declare i8 *@llvm.stacksave()
5232 </pre>
5233
5234 <h5>Overview:</h5>
5235 <p>The '<tt>llvm.stacksave</tt>' intrinsic is used to remember the current state
5236    of the function stack, for use
5237    with <a href="#int_stackrestore"> <tt>llvm.stackrestore</tt></a>.  This is
5238    useful for implementing language features like scoped automatic variable
5239    sized arrays in C99.</p>
5240
5241 <h5>Semantics:</h5>
5242 <p>This intrinsic returns a opaque pointer value that can be passed
5243    to <a href="#int_stackrestore"><tt>llvm.stackrestore</tt></a>.  When
5244    an <tt>llvm.stackrestore</tt> intrinsic is executed with a value saved
5245    from <tt>llvm.stacksave</tt>, it effectively restores the state of the stack
5246    to the state it was in when the <tt>llvm.stacksave</tt> intrinsic executed.
5247    In practice, this pops any <a href="#i_alloca">alloca</a> blocks from the
5248    stack that were allocated after the <tt>llvm.stacksave</tt> was executed.</p>
5249
5250 </div>
5251
5252 <!-- _______________________________________________________________________ -->
5253 <div class="doc_subsubsection">
5254   <a name="int_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a>
5255 </div>
5256
5257 <div class="doc_text">
5258
5259 <h5>Syntax:</h5>
5260 <pre>
5261   declare void @llvm.stackrestore(i8 * %ptr)
5262 </pre>
5263
5264 <h5>Overview:</h5>
5265 <p>The '<tt>llvm.stackrestore</tt>' intrinsic is used to restore the state of
5266    the function stack to the state it was in when the
5267    corresponding <a href="#int_stacksave"><tt>llvm.stacksave</tt></a> intrinsic
5268    executed.  This is useful for implementing language features like scoped
5269    automatic variable sized arrays in C99.</p>
5270
5271 <h5>Semantics:</h5>
5272 <p>See the description
5273    for <a href="#int_stacksave"><tt>llvm.stacksave</tt></a>.</p>
5274
5275 </div>
5276
5277 <!-- _______________________________________________________________________ -->
5278 <div class="doc_subsubsection">
5279   <a name="int_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a>
5280 </div>
5281
5282 <div class="doc_text">
5283
5284 <h5>Syntax:</h5>
5285 <pre>
5286   declare void @llvm.prefetch(i8* &lt;address&gt;, i32 &lt;rw&gt;, i32 &lt;locality&gt;)
5287 </pre>
5288
5289 <h5>Overview:</h5>
5290 <p>The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to
5291    insert a prefetch instruction if supported; otherwise, it is a noop.
5292    Prefetches have no effect on the behavior of the program but can change its
5293    performance characteristics.</p>
5294
5295 <h5>Arguments:</h5>
5296 <p><tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the
5297    specifier determining if the fetch should be for a read (0) or write (1),
5298    and <tt>locality</tt> is a temporal locality specifier ranging from (0) - no
5299    locality, to (3) - extremely local keep in cache.  The <tt>rw</tt>
5300    and <tt>locality</tt> arguments must be constant integers.</p>
5301
5302 <h5>Semantics:</h5>
5303 <p>This intrinsic does not modify the behavior of the program.  In particular,
5304    prefetches cannot trap and do not produce a value.  On targets that support
5305    this intrinsic, the prefetch can provide hints to the processor cache for
5306    better performance.</p>
5307
5308 </div>
5309
5310 <!-- _______________________________________________________________________ -->
5311 <div class="doc_subsubsection">
5312   <a name="int_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a>
5313 </div>
5314
5315 <div class="doc_text">
5316
5317 <h5>Syntax:</h5>
5318 <pre>
5319   declare void @llvm.pcmarker(i32 &lt;id&gt;)
5320 </pre>
5321
5322 <h5>Overview:</h5>
5323 <p>The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a Program
5324    Counter (PC) in a region of code to simulators and other tools.  The method
5325    is target specific, but it is expected that the marker will use exported
5326    symbols to transmit the PC of the marker.  The marker makes no guarantees
5327    that it will remain with any specific instruction after optimizations.  It is
5328    possible that the presence of a marker will inhibit optimizations.  The
5329    intended use is to be inserted after optimizations to allow correlations of
5330    simulation runs.</p>
5331
5332 <h5>Arguments:</h5>
5333 <p><tt>id</tt> is a numerical id identifying the marker.</p>
5334
5335 <h5>Semantics:</h5>
5336 <p>This intrinsic does not modify the behavior of the program.  Backends that do
5337    not support this intrinisic may ignore it.</p>
5338
5339 </div>
5340
5341 <!-- _______________________________________________________________________ -->
5342 <div class="doc_subsubsection">
5343   <a name="int_readcyclecounter">'<tt>llvm.readcyclecounter</tt>' Intrinsic</a>
5344 </div>
5345
5346 <div class="doc_text">
5347
5348 <h5>Syntax:</h5>
5349 <pre>
5350   declare i64 @llvm.readcyclecounter( )
5351 </pre>
5352
5353 <h5>Overview:</h5>
5354 <p>The '<tt>llvm.readcyclecounter</tt>' intrinsic provides access to the cycle
5355    counter register (or similar low latency, high accuracy clocks) on those
5356    targets that support it.  On X86, it should map to RDTSC.  On Alpha, it
5357    should map to RPCC.  As the backing counters overflow quickly (on the order
5358    of 9 seconds on alpha), this should only be used for small timings.</p>
5359
5360 <h5>Semantics:</h5>
5361 <p>When directly supported, reading the cycle counter should not modify any
5362    memory.  Implementations are allowed to either return a application specific
5363    value or a system wide value.  On backends without support, this is lowered
5364    to a constant 0.</p>
5365
5366 </div>
5367
5368 <!-- ======================================================================= -->
5369 <div class="doc_subsection">
5370   <a name="int_libc">Standard C Library Intrinsics</a>
5371 </div>
5372
5373 <div class="doc_text">
5374
5375 <p>LLVM provides intrinsics for a few important standard C library functions.
5376    These intrinsics allow source-language front-ends to pass information about
5377    the alignment of the pointer arguments to the code generator, providing
5378    opportunity for more efficient code generation.</p>
5379
5380 </div>
5381
5382 <!-- _______________________________________________________________________ -->
5383 <div class="doc_subsubsection">
5384   <a name="int_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
5385 </div>
5386
5387 <div class="doc_text">
5388
5389 <h5>Syntax:</h5>
5390 <p>This is an overloaded intrinsic. You can use <tt>llvm.memcpy</tt> on any
5391    integer bit width. Not all targets support all bit widths however.</p>
5392
5393 <pre>
5394   declare void @llvm.memcpy.i8(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5395                                i8 &lt;len&gt;, i32 &lt;align&gt;)
5396   declare void @llvm.memcpy.i16(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5397                                 i16 &lt;len&gt;, i32 &lt;align&gt;)
5398   declare void @llvm.memcpy.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5399                                 i32 &lt;len&gt;, i32 &lt;align&gt;)
5400   declare void @llvm.memcpy.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5401                                 i64 &lt;len&gt;, i32 &lt;align&gt;)
5402 </pre>
5403
5404 <h5>Overview:</h5>
5405 <p>The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the
5406    source location to the destination location.</p>
5407
5408 <p>Note that, unlike the standard libc function, the <tt>llvm.memcpy.*</tt>
5409    intrinsics do not return a value, and takes an extra alignment argument.</p>
5410
5411 <h5>Arguments:</h5>
5412 <p>The first argument is a pointer to the destination, the second is a pointer
5413    to the source.  The third argument is an integer argument specifying the
5414    number of bytes to copy, and the fourth argument is the alignment of the
5415    source and destination locations.</p>
5416
5417 <p>If the call to this intrinisic has an alignment value that is not 0 or 1,
5418    then the caller guarantees that both the source and destination pointers are
5419    aligned to that boundary.</p>
5420
5421 <h5>Semantics:</h5>
5422 <p>The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the
5423    source location to the destination location, which are not allowed to
5424    overlap.  It copies "len" bytes of memory over.  If the argument is known to
5425    be aligned to some boundary, this can be specified as the fourth argument,
5426    otherwise it should be set to 0 or 1.</p>
5427
5428 </div>
5429
5430 <!-- _______________________________________________________________________ -->
5431 <div class="doc_subsubsection">
5432   <a name="int_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
5433 </div>
5434
5435 <div class="doc_text">
5436
5437 <h5>Syntax:</h5>
5438 <p>This is an overloaded intrinsic. You can use llvm.memmove on any integer bit
5439    width. Not all targets support all bit widths however.</p>
5440
5441 <pre>
5442   declare void @llvm.memmove.i8(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5443                                 i8 &lt;len&gt;, i32 &lt;align&gt;)
5444   declare void @llvm.memmove.i16(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5445                                  i16 &lt;len&gt;, i32 &lt;align&gt;)
5446   declare void @llvm.memmove.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5447                                  i32 &lt;len&gt;, i32 &lt;align&gt;)
5448   declare void @llvm.memmove.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5449                                  i64 &lt;len&gt;, i32 &lt;align&gt;)
5450 </pre>
5451
5452 <h5>Overview:</h5>
5453 <p>The '<tt>llvm.memmove.*</tt>' intrinsics move a block of memory from the
5454    source location to the destination location. It is similar to the
5455    '<tt>llvm.memcpy</tt>' intrinsic but allows the two memory locations to
5456    overlap.</p>
5457
5458 <p>Note that, unlike the standard libc function, the <tt>llvm.memmove.*</tt>
5459    intrinsics do not return a value, and takes an extra alignment argument.</p>
5460
5461 <h5>Arguments:</h5>
5462 <p>The first argument is a pointer to the destination, the second is a pointer
5463    to the source.  The third argument is an integer argument specifying the
5464    number of bytes to copy, and the fourth argument is the alignment of the
5465    source and destination locations.</p>
5466
5467 <p>If the call to this intrinisic has an alignment value that is not 0 or 1,
5468    then the caller guarantees that the source and destination pointers are
5469    aligned to that boundary.</p>
5470
5471 <h5>Semantics:</h5>
5472 <p>The '<tt>llvm.memmove.*</tt>' intrinsics copy a block of memory from the
5473    source location to the destination location, which may overlap.  It copies
5474    "len" bytes of memory over.  If the argument is known to be aligned to some
5475    boundary, this can be specified as the fourth argument, otherwise it should
5476    be set to 0 or 1.</p>
5477
5478 </div>
5479
5480 <!-- _______________________________________________________________________ -->
5481 <div class="doc_subsubsection">
5482   <a name="int_memset">'<tt>llvm.memset.*</tt>' Intrinsics</a>
5483 </div>
5484
5485 <div class="doc_text">
5486
5487 <h5>Syntax:</h5>
5488 <p>This is an overloaded intrinsic. You can use llvm.memset on any integer bit
5489    width. Not all targets support all bit widths however.</p>
5490
5491 <pre>
5492   declare void @llvm.memset.i8(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
5493                                i8 &lt;len&gt;, i32 &lt;align&gt;)
5494   declare void @llvm.memset.i16(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
5495                                 i16 &lt;len&gt;, i32 &lt;align&gt;)
5496   declare void @llvm.memset.i32(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
5497                                 i32 &lt;len&gt;, i32 &lt;align&gt;)
5498   declare void @llvm.memset.i64(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
5499                                 i64 &lt;len&gt;, i32 &lt;align&gt;)
5500 </pre>
5501
5502 <h5>Overview:</h5>
5503 <p>The '<tt>llvm.memset.*</tt>' intrinsics fill a block of memory with a
5504    particular byte value.</p>
5505
5506 <p>Note that, unlike the standard libc function, the <tt>llvm.memset</tt>
5507    intrinsic does not return a value, and takes an extra alignment argument.</p>
5508
5509 <h5>Arguments:</h5>
5510 <p>The first argument is a pointer to the destination to fill, the second is the
5511    byte value to fill it with, the third argument is an integer argument
5512    specifying the number of bytes to fill, and the fourth argument is the known
5513    alignment of destination location.</p>
5514
5515 <p>If the call to this intrinisic has an alignment value that is not 0 or 1,
5516    then the caller guarantees that the destination pointer is aligned to that
5517    boundary.</p>
5518
5519 <h5>Semantics:</h5>
5520 <p>The '<tt>llvm.memset.*</tt>' intrinsics fill "len" bytes of memory starting
5521    at the destination location.  If the argument is known to be aligned to some
5522    boundary, this can be specified as the fourth argument, otherwise it should
5523    be set to 0 or 1.</p>
5524
5525 </div>
5526
5527 <!-- _______________________________________________________________________ -->
5528 <div class="doc_subsubsection">
5529   <a name="int_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a>
5530 </div>
5531
5532 <div class="doc_text">
5533
5534 <h5>Syntax:</h5>
5535 <p>This is an overloaded intrinsic. You can use <tt>llvm.sqrt</tt> on any
5536    floating point or vector of floating point type. Not all targets support all
5537    types however.</p>
5538
5539 <pre>
5540   declare float     @llvm.sqrt.f32(float %Val)
5541   declare double    @llvm.sqrt.f64(double %Val)
5542   declare x86_fp80  @llvm.sqrt.f80(x86_fp80 %Val)
5543   declare fp128     @llvm.sqrt.f128(fp128 %Val)
5544   declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val)
5545 </pre>
5546
5547 <h5>Overview:</h5>
5548 <p>The '<tt>llvm.sqrt</tt>' intrinsics return the sqrt of the specified operand,
5549    returning the same value as the libm '<tt>sqrt</tt>' functions would.
5550    Unlike <tt>sqrt</tt> in libm, however, <tt>llvm.sqrt</tt> has undefined
5551    behavior for negative numbers other than -0.0 (which allows for better
5552    optimization, because there is no need to worry about errno being
5553    set).  <tt>llvm.sqrt(-0.0)</tt> is defined to return -0.0 like IEEE sqrt.</p>
5554
5555 <h5>Arguments:</h5>
5556 <p>The argument and return value are floating point numbers of the same
5557    type.</p>
5558
5559 <h5>Semantics:</h5>
5560 <p>This function returns the sqrt of the specified operand if it is a
5561    nonnegative floating point number.</p>
5562
5563 </div>
5564
5565 <!-- _______________________________________________________________________ -->
5566 <div class="doc_subsubsection">
5567   <a name="int_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a>
5568 </div>
5569
5570 <div class="doc_text">
5571
5572 <h5>Syntax:</h5>
5573 <p>This is an overloaded intrinsic. You can use <tt>llvm.powi</tt> on any
5574    floating point or vector of floating point type. Not all targets support all
5575    types however.</p>
5576
5577 <pre>
5578   declare float     @llvm.powi.f32(float  %Val, i32 %power)
5579   declare double    @llvm.powi.f64(double %Val, i32 %power)
5580   declare x86_fp80  @llvm.powi.f80(x86_fp80  %Val, i32 %power)
5581   declare fp128     @llvm.powi.f128(fp128 %Val, i32 %power)
5582   declare ppc_fp128 @llvm.powi.ppcf128(ppc_fp128  %Val, i32 %power)
5583 </pre>
5584
5585 <h5>Overview:</h5>
5586 <p>The '<tt>llvm.powi.*</tt>' intrinsics return the first operand raised to the
5587    specified (positive or negative) power.  The order of evaluation of
5588    multiplications is not defined.  When a vector of floating point type is
5589    used, the second argument remains a scalar integer value.</p>
5590
5591 <h5>Arguments:</h5>
5592 <p>The second argument is an integer power, and the first is a value to raise to
5593    that power.</p>
5594
5595 <h5>Semantics:</h5>
5596 <p>This function returns the first value raised to the second power with an
5597    unspecified sequence of rounding operations.</p>
5598
5599 </div>
5600
5601 <!-- _______________________________________________________________________ -->
5602 <div class="doc_subsubsection">
5603   <a name="int_sin">'<tt>llvm.sin.*</tt>' Intrinsic</a>
5604 </div>
5605
5606 <div class="doc_text">
5607
5608 <h5>Syntax:</h5>
5609 <p>This is an overloaded intrinsic. You can use <tt>llvm.sin</tt> on any
5610    floating point or vector of floating point type. Not all targets support all
5611    types however.</p>
5612
5613 <pre>
5614   declare float     @llvm.sin.f32(float  %Val)
5615   declare double    @llvm.sin.f64(double %Val)
5616   declare x86_fp80  @llvm.sin.f80(x86_fp80  %Val)
5617   declare fp128     @llvm.sin.f128(fp128 %Val)
5618   declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128  %Val)
5619 </pre>
5620
5621 <h5>Overview:</h5>
5622 <p>The '<tt>llvm.sin.*</tt>' intrinsics return the sine of the operand.</p>
5623
5624 <h5>Arguments:</h5>
5625 <p>The argument and return value are floating point numbers of the same
5626    type.</p>
5627
5628 <h5>Semantics:</h5>
5629 <p>This function returns the sine of the specified operand, returning the same
5630    values as the libm <tt>sin</tt> functions would, and handles error conditions
5631    in the same way.</p>
5632
5633 </div>
5634
5635 <!-- _______________________________________________________________________ -->
5636 <div class="doc_subsubsection">
5637   <a name="int_cos">'<tt>llvm.cos.*</tt>' Intrinsic</a>
5638 </div>
5639
5640 <div class="doc_text">
5641
5642 <h5>Syntax:</h5>
5643 <p>This is an overloaded intrinsic. You can use <tt>llvm.cos</tt> on any
5644    floating point or vector of floating point type. Not all targets support all
5645    types however.</p>
5646
5647 <pre>
5648   declare float     @llvm.cos.f32(float  %Val)
5649   declare double    @llvm.cos.f64(double %Val)
5650   declare x86_fp80  @llvm.cos.f80(x86_fp80  %Val)
5651   declare fp128     @llvm.cos.f128(fp128 %Val)
5652   declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128  %Val)
5653 </pre>
5654
5655 <h5>Overview:</h5>
5656 <p>The '<tt>llvm.cos.*</tt>' intrinsics return the cosine of the operand.</p>
5657
5658 <h5>Arguments:</h5>
5659 <p>The argument and return value are floating point numbers of the same
5660    type.</p>
5661
5662 <h5>Semantics:</h5>
5663 <p>This function returns the cosine of the specified operand, returning the same
5664    values as the libm <tt>cos</tt> functions would, and handles error conditions
5665    in the same way.</p>
5666
5667 </div>
5668
5669 <!-- _______________________________________________________________________ -->
5670 <div class="doc_subsubsection">
5671   <a name="int_pow">'<tt>llvm.pow.*</tt>' Intrinsic</a>
5672 </div>
5673
5674 <div class="doc_text">
5675
5676 <h5>Syntax:</h5>
5677 <p>This is an overloaded intrinsic. You can use <tt>llvm.pow</tt> on any
5678    floating point or vector of floating point type. Not all targets support all
5679    types however.</p>
5680
5681 <pre>
5682   declare float     @llvm.pow.f32(float  %Val, float %Power)
5683   declare double    @llvm.pow.f64(double %Val, double %Power)
5684   declare x86_fp80  @llvm.pow.f80(x86_fp80  %Val, x86_fp80 %Power)
5685   declare fp128     @llvm.pow.f128(fp128 %Val, fp128 %Power)
5686   declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128  %Val, ppc_fp128 Power)
5687 </pre>
5688
5689 <h5>Overview:</h5>
5690 <p>The '<tt>llvm.pow.*</tt>' intrinsics return the first operand raised to the
5691    specified (positive or negative) power.</p>
5692
5693 <h5>Arguments:</h5>
5694 <p>The second argument is a floating point power, and the first is a value to
5695    raise to that power.</p>
5696
5697 <h5>Semantics:</h5>
5698 <p>This function returns the first value raised to the second power, returning
5699    the same values as the libm <tt>pow</tt> functions would, and handles error
5700    conditions in the same way.</p>
5701
5702 </div>
5703
5704 <!-- ======================================================================= -->
5705 <div class="doc_subsection">
5706   <a name="int_manip">Bit Manipulation Intrinsics</a>
5707 </div>
5708
5709 <div class="doc_text">
5710
5711 <p>LLVM provides intrinsics for a few important bit manipulation operations.
5712    These allow efficient code generation for some algorithms.</p>
5713
5714 </div>
5715
5716 <!-- _______________________________________________________________________ -->
5717 <div class="doc_subsubsection">
5718   <a name="int_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a>
5719 </div>
5720
5721 <div class="doc_text">
5722
5723 <h5>Syntax:</h5>
5724 <p>This is an overloaded intrinsic function. You can use bswap on any integer
5725    type that is an even number of bytes (i.e. BitWidth % 16 == 0).</p>
5726
5727 <pre>
5728   declare i16 @llvm.bswap.i16(i16 &lt;id&gt;)
5729   declare i32 @llvm.bswap.i32(i32 &lt;id&gt;)
5730   declare i64 @llvm.bswap.i64(i64 &lt;id&gt;)
5731 </pre>
5732
5733 <h5>Overview:</h5>
5734 <p>The '<tt>llvm.bswap</tt>' family of intrinsics is used to byte swap integer
5735    values with an even number of bytes (positive multiple of 16 bits).  These
5736    are useful for performing operations on data that is not in the target's
5737    native byte order.</p>
5738
5739 <h5>Semantics:</h5>
5740 <p>The <tt>llvm.bswap.i16</tt> intrinsic returns an i16 value that has the high
5741    and low byte of the input i16 swapped.  Similarly,
5742    the <tt>llvm.bswap.i32</tt> intrinsic returns an i32 value that has the four
5743    bytes of the input i32 swapped, so that if the input bytes are numbered 0, 1,
5744    2, 3 then the returned i32 will have its bytes in 3, 2, 1, 0 order.
5745    The <tt>llvm.bswap.i48</tt>, <tt>llvm.bswap.i64</tt> and other intrinsics
5746    extend this concept to additional even-byte lengths (6 bytes, 8 bytes and
5747    more, respectively).</p>
5748
5749 </div>
5750
5751 <!-- _______________________________________________________________________ -->
5752 <div class="doc_subsubsection">
5753   <a name="int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic</a>
5754 </div>
5755
5756 <div class="doc_text">
5757
5758 <h5>Syntax:</h5>
5759 <p>This is an overloaded intrinsic. You can use llvm.ctpop on any integer bit
5760    width. Not all targets support all bit widths however.</p>
5761
5762 <pre>
5763   declare i8 @llvm.ctpop.i8(i8  &lt;src&gt;)
5764   declare i16 @llvm.ctpop.i16(i16 &lt;src&gt;)
5765   declare i32 @llvm.ctpop.i32(i32 &lt;src&gt;)
5766   declare i64 @llvm.ctpop.i64(i64 &lt;src&gt;)
5767   declare i256 @llvm.ctpop.i256(i256 &lt;src&gt;)
5768 </pre>
5769
5770 <h5>Overview:</h5>
5771 <p>The '<tt>llvm.ctpop</tt>' family of intrinsics counts the number of bits set
5772    in a value.</p>
5773
5774 <h5>Arguments:</h5>
5775 <p>The only argument is the value to be counted.  The argument may be of any
5776    integer type.  The return type must match the argument type.</p>
5777
5778 <h5>Semantics:</h5>
5779 <p>The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable.</p>
5780
5781 </div>
5782
5783 <!-- _______________________________________________________________________ -->
5784 <div class="doc_subsubsection">
5785   <a name="int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic</a>
5786 </div>
5787
5788 <div class="doc_text">
5789
5790 <h5>Syntax:</h5>
5791 <p>This is an overloaded intrinsic. You can use <tt>llvm.ctlz</tt> on any
5792    integer bit width. Not all targets support all bit widths however.</p>
5793
5794 <pre>
5795   declare i8 @llvm.ctlz.i8 (i8  &lt;src&gt;)
5796   declare i16 @llvm.ctlz.i16(i16 &lt;src&gt;)
5797   declare i32 @llvm.ctlz.i32(i32 &lt;src&gt;)
5798   declare i64 @llvm.ctlz.i64(i64 &lt;src&gt;)
5799   declare i256 @llvm.ctlz.i256(i256 &lt;src&gt;)
5800 </pre>
5801
5802 <h5>Overview:</h5>
5803 <p>The '<tt>llvm.ctlz</tt>' family of intrinsic functions counts the number of
5804    leading zeros in a variable.</p>
5805
5806 <h5>Arguments:</h5>
5807 <p>The only argument is the value to be counted.  The argument may be of any
5808    integer type. The return type must match the argument type.</p>
5809
5810 <h5>Semantics:</h5>
5811 <p>The '<tt>llvm.ctlz</tt>' intrinsic counts the leading (most significant)
5812    zeros in a variable.  If the src == 0 then the result is the size in bits of
5813    the type of src. For example, <tt>llvm.ctlz(i32 2) = 30</tt>.</p>
5814
5815 </div>
5816
5817 <!-- _______________________________________________________________________ -->
5818 <div class="doc_subsubsection">
5819   <a name="int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic</a>
5820 </div>
5821
5822 <div class="doc_text">
5823
5824 <h5>Syntax:</h5>
5825 <p>This is an overloaded intrinsic. You can use <tt>llvm.cttz</tt> on any
5826    integer bit width. Not all targets support all bit widths however.</p>
5827
5828 <pre>
5829   declare i8 @llvm.cttz.i8 (i8  &lt;src&gt;)
5830   declare i16 @llvm.cttz.i16(i16 &lt;src&gt;)
5831   declare i32 @llvm.cttz.i32(i32 &lt;src&gt;)
5832   declare i64 @llvm.cttz.i64(i64 &lt;src&gt;)
5833   declare i256 @llvm.cttz.i256(i256 &lt;src&gt;)
5834 </pre>
5835
5836 <h5>Overview:</h5>
5837 <p>The '<tt>llvm.cttz</tt>' family of intrinsic functions counts the number of
5838    trailing zeros.</p>
5839
5840 <h5>Arguments:</h5>
5841 <p>The only argument is the value to be counted.  The argument may be of any
5842    integer type.  The return type must match the argument type.</p>
5843
5844 <h5>Semantics:</h5>
5845 <p>The '<tt>llvm.cttz</tt>' intrinsic counts the trailing (least significant)
5846    zeros in a variable.  If the src == 0 then the result is the size in bits of
5847    the type of src.  For example, <tt>llvm.cttz(2) = 1</tt>.</p>
5848
5849 </div>
5850
5851 <!-- ======================================================================= -->
5852 <div class="doc_subsection">
5853   <a name="int_overflow">Arithmetic with Overflow Intrinsics</a>
5854 </div>
5855
5856 <div class="doc_text">
5857
5858 <p>LLVM provides intrinsics for some arithmetic with overflow operations.</p>
5859
5860 </div>
5861
5862 <!-- _______________________________________________________________________ -->
5863 <div class="doc_subsubsection">
5864   <a name="int_sadd_overflow">'<tt>llvm.sadd.with.overflow.*</tt>' Intrinsics</a>
5865 </div>
5866
5867 <div class="doc_text">
5868
5869 <h5>Syntax:</h5>
5870 <p>This is an overloaded intrinsic. You can use <tt>llvm.sadd.with.overflow</tt>
5871    on any integer bit width.</p>
5872
5873 <pre>
5874   declare {i16, i1} @llvm.sadd.with.overflow.i16(i16 %a, i16 %b)
5875   declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
5876   declare {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 %b)
5877 </pre>
5878
5879 <h5>Overview:</h5>
5880 <p>The '<tt>llvm.sadd.with.overflow</tt>' family of intrinsic functions perform
5881    a signed addition of the two arguments, and indicate whether an overflow
5882    occurred during the signed summation.</p>
5883
5884 <h5>Arguments:</h5>
5885 <p>The arguments (%a and %b) and the first element of the result structure may
5886    be of integer types of any bit width, but they must have the same bit
5887    width. The second element of the result structure must be of
5888    type <tt>i1</tt>. <tt>%a</tt> and <tt>%b</tt> are the two values that will
5889    undergo signed addition.</p>
5890
5891 <h5>Semantics:</h5>
5892 <p>The '<tt>llvm.sadd.with.overflow</tt>' family of intrinsic functions perform
5893    a signed addition of the two variables. They return a structure &mdash; the
5894    first element of which is the signed summation, and the second element of
5895    which is a bit specifying if the signed summation resulted in an
5896    overflow.</p>
5897
5898 <h5>Examples:</h5>
5899 <pre>
5900   %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
5901   %sum = extractvalue {i32, i1} %res, 0
5902   %obit = extractvalue {i32, i1} %res, 1
5903   br i1 %obit, label %overflow, label %normal
5904 </pre>
5905
5906 </div>
5907
5908 <!-- _______________________________________________________________________ -->
5909 <div class="doc_subsubsection">
5910   <a name="int_uadd_overflow">'<tt>llvm.uadd.with.overflow.*</tt>' Intrinsics</a>
5911 </div>
5912
5913 <div class="doc_text">
5914
5915 <h5>Syntax:</h5>
5916 <p>This is an overloaded intrinsic. You can use <tt>llvm.uadd.with.overflow</tt>
5917    on any integer bit width.</p>
5918
5919 <pre>
5920   declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b)
5921   declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
5922   declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b)
5923 </pre>
5924
5925 <h5>Overview:</h5>
5926 <p>The '<tt>llvm.uadd.with.overflow</tt>' family of intrinsic functions perform
5927    an unsigned addition of the two arguments, and indicate whether a carry
5928    occurred during the unsigned summation.</p>
5929
5930 <h5>Arguments:</h5>
5931 <p>The arguments (%a and %b) and the first element of the result structure may
5932    be of integer types of any bit width, but they must have the same bit
5933    width. The second element of the result structure must be of
5934    type <tt>i1</tt>. <tt>%a</tt> and <tt>%b</tt> are the two values that will
5935    undergo unsigned addition.</p>
5936
5937 <h5>Semantics:</h5>
5938 <p>The '<tt>llvm.uadd.with.overflow</tt>' family of intrinsic functions perform
5939    an unsigned addition of the two arguments. They return a structure &mdash;
5940    the first element of which is the sum, and the second element of which is a
5941    bit specifying if the unsigned summation resulted in a carry.</p>
5942
5943 <h5>Examples:</h5>
5944 <pre>
5945   %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
5946   %sum = extractvalue {i32, i1} %res, 0
5947   %obit = extractvalue {i32, i1} %res, 1
5948   br i1 %obit, label %carry, label %normal
5949 </pre>
5950
5951 </div>
5952
5953 <!-- _______________________________________________________________________ -->
5954 <div class="doc_subsubsection">
5955   <a name="int_ssub_overflow">'<tt>llvm.ssub.with.overflow.*</tt>' Intrinsics</a>
5956 </div>
5957
5958 <div class="doc_text">
5959
5960 <h5>Syntax:</h5>
5961 <p>This is an overloaded intrinsic. You can use <tt>llvm.ssub.with.overflow</tt>
5962    on any integer bit width.</p>
5963
5964 <pre>
5965   declare {i16, i1} @llvm.ssub.with.overflow.i16(i16 %a, i16 %b)
5966   declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
5967   declare {i64, i1} @llvm.ssub.with.overflow.i64(i64 %a, i64 %b)
5968 </pre>
5969
5970 <h5>Overview:</h5>
5971 <p>The '<tt>llvm.ssub.with.overflow</tt>' family of intrinsic functions perform
5972    a signed subtraction of the two arguments, and indicate whether an overflow
5973    occurred during the signed subtraction.</p>
5974
5975 <h5>Arguments:</h5>
5976 <p>The arguments (%a and %b) and the first element of the result structure may
5977    be of integer types of any bit width, but they must have the same bit
5978    width. The second element of the result structure must be of
5979    type <tt>i1</tt>. <tt>%a</tt> and <tt>%b</tt> are the two values that will
5980    undergo signed subtraction.</p>
5981
5982 <h5>Semantics:</h5>
5983 <p>The '<tt>llvm.ssub.with.overflow</tt>' family of intrinsic functions perform
5984    a signed subtraction of the two arguments. They return a structure &mdash;
5985    the first element of which is the subtraction, and the second element of
5986    which is a bit specifying if the signed subtraction resulted in an
5987    overflow.</p>
5988
5989 <h5>Examples:</h5>
5990 <pre>
5991   %res = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
5992   %sum = extractvalue {i32, i1} %res, 0
5993   %obit = extractvalue {i32, i1} %res, 1
5994   br i1 %obit, label %overflow, label %normal
5995 </pre>
5996
5997 </div>
5998
5999 <!-- _______________________________________________________________________ -->
6000 <div class="doc_subsubsection">
6001   <a name="int_usub_overflow">'<tt>llvm.usub.with.overflow.*</tt>' Intrinsics</a>
6002 </div>
6003
6004 <div class="doc_text">
6005
6006 <h5>Syntax:</h5>
6007 <p>This is an overloaded intrinsic. You can use <tt>llvm.usub.with.overflow</tt>
6008    on any integer bit width.</p>
6009
6010 <pre>
6011   declare {i16, i1} @llvm.usub.with.overflow.i16(i16 %a, i16 %b)
6012   declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
6013   declare {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b)
6014 </pre>
6015
6016 <h5>Overview:</h5>
6017 <p>The '<tt>llvm.usub.with.overflow</tt>' family of intrinsic functions perform
6018    an unsigned subtraction of the two arguments, and indicate whether an
6019    overflow occurred during the unsigned subtraction.</p>
6020
6021 <h5>Arguments:</h5>
6022 <p>The arguments (%a and %b) and the first element of the result structure may
6023    be of integer types of any bit width, but they must have the same bit
6024    width. The second element of the result structure must be of
6025    type <tt>i1</tt>. <tt>%a</tt> and <tt>%b</tt> are the two values that will
6026    undergo unsigned subtraction.</p>
6027
6028 <h5>Semantics:</h5>
6029 <p>The '<tt>llvm.usub.with.overflow</tt>' family of intrinsic functions perform
6030    an unsigned subtraction of the two arguments. They return a structure &mdash;
6031    the first element of which is the subtraction, and the second element of
6032    which is a bit specifying if the unsigned subtraction resulted in an
6033    overflow.</p>
6034
6035 <h5>Examples:</h5>
6036 <pre>
6037   %res = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
6038   %sum = extractvalue {i32, i1} %res, 0
6039   %obit = extractvalue {i32, i1} %res, 1
6040   br i1 %obit, label %overflow, label %normal
6041 </pre>
6042
6043 </div>
6044
6045 <!-- _______________________________________________________________________ -->
6046 <div class="doc_subsubsection">
6047   <a name="int_smul_overflow">'<tt>llvm.smul.with.overflow.*</tt>' Intrinsics</a>
6048 </div>
6049
6050 <div class="doc_text">
6051
6052 <h5>Syntax:</h5>
6053 <p>This is an overloaded intrinsic. You can use <tt>llvm.smul.with.overflow</tt>
6054    on any integer bit width.</p>
6055
6056 <pre>
6057   declare {i16, i1} @llvm.smul.with.overflow.i16(i16 %a, i16 %b)
6058   declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
6059   declare {i64, i1} @llvm.smul.with.overflow.i64(i64 %a, i64 %b)
6060 </pre>
6061
6062 <h5>Overview:</h5>
6063
6064 <p>The '<tt>llvm.smul.with.overflow</tt>' family of intrinsic functions perform
6065    a signed multiplication of the two arguments, and indicate whether an
6066    overflow occurred during the signed multiplication.</p>
6067
6068 <h5>Arguments:</h5>
6069 <p>The arguments (%a and %b) and the first element of the result structure may
6070    be of integer types of any bit width, but they must have the same bit
6071    width. The second element of the result structure must be of
6072    type <tt>i1</tt>. <tt>%a</tt> and <tt>%b</tt> are the two values that will
6073    undergo signed multiplication.</p>
6074
6075 <h5>Semantics:</h5>
6076 <p>The '<tt>llvm.smul.with.overflow</tt>' family of intrinsic functions perform
6077    a signed multiplication of the two arguments. They return a structure &mdash;
6078    the first element of which is the multiplication, and the second element of
6079    which is a bit specifying if the signed multiplication resulted in an
6080    overflow.</p>
6081
6082 <h5>Examples:</h5>
6083 <pre>
6084   %res = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
6085   %sum = extractvalue {i32, i1} %res, 0
6086   %obit = extractvalue {i32, i1} %res, 1
6087   br i1 %obit, label %overflow, label %normal
6088 </pre>
6089
6090 </div>
6091
6092 <!-- _______________________________________________________________________ -->
6093 <div class="doc_subsubsection">
6094   <a name="int_umul_overflow">'<tt>llvm.umul.with.overflow.*</tt>' Intrinsics</a>
6095 </div>
6096
6097 <div class="doc_text">
6098
6099 <h5>Syntax:</h5>
6100 <p>This is an overloaded intrinsic. You can use <tt>llvm.umul.with.overflow</tt>
6101    on any integer bit width.</p>
6102
6103 <pre>
6104   declare {i16, i1} @llvm.umul.with.overflow.i16(i16 %a, i16 %b)
6105   declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
6106   declare {i64, i1} @llvm.umul.with.overflow.i64(i64 %a, i64 %b)
6107 </pre>
6108
6109 <h5>Overview:</h5>
6110 <p>The '<tt>llvm.umul.with.overflow</tt>' family of intrinsic functions perform
6111    a unsigned multiplication of the two arguments, and indicate whether an
6112    overflow occurred during the unsigned multiplication.</p>
6113
6114 <h5>Arguments:</h5>
6115 <p>The arguments (%a and %b) and the first element of the result structure may
6116    be of integer types of any bit width, but they must have the same bit
6117    width. The second element of the result structure must be of
6118    type <tt>i1</tt>. <tt>%a</tt> and <tt>%b</tt> are the two values that will
6119    undergo unsigned multiplication.</p>
6120
6121 <h5>Semantics:</h5>
6122 <p>The '<tt>llvm.umul.with.overflow</tt>' family of intrinsic functions perform
6123    an unsigned multiplication of the two arguments. They return a structure
6124    &mdash; the first element of which is the multiplication, and the second
6125    element of which is a bit specifying if the unsigned multiplication resulted
6126    in an overflow.</p>
6127
6128 <h5>Examples:</h5>
6129 <pre>
6130   %res = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
6131   %sum = extractvalue {i32, i1} %res, 0
6132   %obit = extractvalue {i32, i1} %res, 1
6133   br i1 %obit, label %overflow, label %normal
6134 </pre>
6135
6136 </div>
6137
6138 <!-- ======================================================================= -->
6139 <div class="doc_subsection">
6140   <a name="int_debugger">Debugger Intrinsics</a>
6141 </div>
6142
6143 <div class="doc_text">
6144
6145 <p>The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt>
6146    prefix), are described in
6147    the <a href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source
6148    Level Debugging</a> document.</p>
6149
6150 </div>
6151
6152 <!-- ======================================================================= -->
6153 <div class="doc_subsection">
6154   <a name="int_eh">Exception Handling Intrinsics</a>
6155 </div>
6156
6157 <div class="doc_text">
6158
6159 <p>The LLVM exception handling intrinsics (which all start with
6160    <tt>llvm.eh.</tt> prefix), are described in
6161    the <a href="ExceptionHandling.html#format_common_intrinsics">LLVM Exception
6162    Handling</a> document.</p>
6163
6164 </div>
6165
6166 <!-- ======================================================================= -->
6167 <div class="doc_subsection">
6168   <a name="int_trampoline">Trampoline Intrinsic</a>
6169 </div>
6170
6171 <div class="doc_text">
6172
6173 <p>This intrinsic makes it possible to excise one parameter, marked with
6174    the <tt>nest</tt> attribute, from a function.  The result is a callable
6175    function pointer lacking the nest parameter - the caller does not need to
6176    provide a value for it.  Instead, the value to use is stored in advance in a
6177    "trampoline", a block of memory usually allocated on the stack, which also
6178    contains code to splice the nest value into the argument list.  This is used
6179    to implement the GCC nested function address extension.</p>
6180
6181 <p>For example, if the function is
6182    <tt>i32 f(i8* nest %c, i32 %x, i32 %y)</tt> then the resulting function
6183    pointer has signature <tt>i32 (i32, i32)*</tt>.  It can be created as
6184    follows:</p>
6185
6186 <div class="doc_code">
6187 <pre>
6188   %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86
6189   %tramp1 = getelementptr [10 x i8]* %tramp, i32 0, i32 0
6190   %p = call i8* @llvm.init.trampoline( i8* %tramp1, i8* bitcast (i32 (i8* nest , i32, i32)* @f to i8*), i8* %nval )
6191   %fp = bitcast i8* %p to i32 (i32, i32)*
6192 </pre>
6193 </div>
6194
6195 <p>The call <tt>%val = call i32 %fp( i32 %x, i32 %y )</tt> is then equivalent
6196    to <tt>%val = call i32 %f( i8* %nval, i32 %x, i32 %y )</tt>.</p>
6197
6198 </div>
6199
6200 <!-- _______________________________________________________________________ -->
6201 <div class="doc_subsubsection">
6202   <a name="int_it">'<tt>llvm.init.trampoline</tt>' Intrinsic</a>
6203 </div>
6204
6205 <div class="doc_text">
6206
6207 <h5>Syntax:</h5>
6208 <pre>
6209   declare i8* @llvm.init.trampoline(i8* &lt;tramp&gt;, i8* &lt;func&gt;, i8* &lt;nval&gt;)
6210 </pre>
6211
6212 <h5>Overview:</h5>
6213 <p>This fills the memory pointed to by <tt>tramp</tt> with code and returns a
6214    function pointer suitable for executing it.</p>
6215
6216 <h5>Arguments:</h5>
6217 <p>The <tt>llvm.init.trampoline</tt> intrinsic takes three arguments, all
6218    pointers.  The <tt>tramp</tt> argument must point to a sufficiently large and
6219    sufficiently aligned block of memory; this memory is written to by the
6220    intrinsic.  Note that the size and the alignment are target-specific - LLVM
6221    currently provides no portable way of determining them, so a front-end that
6222    generates this intrinsic needs to have some target-specific knowledge.
6223    The <tt>func</tt> argument must hold a function bitcast to
6224    an <tt>i8*</tt>.</p>
6225
6226 <h5>Semantics:</h5>
6227 <p>The block of memory pointed to by <tt>tramp</tt> is filled with target
6228    dependent code, turning it into a function.  A pointer to this function is
6229    returned, but needs to be bitcast to an <a href="#int_trampoline">appropriate
6230    function pointer type</a> before being called.  The new function's signature
6231    is the same as that of <tt>func</tt> with any arguments marked with
6232    the <tt>nest</tt> attribute removed.  At most one such <tt>nest</tt> argument
6233    is allowed, and it must be of pointer type.  Calling the new function is
6234    equivalent to calling <tt>func</tt> with the same argument list, but
6235    with <tt>nval</tt> used for the missing <tt>nest</tt> argument.  If, after
6236    calling <tt>llvm.init.trampoline</tt>, the memory pointed to
6237    by <tt>tramp</tt> is modified, then the effect of any later call to the
6238    returned function pointer is undefined.</p>
6239
6240 </div>
6241
6242 <!-- ======================================================================= -->
6243 <div class="doc_subsection">
6244   <a name="int_atomics">Atomic Operations and Synchronization Intrinsics</a>
6245 </div>
6246
6247 <div class="doc_text">
6248
6249 <p>These intrinsic functions expand the "universal IR" of LLVM to represent
6250    hardware constructs for atomic operations and memory synchronization.  This
6251    provides an interface to the hardware, not an interface to the programmer. It
6252    is aimed at a low enough level to allow any programming models or APIs
6253    (Application Programming Interfaces) which need atomic behaviors to map
6254    cleanly onto it. It is also modeled primarily on hardware behavior. Just as
6255    hardware provides a "universal IR" for source languages, it also provides a
6256    starting point for developing a "universal" atomic operation and
6257    synchronization IR.</p>
6258
6259 <p>These do <em>not</em> form an API such as high-level threading libraries,
6260    software transaction memory systems, atomic primitives, and intrinsic
6261    functions as found in BSD, GNU libc, atomic_ops, APR, and other system and
6262    application libraries.  The hardware interface provided by LLVM should allow
6263    a clean implementation of all of these APIs and parallel programming models.
6264    No one model or paradigm should be selected above others unless the hardware
6265    itself ubiquitously does so.</p>
6266
6267 </div>
6268
6269 <!-- _______________________________________________________________________ -->
6270 <div class="doc_subsubsection">
6271   <a name="int_memory_barrier">'<tt>llvm.memory.barrier</tt>' Intrinsic</a>
6272 </div>
6273 <div class="doc_text">
6274 <h5>Syntax:</h5>
6275 <pre>
6276   declare void @llvm.memory.barrier( i1 &lt;ll&gt;, i1 &lt;ls&gt;, i1 &lt;sl&gt;, i1 &lt;ss&gt;, i1 &lt;device&gt; )
6277 </pre>
6278
6279 <h5>Overview:</h5>
6280 <p>The <tt>llvm.memory.barrier</tt> intrinsic guarantees ordering between
6281    specific pairs of memory access types.</p>
6282
6283 <h5>Arguments:</h5>
6284 <p>The <tt>llvm.memory.barrier</tt> intrinsic requires five boolean arguments.
6285    The first four arguments enables a specific barrier as listed below.  The
6286    fith argument specifies that the barrier applies to io or device or uncached
6287    memory.</p>
6288
6289 <ul>
6290   <li><tt>ll</tt>: load-load barrier</li>
6291   <li><tt>ls</tt>: load-store barrier</li>
6292   <li><tt>sl</tt>: store-load barrier</li>
6293   <li><tt>ss</tt>: store-store barrier</li>
6294   <li><tt>device</tt>: barrier applies to device and uncached memory also.</li>
6295 </ul>
6296
6297 <h5>Semantics:</h5>
6298 <p>This intrinsic causes the system to enforce some ordering constraints upon
6299    the loads and stores of the program. This barrier does not
6300    indicate <em>when</em> any events will occur, it only enforces
6301    an <em>order</em> in which they occur. For any of the specified pairs of load
6302    and store operations (f.ex.  load-load, or store-load), all of the first
6303    operations preceding the barrier will complete before any of the second
6304    operations succeeding the barrier begin. Specifically the semantics for each
6305    pairing is as follows:</p>
6306
6307 <ul>
6308   <li><tt>ll</tt>: All loads before the barrier must complete before any load
6309       after the barrier begins.</li>
6310   <li><tt>ls</tt>: All loads before the barrier must complete before any 
6311       store after the barrier begins.</li>
6312   <li><tt>ss</tt>: All stores before the barrier must complete before any 
6313       store after the barrier begins.</li>
6314   <li><tt>sl</tt>: All stores before the barrier must complete before any 
6315       load after the barrier begins.</li>
6316 </ul>
6317
6318 <p>These semantics are applied with a logical "and" behavior when more than one
6319    is enabled in a single memory barrier intrinsic.</p>
6320
6321 <p>Backends may implement stronger barriers than those requested when they do
6322    not support as fine grained a barrier as requested.  Some architectures do
6323    not need all types of barriers and on such architectures, these become
6324    noops.</p>
6325
6326 <h5>Example:</h5>
6327 <pre>
6328 %ptr      = malloc i32
6329             store i32 4, %ptr
6330
6331 %result1  = load i32* %ptr      <i>; yields {i32}:result1 = 4</i>
6332             call void @llvm.memory.barrier( i1 false, i1 true, i1 false, i1 false )
6333                                 <i>; guarantee the above finishes</i>
6334             store i32 8, %ptr   <i>; before this begins</i>
6335 </pre>
6336
6337 </div>
6338
6339 <!-- _______________________________________________________________________ -->
6340 <div class="doc_subsubsection">
6341   <a name="int_atomic_cmp_swap">'<tt>llvm.atomic.cmp.swap.*</tt>' Intrinsic</a>
6342 </div>
6343
6344 <div class="doc_text">
6345
6346 <h5>Syntax:</h5>
6347 <p>This is an overloaded intrinsic. You can use <tt>llvm.atomic.cmp.swap</tt> on
6348    any integer bit width and for different address spaces. Not all targets
6349    support all bit widths however.</p>
6350
6351 <pre>
6352   declare i8 @llvm.atomic.cmp.swap.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;cmp&gt;, i8 &lt;val&gt; )
6353   declare i16 @llvm.atomic.cmp.swap.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;cmp&gt;, i16 &lt;val&gt; )
6354   declare i32 @llvm.atomic.cmp.swap.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;cmp&gt;, i32 &lt;val&gt; )
6355   declare i64 @llvm.atomic.cmp.swap.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;cmp&gt;, i64 &lt;val&gt; )
6356 </pre>
6357
6358 <h5>Overview:</h5>
6359 <p>This loads a value in memory and compares it to a given value. If they are
6360    equal, it stores a new value into the memory.</p>
6361
6362 <h5>Arguments:</h5>
6363 <p>The <tt>llvm.atomic.cmp.swap</tt> intrinsic takes three arguments. The result
6364    as well as both <tt>cmp</tt> and <tt>val</tt> must be integer values with the
6365    same bit width. The <tt>ptr</tt> argument must be a pointer to a value of
6366    this integer type. While any bit width integer may be used, targets may only
6367    lower representations they support in hardware.</p>
6368
6369 <h5>Semantics:</h5>
6370 <p>This entire intrinsic must be executed atomically. It first loads the value
6371    in memory pointed to by <tt>ptr</tt> and compares it with the
6372    value <tt>cmp</tt>. If they are equal, <tt>val</tt> is stored into the
6373    memory. The loaded value is yielded in all cases. This provides the
6374    equivalent of an atomic compare-and-swap operation within the SSA
6375    framework.</p>
6376
6377 <h5>Examples:</h5>
6378 <pre>
6379 %ptr      = malloc i32
6380             store i32 4, %ptr
6381
6382 %val1     = add i32 4, 4
6383 %result1  = call i32 @llvm.atomic.cmp.swap.i32.p0i32( i32* %ptr, i32 4, %val1 )
6384                                           <i>; yields {i32}:result1 = 4</i>
6385 %stored1  = icmp eq i32 %result1, 4       <i>; yields {i1}:stored1 = true</i>
6386 %memval1  = load i32* %ptr                <i>; yields {i32}:memval1 = 8</i>
6387
6388 %val2     = add i32 1, 1
6389 %result2  = call i32 @llvm.atomic.cmp.swap.i32.p0i32( i32* %ptr, i32 5, %val2 )
6390                                           <i>; yields {i32}:result2 = 8</i>
6391 %stored2  = icmp eq i32 %result2, 5       <i>; yields {i1}:stored2 = false</i>
6392
6393 %memval2  = load i32* %ptr                <i>; yields {i32}:memval2 = 8</i>
6394 </pre>
6395
6396 </div>
6397
6398 <!-- _______________________________________________________________________ -->
6399 <div class="doc_subsubsection">
6400   <a name="int_atomic_swap">'<tt>llvm.atomic.swap.*</tt>' Intrinsic</a>
6401 </div>
6402 <div class="doc_text">
6403 <h5>Syntax:</h5>
6404
6405 <p>This is an overloaded intrinsic. You can use <tt>llvm.atomic.swap</tt> on any
6406    integer bit width. Not all targets support all bit widths however.</p>
6407
6408 <pre>
6409   declare i8 @llvm.atomic.swap.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;val&gt; )
6410   declare i16 @llvm.atomic.swap.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;val&gt; )
6411   declare i32 @llvm.atomic.swap.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;val&gt; )
6412   declare i64 @llvm.atomic.swap.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;val&gt; )
6413 </pre>
6414
6415 <h5>Overview:</h5>
6416 <p>This intrinsic loads the value stored in memory at <tt>ptr</tt> and yields
6417    the value from memory. It then stores the value in <tt>val</tt> in the memory
6418    at <tt>ptr</tt>.</p>
6419
6420 <h5>Arguments:</h5>
6421 <p>The <tt>llvm.atomic.swap</tt> intrinsic takes two arguments. Both
6422   the <tt>val</tt> argument and the result must be integers of the same bit
6423   width.  The first argument, <tt>ptr</tt>, must be a pointer to a value of this
6424   integer type. The targets may only lower integer representations they
6425   support.</p>
6426
6427 <h5>Semantics:</h5>
6428 <p>This intrinsic loads the value pointed to by <tt>ptr</tt>, yields it, and
6429    stores <tt>val</tt> back into <tt>ptr</tt> atomically. This provides the
6430    equivalent of an atomic swap operation within the SSA framework.</p>
6431
6432 <h5>Examples:</h5>
6433 <pre>
6434 %ptr      = malloc i32
6435             store i32 4, %ptr
6436
6437 %val1     = add i32 4, 4
6438 %result1  = call i32 @llvm.atomic.swap.i32.p0i32( i32* %ptr, i32 %val1 )
6439                                         <i>; yields {i32}:result1 = 4</i>
6440 %stored1  = icmp eq i32 %result1, 4     <i>; yields {i1}:stored1 = true</i>
6441 %memval1  = load i32* %ptr              <i>; yields {i32}:memval1 = 8</i>
6442
6443 %val2     = add i32 1, 1
6444 %result2  = call i32 @llvm.atomic.swap.i32.p0i32( i32* %ptr, i32 %val2 )
6445                                         <i>; yields {i32}:result2 = 8</i>
6446
6447 %stored2  = icmp eq i32 %result2, 8     <i>; yields {i1}:stored2 = true</i>
6448 %memval2  = load i32* %ptr              <i>; yields {i32}:memval2 = 2</i>
6449 </pre>
6450
6451 </div>
6452
6453 <!-- _______________________________________________________________________ -->
6454 <div class="doc_subsubsection">
6455   <a name="int_atomic_load_add">'<tt>llvm.atomic.load.add.*</tt>' Intrinsic</a>
6456
6457 </div>
6458
6459 <div class="doc_text">
6460
6461 <h5>Syntax:</h5>
6462 <p>This is an overloaded intrinsic. You can use <tt>llvm.atomic.load.add</tt> on
6463    any integer bit width. Not all targets support all bit widths however.</p>
6464
6465 <pre>
6466   declare i8 @llvm.atomic.load.add.i8..p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6467   declare i16 @llvm.atomic.load.add.i16..p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6468   declare i32 @llvm.atomic.load.add.i32..p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6469   declare i64 @llvm.atomic.load.add.i64..p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
6470 </pre>
6471
6472 <h5>Overview:</h5>
6473 <p>This intrinsic adds <tt>delta</tt> to the value stored in memory
6474    at <tt>ptr</tt>. It yields the original value at <tt>ptr</tt>.</p>
6475
6476 <h5>Arguments:</h5>
6477 <p>The intrinsic takes two arguments, the first a pointer to an integer value
6478    and the second an integer value. The result is also an integer value. These
6479    integer types can have any bit width, but they must all have the same bit
6480    width. The targets may only lower integer representations they support.</p>
6481
6482 <h5>Semantics:</h5>
6483 <p>This intrinsic does a series of operations atomically. It first loads the
6484    value stored at <tt>ptr</tt>. It then adds <tt>delta</tt>, stores the result
6485    to <tt>ptr</tt>. It yields the original value stored at <tt>ptr</tt>.</p>
6486
6487 <h5>Examples:</h5>
6488 <pre>
6489 %ptr      = malloc i32
6490         store i32 4, %ptr
6491 %result1  = call i32 @llvm.atomic.load.add.i32.p0i32( i32* %ptr, i32 4 )
6492                                 <i>; yields {i32}:result1 = 4</i>
6493 %result2  = call i32 @llvm.atomic.load.add.i32.p0i32( i32* %ptr, i32 2 )
6494                                 <i>; yields {i32}:result2 = 8</i>
6495 %result3  = call i32 @llvm.atomic.load.add.i32.p0i32( i32* %ptr, i32 5 )
6496                                 <i>; yields {i32}:result3 = 10</i>
6497 %memval1  = load i32* %ptr      <i>; yields {i32}:memval1 = 15</i>
6498 </pre>
6499
6500 </div>
6501
6502 <!-- _______________________________________________________________________ -->
6503 <div class="doc_subsubsection">
6504   <a name="int_atomic_load_sub">'<tt>llvm.atomic.load.sub.*</tt>' Intrinsic</a>
6505
6506 </div>
6507
6508 <div class="doc_text">
6509
6510 <h5>Syntax:</h5>
6511 <p>This is an overloaded intrinsic. You can use <tt>llvm.atomic.load.sub</tt> on
6512    any integer bit width and for different address spaces. Not all targets
6513    support all bit widths however.</p>
6514
6515 <pre>
6516   declare i8 @llvm.atomic.load.sub.i8.p0i32( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6517   declare i16 @llvm.atomic.load.sub.i16.p0i32( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6518   declare i32 @llvm.atomic.load.sub.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6519   declare i64 @llvm.atomic.load.sub.i64.p0i32( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
6520 </pre>
6521
6522 <h5>Overview:</h5>
6523 <p>This intrinsic subtracts <tt>delta</tt> to the value stored in memory at 
6524    <tt>ptr</tt>. It yields the original value at <tt>ptr</tt>.</p>
6525
6526 <h5>Arguments:</h5>
6527 <p>The intrinsic takes two arguments, the first a pointer to an integer value
6528    and the second an integer value. The result is also an integer value. These
6529    integer types can have any bit width, but they must all have the same bit
6530    width. The targets may only lower integer representations they support.</p>
6531
6532 <h5>Semantics:</h5>
6533 <p>This intrinsic does a series of operations atomically. It first loads the
6534    value stored at <tt>ptr</tt>. It then subtracts <tt>delta</tt>, stores the
6535    result to <tt>ptr</tt>. It yields the original value stored
6536    at <tt>ptr</tt>.</p>
6537
6538 <h5>Examples:</h5>
6539 <pre>
6540 %ptr      = malloc i32
6541         store i32 8, %ptr
6542 %result1  = call i32 @llvm.atomic.load.sub.i32.p0i32( i32* %ptr, i32 4 )
6543                                 <i>; yields {i32}:result1 = 8</i>
6544 %result2  = call i32 @llvm.atomic.load.sub.i32.p0i32( i32* %ptr, i32 2 )
6545                                 <i>; yields {i32}:result2 = 4</i>
6546 %result3  = call i32 @llvm.atomic.load.sub.i32.p0i32( i32* %ptr, i32 5 )
6547                                 <i>; yields {i32}:result3 = 2</i>
6548 %memval1  = load i32* %ptr      <i>; yields {i32}:memval1 = -3</i>
6549 </pre>
6550
6551 </div>
6552
6553 <!-- _______________________________________________________________________ -->
6554 <div class="doc_subsubsection">
6555   <a name="int_atomic_load_and">'<tt>llvm.atomic.load.and.*</tt>' Intrinsic</a><br>
6556   <a name="int_atomic_load_nand">'<tt>llvm.atomic.load.nand.*</tt>' Intrinsic</a><br>
6557   <a name="int_atomic_load_or">'<tt>llvm.atomic.load.or.*</tt>' Intrinsic</a><br>
6558   <a name="int_atomic_load_xor">'<tt>llvm.atomic.load.xor.*</tt>' Intrinsic</a><br>
6559 </div>
6560
6561 <div class="doc_text">
6562
6563 <h5>Syntax:</h5>
6564 <p>These are overloaded intrinsics. You can
6565   use <tt>llvm.atomic.load_and</tt>, <tt>llvm.atomic.load_nand</tt>,
6566   <tt>llvm.atomic.load_or</tt>, and <tt>llvm.atomic.load_xor</tt> on any integer
6567   bit width and for different address spaces. Not all targets support all bit
6568   widths however.</p>
6569
6570 <pre>
6571   declare i8 @llvm.atomic.load.and.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6572   declare i16 @llvm.atomic.load.and.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6573   declare i32 @llvm.atomic.load.and.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6574   declare i64 @llvm.atomic.load.and.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
6575 </pre>
6576
6577 <pre>
6578   declare i8 @llvm.atomic.load.or.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6579   declare i16 @llvm.atomic.load.or.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6580   declare i32 @llvm.atomic.load.or.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6581   declare i64 @llvm.atomic.load.or.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
6582 </pre>
6583
6584 <pre>
6585   declare i8 @llvm.atomic.load.nand.i8.p0i32( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6586   declare i16 @llvm.atomic.load.nand.i16.p0i32( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6587   declare i32 @llvm.atomic.load.nand.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6588   declare i64 @llvm.atomic.load.nand.i64.p0i32( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
6589 </pre>
6590
6591 <pre>
6592   declare i8 @llvm.atomic.load.xor.i8.p0i32( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6593   declare i16 @llvm.atomic.load.xor.i16.p0i32( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6594   declare i32 @llvm.atomic.load.xor.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6595   declare i64 @llvm.atomic.load.xor.i64.p0i32( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
6596 </pre>
6597
6598 <h5>Overview:</h5>
6599 <p>These intrinsics bitwise the operation (and, nand, or, xor) <tt>delta</tt> to
6600    the value stored in memory at <tt>ptr</tt>. It yields the original value
6601    at <tt>ptr</tt>.</p>
6602
6603 <h5>Arguments:</h5>
6604 <p>These intrinsics take two arguments, the first a pointer to an integer value
6605    and the second an integer value. The result is also an integer value. These
6606    integer types can have any bit width, but they must all have the same bit
6607    width. The targets may only lower integer representations they support.</p>
6608
6609 <h5>Semantics:</h5>
6610 <p>These intrinsics does a series of operations atomically. They first load the
6611    value stored at <tt>ptr</tt>. They then do the bitwise
6612    operation <tt>delta</tt>, store the result to <tt>ptr</tt>. They yield the
6613    original value stored at <tt>ptr</tt>.</p>
6614
6615 <h5>Examples:</h5>
6616 <pre>
6617 %ptr      = malloc i32
6618         store i32 0x0F0F, %ptr
6619 %result0  = call i32 @llvm.atomic.load.nand.i32.p0i32( i32* %ptr, i32 0xFF )
6620                                 <i>; yields {i32}:result0 = 0x0F0F</i>
6621 %result1  = call i32 @llvm.atomic.load.and.i32.p0i32( i32* %ptr, i32 0xFF )
6622                                 <i>; yields {i32}:result1 = 0xFFFFFFF0</i>
6623 %result2  = call i32 @llvm.atomic.load.or.i32.p0i32( i32* %ptr, i32 0F )
6624                                 <i>; yields {i32}:result2 = 0xF0</i>
6625 %result3  = call i32 @llvm.atomic.load.xor.i32.p0i32( i32* %ptr, i32 0F )
6626                                 <i>; yields {i32}:result3 = FF</i>
6627 %memval1  = load i32* %ptr      <i>; yields {i32}:memval1 = F0</i>
6628 </pre>
6629
6630 </div>
6631
6632 <!-- _______________________________________________________________________ -->
6633 <div class="doc_subsubsection">
6634   <a name="int_atomic_load_max">'<tt>llvm.atomic.load.max.*</tt>' Intrinsic</a><br>
6635   <a name="int_atomic_load_min">'<tt>llvm.atomic.load.min.*</tt>' Intrinsic</a><br>
6636   <a name="int_atomic_load_umax">'<tt>llvm.atomic.load.umax.*</tt>' Intrinsic</a><br>
6637   <a name="int_atomic_load_umin">'<tt>llvm.atomic.load.umin.*</tt>' Intrinsic</a><br>
6638 </div>
6639
6640 <div class="doc_text">
6641
6642 <h5>Syntax:</h5>
6643 <p>These are overloaded intrinsics. You can use <tt>llvm.atomic.load_max</tt>,
6644    <tt>llvm.atomic.load_min</tt>, <tt>llvm.atomic.load_umax</tt>, and
6645    <tt>llvm.atomic.load_umin</tt> on any integer bit width and for different
6646    address spaces. Not all targets support all bit widths however.</p>
6647
6648 <pre>
6649   declare i8 @llvm.atomic.load.max.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6650   declare i16 @llvm.atomic.load.max.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6651   declare i32 @llvm.atomic.load.max.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6652   declare i64 @llvm.atomic.load.max.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
6653 </pre>
6654
6655 <pre>
6656   declare i8 @llvm.atomic.load.min.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6657   declare i16 @llvm.atomic.load.min.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6658   declare i32 @llvm.atomic.load.min.i32..p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6659   declare i64 @llvm.atomic.load.min.i64..p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
6660 </pre>
6661
6662 <pre>
6663   declare i8 @llvm.atomic.load.umax.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6664   declare i16 @llvm.atomic.load.umax.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6665   declare i32 @llvm.atomic.load.umax.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6666   declare i64 @llvm.atomic.load.umax.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
6667 </pre>
6668
6669 <pre>
6670   declare i8 @llvm.atomic.load.umin.i8..p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6671   declare i16 @llvm.atomic.load.umin.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6672   declare i32 @llvm.atomic.load.umin.i32..p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6673   declare i64 @llvm.atomic.load.umin.i64..p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
6674 </pre>
6675
6676 <h5>Overview:</h5>
6677 <p>These intrinsics takes the signed or unsigned minimum or maximum of 
6678    <tt>delta</tt> and the value stored in memory at <tt>ptr</tt>. It yields the
6679    original value at <tt>ptr</tt>.</p>
6680
6681 <h5>Arguments:</h5>
6682 <p>These intrinsics take two arguments, the first a pointer to an integer value
6683    and the second an integer value. The result is also an integer value. These
6684    integer types can have any bit width, but they must all have the same bit
6685    width. The targets may only lower integer representations they support.</p>
6686
6687 <h5>Semantics:</h5>
6688 <p>These intrinsics does a series of operations atomically. They first load the
6689    value stored at <tt>ptr</tt>. They then do the signed or unsigned min or
6690    max <tt>delta</tt> and the value, store the result to <tt>ptr</tt>. They
6691    yield the original value stored at <tt>ptr</tt>.</p>
6692
6693 <h5>Examples:</h5>
6694 <pre>
6695 %ptr      = malloc i32
6696         store i32 7, %ptr
6697 %result0  = call i32 @llvm.atomic.load.min.i32.p0i32( i32* %ptr, i32 -2 )
6698                                 <i>; yields {i32}:result0 = 7</i>
6699 %result1  = call i32 @llvm.atomic.load.max.i32.p0i32( i32* %ptr, i32 8 )
6700                                 <i>; yields {i32}:result1 = -2</i>
6701 %result2  = call i32 @llvm.atomic.load.umin.i32.p0i32( i32* %ptr, i32 10 )
6702                                 <i>; yields {i32}:result2 = 8</i>
6703 %result3  = call i32 @llvm.atomic.load.umax.i32.p0i32( i32* %ptr, i32 30 )
6704                                 <i>; yields {i32}:result3 = 8</i>
6705 %memval1  = load i32* %ptr      <i>; yields {i32}:memval1 = 30</i>
6706 </pre>
6707
6708 </div>
6709
6710 <!-- ======================================================================= -->
6711 <div class="doc_subsection">
6712   <a name="int_general">General Intrinsics</a>
6713 </div>
6714
6715 <div class="doc_text">
6716
6717 <p>This class of intrinsics is designed to be generic and has no specific
6718    purpose.</p>
6719
6720 </div>
6721
6722 <!-- _______________________________________________________________________ -->
6723 <div class="doc_subsubsection">
6724   <a name="int_var_annotation">'<tt>llvm.var.annotation</tt>' Intrinsic</a>
6725 </div>
6726
6727 <div class="doc_text">
6728
6729 <h5>Syntax:</h5>
6730 <pre>
6731   declare void @llvm.var.annotation(i8* &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32  &lt;int&gt; )
6732 </pre>
6733
6734 <h5>Overview:</h5>
6735 <p>The '<tt>llvm.var.annotation</tt>' intrinsic.</p>
6736
6737 <h5>Arguments:</h5>
6738 <p>The first argument is a pointer to a value, the second is a pointer to a
6739    global string, the third is a pointer to a global string which is the source
6740    file name, and the last argument is the line number.</p>
6741
6742 <h5>Semantics:</h5>
6743 <p>This intrinsic allows annotation of local variables with arbitrary strings.
6744    This can be useful for special purpose optimizations that want to look for
6745    these annotations.  These have no other defined use, they are ignored by code
6746    generation and optimization.</p>
6747
6748 </div>
6749
6750 <!-- _______________________________________________________________________ -->
6751 <div class="doc_subsubsection">
6752   <a name="int_annotation">'<tt>llvm.annotation.*</tt>' Intrinsic</a>
6753 </div>
6754
6755 <div class="doc_text">
6756
6757 <h5>Syntax:</h5>
6758 <p>This is an overloaded intrinsic. You can use '<tt>llvm.annotation</tt>' on
6759    any integer bit width.</p>
6760
6761 <pre>
6762   declare i8 @llvm.annotation.i8(i8 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32  &lt;int&gt; )
6763   declare i16 @llvm.annotation.i16(i16 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32  &lt;int&gt; )
6764   declare i32 @llvm.annotation.i32(i32 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32  &lt;int&gt; )
6765   declare i64 @llvm.annotation.i64(i64 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32  &lt;int&gt; )
6766   declare i256 @llvm.annotation.i256(i256 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32  &lt;int&gt; )
6767 </pre>
6768
6769 <h5>Overview:</h5>
6770 <p>The '<tt>llvm.annotation</tt>' intrinsic.</p>
6771
6772 <h5>Arguments:</h5>
6773 <p>The first argument is an integer value (result of some expression), the
6774    second is a pointer to a global string, the third is a pointer to a global
6775    string which is the source file name, and the last argument is the line
6776    number.  It returns the value of the first argument.</p>
6777
6778 <h5>Semantics:</h5>
6779 <p>This intrinsic allows annotations to be put on arbitrary expressions with
6780    arbitrary strings.  This can be useful for special purpose optimizations that
6781    want to look for these annotations.  These have no other defined use, they
6782    are ignored by code generation and optimization.</p>
6783
6784 </div>
6785
6786 <!-- _______________________________________________________________________ -->
6787 <div class="doc_subsubsection">
6788   <a name="int_trap">'<tt>llvm.trap</tt>' Intrinsic</a>
6789 </div>
6790
6791 <div class="doc_text">
6792
6793 <h5>Syntax:</h5>
6794 <pre>
6795   declare void @llvm.trap()
6796 </pre>
6797
6798 <h5>Overview:</h5>
6799 <p>The '<tt>llvm.trap</tt>' intrinsic.</p>
6800
6801 <h5>Arguments:</h5>
6802 <p>None.</p>
6803
6804 <h5>Semantics:</h5>
6805 <p>This intrinsics is lowered to the target dependent trap instruction. If the
6806    target does not have a trap instruction, this intrinsic will be lowered to
6807    the call of the <tt>abort()</tt> function.</p>
6808
6809 </div>
6810
6811 <!-- _______________________________________________________________________ -->
6812 <div class="doc_subsubsection">
6813   <a name="int_stackprotector">'<tt>llvm.stackprotector</tt>' Intrinsic</a>
6814 </div>
6815
6816 <div class="doc_text">
6817
6818 <h5>Syntax:</h5>
6819 <pre>
6820   declare void @llvm.stackprotector( i8* &lt;guard&gt;, i8** &lt;slot&gt; )
6821 </pre>
6822
6823 <h5>Overview:</h5>
6824 <p>The <tt>llvm.stackprotector</tt> intrinsic takes the <tt>guard</tt> and
6825    stores it onto the stack at <tt>slot</tt>. The stack slot is adjusted to
6826    ensure that it is placed on the stack before local variables.</p>
6827
6828 <h5>Arguments:</h5>
6829 <p>The <tt>llvm.stackprotector</tt> intrinsic requires two pointer
6830    arguments. The first argument is the value loaded from the stack
6831    guard <tt>@__stack_chk_guard</tt>. The second variable is an <tt>alloca</tt>
6832    that has enough space to hold the value of the guard.</p>
6833
6834 <h5>Semantics:</h5>
6835 <p>This intrinsic causes the prologue/epilogue inserter to force the position of
6836    the <tt>AllocaInst</tt> stack slot to be before local variables on the
6837    stack. This is to ensure that if a local variable on the stack is
6838    overwritten, it will destroy the value of the guard. When the function exits,
6839    the guard on the stack is checked against the original guard. If they're
6840    different, then the program aborts by calling the <tt>__stack_chk_fail()</tt>
6841    function.</p>
6842
6843 </div>
6844
6845 <!-- *********************************************************************** -->
6846 <hr>
6847 <address>
6848   <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
6849   src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
6850   <a href="http://validator.w3.org/check/referer"><img
6851   src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
6852
6853   <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
6854   <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
6855   Last modified: $Date$
6856 </address>
6857
6858 </body>
6859 </html>