blob: d0304f98d51ed6d8006d2f1cfcc74bc6b4b62947 [file] [log] [blame]
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
Misha Brukman9d0919f2003-11-08 01:05:38 +00003<html>
4<head>
5 <title>LLVM Assembly Language Reference Manual</title>
Reid Spencer3921c742004-08-26 20:44:00 +00006 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7 <meta name="author" content="Chris Lattner">
8 <meta name="description"
9 content="LLVM Assembly Language Reference Manual.">
Misha Brukman9d0919f2003-11-08 01:05:38 +000010 <link rel="stylesheet" href="llvm.css" type="text/css">
11</head>
Chris Lattnerd7923912004-05-23 21:06:01 +000012
Misha Brukman9d0919f2003-11-08 01:05:38 +000013<body>
Chris Lattnerd7923912004-05-23 21:06:01 +000014
Chris Lattner261efe92003-11-25 01:02:51 +000015<div class="doc_title"> LLVM Language Reference Manual </div>
Chris Lattner00950542001-06-06 20:29:01 +000016<ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000017 <li><a href="#abstract">Abstract</a></li>
18 <li><a href="#introduction">Introduction</a></li>
19 <li><a href="#identifiers">Identifiers</a></li>
Chris Lattnerfa730212004-12-09 16:11:40 +000020 <li><a href="#highlevel">High Level Structure</a>
21 <ol>
22 <li><a href="#modulestructure">Module Structure</a></li>
Chris Lattnere5d947b2004-12-09 16:36:40 +000023 <li><a href="#linkage">Linkage Types</a></li>
Chris Lattnerbad10ee2005-05-06 22:57:40 +000024 <li><a href="#callingconv">Calling Conventions</a></li>
Chris Lattnerfa730212004-12-09 16:11:40 +000025 <li><a href="#globalvars">Global Variables</a></li>
Chris Lattner4e9aba72006-01-23 23:23:47 +000026 <li><a href="#functionstructure">Functions</a></li>
27 <li><a href="#moduleasm">Module-Level Inline Assembly</a></li>
Chris Lattnerfa730212004-12-09 16:11:40 +000028 </ol>
29 </li>
Chris Lattner00950542001-06-06 20:29:01 +000030 <li><a href="#typesystem">Type System</a>
31 <ol>
Robert Bocchino7b81c752006-02-17 21:18:08 +000032 <li><a href="#t_primitive">Primitive Types</a>
Chris Lattner261efe92003-11-25 01:02:51 +000033 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000034 <li><a href="#t_classifications">Type Classifications</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000035 </ol>
36 </li>
Chris Lattner00950542001-06-06 20:29:01 +000037 <li><a href="#t_derived">Derived Types</a>
38 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000039 <li><a href="#t_array">Array Type</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000040 <li><a href="#t_function">Function Type</a></li>
41 <li><a href="#t_pointer">Pointer Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000042 <li><a href="#t_struct">Structure Type</a></li>
Chris Lattnera58561b2004-08-12 19:12:28 +000043 <li><a href="#t_packed">Packed Type</a></li>
Chris Lattner69c11bb2005-04-25 17:34:15 +000044 <li><a href="#t_opaque">Opaque Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000045 </ol>
46 </li>
47 </ol>
48 </li>
Chris Lattnerfa730212004-12-09 16:11:40 +000049 <li><a href="#constants">Constants</a>
Chris Lattnerc3f59762004-12-09 17:30:23 +000050 <ol>
51 <li><a href="#simpleconstants">Simple Constants</a>
52 <li><a href="#aggregateconstants">Aggregate Constants</a>
53 <li><a href="#globalconstants">Global Variable and Function Addresses</a>
54 <li><a href="#undefvalues">Undefined Values</a>
55 <li><a href="#constantexprs">Constant Expressions</a>
56 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +000057 </li>
Chris Lattnere87d6532006-01-25 23:47:57 +000058 <li><a href="#othervalues">Other Values</a>
59 <ol>
60 <li><a href="#inlineasm">Inline Assembler Expressions</a>
61 </ol>
62 </li>
Chris Lattner00950542001-06-06 20:29:01 +000063 <li><a href="#instref">Instruction Reference</a>
64 <ol>
65 <li><a href="#terminators">Terminator Instructions</a>
66 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000067 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
68 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000069 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
70 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000071 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
Chris Lattner35eca582004-10-16 18:04:13 +000072 <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000073 </ol>
74 </li>
Chris Lattner00950542001-06-06 20:29:01 +000075 <li><a href="#binaryops">Binary Operations</a>
76 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000077 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
78 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
79 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
80 <li><a href="#i_div">'<tt>div</tt>' Instruction</a></li>
81 <li><a href="#i_rem">'<tt>rem</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000082 <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000083 </ol>
84 </li>
Chris Lattner00950542001-06-06 20:29:01 +000085 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
86 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000087 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000088 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000089 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
90 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
91 <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000092 </ol>
93 </li>
Chris Lattner00950542001-06-06 20:29:01 +000094 <li><a href="#memoryops">Memory Access Operations</a>
95 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000096 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
97 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
98 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
Robert Bocchino7b81c752006-02-17 21:18:08 +000099 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
100 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
101 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000102 </ol>
103 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000104 <li><a href="#otherops">Other Operations</a>
105 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000106 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000107 <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li>
Chris Lattnercc37aae2004-03-12 05:50:16 +0000108 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Robert Bocchino8949de22006-03-14 20:55:28 +0000109 <li><a href="#i_vsetint">'<tt>vsetint</tt>' Instruction</a></li>
110 <li><a href="#i_vsetfp">'<tt>vsetfp</tt>' Instruction</a></li>
Robert Bocchino7b81c752006-02-17 21:18:08 +0000111 <li><a href="#i_vselect">'<tt>vselect</tt>' Instruction</a></li>
Robert Bocchino3a558662006-01-05 17:37:02 +0000112 <li><a href="#i_extractelement">'<tt>extractelement</tt>' Instruction</a></li>
Robert Bocchino05ccd702006-01-15 20:48:27 +0000113 <li><a href="#i_insertelement">'<tt>insertelement</tt>' Instruction</a></li>
Chris Lattnerc1989542006-04-08 00:13:41 +0000114 <li><a href="#i_shufflevector">'<tt>shufflevector</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000115 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Chris Lattnerfb6977d2006-01-13 23:26:01 +0000116 <li><a href="#i_va_arg">'<tt>va_arg</tt>' Instruction</a></li>
Chris Lattner00950542001-06-06 20:29:01 +0000117 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000118 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000119 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000120 </li>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +0000121 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +0000122 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000123 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
124 <ol>
125 <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
126 <li><a href="#i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
127 <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
128 </ol>
129 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000130 <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
131 <ol>
132 <li><a href="#i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li>
133 <li><a href="#i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li>
134 <li><a href="#i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li>
135 </ol>
136 </li>
Chris Lattner10610642004-02-14 04:08:35 +0000137 <li><a href="#int_codegen">Code Generator Intrinsics</a>
138 <ol>
139 <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
140 <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
Chris Lattner57e1f392006-01-13 02:03:13 +0000141 <li><a href="#i_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a></li>
142 <li><a href="#i_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a></li>
Chris Lattner9a9d7ac2005-02-28 19:24:19 +0000143 <li><a href="#i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a></li>
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +0000144 <li><a href="#i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a></li>
Andrew Lenharth51b8d542005-11-11 16:47:30 +0000145 <li><a href="#i_readcyclecounter"><tt>llvm.readcyclecounter</tt>' Intrinsic</a></li>
John Criswell7123e272004-04-09 16:43:20 +0000146 </ol>
147 </li>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000148 <li><a href="#int_libc">Standard C Library Intrinsics</a>
149 <ol>
Chris Lattner5b310c32006-03-03 00:07:20 +0000150 <li><a href="#i_memcpy">'<tt>llvm.memcpy.*</tt>' Intrinsic</a></li>
151 <li><a href="#i_memmove">'<tt>llvm.memmove.*</tt>' Intrinsic</a></li>
152 <li><a href="#i_memset">'<tt>llvm.memset.*</tt>' Intrinsic</a></li>
Chris Lattnerec6cb612006-01-16 22:38:59 +0000153 <li><a href="#i_isunordered">'<tt>llvm.isunordered.*</tt>' Intrinsic</a></li>
154 <li><a href="#i_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a></li>
Chris Lattnera4d74142005-07-21 01:29:16 +0000155
Chris Lattner33aec9e2004-02-12 17:01:32 +0000156 </ol>
157 </li>
Nate Begeman7e36c472006-01-13 23:26:38 +0000158 <li><a href="#int_manip">Bit Manipulation Intrinsics</a>
Andrew Lenharthec370fd2005-05-03 18:01:48 +0000159 <ol>
Nate Begeman7e36c472006-01-13 23:26:38 +0000160 <li><a href="#i_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a></li>
Chris Lattner8a886be2006-01-16 22:34:14 +0000161 <li><a href="#int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic </a></li>
162 <li><a href="#int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic </a></li>
163 <li><a href="#int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic </a></li>
Andrew Lenharthec370fd2005-05-03 18:01:48 +0000164 </ol>
165 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000166 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000167 </ol>
168 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000169</ol>
Chris Lattnerd7923912004-05-23 21:06:01 +0000170
171<div class="doc_author">
172 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
173 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000174</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000175
Chris Lattner00950542001-06-06 20:29:01 +0000176<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000177<div class="doc_section"> <a name="abstract">Abstract </a></div>
178<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000179
Misha Brukman9d0919f2003-11-08 01:05:38 +0000180<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000181<p>This document is a reference manual for the LLVM assembly language.
182LLVM is an SSA based representation that provides type safety,
183low-level operations, flexibility, and the capability of representing
184'all' high-level languages cleanly. It is the common code
185representation used throughout all phases of the LLVM compilation
186strategy.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000187</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000188
Chris Lattner00950542001-06-06 20:29:01 +0000189<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000190<div class="doc_section"> <a name="introduction">Introduction</a> </div>
191<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000192
Misha Brukman9d0919f2003-11-08 01:05:38 +0000193<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000194
Chris Lattner261efe92003-11-25 01:02:51 +0000195<p>The LLVM code representation is designed to be used in three
196different forms: as an in-memory compiler IR, as an on-disk bytecode
197representation (suitable for fast loading by a Just-In-Time compiler),
198and as a human readable assembly language representation. This allows
199LLVM to provide a powerful intermediate representation for efficient
200compiler transformations and analysis, while providing a natural means
201to debug and visualize the transformations. The three different forms
202of LLVM are all equivalent. This document describes the human readable
203representation and notation.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000204
John Criswellc1f786c2005-05-13 22:25:59 +0000205<p>The LLVM representation aims to be light-weight and low-level
Chris Lattner261efe92003-11-25 01:02:51 +0000206while being expressive, typed, and extensible at the same time. It
207aims to be a "universal IR" of sorts, by being at a low enough level
208that high-level ideas may be cleanly mapped to it (similar to how
209microprocessors are "universal IR's", allowing many source languages to
210be mapped to them). By providing type information, LLVM can be used as
211the target of optimizations: for example, through pointer analysis, it
212can be proven that a C automatic variable is never accessed outside of
213the current function... allowing it to be promoted to a simple SSA
214value instead of a memory location.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000215
Misha Brukman9d0919f2003-11-08 01:05:38 +0000216</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000217
Chris Lattner00950542001-06-06 20:29:01 +0000218<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000219<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000220
Misha Brukman9d0919f2003-11-08 01:05:38 +0000221<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000222
Chris Lattner261efe92003-11-25 01:02:51 +0000223<p>It is important to note that this document describes 'well formed'
224LLVM assembly language. There is a difference between what the parser
225accepts and what is considered 'well formed'. For example, the
226following instruction is syntactically okay, but not well formed:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000227
228<pre>
229 %x = <a href="#i_add">add</a> int 1, %x
230</pre>
231
Chris Lattner261efe92003-11-25 01:02:51 +0000232<p>...because the definition of <tt>%x</tt> does not dominate all of
233its uses. The LLVM infrastructure provides a verification pass that may
234be used to verify that an LLVM module is well formed. This pass is
John Criswellc1f786c2005-05-13 22:25:59 +0000235automatically run by the parser after parsing input assembly and by
Chris Lattner261efe92003-11-25 01:02:51 +0000236the optimizer before it outputs bytecode. The violations pointed out
237by the verifier pass indicate bugs in transformation passes or input to
238the parser.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000239
Chris Lattner261efe92003-11-25 01:02:51 +0000240<!-- Describe the typesetting conventions here. --> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000241
Chris Lattner00950542001-06-06 20:29:01 +0000242<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000243<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000244<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000245
Misha Brukman9d0919f2003-11-08 01:05:38 +0000246<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000247
Chris Lattner261efe92003-11-25 01:02:51 +0000248<p>LLVM uses three different forms of identifiers, for different
249purposes:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000250
Chris Lattner00950542001-06-06 20:29:01 +0000251<ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000252 <li>Named values are represented as a string of characters with a '%' prefix.
253 For example, %foo, %DivisionByZero, %a.really.long.identifier. The actual
254 regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
255 Identifiers which require other characters in their names can be surrounded
256 with quotes. In this way, anything except a <tt>"</tt> character can be used
257 in a name.</li>
258
259 <li>Unnamed values are represented as an unsigned numeric value with a '%'
260 prefix. For example, %12, %2, %44.</li>
261
Reid Spencercc16dc32004-12-09 18:02:53 +0000262 <li>Constants, which are described in a <a href="#constants">section about
263 constants</a>, below.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000264</ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000265
266<p>LLVM requires that values start with a '%' sign for two reasons: Compilers
267don't need to worry about name clashes with reserved words, and the set of
268reserved words may be expanded in the future without penalty. Additionally,
269unnamed identifiers allow a compiler to quickly come up with a temporary
270variable without having to avoid symbol table conflicts.</p>
271
Chris Lattner261efe92003-11-25 01:02:51 +0000272<p>Reserved words in LLVM are very similar to reserved words in other
273languages. There are keywords for different opcodes ('<tt><a
Chris Lattnere5d947b2004-12-09 16:36:40 +0000274href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
275href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
276href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>', etc...),
277and others. These reserved words cannot conflict with variable names, because
278none of them start with a '%' character.</p>
279
280<p>Here is an example of LLVM code to multiply the integer variable
281'<tt>%X</tt>' by 8:</p>
282
Misha Brukman9d0919f2003-11-08 01:05:38 +0000283<p>The easy way:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000284
285<pre>
286 %result = <a href="#i_mul">mul</a> uint %X, 8
287</pre>
288
Misha Brukman9d0919f2003-11-08 01:05:38 +0000289<p>After strength reduction:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000290
291<pre>
292 %result = <a href="#i_shl">shl</a> uint %X, ubyte 3
293</pre>
294
Misha Brukman9d0919f2003-11-08 01:05:38 +0000295<p>And the hard way:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000296
297<pre>
298 <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
299 <a href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
300 %result = <a href="#i_add">add</a> uint %1, %1
301</pre>
302
Chris Lattner261efe92003-11-25 01:02:51 +0000303<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
304important lexical features of LLVM:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000305
Chris Lattner00950542001-06-06 20:29:01 +0000306<ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000307
308 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
309 line.</li>
310
311 <li>Unnamed temporaries are created when the result of a computation is not
312 assigned to a named value.</li>
313
Misha Brukman9d0919f2003-11-08 01:05:38 +0000314 <li>Unnamed temporaries are numbered sequentially</li>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000315
Misha Brukman9d0919f2003-11-08 01:05:38 +0000316</ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000317
John Criswelle4c57cc2005-05-12 16:52:32 +0000318<p>...and it also shows a convention that we follow in this document. When
Chris Lattnere5d947b2004-12-09 16:36:40 +0000319demonstrating instructions, we will follow an instruction with a comment that
320defines the type and name of value produced. Comments are shown in italic
321text.</p>
322
Misha Brukman9d0919f2003-11-08 01:05:38 +0000323</div>
Chris Lattnerfa730212004-12-09 16:11:40 +0000324
325<!-- *********************************************************************** -->
326<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
327<!-- *********************************************************************** -->
328
329<!-- ======================================================================= -->
330<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
331</div>
332
333<div class="doc_text">
334
335<p>LLVM programs are composed of "Module"s, each of which is a
336translation unit of the input programs. Each module consists of
337functions, global variables, and symbol table entries. Modules may be
338combined together with the LLVM linker, which merges function (and
339global variable) definitions, resolves forward declarations, and merges
340symbol table entries. Here is an example of the "hello world" module:</p>
341
342<pre><i>; Declare the string constant as a global constant...</i>
343<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
344 href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00" <i>; [13 x sbyte]*</i>
345
346<i>; External declaration of the puts function</i>
347<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
348
349<i>; Definition of main function</i>
350int %main() { <i>; int()* </i>
351 <i>; Convert [13x sbyte]* to sbyte *...</i>
352 %cast210 = <a
353 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
354
355 <i>; Call puts function to write out the string to stdout...</i>
356 <a
357 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
358 <a
359 href="#i_ret">ret</a> int 0<br>}<br></pre>
360
361<p>This example is made up of a <a href="#globalvars">global variable</a>
362named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
363function, and a <a href="#functionstructure">function definition</a>
364for "<tt>main</tt>".</p>
365
Chris Lattnere5d947b2004-12-09 16:36:40 +0000366<p>In general, a module is made up of a list of global values,
367where both functions and global variables are global values. Global values are
368represented by a pointer to a memory location (in this case, a pointer to an
369array of char, and a pointer to a function), and have one of the following <a
370href="#linkage">linkage types</a>.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000371
Chris Lattnere5d947b2004-12-09 16:36:40 +0000372</div>
373
374<!-- ======================================================================= -->
375<div class="doc_subsection">
376 <a name="linkage">Linkage Types</a>
377</div>
378
379<div class="doc_text">
380
381<p>
382All Global Variables and Functions have one of the following types of linkage:
383</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000384
385<dl>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000386
Chris Lattnerfa730212004-12-09 16:11:40 +0000387 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000388
389 <dd>Global values with internal linkage are only directly accessible by
390 objects in the current module. In particular, linking code into a module with
391 an internal global value may cause the internal to be renamed as necessary to
392 avoid collisions. Because the symbol is internal to the module, all
393 references can be updated. This corresponds to the notion of the
394 '<tt>static</tt>' keyword in C, or the idea of "anonymous namespaces" in C++.
Chris Lattnerfa730212004-12-09 16:11:40 +0000395 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000396
Chris Lattnerfa730212004-12-09 16:11:40 +0000397 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000398
399 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt> linkage, with
400 the twist that linking together two modules defining the same
401 <tt>linkonce</tt> globals will cause one of the globals to be discarded. This
402 is typically used to implement inline functions. Unreferenced
403 <tt>linkonce</tt> globals are allowed to be discarded.
Chris Lattnerfa730212004-12-09 16:11:40 +0000404 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000405
Chris Lattnerfa730212004-12-09 16:11:40 +0000406 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000407
408 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage,
409 except that unreferenced <tt>weak</tt> globals may not be discarded. This is
410 used to implement constructs in C such as "<tt>int X;</tt>" at global scope.
Chris Lattnerfa730212004-12-09 16:11:40 +0000411 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000412
Chris Lattnerfa730212004-12-09 16:11:40 +0000413 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000414
415 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
416 pointer to array type. When two global variables with appending linkage are
417 linked together, the two global arrays are appended together. This is the
418 LLVM, typesafe, equivalent of having the system linker append together
419 "sections" with identical names when .o files are linked.
Chris Lattnerfa730212004-12-09 16:11:40 +0000420 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000421
Chris Lattnerfa730212004-12-09 16:11:40 +0000422 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000423
424 <dd>If none of the above identifiers are used, the global is externally
425 visible, meaning that it participates in linkage and can be used to resolve
426 external symbol references.
Chris Lattnerfa730212004-12-09 16:11:40 +0000427 </dd>
428</dl>
429
Chris Lattnerfa730212004-12-09 16:11:40 +0000430<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
431variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
432variable and was linked with this one, one of the two would be renamed,
433preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
434external (i.e., lacking any linkage declarations), they are accessible
435outside of the current module. It is illegal for a function <i>declaration</i>
436to have any linkage type other than "externally visible".</a></p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000437
Chris Lattnerfa730212004-12-09 16:11:40 +0000438</div>
439
440<!-- ======================================================================= -->
441<div class="doc_subsection">
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000442 <a name="callingconv">Calling Conventions</a>
443</div>
444
445<div class="doc_text">
446
447<p>LLVM <a href="#functionstructure">functions</a>, <a href="#i_call">calls</a>
448and <a href="#i_invoke">invokes</a> can all have an optional calling convention
449specified for the call. The calling convention of any pair of dynamic
450caller/callee must match, or the behavior of the program is undefined. The
451following calling conventions are supported by LLVM, and more may be added in
452the future:</p>
453
454<dl>
455 <dt><b>"<tt>ccc</tt>" - The C calling convention</b>:</dt>
456
457 <dd>This calling convention (the default if no other calling convention is
458 specified) matches the target C calling conventions. This calling convention
John Criswelle4c57cc2005-05-12 16:52:32 +0000459 supports varargs function calls and tolerates some mismatch in the declared
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000460 prototype and implemented declaration of the function (as does normal C).
461 </dd>
462
463 <dt><b>"<tt>fastcc</tt>" - The fast calling convention</b>:</dt>
464
465 <dd>This calling convention attempts to make calls as fast as possible
466 (e.g. by passing things in registers). This calling convention allows the
467 target to use whatever tricks it wants to produce fast code for the target,
Chris Lattner8cdc5bc2005-05-06 23:08:23 +0000468 without having to conform to an externally specified ABI. Implementations of
469 this convention should allow arbitrary tail call optimization to be supported.
470 This calling convention does not support varargs and requires the prototype of
471 all callees to exactly match the prototype of the function definition.
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000472 </dd>
473
474 <dt><b>"<tt>coldcc</tt>" - The cold calling convention</b>:</dt>
475
476 <dd>This calling convention attempts to make code in the caller as efficient
477 as possible under the assumption that the call is not commonly executed. As
478 such, these calls often preserve all registers so that the call does not break
479 any live ranges in the caller side. This calling convention does not support
480 varargs and requires the prototype of all callees to exactly match the
481 prototype of the function definition.
482 </dd>
483
Chris Lattnercfe6b372005-05-07 01:46:40 +0000484 <dt><b>"<tt>cc &lt;<em>n</em>&gt;</tt>" - Numbered convention</b>:</dt>
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000485
486 <dd>Any calling convention may be specified by number, allowing
487 target-specific calling conventions to be used. Target specific calling
488 conventions start at 64.
489 </dd>
Chris Lattnercfe6b372005-05-07 01:46:40 +0000490</dl>
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000491
492<p>More calling conventions can be added/defined on an as-needed basis, to
493support pascal conventions or any other well-known target-independent
494convention.</p>
495
496</div>
497
498<!-- ======================================================================= -->
499<div class="doc_subsection">
Chris Lattnerfa730212004-12-09 16:11:40 +0000500 <a name="globalvars">Global Variables</a>
501</div>
502
503<div class="doc_text">
504
Chris Lattner3689a342005-02-12 19:30:21 +0000505<p>Global variables define regions of memory allocated at compilation time
Chris Lattner88f6c462005-11-12 00:45:07 +0000506instead of run-time. Global variables may optionally be initialized, may have
507an explicit section to be placed in, and may
Chris Lattner2cbdc452005-11-06 08:02:57 +0000508have an optional explicit alignment specified. A
John Criswell0ec250c2005-10-24 16:17:18 +0000509variable may be defined as a global "constant," which indicates that the
Chris Lattner3689a342005-02-12 19:30:21 +0000510contents of the variable will <b>never</b> be modified (enabling better
511optimization, allowing the global data to be placed in the read-only section of
512an executable, etc). Note that variables that need runtime initialization
John Criswell0ec250c2005-10-24 16:17:18 +0000513cannot be marked "constant" as there is a store to the variable.</p>
Chris Lattner3689a342005-02-12 19:30:21 +0000514
515<p>
516LLVM explicitly allows <em>declarations</em> of global variables to be marked
517constant, even if the final definition of the global is not. This capability
518can be used to enable slightly better optimization of the program, but requires
519the language definition to guarantee that optimizations based on the
520'constantness' are valid for the translation units that do not include the
521definition.
522</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000523
524<p>As SSA values, global variables define pointer values that are in
525scope (i.e. they dominate) all basic blocks in the program. Global
526variables always define a pointer to their "content" type because they
527describe a region of memory, and all memory objects in LLVM are
528accessed through pointers.</p>
529
Chris Lattner88f6c462005-11-12 00:45:07 +0000530<p>LLVM allows an explicit section to be specified for globals. If the target
531supports it, it will emit globals to the section specified.</p>
532
Chris Lattner2cbdc452005-11-06 08:02:57 +0000533<p>An explicit alignment may be specified for a global. If not present, or if
534the alignment is set to zero, the alignment of the global is set by the target
535to whatever it feels convenient. If an explicit alignment is specified, the
536global is forced to have at least that much alignment. All alignments must be
537a power of 2.</p>
538
Chris Lattnerfa730212004-12-09 16:11:40 +0000539</div>
540
541
542<!-- ======================================================================= -->
543<div class="doc_subsection">
544 <a name="functionstructure">Functions</a>
545</div>
546
547<div class="doc_text">
548
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000549<p>LLVM function definitions consist of an optional <a href="#linkage">linkage
550type</a>, an optional <a href="#callingconv">calling convention</a>, a return
Chris Lattner88f6c462005-11-12 00:45:07 +0000551type, a function name, a (possibly empty) argument list, an optional section,
552an optional alignment, an opening curly brace,
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000553a list of basic blocks, and a closing curly brace. LLVM function declarations
554are defined with the "<tt>declare</tt>" keyword, an optional <a
Chris Lattner2cbdc452005-11-06 08:02:57 +0000555href="#callingconv">calling convention</a>, a return type, a function name,
556a possibly empty list of arguments, and an optional alignment.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000557
558<p>A function definition contains a list of basic blocks, forming the CFG for
559the function. Each basic block may optionally start with a label (giving the
560basic block a symbol table entry), contains a list of instructions, and ends
561with a <a href="#terminators">terminator</a> instruction (such as a branch or
562function return).</p>
563
John Criswelle4c57cc2005-05-12 16:52:32 +0000564<p>The first basic block in a program is special in two ways: it is immediately
Chris Lattnerfa730212004-12-09 16:11:40 +0000565executed on entrance to the function, and it is not allowed to have predecessor
566basic blocks (i.e. there can not be any branches to the entry block of a
567function). Because the block can have no predecessors, it also cannot have any
568<a href="#i_phi">PHI nodes</a>.</p>
569
570<p>LLVM functions are identified by their name and type signature. Hence, two
571functions with the same name but different parameter lists or return values are
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000572considered different functions, and LLVM will resolve references to each
Chris Lattnerfa730212004-12-09 16:11:40 +0000573appropriately.</p>
574
Chris Lattner88f6c462005-11-12 00:45:07 +0000575<p>LLVM allows an explicit section to be specified for functions. If the target
576supports it, it will emit functions to the section specified.</p>
577
Chris Lattner2cbdc452005-11-06 08:02:57 +0000578<p>An explicit alignment may be specified for a function. If not present, or if
579the alignment is set to zero, the alignment of the function is set by the target
580to whatever it feels convenient. If an explicit alignment is specified, the
581function is forced to have at least that much alignment. All alignments must be
582a power of 2.</p>
583
Chris Lattnerfa730212004-12-09 16:11:40 +0000584</div>
585
Chris Lattner4e9aba72006-01-23 23:23:47 +0000586<!-- ======================================================================= -->
587<div class="doc_subsection">
588 <a name="moduleasm">Module-Level Inline Assembly</a></li>
589</div>
590
591<div class="doc_text">
592<p>
593Modules may contain "module-level inline asm" blocks, which corresponds to the
594GCC "file scope inline asm" blocks. These blocks are internally concatenated by
595LLVM and treated as a single unit, but may be separated in the .ll file if
596desired. The syntax is very simple:
597</p>
598
599<div class="doc_code"><pre>
Chris Lattner52599e12006-01-24 00:37:20 +0000600 module asm "inline asm code goes here"
601 module asm "more can go here"
Chris Lattner4e9aba72006-01-23 23:23:47 +0000602</pre></div>
603
604<p>The strings can contain any character by escaping non-printable characters.
605 The escape sequence used is simply "\xx" where "xx" is the two digit hex code
606 for the number.
607</p>
608
609<p>
610 The inline asm code is simply printed to the machine code .s file when
611 assembly code is generated.
612</p>
613</div>
Chris Lattnerfa730212004-12-09 16:11:40 +0000614
615
Chris Lattner00950542001-06-06 20:29:01 +0000616<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000617<div class="doc_section"> <a name="typesystem">Type System</a> </div>
618<!-- *********************************************************************** -->
Chris Lattnerfa730212004-12-09 16:11:40 +0000619
Misha Brukman9d0919f2003-11-08 01:05:38 +0000620<div class="doc_text">
Chris Lattnerfa730212004-12-09 16:11:40 +0000621
Misha Brukman9d0919f2003-11-08 01:05:38 +0000622<p>The LLVM type system is one of the most important features of the
Chris Lattner261efe92003-11-25 01:02:51 +0000623intermediate representation. Being typed enables a number of
624optimizations to be performed on the IR directly, without having to do
625extra analyses on the side before the transformation. A strong type
626system makes it easier to read the generated code and enables novel
627analyses and transformations that are not feasible to perform on normal
628three address code representations.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000629
630</div>
631
Chris Lattner00950542001-06-06 20:29:01 +0000632<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000633<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000634<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +0000635<p>The primitive types are the fundamental building blocks of the LLVM
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000636system. The current set of primitive types is as follows:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000637
Reid Spencerd3f876c2004-11-01 08:19:36 +0000638<table class="layout">
639 <tr class="layout">
640 <td class="left">
641 <table>
Chris Lattner261efe92003-11-25 01:02:51 +0000642 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000643 <tr><th>Type</th><th>Description</th></tr>
644 <tr><td><tt>void</tt></td><td>No value</td></tr>
Misha Brukmancfa87bc2005-04-22 18:02:52 +0000645 <tr><td><tt>ubyte</tt></td><td>Unsigned 8-bit value</td></tr>
646 <tr><td><tt>ushort</tt></td><td>Unsigned 16-bit value</td></tr>
647 <tr><td><tt>uint</tt></td><td>Unsigned 32-bit value</td></tr>
648 <tr><td><tt>ulong</tt></td><td>Unsigned 64-bit value</td></tr>
649 <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000650 <tr><td><tt>label</tt></td><td>Branch destination</td></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000651 </tbody>
652 </table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000653 </td>
654 <td class="right">
655 <table>
Chris Lattner261efe92003-11-25 01:02:51 +0000656 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000657 <tr><th>Type</th><th>Description</th></tr>
658 <tr><td><tt>bool</tt></td><td>True or False value</td></tr>
Misha Brukmancfa87bc2005-04-22 18:02:52 +0000659 <tr><td><tt>sbyte</tt></td><td>Signed 8-bit value</td></tr>
660 <tr><td><tt>short</tt></td><td>Signed 16-bit value</td></tr>
661 <tr><td><tt>int</tt></td><td>Signed 32-bit value</td></tr>
662 <tr><td><tt>long</tt></td><td>Signed 64-bit value</td></tr>
663 <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000664 </tbody>
665 </table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000666 </td>
667 </tr>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000668</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000669</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000670
Chris Lattner00950542001-06-06 20:29:01 +0000671<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000672<div class="doc_subsubsection"> <a name="t_classifications">Type
673Classifications</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000674<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000675<p>These different primitive types fall into a few useful
676classifications:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000677
678<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +0000679 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000680 <tr><th>Classification</th><th>Types</th></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000681 <tr>
682 <td><a name="t_signed">signed</a></td>
683 <td><tt>sbyte, short, int, long, float, double</tt></td>
684 </tr>
685 <tr>
686 <td><a name="t_unsigned">unsigned</a></td>
687 <td><tt>ubyte, ushort, uint, ulong</tt></td>
688 </tr>
689 <tr>
690 <td><a name="t_integer">integer</a></td>
691 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
692 </tr>
693 <tr>
694 <td><a name="t_integral">integral</a></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000695 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt>
696 </td>
Chris Lattner261efe92003-11-25 01:02:51 +0000697 </tr>
698 <tr>
699 <td><a name="t_floating">floating point</a></td>
700 <td><tt>float, double</tt></td>
701 </tr>
702 <tr>
703 <td><a name="t_firstclass">first class</a></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000704 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long,<br>
705 float, double, <a href="#t_pointer">pointer</a>,
706 <a href="#t_packed">packed</a></tt></td>
Chris Lattner261efe92003-11-25 01:02:51 +0000707 </tr>
708 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000709</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000710
Chris Lattner261efe92003-11-25 01:02:51 +0000711<p>The <a href="#t_firstclass">first class</a> types are perhaps the
712most important. Values of these types are the only ones which can be
713produced by instructions, passed as arguments, or used as operands to
714instructions. This means that all structures and arrays must be
715manipulated either by pointer or by component.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000716</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000717
Chris Lattner00950542001-06-06 20:29:01 +0000718<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000719<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000720
Misha Brukman9d0919f2003-11-08 01:05:38 +0000721<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +0000722
Chris Lattner261efe92003-11-25 01:02:51 +0000723<p>The real power in LLVM comes from the derived types in the system.
724This is what allows a programmer to represent arrays, functions,
725pointers, and other useful types. Note that these derived types may be
726recursive: For example, it is possible to have a two dimensional array.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000727
Misha Brukman9d0919f2003-11-08 01:05:38 +0000728</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000729
Chris Lattner00950542001-06-06 20:29:01 +0000730<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000731<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000732
Misha Brukman9d0919f2003-11-08 01:05:38 +0000733<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +0000734
Chris Lattner00950542001-06-06 20:29:01 +0000735<h5>Overview:</h5>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000736
Misha Brukman9d0919f2003-11-08 01:05:38 +0000737<p>The array type is a very simple derived type that arranges elements
Chris Lattner261efe92003-11-25 01:02:51 +0000738sequentially in memory. The array type requires a size (number of
739elements) and an underlying data type.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000740
Chris Lattner7faa8832002-04-14 06:13:44 +0000741<h5>Syntax:</h5>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000742
743<pre>
744 [&lt;# elements&gt; x &lt;elementtype&gt;]
745</pre>
746
John Criswelle4c57cc2005-05-12 16:52:32 +0000747<p>The number of elements is a constant integer value; elementtype may
Chris Lattner261efe92003-11-25 01:02:51 +0000748be any type with a size.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000749
Chris Lattner7faa8832002-04-14 06:13:44 +0000750<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000751<table class="layout">
752 <tr class="layout">
753 <td class="left">
754 <tt>[40 x int ]</tt><br/>
755 <tt>[41 x int ]</tt><br/>
756 <tt>[40 x uint]</tt><br/>
757 </td>
758 <td class="left">
759 Array of 40 integer values.<br/>
760 Array of 41 integer values.<br/>
761 Array of 40 unsigned integer values.<br/>
762 </td>
763 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000764</table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000765<p>Here are some examples of multidimensional arrays:</p>
766<table class="layout">
767 <tr class="layout">
768 <td class="left">
769 <tt>[3 x [4 x int]]</tt><br/>
770 <tt>[12 x [10 x float]]</tt><br/>
771 <tt>[2 x [3 x [4 x uint]]]</tt><br/>
772 </td>
773 <td class="left">
John Criswellc1f786c2005-05-13 22:25:59 +0000774 3x4 array of integer values.<br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000775 12x10 array of single precision floating point values.<br/>
776 2x3x4 array of unsigned integer values.<br/>
777 </td>
778 </tr>
779</table>
Chris Lattnere67a9512005-06-24 17:22:57 +0000780
John Criswell0ec250c2005-10-24 16:17:18 +0000781<p>Note that 'variable sized arrays' can be implemented in LLVM with a zero
782length array. Normally, accesses past the end of an array are undefined in
Chris Lattnere67a9512005-06-24 17:22:57 +0000783LLVM (e.g. it is illegal to access the 5th element of a 3 element array).
784As a special case, however, zero length arrays are recognized to be variable
785length. This allows implementation of 'pascal style arrays' with the LLVM
786type "{ int, [0 x float]}", for example.</p>
787
Misha Brukman9d0919f2003-11-08 01:05:38 +0000788</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000789
Chris Lattner00950542001-06-06 20:29:01 +0000790<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000791<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000792<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000793<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000794<p>The function type can be thought of as a function signature. It
795consists of a return type and a list of formal parameter types.
John Criswell009900b2003-11-25 21:45:46 +0000796Function types are usually used to build virtual function tables
Chris Lattner261efe92003-11-25 01:02:51 +0000797(which are structures of pointers to functions), for indirect function
798calls, and when defining a function.</p>
John Criswell009900b2003-11-25 21:45:46 +0000799<p>
800The return type of a function type cannot be an aggregate type.
801</p>
Chris Lattner00950542001-06-06 20:29:01 +0000802<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000803<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
John Criswell0ec250c2005-10-24 16:17:18 +0000804<p>...where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
Misha Brukmanc24b7582004-08-12 20:16:08 +0000805specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner27f71f22003-09-03 00:41:47 +0000806which indicates that the function takes a variable number of arguments.
807Variable argument functions can access their arguments with the <a
Chris Lattner261efe92003-11-25 01:02:51 +0000808 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000809<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000810<table class="layout">
811 <tr class="layout">
812 <td class="left">
813 <tt>int (int)</tt> <br/>
814 <tt>float (int, int *) *</tt><br/>
815 <tt>int (sbyte *, ...)</tt><br/>
816 </td>
817 <td class="left">
818 function taking an <tt>int</tt>, returning an <tt>int</tt><br/>
819 <a href="#t_pointer">Pointer</a> to a function that takes an
Misha Brukmanc24b7582004-08-12 20:16:08 +0000820 <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
Reid Spencerd3f876c2004-11-01 08:19:36 +0000821 returning <tt>float</tt>.<br/>
822 A vararg function that takes at least one <a href="#t_pointer">pointer</a>
823 to <tt>sbyte</tt> (signed char in C), which returns an integer. This is
824 the signature for <tt>printf</tt> in LLVM.<br/>
825 </td>
826 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000827</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000828
Misha Brukman9d0919f2003-11-08 01:05:38 +0000829</div>
Chris Lattner00950542001-06-06 20:29:01 +0000830<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000831<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000832<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000833<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000834<p>The structure type is used to represent a collection of data members
835together in memory. The packing of the field types is defined to match
836the ABI of the underlying processor. The elements of a structure may
837be any type that has a size.</p>
838<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
839and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
840field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
841instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000842<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000843<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +0000844<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000845<table class="layout">
846 <tr class="layout">
847 <td class="left">
848 <tt>{ int, int, int }</tt><br/>
849 <tt>{ float, int (int) * }</tt><br/>
850 </td>
851 <td class="left">
852 a triple of three <tt>int</tt> values<br/>
853 A pair, where the first element is a <tt>float</tt> and the second element
854 is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a>
855 that takes an <tt>int</tt>, returning an <tt>int</tt>.<br/>
856 </td>
857 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000858</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000859</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000860
Chris Lattner00950542001-06-06 20:29:01 +0000861<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000862<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000863<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +0000864<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000865<p>As in many languages, the pointer type represents a pointer or
866reference to another object, which must live in memory.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000867<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000868<pre> &lt;type&gt; *<br></pre>
Chris Lattner7faa8832002-04-14 06:13:44 +0000869<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000870<table class="layout">
871 <tr class="layout">
872 <td class="left">
873 <tt>[4x int]*</tt><br/>
874 <tt>int (int *) *</tt><br/>
875 </td>
876 <td class="left">
877 A <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of
878 four <tt>int</tt> values<br/>
879 A <a href="#t_pointer">pointer</a> to a <a
Chris Lattnera977c482005-02-19 02:22:14 +0000880 href="#t_function">function</a> that takes an <tt>int*</tt>, returning an
Reid Spencerd3f876c2004-11-01 08:19:36 +0000881 <tt>int</tt>.<br/>
882 </td>
883 </tr>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000884</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000885</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000886
Chris Lattnera58561b2004-08-12 19:12:28 +0000887<!-- _______________________________________________________________________ -->
888<div class="doc_subsubsection"> <a name="t_packed">Packed Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000889<div class="doc_text">
Chris Lattner69c11bb2005-04-25 17:34:15 +0000890
Chris Lattnera58561b2004-08-12 19:12:28 +0000891<h5>Overview:</h5>
Chris Lattner69c11bb2005-04-25 17:34:15 +0000892
Chris Lattnera58561b2004-08-12 19:12:28 +0000893<p>A packed type is a simple derived type that represents a vector
894of elements. Packed types are used when multiple primitive data
895are operated in parallel using a single instruction (SIMD).
896A packed type requires a size (number of
Chris Lattnerb8d172f2005-11-10 01:44:22 +0000897elements) and an underlying primitive data type. Vectors must have a power
898of two length (1, 2, 4, 8, 16 ...). Packed types are
Chris Lattnera58561b2004-08-12 19:12:28 +0000899considered <a href="#t_firstclass">first class</a>.</p>
Chris Lattner69c11bb2005-04-25 17:34:15 +0000900
Chris Lattnera58561b2004-08-12 19:12:28 +0000901<h5>Syntax:</h5>
Chris Lattner69c11bb2005-04-25 17:34:15 +0000902
903<pre>
904 &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;
905</pre>
906
John Criswellc1f786c2005-05-13 22:25:59 +0000907<p>The number of elements is a constant integer value; elementtype may
Chris Lattnera58561b2004-08-12 19:12:28 +0000908be any integral or floating point type.</p>
Chris Lattner69c11bb2005-04-25 17:34:15 +0000909
Chris Lattnera58561b2004-08-12 19:12:28 +0000910<h5>Examples:</h5>
Chris Lattner69c11bb2005-04-25 17:34:15 +0000911
Reid Spencerd3f876c2004-11-01 08:19:36 +0000912<table class="layout">
913 <tr class="layout">
914 <td class="left">
915 <tt>&lt;4 x int&gt;</tt><br/>
916 <tt>&lt;8 x float&gt;</tt><br/>
917 <tt>&lt;2 x uint&gt;</tt><br/>
918 </td>
919 <td class="left">
920 Packed vector of 4 integer values.<br/>
921 Packed vector of 8 floating-point values.<br/>
922 Packed vector of 2 unsigned integer values.<br/>
923 </td>
924 </tr>
925</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000926</div>
927
Chris Lattner69c11bb2005-04-25 17:34:15 +0000928<!-- _______________________________________________________________________ -->
929<div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div>
930<div class="doc_text">
931
932<h5>Overview:</h5>
933
934<p>Opaque types are used to represent unknown types in the system. This
935corresponds (for example) to the C notion of a foward declared structure type.
936In LLVM, opaque types can eventually be resolved to any type (not just a
937structure type).</p>
938
939<h5>Syntax:</h5>
940
941<pre>
942 opaque
943</pre>
944
945<h5>Examples:</h5>
946
947<table class="layout">
948 <tr class="layout">
949 <td class="left">
950 <tt>opaque</tt>
951 </td>
952 <td class="left">
953 An opaque type.<br/>
954 </td>
955 </tr>
956</table>
957</div>
958
959
Chris Lattnerc3f59762004-12-09 17:30:23 +0000960<!-- *********************************************************************** -->
961<div class="doc_section"> <a name="constants">Constants</a> </div>
962<!-- *********************************************************************** -->
963
964<div class="doc_text">
965
966<p>LLVM has several different basic types of constants. This section describes
967them all and their syntax.</p>
968
969</div>
970
971<!-- ======================================================================= -->
Reid Spencercc16dc32004-12-09 18:02:53 +0000972<div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000973
974<div class="doc_text">
975
976<dl>
977 <dt><b>Boolean constants</b></dt>
978
979 <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
980 constants of the <tt><a href="#t_primitive">bool</a></tt> type.
981 </dd>
982
983 <dt><b>Integer constants</b></dt>
984
Reid Spencercc16dc32004-12-09 18:02:53 +0000985 <dd>Standard integers (such as '4') are constants of the <a
Chris Lattnerc3f59762004-12-09 17:30:23 +0000986 href="#t_integer">integer</a> type. Negative numbers may be used with signed
987 integer types.
988 </dd>
989
990 <dt><b>Floating point constants</b></dt>
991
992 <dd>Floating point constants use standard decimal notation (e.g. 123.421),
993 exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
Chris Lattnerc3f59762004-12-09 17:30:23 +0000994 notation (see below). Floating point constants must have a <a
995 href="#t_floating">floating point</a> type. </dd>
996
997 <dt><b>Null pointer constants</b></dt>
998
John Criswell9e2485c2004-12-10 15:51:16 +0000999 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
Chris Lattnerc3f59762004-12-09 17:30:23 +00001000 and must be of <a href="#t_pointer">pointer type</a>.</dd>
1001
1002</dl>
1003
John Criswell9e2485c2004-12-10 15:51:16 +00001004<p>The one non-intuitive notation for constants is the optional hexadecimal form
Chris Lattnerc3f59762004-12-09 17:30:23 +00001005of floating point constants. For example, the form '<tt>double
10060x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
10074.5e+15</tt>'. The only time hexadecimal floating point constants are required
Reid Spencercc16dc32004-12-09 18:02:53 +00001008(and the only time that they are generated by the disassembler) is when a
1009floating point constant must be emitted but it cannot be represented as a
1010decimal floating point number. For example, NaN's, infinities, and other
1011special values are represented in their IEEE hexadecimal format so that
1012assembly and disassembly do not cause any bits to change in the constants.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001013
1014</div>
1015
1016<!-- ======================================================================= -->
1017<div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a>
1018</div>
1019
1020<div class="doc_text">
Chris Lattnerd4f6b172005-03-07 22:13:59 +00001021<p>Aggregate constants arise from aggregation of simple constants
1022and smaller aggregate constants.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001023
1024<dl>
1025 <dt><b>Structure constants</b></dt>
1026
1027 <dd>Structure constants are represented with notation similar to structure
1028 type definitions (a comma separated list of elements, surrounded by braces
Chris Lattnerd4f6b172005-03-07 22:13:59 +00001029 (<tt>{}</tt>)). For example: "<tt>{ int 4, float 17.0, int* %G }</tt>",
1030 where "<tt>%G</tt>" is declared as "<tt>%G = external global int</tt>". Structure constants
1031 must have <a href="#t_struct">structure type</a>, and the number and
Chris Lattnerc3f59762004-12-09 17:30:23 +00001032 types of elements must match those specified by the type.
1033 </dd>
1034
1035 <dt><b>Array constants</b></dt>
1036
1037 <dd>Array constants are represented with notation similar to array type
1038 definitions (a comma separated list of elements, surrounded by square brackets
John Criswell9e2485c2004-12-10 15:51:16 +00001039 (<tt>[]</tt>)). For example: "<tt>[ int 42, int 11, int 74 ]</tt>". Array
Chris Lattnerc3f59762004-12-09 17:30:23 +00001040 constants must have <a href="#t_array">array type</a>, and the number and
1041 types of elements must match those specified by the type.
1042 </dd>
1043
1044 <dt><b>Packed constants</b></dt>
1045
1046 <dd>Packed constants are represented with notation similar to packed type
1047 definitions (a comma separated list of elements, surrounded by
John Criswell9e2485c2004-12-10 15:51:16 +00001048 less-than/greater-than's (<tt>&lt;&gt;</tt>)). For example: "<tt>&lt; int 42,
Chris Lattnerc3f59762004-12-09 17:30:23 +00001049 int 11, int 74, int 100 &gt;</tt>". Packed constants must have <a
1050 href="#t_packed">packed type</a>, and the number and types of elements must
1051 match those specified by the type.
1052 </dd>
1053
1054 <dt><b>Zero initialization</b></dt>
1055
1056 <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
1057 value to zero of <em>any</em> type, including scalar and aggregate types.
1058 This is often used to avoid having to print large zero initializers (e.g. for
John Criswell0ec250c2005-10-24 16:17:18 +00001059 large arrays) and is always exactly equivalent to using explicit zero
Chris Lattnerc3f59762004-12-09 17:30:23 +00001060 initializers.
1061 </dd>
1062</dl>
1063
1064</div>
1065
1066<!-- ======================================================================= -->
1067<div class="doc_subsection">
1068 <a name="globalconstants">Global Variable and Function Addresses</a>
1069</div>
1070
1071<div class="doc_text">
1072
1073<p>The addresses of <a href="#globalvars">global variables</a> and <a
1074href="#functionstructure">functions</a> are always implicitly valid (link-time)
John Criswell9e2485c2004-12-10 15:51:16 +00001075constants. These constants are explicitly referenced when the <a
1076href="#identifiers">identifier for the global</a> is used and always have <a
Chris Lattnerc3f59762004-12-09 17:30:23 +00001077href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
1078file:</p>
1079
1080<pre>
1081 %X = global int 17
1082 %Y = global int 42
1083 %Z = global [2 x int*] [ int* %X, int* %Y ]
1084</pre>
1085
1086</div>
1087
1088<!-- ======================================================================= -->
Reid Spencer2dc45b82004-12-09 18:13:12 +00001089<div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001090<div class="doc_text">
Reid Spencer2dc45b82004-12-09 18:13:12 +00001091 <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has
John Criswellc1f786c2005-05-13 22:25:59 +00001092 no specific value. Undefined values may be of any type and be used anywhere
Reid Spencer2dc45b82004-12-09 18:13:12 +00001093 a constant is permitted.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001094
Reid Spencer2dc45b82004-12-09 18:13:12 +00001095 <p>Undefined values indicate to the compiler that the program is well defined
1096 no matter what value is used, giving the compiler more freedom to optimize.
1097 </p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001098</div>
1099
1100<!-- ======================================================================= -->
1101<div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
1102</div>
1103
1104<div class="doc_text">
1105
1106<p>Constant expressions are used to allow expressions involving other constants
1107to be used as constants. Constant expressions may be of any <a
John Criswellc1f786c2005-05-13 22:25:59 +00001108href="#t_firstclass">first class</a> type and may involve any LLVM operation
Chris Lattnerc3f59762004-12-09 17:30:23 +00001109that does not have side effects (e.g. load and call are not supported). The
1110following is the syntax for constant expressions:</p>
1111
1112<dl>
1113 <dt><b><tt>cast ( CST to TYPE )</tt></b></dt>
1114
1115 <dd>Cast a constant to another type.</dd>
1116
1117 <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
1118
1119 <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
1120 constants. As with the <a href="#i_getelementptr">getelementptr</a>
1121 instruction, the index list may have zero or more indexes, which are required
1122 to make sense for the type of "CSTPTR".</dd>
1123
Robert Bocchino9fbe1452006-01-10 19:31:34 +00001124 <dt><b><tt>select ( COND, VAL1, VAL2 )</tt></b></dt>
1125
1126 <dd>Perform the <a href="#i_select">select operation</a> on
1127 constants.
1128
1129 <dt><b><tt>extractelement ( VAL, IDX )</tt></b></dt>
1130
1131 <dd>Perform the <a href="#i_extractelement">extractelement
1132 operation</a> on constants.
1133
Robert Bocchino05ccd702006-01-15 20:48:27 +00001134 <dt><b><tt>insertelement ( VAL, ELT, IDX )</tt></b></dt>
1135
1136 <dd>Perform the <a href="#i_insertelement">insertelement
1137 operation</a> on constants.
1138
Chris Lattnerc1989542006-04-08 00:13:41 +00001139
1140 <dt><b><tt>shufflevector ( VEC1, VEC2, IDXMASK )</tt></b></dt>
1141
1142 <dd>Perform the <a href="#i_shufflevector">shufflevector
1143 operation</a> on constants.
1144
Chris Lattnerc3f59762004-12-09 17:30:23 +00001145 <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
1146
Reid Spencer2dc45b82004-12-09 18:13:12 +00001147 <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
1148 be any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise
Chris Lattnerc3f59762004-12-09 17:30:23 +00001149 binary</a> operations. The constraints on operands are the same as those for
1150 the corresponding instruction (e.g. no bitwise operations on floating point
John Criswelle4c57cc2005-05-12 16:52:32 +00001151 values are allowed).</dd>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001152</dl>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001153</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +00001154
Chris Lattner00950542001-06-06 20:29:01 +00001155<!-- *********************************************************************** -->
Chris Lattnere87d6532006-01-25 23:47:57 +00001156<div class="doc_section"> <a name="othervalues">Other Values</a> </div>
1157<!-- *********************************************************************** -->
1158
1159<!-- ======================================================================= -->
1160<div class="doc_subsection">
1161<a name="inlineasm">Inline Assembler Expressions</a>
1162</div>
1163
1164<div class="doc_text">
1165
1166<p>
1167LLVM supports inline assembler expressions (as opposed to <a href="#moduleasm">
1168Module-Level Inline Assembly</a>) through the use of a special value. This
1169value represents the inline assembler as a string (containing the instructions
1170to emit), a list of operand constraints (stored as a string), and a flag that
1171indicates whether or not the inline asm expression has side effects. An example
1172inline assembler expression is:
1173</p>
1174
1175<pre>
1176 int(int) asm "bswap $0", "=r,r"
1177</pre>
1178
1179<p>
1180Inline assembler expressions may <b>only</b> be used as the callee operand of
1181a <a href="#i_call"><tt>call</tt> instruction</a>. Thus, typically we have:
1182</p>
1183
1184<pre>
1185 %X = call int asm "<a href="#i_bswap">bswap</a> $0", "=r,r"(int %Y)
1186</pre>
1187
1188<p>
1189Inline asms with side effects not visible in the constraint list must be marked
1190as having side effects. This is done through the use of the
1191'<tt>sideeffect</tt>' keyword, like so:
1192</p>
1193
1194<pre>
1195 call void asm sideeffect "eieio", ""()
1196</pre>
1197
1198<p>TODO: The format of the asm and constraints string still need to be
1199documented here. Constraints on what can be done (e.g. duplication, moving, etc
1200need to be documented).
1201</p>
1202
1203</div>
1204
1205<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00001206<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
1207<!-- *********************************************************************** -->
Chris Lattnerc3f59762004-12-09 17:30:23 +00001208
Misha Brukman9d0919f2003-11-08 01:05:38 +00001209<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +00001210
Chris Lattner261efe92003-11-25 01:02:51 +00001211<p>The LLVM instruction set consists of several different
1212classifications of instructions: <a href="#terminators">terminator
John Criswellc1f786c2005-05-13 22:25:59 +00001213instructions</a>, <a href="#binaryops">binary instructions</a>,
1214<a href="#bitwiseops">bitwise binary instructions</a>, <a
Chris Lattner261efe92003-11-25 01:02:51 +00001215 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
1216instructions</a>.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001217
Misha Brukman9d0919f2003-11-08 01:05:38 +00001218</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001219
Chris Lattner00950542001-06-06 20:29:01 +00001220<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001221<div class="doc_subsection"> <a name="terminators">Terminator
1222Instructions</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001223
Misha Brukman9d0919f2003-11-08 01:05:38 +00001224<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +00001225
Chris Lattner261efe92003-11-25 01:02:51 +00001226<p>As mentioned <a href="#functionstructure">previously</a>, every
1227basic block in a program ends with a "Terminator" instruction, which
1228indicates which block should be executed after the current block is
1229finished. These terminator instructions typically yield a '<tt>void</tt>'
1230value: they produce control flow, not values (the one exception being
1231the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
John Criswell9e2485c2004-12-10 15:51:16 +00001232<p>There are six different terminator instructions: the '<a
Chris Lattner261efe92003-11-25 01:02:51 +00001233 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
1234instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
Chris Lattner35eca582004-10-16 18:04:13 +00001235the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
1236 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
1237 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001238
Misha Brukman9d0919f2003-11-08 01:05:38 +00001239</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001240
Chris Lattner00950542001-06-06 20:29:01 +00001241<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001242<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
1243Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001244<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001245<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001246<pre> ret &lt;type&gt; &lt;value&gt; <i>; Return a value from a non-void function</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001247 ret void <i>; Return from void function</i>
Chris Lattner00950542001-06-06 20:29:01 +00001248</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001249<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001250<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
John Criswellc1f786c2005-05-13 22:25:59 +00001251value) from a function back to the caller.</p>
John Criswell4457dc92004-04-09 16:48:45 +00001252<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner261efe92003-11-25 01:02:51 +00001253returns a value and then causes control flow, and one that just causes
1254control flow to occur.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001255<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001256<p>The '<tt>ret</tt>' instruction may return any '<a
1257 href="#t_firstclass">first class</a>' type. Notice that a function is
1258not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
1259instruction inside of the function that returns a value that does not
1260match the return type of the function.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001261<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001262<p>When the '<tt>ret</tt>' instruction is executed, control flow
1263returns back to the calling function's context. If the caller is a "<a
John Criswellfa081872004-06-25 15:16:57 +00001264 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner261efe92003-11-25 01:02:51 +00001265the instruction after the call. If the caller was an "<a
1266 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
John Criswelle4c57cc2005-05-12 16:52:32 +00001267at the beginning of the "normal" destination block. If the instruction
Chris Lattner261efe92003-11-25 01:02:51 +00001268returns a value, that value shall set the call or invoke instruction's
1269return value.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001270<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001271<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001272 ret void <i>; Return from a void function</i>
Chris Lattner00950542001-06-06 20:29:01 +00001273</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001274</div>
Chris Lattner00950542001-06-06 20:29:01 +00001275<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001276<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001277<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001278<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001279<pre> br bool &lt;cond&gt;, label &lt;iftrue&gt;, label &lt;iffalse&gt;<br> br label &lt;dest&gt; <i>; Unconditional branch</i>
Chris Lattner00950542001-06-06 20:29:01 +00001280</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001281<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001282<p>The '<tt>br</tt>' instruction is used to cause control flow to
1283transfer to a different basic block in the current function. There are
1284two forms of this instruction, corresponding to a conditional branch
1285and an unconditional branch.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001286<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001287<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
1288single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
1289unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
1290value as a target.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001291<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001292<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
1293argument is evaluated. If the value is <tt>true</tt>, control flows
1294to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
1295control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001296<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001297<pre>Test:<br> %cond = <a href="#i_setcc">seteq</a> int %a, %b<br> br bool %cond, label %IfEqual, label %IfUnequal<br>IfEqual:<br> <a
1298 href="#i_ret">ret</a> int 1<br>IfUnequal:<br> <a href="#i_ret">ret</a> int 0<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001299</div>
Chris Lattner00950542001-06-06 20:29:01 +00001300<!-- _______________________________________________________________________ -->
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001301<div class="doc_subsubsection">
1302 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
1303</div>
1304
Misha Brukman9d0919f2003-11-08 01:05:38 +00001305<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001306<h5>Syntax:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001307
1308<pre>
1309 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
1310</pre>
1311
Chris Lattner00950542001-06-06 20:29:01 +00001312<h5>Overview:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001313
1314<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
1315several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +00001316instruction, allowing a branch to occur to one of many possible
1317destinations.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001318
1319
Chris Lattner00950542001-06-06 20:29:01 +00001320<h5>Arguments:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001321
1322<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
1323comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
1324an array of pairs of comparison value constants and '<tt>label</tt>'s. The
1325table is not allowed to contain duplicate constant entries.</p>
1326
Chris Lattner00950542001-06-06 20:29:01 +00001327<h5>Semantics:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001328
Chris Lattner261efe92003-11-25 01:02:51 +00001329<p>The <tt>switch</tt> instruction specifies a table of values and
1330destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswell84114752004-06-25 16:05:06 +00001331table is searched for the given value. If the value is found, control flow is
1332transfered to the corresponding destination; otherwise, control flow is
1333transfered to the default destination.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001334
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001335<h5>Implementation:</h5>
1336
1337<p>Depending on properties of the target machine and the particular
1338<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswell84114752004-06-25 16:05:06 +00001339ways. For example, it could be generated as a series of chained conditional
1340branches or with a lookup table.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001341
1342<h5>Example:</h5>
1343
1344<pre>
1345 <i>; Emulate a conditional br instruction</i>
1346 %Val = <a href="#i_cast">cast</a> bool %value to int
1347 switch int %Val, label %truedest [int 0, label %falsedest ]
1348
1349 <i>; Emulate an unconditional br instruction</i>
1350 switch uint 0, label %dest [ ]
1351
1352 <i>; Implement a jump table:</i>
1353 switch uint %val, label %otherwise [ uint 0, label %onzero
1354 uint 1, label %onone
1355 uint 2, label %ontwo ]
Chris Lattner00950542001-06-06 20:29:01 +00001356</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001357</div>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001358
Chris Lattner00950542001-06-06 20:29:01 +00001359<!-- _______________________________________________________________________ -->
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001360<div class="doc_subsubsection">
1361 <a name="i_invoke">'<tt>invoke</tt>' Instruction</a>
1362</div>
1363
Misha Brukman9d0919f2003-11-08 01:05:38 +00001364<div class="doc_text">
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001365
Chris Lattner00950542001-06-06 20:29:01 +00001366<h5>Syntax:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001367
1368<pre>
1369 &lt;result&gt; = invoke [<a href="#callingconv">cconv</a>] &lt;ptr to function ty&gt; %&lt;function ptr val&gt;(&lt;function args&gt;)
1370 to label &lt;normal label&gt; except label &lt;exception label&gt;
1371</pre>
1372
Chris Lattner6536cfe2002-05-06 22:08:29 +00001373<h5>Overview:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001374
1375<p>The '<tt>invoke</tt>' instruction causes control to transfer to a specified
1376function, with the possibility of control flow transfer to either the
John Criswelle4c57cc2005-05-12 16:52:32 +00001377'<tt>normal</tt>' label or the
1378'<tt>exception</tt>' label. If the callee function returns with the
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001379"<tt><a href="#i_ret">ret</a></tt>" instruction, control flow will return to the
1380"normal" label. If the callee (or any indirect callees) returns with the "<a
John Criswelle4c57cc2005-05-12 16:52:32 +00001381href="#i_unwind"><tt>unwind</tt></a>" instruction, control is interrupted and
1382continued at the dynamically nearest "exception" label.</p>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001383
Chris Lattner00950542001-06-06 20:29:01 +00001384<h5>Arguments:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001385
Misha Brukman9d0919f2003-11-08 01:05:38 +00001386<p>This instruction requires several arguments:</p>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001387
Chris Lattner00950542001-06-06 20:29:01 +00001388<ol>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001389 <li>
John Criswellc1f786c2005-05-13 22:25:59 +00001390 The optional "cconv" marker indicates which <a href="callingconv">calling
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001391 convention</a> the call should use. If none is specified, the call defaults
1392 to using C calling conventions.
1393 </li>
1394 <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to
1395 function value being invoked. In most cases, this is a direct function
1396 invocation, but indirect <tt>invoke</tt>s are just as possible, branching off
1397 an arbitrary pointer to function value.
1398 </li>
1399
1400 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a
1401 function to be invoked. </li>
1402
1403 <li>'<tt>function args</tt>': argument list whose types match the function
1404 signature argument types. If the function signature indicates the function
1405 accepts a variable number of arguments, the extra arguments can be
1406 specified. </li>
1407
1408 <li>'<tt>normal label</tt>': the label reached when the called function
1409 executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
1410
1411 <li>'<tt>exception label</tt>': the label reached when a callee returns with
1412 the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
1413
Chris Lattner00950542001-06-06 20:29:01 +00001414</ol>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001415
Chris Lattner00950542001-06-06 20:29:01 +00001416<h5>Semantics:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001417
Misha Brukman9d0919f2003-11-08 01:05:38 +00001418<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001419href="#i_call">call</a></tt>' instruction in most regards. The primary
1420difference is that it establishes an association with a label, which is used by
1421the runtime library to unwind the stack.</p>
1422
1423<p>This instruction is used in languages with destructors to ensure that proper
1424cleanup is performed in the case of either a <tt>longjmp</tt> or a thrown
1425exception. Additionally, this is important for implementation of
1426'<tt>catch</tt>' clauses in high-level languages that support them.</p>
1427
Chris Lattner00950542001-06-06 20:29:01 +00001428<h5>Example:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001429<pre>
1430 %retval = invoke int %Test(int 15) to label %Continue
1431 except label %TestCleanup <i>; {int}:retval set</i>
1432 %retval = invoke <a href="#callingconv">coldcc</a> int %Test(int 15) to label %Continue
1433 except label %TestCleanup <i>; {int}:retval set</i>
Chris Lattner00950542001-06-06 20:29:01 +00001434</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001435</div>
Chris Lattner35eca582004-10-16 18:04:13 +00001436
1437
Chris Lattner27f71f22003-09-03 00:41:47 +00001438<!-- _______________________________________________________________________ -->
Chris Lattner35eca582004-10-16 18:04:13 +00001439
Chris Lattner261efe92003-11-25 01:02:51 +00001440<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
1441Instruction</a> </div>
Chris Lattner35eca582004-10-16 18:04:13 +00001442
Misha Brukman9d0919f2003-11-08 01:05:38 +00001443<div class="doc_text">
Chris Lattner35eca582004-10-16 18:04:13 +00001444
Chris Lattner27f71f22003-09-03 00:41:47 +00001445<h5>Syntax:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001446<pre>
1447 unwind
1448</pre>
1449
Chris Lattner27f71f22003-09-03 00:41:47 +00001450<h5>Overview:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001451
1452<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
1453at the first callee in the dynamic call stack which used an <a
1454href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
1455primarily used to implement exception handling.</p>
1456
Chris Lattner27f71f22003-09-03 00:41:47 +00001457<h5>Semantics:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001458
1459<p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to
1460immediately halt. The dynamic call stack is then searched for the first <a
1461href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
1462execution continues at the "exceptional" destination block specified by the
1463<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
1464dynamic call chain, undefined behavior results.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001465</div>
Chris Lattner35eca582004-10-16 18:04:13 +00001466
1467<!-- _______________________________________________________________________ -->
1468
1469<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
1470Instruction</a> </div>
1471
1472<div class="doc_text">
1473
1474<h5>Syntax:</h5>
1475<pre>
1476 unreachable
1477</pre>
1478
1479<h5>Overview:</h5>
1480
1481<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
1482instruction is used to inform the optimizer that a particular portion of the
1483code is not reachable. This can be used to indicate that the code after a
1484no-return function cannot be reached, and other facts.</p>
1485
1486<h5>Semantics:</h5>
1487
1488<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
1489</div>
1490
1491
1492
Chris Lattner00950542001-06-06 20:29:01 +00001493<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001494<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001495<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001496<p>Binary operators are used to do most of the computation in a
1497program. They require two operands, execute an operation on them, and
John Criswell9e2485c2004-12-10 15:51:16 +00001498produce a single value. The operands might represent
Chris Lattnera58561b2004-08-12 19:12:28 +00001499multiple data, as is the case with the <a href="#t_packed">packed</a> data type.
1500The result value of a binary operator is not
Chris Lattner261efe92003-11-25 01:02:51 +00001501necessarily the same type as its operands.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001502<p>There are several different binary operators:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001503</div>
Chris Lattner00950542001-06-06 20:29:01 +00001504<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001505<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
1506Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001507<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001508<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001509<pre> &lt;result&gt; = add &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001510</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001511<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001512<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001513<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001514<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattnera58561b2004-08-12 19:12:28 +00001515 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
1516 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1517Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001518<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001519<p>The value produced is the integer or floating point sum of the two
1520operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001521<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001522<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001523</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001524</div>
Chris Lattner00950542001-06-06 20:29:01 +00001525<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001526<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
1527Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001528<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001529<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001530<pre> &lt;result&gt; = sub &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001531</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001532<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001533<p>The '<tt>sub</tt>' instruction returns the difference of its two
1534operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001535<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
1536instruction present in most other intermediate representations.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001537<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001538<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001539 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001540values.
1541This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1542Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001543<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001544<p>The value produced is the integer or floating point difference of
1545the two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001546<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001547<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001548 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
1549</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001550</div>
Chris Lattner00950542001-06-06 20:29:01 +00001551<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001552<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
1553Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001554<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001555<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001556<pre> &lt;result&gt; = mul &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001557</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001558<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001559<p>The '<tt>mul</tt>' instruction returns the product of its two
1560operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001561<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001562<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001563 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001564values.
1565This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1566Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001567<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001568<p>The value produced is the integer or floating point product of the
Misha Brukman9d0919f2003-11-08 01:05:38 +00001569two operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001570<p>There is no signed vs unsigned multiplication. The appropriate
1571action is taken based on the type of the operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001572<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001573<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001574</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001575</div>
Chris Lattner00950542001-06-06 20:29:01 +00001576<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001577<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
1578Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001579<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001580<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001581<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1582</pre>
1583<h5>Overview:</h5>
1584<p>The '<tt>div</tt>' instruction returns the quotient of its two
1585operands.</p>
1586<h5>Arguments:</h5>
1587<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
1588 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001589values.
1590This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1591Both arguments must have identical types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001592<h5>Semantics:</h5>
1593<p>The value produced is the integer or floating point quotient of the
1594two operands.</p>
1595<h5>Example:</h5>
1596<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
1597</pre>
1598</div>
1599<!-- _______________________________________________________________________ -->
1600<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
1601Instruction</a> </div>
1602<div class="doc_text">
1603<h5>Syntax:</h5>
1604<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1605</pre>
1606<h5>Overview:</h5>
1607<p>The '<tt>rem</tt>' instruction returns the remainder from the
1608division of its two operands.</p>
1609<h5>Arguments:</h5>
1610<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1611 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001612values.
1613This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1614Both arguments must have identical types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001615<h5>Semantics:</h5>
1616<p>This returns the <i>remainder</i> of a division (where the result
1617has the same sign as the divisor), not the <i>modulus</i> (where the
1618result has the same sign as the dividend) of a value. For more
John Criswell0ec250c2005-10-24 16:17:18 +00001619information about the difference, see <a
Chris Lattner261efe92003-11-25 01:02:51 +00001620 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1621Math Forum</a>.</p>
1622<h5>Example:</h5>
1623<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1624</pre>
Robert Bocchino7b81c752006-02-17 21:18:08 +00001625
Chris Lattner261efe92003-11-25 01:02:51 +00001626</div>
1627<!-- _______________________________________________________________________ -->
1628<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1629Instructions</a> </div>
1630<div class="doc_text">
1631<h5>Syntax:</h5>
1632<pre> &lt;result&gt; = seteq &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001633 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1634 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1635 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1636 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1637 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1638</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001639<h5>Overview:</h5>
1640<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1641value based on a comparison of their two operands.</p>
1642<h5>Arguments:</h5>
1643<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1644be of <a href="#t_firstclass">first class</a> type (it is not possible
1645to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1646or '<tt>void</tt>' values, etc...). Both arguments must have identical
1647types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001648<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001649<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1650value if both operands are equal.<br>
1651The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1652value if both operands are unequal.<br>
1653The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1654value if the first operand is less than the second operand.<br>
1655The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1656value if the first operand is greater than the second operand.<br>
1657The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1658value if the first operand is less than or equal to the second operand.<br>
1659The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1660value if the first operand is greater than or equal to the second
1661operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001662<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001663<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner00950542001-06-06 20:29:01 +00001664 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
1665 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1666 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1667 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1668 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1669</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001670</div>
Robert Bocchino7b81c752006-02-17 21:18:08 +00001671
Chris Lattner00950542001-06-06 20:29:01 +00001672<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001673<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1674Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001675<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001676<p>Bitwise binary operators are used to do various forms of
1677bit-twiddling in a program. They are generally very efficient
John Criswell9e2485c2004-12-10 15:51:16 +00001678instructions and can commonly be strength reduced from other
Chris Lattner261efe92003-11-25 01:02:51 +00001679instructions. They require two operands, execute an operation on them,
1680and produce a single value. The resulting value of the bitwise binary
1681operators is always the same type as its first operand.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001682</div>
Chris Lattner00950542001-06-06 20:29:01 +00001683<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001684<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1685Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001686<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001687<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001688<pre> &lt;result&gt; = and &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001689</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001690<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001691<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1692its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001693<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001694<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001695 href="#t_integral">integral</a> values. Both arguments must have
1696identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001697<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001698<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001699<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001700<div style="align: center">
Misha Brukman9d0919f2003-11-08 01:05:38 +00001701<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +00001702 <tbody>
1703 <tr>
1704 <td>In0</td>
1705 <td>In1</td>
1706 <td>Out</td>
1707 </tr>
1708 <tr>
1709 <td>0</td>
1710 <td>0</td>
1711 <td>0</td>
1712 </tr>
1713 <tr>
1714 <td>0</td>
1715 <td>1</td>
1716 <td>0</td>
1717 </tr>
1718 <tr>
1719 <td>1</td>
1720 <td>0</td>
1721 <td>0</td>
1722 </tr>
1723 <tr>
1724 <td>1</td>
1725 <td>1</td>
1726 <td>1</td>
1727 </tr>
1728 </tbody>
1729</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001730</div>
Chris Lattner00950542001-06-06 20:29:01 +00001731<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001732<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001733 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1734 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1735</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001736</div>
Chris Lattner00950542001-06-06 20:29:01 +00001737<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001738<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001739<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001740<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001741<pre> &lt;result&gt; = or &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001742</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001743<h5>Overview:</h5>
1744<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1745or of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001746<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001747<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001748 href="#t_integral">integral</a> values. Both arguments must have
1749identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001750<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001751<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001752<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001753<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001754<table border="1" cellspacing="0" cellpadding="4">
1755 <tbody>
1756 <tr>
1757 <td>In0</td>
1758 <td>In1</td>
1759 <td>Out</td>
1760 </tr>
1761 <tr>
1762 <td>0</td>
1763 <td>0</td>
1764 <td>0</td>
1765 </tr>
1766 <tr>
1767 <td>0</td>
1768 <td>1</td>
1769 <td>1</td>
1770 </tr>
1771 <tr>
1772 <td>1</td>
1773 <td>0</td>
1774 <td>1</td>
1775 </tr>
1776 <tr>
1777 <td>1</td>
1778 <td>1</td>
1779 <td>1</td>
1780 </tr>
1781 </tbody>
1782</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001783</div>
Chris Lattner00950542001-06-06 20:29:01 +00001784<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001785<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001786 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1787 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1788</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001789</div>
Chris Lattner00950542001-06-06 20:29:01 +00001790<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001791<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1792Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001793<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001794<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001795<pre> &lt;result&gt; = xor &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001796</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001797<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001798<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1799or of its two operands. The <tt>xor</tt> is used to implement the
1800"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001801<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001802<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001803 href="#t_integral">integral</a> values. Both arguments must have
1804identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001805<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001806<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001807<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001808<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001809<table border="1" cellspacing="0" cellpadding="4">
1810 <tbody>
1811 <tr>
1812 <td>In0</td>
1813 <td>In1</td>
1814 <td>Out</td>
1815 </tr>
1816 <tr>
1817 <td>0</td>
1818 <td>0</td>
1819 <td>0</td>
1820 </tr>
1821 <tr>
1822 <td>0</td>
1823 <td>1</td>
1824 <td>1</td>
1825 </tr>
1826 <tr>
1827 <td>1</td>
1828 <td>0</td>
1829 <td>1</td>
1830 </tr>
1831 <tr>
1832 <td>1</td>
1833 <td>1</td>
1834 <td>0</td>
1835 </tr>
1836 </tbody>
1837</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001838</div>
Chris Lattner261efe92003-11-25 01:02:51 +00001839<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001840<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001841<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001842 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1843 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner27f71f22003-09-03 00:41:47 +00001844 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner00950542001-06-06 20:29:01 +00001845</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001846</div>
Chris Lattner00950542001-06-06 20:29:01 +00001847<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001848<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1849Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001850<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001851<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001852<pre> &lt;result&gt; = shl &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001853</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001854<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001855<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1856the left a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001857<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001858<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001859 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1860type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001861<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001862<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001863<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001864<pre> &lt;result&gt; = shl int 4, ubyte %var <i>; yields {int}:result = 4 &lt;&lt; %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001865 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1866 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1867</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001868</div>
Chris Lattner00950542001-06-06 20:29:01 +00001869<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001870<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1871Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001872<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001873<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001874<pre> &lt;result&gt; = shr &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001875</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001876<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001877<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1878the right a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001879<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001880<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001881 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1882type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001883<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001884<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1885most significant bit is duplicated in the newly free'd bit positions.
1886If the first argument is unsigned, zero bits shall fill the empty
1887positions.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001888<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001889<pre> &lt;result&gt; = shr int 4, ubyte %var <i>; yields {int}:result = 4 &gt;&gt; %var</i>
Chris Lattner8c6bb902003-06-18 21:30:51 +00001890 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001891 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner8c6bb902003-06-18 21:30:51 +00001892 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1893 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner00950542001-06-06 20:29:01 +00001894</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001895</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001896
Chris Lattner00950542001-06-06 20:29:01 +00001897<!-- ======================================================================= -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00001898<div class="doc_subsection">
1899 <a name="memoryops">Memory Access Operations</a>
1900</div>
1901
Misha Brukman9d0919f2003-11-08 01:05:38 +00001902<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00001903
Chris Lattner261efe92003-11-25 01:02:51 +00001904<p>A key design point of an SSA-based representation is how it
1905represents memory. In LLVM, no memory locations are in SSA form, which
1906makes things very simple. This section describes how to read, write,
John Criswell9e2485c2004-12-10 15:51:16 +00001907allocate, and free memory in LLVM.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001908
Misha Brukman9d0919f2003-11-08 01:05:38 +00001909</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001910
Chris Lattner00950542001-06-06 20:29:01 +00001911<!-- _______________________________________________________________________ -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00001912<div class="doc_subsubsection">
1913 <a name="i_malloc">'<tt>malloc</tt>' Instruction</a>
1914</div>
1915
Misha Brukman9d0919f2003-11-08 01:05:38 +00001916<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00001917
Chris Lattner00950542001-06-06 20:29:01 +00001918<h5>Syntax:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001919
1920<pre>
1921 &lt;result&gt; = malloc &lt;type&gt;[, uint &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001922</pre>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001923
Chris Lattner00950542001-06-06 20:29:01 +00001924<h5>Overview:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001925
Chris Lattner261efe92003-11-25 01:02:51 +00001926<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1927heap and returns a pointer to it.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001928
Chris Lattner00950542001-06-06 20:29:01 +00001929<h5>Arguments:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001930
1931<p>The '<tt>malloc</tt>' instruction allocates
1932<tt>sizeof(&lt;type&gt;)*NumElements</tt>
John Criswell6e4ca612004-02-24 16:13:56 +00001933bytes of memory from the operating system and returns a pointer of the
Chris Lattner2cbdc452005-11-06 08:02:57 +00001934appropriate type to the program. If "NumElements" is specified, it is the
1935number of elements allocated. If an alignment is specified, the value result
1936of the allocation is guaranteed to be aligned to at least that boundary. If
1937not specified, or if zero, the target can choose to align the allocation on any
1938convenient boundary.</p>
1939
Misha Brukman9d0919f2003-11-08 01:05:38 +00001940<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001941
Chris Lattner00950542001-06-06 20:29:01 +00001942<h5>Semantics:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001943
Chris Lattner261efe92003-11-25 01:02:51 +00001944<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1945a pointer is returned.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001946
Chris Lattner2cbdc452005-11-06 08:02:57 +00001947<h5>Example:</h5>
1948
1949<pre>
1950 %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
1951
1952 %size = <a href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001953 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1954 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001955 %array3 = malloc int, uint 4, align 1024 <i>; yields {int*}:array3</i>
1956 %array4 = malloc int, align 1024 <i>; yields {int*}:array4</i>
Chris Lattner00950542001-06-06 20:29:01 +00001957</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001958</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001959
Chris Lattner00950542001-06-06 20:29:01 +00001960<!-- _______________________________________________________________________ -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00001961<div class="doc_subsubsection">
1962 <a name="i_free">'<tt>free</tt>' Instruction</a>
1963</div>
1964
Misha Brukman9d0919f2003-11-08 01:05:38 +00001965<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00001966
Chris Lattner00950542001-06-06 20:29:01 +00001967<h5>Syntax:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001968
1969<pre>
1970 free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner00950542001-06-06 20:29:01 +00001971</pre>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001972
Chris Lattner00950542001-06-06 20:29:01 +00001973<h5>Overview:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001974
Chris Lattner261efe92003-11-25 01:02:51 +00001975<p>The '<tt>free</tt>' instruction returns memory back to the unused
John Criswellc1f786c2005-05-13 22:25:59 +00001976memory heap to be reallocated in the future.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001977
Chris Lattner00950542001-06-06 20:29:01 +00001978<h5>Arguments:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001979
Chris Lattner261efe92003-11-25 01:02:51 +00001980<p>'<tt>value</tt>' shall be a pointer value that points to a value
1981that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1982instruction.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001983
Chris Lattner00950542001-06-06 20:29:01 +00001984<h5>Semantics:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001985
John Criswell9e2485c2004-12-10 15:51:16 +00001986<p>Access to the memory pointed to by the pointer is no longer defined
Chris Lattner261efe92003-11-25 01:02:51 +00001987after this instruction executes.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001988
Chris Lattner00950542001-06-06 20:29:01 +00001989<h5>Example:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001990
1991<pre>
1992 %array = <a href="#i_malloc">malloc</a> [4 x ubyte] <i>; yields {[4 x ubyte]*}:array</i>
Chris Lattner00950542001-06-06 20:29:01 +00001993 free [4 x ubyte]* %array
1994</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001995</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001996
Chris Lattner00950542001-06-06 20:29:01 +00001997<!-- _______________________________________________________________________ -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00001998<div class="doc_subsubsection">
1999 <a name="i_alloca">'<tt>alloca</tt>' Instruction</a>
2000</div>
2001
Misha Brukman9d0919f2003-11-08 01:05:38 +00002002<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00002003
Chris Lattner00950542001-06-06 20:29:01 +00002004<h5>Syntax:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002005
2006<pre>
2007 &lt;result&gt; = alloca &lt;type&gt;[, uint &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00002008</pre>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002009
Chris Lattner00950542001-06-06 20:29:01 +00002010<h5>Overview:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002011
Chris Lattner261efe92003-11-25 01:02:51 +00002012<p>The '<tt>alloca</tt>' instruction allocates memory on the current
2013stack frame of the procedure that is live until the current function
2014returns to its caller.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002015
Chris Lattner00950542001-06-06 20:29:01 +00002016<h5>Arguments:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002017
John Criswell9e2485c2004-12-10 15:51:16 +00002018<p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002019bytes of memory on the runtime stack, returning a pointer of the
Chris Lattner2cbdc452005-11-06 08:02:57 +00002020appropriate type to the program. If "NumElements" is specified, it is the
2021number of elements allocated. If an alignment is specified, the value result
2022of the allocation is guaranteed to be aligned to at least that boundary. If
2023not specified, or if zero, the target can choose to align the allocation on any
2024convenient boundary.</p>
2025
Misha Brukman9d0919f2003-11-08 01:05:38 +00002026<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002027
Chris Lattner00950542001-06-06 20:29:01 +00002028<h5>Semantics:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002029
John Criswellc1f786c2005-05-13 22:25:59 +00002030<p>Memory is allocated; a pointer is returned. '<tt>alloca</tt>'d
Chris Lattner261efe92003-11-25 01:02:51 +00002031memory is automatically released when the function returns. The '<tt>alloca</tt>'
2032instruction is commonly used to represent automatic variables that must
2033have an address available. When the function returns (either with the <tt><a
John Criswelldae2e932005-05-12 16:55:34 +00002034 href="#i_ret">ret</a></tt> or <tt><a href="#i_unwind">unwind</a></tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002035instructions), the memory is reclaimed.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002036
Chris Lattner00950542001-06-06 20:29:01 +00002037<h5>Example:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002038
2039<pre>
2040 %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00002041 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002042 %ptr = alloca int, uint 4, align 1024 <i>; yields {int*}:ptr</i>
2043 %ptr = alloca int, align 1024 <i>; yields {int*}:ptr</i>
Chris Lattner00950542001-06-06 20:29:01 +00002044</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002045</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002046
Chris Lattner00950542001-06-06 20:29:01 +00002047<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00002048<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
2049Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002050<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00002051<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002052<pre> &lt;result&gt; = load &lt;ty&gt;* &lt;pointer&gt;<br> &lt;result&gt; = volatile load &lt;ty&gt;* &lt;pointer&gt;<br></pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002053<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002054<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002055<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002056<p>The argument to the '<tt>load</tt>' instruction specifies the memory
John Criswell0ec250c2005-10-24 16:17:18 +00002057address from which to load. The pointer must point to a <a
Chris Lattnere53e5082004-06-03 22:57:15 +00002058 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
John Criswell0ec250c2005-10-24 16:17:18 +00002059marked as <tt>volatile</tt>, then the optimizer is not allowed to modify
Chris Lattner261efe92003-11-25 01:02:51 +00002060the number or order of execution of this <tt>load</tt> with other
2061volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
2062instructions. </p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002063<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002064<p>The location of memory pointed to is loaded.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002065<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002066<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
2067 <a
2068 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002069 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
2070</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002071</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002072<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00002073<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
2074Instruction</a> </div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002075<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002076<pre> store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt; <i>; yields {void}</i>
Chris Lattnerf0651072003-09-08 18:27:49 +00002077 volatile store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt; <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002078</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002079<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002080<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002081<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002082<p>There are two arguments to the '<tt>store</tt>' instruction: a value
John Criswell0ec250c2005-10-24 16:17:18 +00002083to store and an address in which to store it. The type of the '<tt>&lt;pointer&gt;</tt>'
Chris Lattner261efe92003-11-25 01:02:51 +00002084operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
John Criswellc1f786c2005-05-13 22:25:59 +00002085operand. If the <tt>store</tt> is marked as <tt>volatile</tt>, then the
Chris Lattner261efe92003-11-25 01:02:51 +00002086optimizer is not allowed to modify the number or order of execution of
2087this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
2088 href="#i_store">store</a></tt> instructions.</p>
2089<h5>Semantics:</h5>
2090<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
2091at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002092<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002093<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
2094 <a
2095 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002096 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
2097</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002098<!-- _______________________________________________________________________ -->
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002099<div class="doc_subsubsection">
2100 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
2101</div>
2102
Misha Brukman9d0919f2003-11-08 01:05:38 +00002103<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00002104<h5>Syntax:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002105<pre>
2106 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
2107</pre>
2108
Chris Lattner7faa8832002-04-14 06:13:44 +00002109<h5>Overview:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002110
2111<p>
2112The '<tt>getelementptr</tt>' instruction is used to get the address of a
2113subelement of an aggregate data structure.</p>
2114
Chris Lattner7faa8832002-04-14 06:13:44 +00002115<h5>Arguments:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002116
2117<p>This instruction takes a list of integer constants that indicate what
2118elements of the aggregate object to index to. The actual types of the arguments
2119provided depend on the type of the first pointer argument. The
2120'<tt>getelementptr</tt>' instruction is used to index down through the type
John Criswellfc6b8952005-05-16 16:17:45 +00002121levels of a structure or to a specific index in an array. When indexing into a
2122structure, only <tt>uint</tt>
John Criswellc1f786c2005-05-13 22:25:59 +00002123integer constants are allowed. When indexing into an array or pointer,
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002124<tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
2125
Chris Lattner261efe92003-11-25 01:02:51 +00002126<p>For example, let's consider a C code fragment and how it gets
2127compiled to LLVM:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002128
2129<pre>
2130 struct RT {
2131 char A;
2132 int B[10][20];
2133 char C;
2134 };
2135 struct ST {
2136 int X;
2137 double Y;
2138 struct RT Z;
2139 };
2140
2141 int *foo(struct ST *s) {
2142 return &amp;s[1].Z.B[5][13];
2143 }
2144</pre>
2145
Misha Brukman9d0919f2003-11-08 01:05:38 +00002146<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002147
2148<pre>
2149 %RT = type { sbyte, [10 x [20 x int]], sbyte }
2150 %ST = type { int, double, %RT }
2151
Brian Gaeke7283e7c2004-07-02 21:08:14 +00002152 implementation
2153
2154 int* %foo(%ST* %s) {
2155 entry:
2156 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002157 ret int* %reg
2158 }
2159</pre>
2160
Chris Lattner7faa8832002-04-14 06:13:44 +00002161<h5>Semantics:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002162
2163<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
John Criswellc1f786c2005-05-13 22:25:59 +00002164on the pointer type that is being indexed into. <a href="#t_pointer">Pointer</a>
Chris Lattnere53e5082004-06-03 22:57:15 +00002165and <a href="#t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
2166<tt>ulong</tt>, or <tt>long</tt> values, and <a href="#t_struct">structure</a>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002167types require <tt>uint</tt> <b>constants</b>.</p>
2168
Misha Brukman9d0919f2003-11-08 01:05:38 +00002169<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002170type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
2171}</tt>' type, a structure. The second index indexes into the third element of
2172the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
2173sbyte }</tt>' type, another structure. The third index indexes into the second
2174element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
2175array. The two dimensions of the array are subscripted into, yielding an
John Criswellfc6b8952005-05-16 16:17:45 +00002176'<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction returns a pointer
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002177to this element, thus computing a value of '<tt>int*</tt>' type.</p>
2178
Chris Lattner261efe92003-11-25 01:02:51 +00002179<p>Note that it is perfectly legal to index partially through a
2180structure, returning a pointer to an inner element. Because of this,
2181the LLVM code for the given testcase is equivalent to:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002182
2183<pre>
Chris Lattnerd4f6b172005-03-07 22:13:59 +00002184 int* %foo(%ST* %s) {
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002185 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
2186 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
2187 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
2188 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
2189 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
2190 ret int* %t5
2191 }
Chris Lattner6536cfe2002-05-06 22:08:29 +00002192</pre>
Chris Lattnere67a9512005-06-24 17:22:57 +00002193
2194<p>Note that it is undefined to access an array out of bounds: array and
2195pointer indexes must always be within the defined bounds of the array type.
2196The one exception for this rules is zero length arrays. These arrays are
2197defined to be accessible as variable length arrays, which requires access
2198beyond the zero'th element.</p>
2199
Chris Lattner7faa8832002-04-14 06:13:44 +00002200<h5>Example:</h5>
Chris Lattnere67a9512005-06-24 17:22:57 +00002201
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002202<pre>
2203 <i>; yields [12 x ubyte]*:aptr</i>
2204 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
2205</pre>
2206
2207</div>
Chris Lattner00950542001-06-06 20:29:01 +00002208<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00002209<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002210<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +00002211<p>The instructions in this category are the "miscellaneous"
Chris Lattner261efe92003-11-25 01:02:51 +00002212instructions, which defy better classification.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002213</div>
Chris Lattner00950542001-06-06 20:29:01 +00002214<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00002215<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
2216Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002217<div class="doc_text">
Chris Lattner33ba0d92001-07-09 00:26:23 +00002218<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002219<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner33ba0d92001-07-09 00:26:23 +00002220<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002221<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
2222the SSA graph representing the function.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00002223<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002224<p>The type of the incoming values are specified with the first type
2225field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
2226as arguments, with one pair for each predecessor basic block of the
2227current block. Only values of <a href="#t_firstclass">first class</a>
2228type may be used as the value arguments to the PHI node. Only labels
2229may be used as the label arguments.</p>
2230<p>There must be no non-phi instructions between the start of a basic
2231block and the PHI instructions: i.e. PHI instructions must be first in
2232a basic block.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00002233<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002234<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
2235value specified by the parameter, depending on which basic block we
2236came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00002237<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002238<pre>Loop: ; Infinite loop that counts from 0 on up...<br> %indvar = phi uint [ 0, %LoopHeader ], [ %nextindvar, %Loop ]<br> %nextindvar = add uint %indvar, 1<br> br label %Loop<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002239</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002240
Chris Lattner6536cfe2002-05-06 22:08:29 +00002241<!-- _______________________________________________________________________ -->
Chris Lattnercc37aae2004-03-12 05:50:16 +00002242<div class="doc_subsubsection">
2243 <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
2244</div>
2245
Misha Brukman9d0919f2003-11-08 01:05:38 +00002246<div class="doc_text">
Chris Lattnercc37aae2004-03-12 05:50:16 +00002247
Chris Lattner6536cfe2002-05-06 22:08:29 +00002248<h5>Syntax:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002249
2250<pre>
2251 &lt;result&gt; = cast &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Chris Lattner6536cfe2002-05-06 22:08:29 +00002252</pre>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002253
Chris Lattner6536cfe2002-05-06 22:08:29 +00002254<h5>Overview:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002255
2256<p>
2257The '<tt>cast</tt>' instruction is used as the primitive means to convert
2258integers to floating point, change data type sizes, and break type safety (by
2259casting pointers).
2260</p>
2261
2262
Chris Lattner6536cfe2002-05-06 22:08:29 +00002263<h5>Arguments:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002264
2265<p>
2266The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
2267class value, and a type to cast it to, which must also be a <a
2268href="#t_firstclass">first class</a> type.
2269</p>
2270
Chris Lattner6536cfe2002-05-06 22:08:29 +00002271<h5>Semantics:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002272
2273<p>
2274This instruction follows the C rules for explicit casts when determining how the
2275data being cast must change to fit in its new container.
2276</p>
2277
2278<p>
2279When casting to bool, any value that would be considered true in the context of
2280a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
2281all else are '<tt>false</tt>'.
2282</p>
2283
2284<p>
2285When extending an integral value from a type of one signness to another (for
2286example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
2287<b>source</b> value is signed, and zero-extended if the source value is
2288unsigned. <tt>bool</tt> values are always zero extended into either zero or
2289one.
2290</p>
2291
Chris Lattner33ba0d92001-07-09 00:26:23 +00002292<h5>Example:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002293
2294<pre>
2295 %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattner7bae3952002-06-25 18:03:17 +00002296 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner33ba0d92001-07-09 00:26:23 +00002297</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002298</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002299
2300<!-- _______________________________________________________________________ -->
2301<div class="doc_subsubsection">
2302 <a name="i_select">'<tt>select</tt>' Instruction</a>
2303</div>
2304
2305<div class="doc_text">
2306
2307<h5>Syntax:</h5>
2308
2309<pre>
2310 &lt;result&gt; = select bool &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
2311</pre>
2312
2313<h5>Overview:</h5>
2314
2315<p>
2316The '<tt>select</tt>' instruction is used to choose one value based on a
2317condition, without branching.
2318</p>
2319
2320
2321<h5>Arguments:</h5>
2322
2323<p>
2324The '<tt>select</tt>' instruction requires a boolean value indicating the condition, and two values of the same <a href="#t_firstclass">first class</a> type.
2325</p>
2326
2327<h5>Semantics:</h5>
2328
2329<p>
2330If the boolean condition evaluates to true, the instruction returns the first
John Criswellfc6b8952005-05-16 16:17:45 +00002331value argument; otherwise, it returns the second value argument.
Chris Lattnercc37aae2004-03-12 05:50:16 +00002332</p>
2333
2334<h5>Example:</h5>
2335
2336<pre>
2337 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
2338</pre>
2339</div>
2340
Robert Bocchino7b81c752006-02-17 21:18:08 +00002341<!-- _______________________________________________________________________ -->
Robert Bocchino8949de22006-03-14 20:55:28 +00002342<div class="doc_subsubsection"> <a name="i_vsetint">'<tt>vsetint</tt>'
Robert Bocchino7b81c752006-02-17 21:18:08 +00002343Instruction</a> </div>
2344<div class="doc_text">
2345<h5>Syntax:</h5>
Robert Bocchino8949de22006-03-14 20:55:28 +00002346<pre>&lt;result&gt; = vsetint &lt;op&gt;, &lt;n x &lt;ty&gt;&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields &lt;n x bool&gt;</i>
Robert Bocchino7b81c752006-02-17 21:18:08 +00002347</pre>
2348
2349<h5>Overview:</h5>
2350
Robert Bocchino8949de22006-03-14 20:55:28 +00002351<p>The '<tt>vsetint</tt>' instruction takes two integer vectors and
2352returns a vector of boolean values representing, at each position, the
2353result of the comparison between the values at that position in the
2354two operands.</p>
Robert Bocchino7b81c752006-02-17 21:18:08 +00002355
2356<h5>Arguments:</h5>
2357
Robert Bocchino8949de22006-03-14 20:55:28 +00002358<p>The arguments to a '<tt>vsetint</tt>' instruction are a comparison
Robert Bocchino7b81c752006-02-17 21:18:08 +00002359operation and two value arguments. The value arguments must be of <a
Robert Bocchino8949de22006-03-14 20:55:28 +00002360href="#t_integral">integral</a> <a href="#t_packed">packed</a> type,
2361and they must have identical types. The operation argument must be
2362one of <tt>eq</tt>, <tt>ne</tt>, <tt>slt</tt>, <tt>sgt</tt>,
2363<tt>sle</tt>, <tt>sge</tt>, <tt>ult</tt>, <tt>ugt</tt>, <tt>ule</tt>,
2364<tt>uge</tt>, <tt>true</tt>, and <tt>false</tt>. The result is a
2365packed <tt>bool</tt> value with the same length as each operand.</p>
Robert Bocchino7b81c752006-02-17 21:18:08 +00002366
2367<h5>Semantics:</h5>
2368
Robert Bocchino8949de22006-03-14 20:55:28 +00002369<p>The following table shows the semantics of '<tt>vsetint</tt>'. For
2370each position of the result, the comparison is done on the
2371corresponding positions of the two value arguments. Note that the
2372signedness of the comparison depends on the comparison opcode and
2373<i>not</i> on the signedness of the value operands. E.g., <tt>vsetint
2374slt <4 x unsigned> %x, %y</tt> does an elementwise <i>signed</i>
2375comparison of <tt>%x</tt> and <tt>%y</tt>.</p>
Robert Bocchino7b81c752006-02-17 21:18:08 +00002376
2377<table border="1" cellspacing="0" cellpadding="4">
2378 <tbody>
2379 <tr><th>Operation</th><th>Result is true iff</th><th>Comparison is</th></tr>
2380 <tr><td><tt>eq</tt></td><td>var1 == var2</td><td>--</td></tr>
2381 <tr><td><tt>ne</tt></td><td>var1 != var2</td><td>--</td></tr>
Robert Bocchino8949de22006-03-14 20:55:28 +00002382 <tr><td><tt>slt</tt></td><td>var1 &lt; var2</td><td>signed</td></tr>
2383 <tr><td><tt>sgt</tt></td><td>var1 &gt; var2</td><td>signed</td></tr>
2384 <tr><td><tt>sle</tt></td><td>var1 &lt;= var2</td><td>signed</td></tr>
2385 <tr><td><tt>sge</tt></td><td>var1 &gt;= var2</td><td>signed</td></tr>
Robert Bocchino7b81c752006-02-17 21:18:08 +00002386 <tr><td><tt>ult</tt></td><td>var1 &lt; var2</td><td>unsigned</td></tr>
2387 <tr><td><tt>ugt</tt></td><td>var1 &gt; var2</td><td>unsigned</td></tr>
2388 <tr><td><tt>ule</tt></td><td>var1 &lt;= var2</td><td>unsigned</td></tr>
2389 <tr><td><tt>uge</tt></td><td>var1 &gt;= var2</td><td>unsigned</td></tr>
2390 <tr><td><tt>true</tt></td><td>always</td><td>--</td></tr>
2391 <tr><td><tt>false</tt></td><td>never</td><td>--</td></tr>
2392 </tbody>
2393</table>
2394
Robert Bocchino8949de22006-03-14 20:55:28 +00002395<h5>Example:</h5>
2396<pre> &lt;result&gt; = vsetint eq &lt;2 x int&gt; &lt;int 0, int 1&gt;, &lt;int 1, int 0&gt; <i>; yields {&lt;2 x bool&gt;}:result = false, false</i>
2397 &lt;result&gt; = vsetint ne &lt;2 x int&gt; &lt;int 0, int 1&gt;, &lt;int 1, int 0&gt; <i>; yields {&lt;2 x bool&gt;}:result = true, true</i>
2398 &lt;result&gt; = vsetint slt &lt;2 x int&gt; &lt;int 0, int 1&gt;, &lt;int 1, int 0&gt; <i>; yields {&lt;2 x bool&gt;}:result = true, false</i>
2399 &lt;result&gt; = vsetint sgt &lt;2 x int&gt; &lt;int 0, int 1&gt;, &lt;int 1, int 0&gt; <i>; yields {&lt;2 x bool&gt;}:result = false, true</i>
2400 &lt;result&gt; = vsetint sle &lt;2 x int&gt; &lt;int 0, int 1&gt;, &lt;int 1, int 0&gt; <i>; yields {&lt;2 x bool&gt;}:result = true, false</i>
2401 &lt;result&gt; = vsetint sge &lt;2 x int&gt; &lt;int 0, int 1&gt;, &lt;int 1, int 0&gt; <i>; yields {&lt;2 x bool&gt;}:result = false, true</i>
2402</pre>
2403</div>
2404
2405<!-- _______________________________________________________________________ -->
2406<div class="doc_subsubsection"> <a name="i_vsetfp">'<tt>vsetfp</tt>'
2407Instruction</a> </div>
2408<div class="doc_text">
2409<h5>Syntax:</h5>
2410<pre>&lt;result&gt; = vsetfp &lt;op&gt;, &lt;n x &lt;ty&gt;&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields &lt;n x bool&gt;</i>
2411</pre>
2412
2413<h5>Overview:</h5>
2414
2415<p>The '<tt>vsetfp</tt>' instruction takes two floating point vector
2416arguments and returns a vector of boolean values representing, at each
2417position, the result of the comparison between the values at that
2418position in the two operands.</p>
2419
2420<h5>Arguments:</h5>
2421
2422<p>The arguments to a '<tt>vsetfp</tt>' instruction are a comparison
2423operation and two value arguments. The value arguments must be of <a
2424href="t_floating">floating point</a> <a href="#t_packed">packed</a>
2425type, and they must have identical types. The operation argument must
2426be one of <tt>eq</tt>, <tt>ne</tt>, <tt>lt</tt>, <tt>gt</tt>,
2427<tt>le</tt>, <tt>ge</tt>, <tt>oeq</tt>, <tt>one</tt>, <tt>olt</tt>,
2428<tt>ogt</tt>, <tt>ole</tt>, <tt>oge</tt>, <tt>ueq</tt>, <tt>une</tt>,
2429<tt>ult</tt>, <tt>ugt</tt>, <tt>ule</tt>, <tt>uge</tt>, <tt>o</tt>,
2430<tt>u</tt>, <tt>true</tt>, and <tt>false</tt>. The result is a packed
2431<tt>bool</tt> value with the same length as each operand.</p>
2432
2433<h5>Semantics:</h5>
2434
2435<p>The following table shows the semantics of '<tt>vsetfp</tt>' for
Robert Bocchino7b81c752006-02-17 21:18:08 +00002436floating point types. If either operand is a floating point Not a
2437Number (NaN) value, the operation is unordered, and the value in the
2438first column below is produced at that position. Otherwise, the
2439operation is ordered, and the value in the second column is
2440produced.</p>
2441
2442<table border="1" cellspacing="0" cellpadding="4">
2443 <tbody>
2444 <tr><th>Operation</th><th>If unordered<th>Otherwise true iff</th></tr>
2445 <tr><td><tt>eq</tt></td><td>undefined</td><td>var1 == var2</td></tr>
2446 <tr><td><tt>ne</tt></td><td>undefined</td><td>var1 != var2</td></tr>
2447 <tr><td><tt>lt</tt></td><td>undefined</td><td>var1 &lt; var2</td></tr>
2448 <tr><td><tt>gt</tt></td><td>undefined</td><td>var1 &gt; var2</td></tr>
2449 <tr><td><tt>le</tt></td><td>undefined</td><td>var1 &lt;= var2</td></tr>
2450 <tr><td><tt>ge</tt></td><td>undefined</td><td>var1 &gt;= var2</td></tr>
2451 <tr><td><tt>oeq</tt></td><td>false</td><td>var1 == var2</td></tr>
2452 <tr><td><tt>one</tt></td><td>false</td><td>var1 != var2</td></tr>
2453 <tr><td><tt>olt</tt></td><td>false</td><td>var1 &lt; var2</td></tr>
2454 <tr><td><tt>ogt</tt></td><td>false</td><td>var1 &gt; var2</td></tr>
2455 <tr><td><tt>ole</tt></td><td>false</td><td>var1 &lt;= var2</td></tr>
2456 <tr><td><tt>oge</tt></td><td>false</td><td>var1 &gt;= var2</td></tr>
2457 <tr><td><tt>ueq</tt></td><td>true</td><td>var1 == var2</td></tr>
2458 <tr><td><tt>une</tt></td><td>true</td><td>var1 != var2</td></tr>
2459 <tr><td><tt>ult</tt></td><td>true</td><td>var1 &lt; var2</td></tr>
2460 <tr><td><tt>ugt</tt></td><td>true</td><td>var1 &gt; var2</td></tr>
2461 <tr><td><tt>ule</tt></td><td>true</td><td>var1 &lt;= var2</td></tr>
2462 <tr><td><tt>uge</tt></td><td>true</td><td>var1 &gt;= var2</td></tr>
2463 <tr><td><tt>o</tt></td><td>false</td><td>always</td></tr>
2464 <tr><td><tt>u</tt></td><td>true</td><td>never</td></tr>
2465 <tr><td><tt>true</tt></td><td>true</td><td>always</td></tr>
2466 <tr><td><tt>false</tt></td><td>false</td><td>never</td></tr>
2467 </tbody>
2468</table>
2469
2470<h5>Example:</h5>
Robert Bocchino230bd092006-03-14 23:22:57 +00002471<pre> &lt;result&gt; = vsetfp eq &lt;2 x float&gt; &lt;float 0.0, float 1.0&gt;, &lt;float 1.0, float 0.0&gt; <i>; yields {&lt;2 x bool&gt;}:result = false, false</i>
2472 &lt;result&gt; = vsetfp ne &lt;2 x float&gt; &lt;float 0.0, float 1.0&gt;, &lt;float 1.0, float 0.0&gt; <i>; yields {&lt;2 x bool&gt;}:result = true, true</i>
2473 &lt;result&gt; = vsetfp lt &lt;2 x float&gt; &lt;float 0.0, float 1.0&gt;, &lt;float 1.0, float 0.0&gt; <i>; yields {&lt;2 x bool&gt;}:result = true, false</i>
2474 &lt;result&gt; = vsetfp gt &lt;2 x float&gt; &lt;float 0.0, float 1.0&gt;, &lt;float 1.0, float 0.0&gt; <i>; yields {&lt;2 x bool&gt;}:result = false, true</i>
2475 &lt;result&gt; = vsetfp le &lt;2 x float&gt; &lt;float 0.0, float 1.0&gt;, &lt;float 1.0, float 0.0&gt; <i>; yields {&lt;2 x bool&gt;}:result = true, false</i>
2476 &lt;result&gt; = vsetfp ge &lt;2 x float&gt; &lt;float 0.0, float 1.0&gt;, &lt;float 1.0, float 0.0&gt; <i>; yields {&lt;2 x bool&gt;}:result = false, true</i>
Robert Bocchino7b81c752006-02-17 21:18:08 +00002477</pre>
2478</div>
2479
2480<!-- _______________________________________________________________________ -->
2481<div class="doc_subsubsection">
2482 <a name="i_vselect">'<tt>vselect</tt>' Instruction</a>
2483</div>
2484
2485<div class="doc_text">
2486
2487<h5>Syntax:</h5>
2488
2489<pre>
2490 &lt;result&gt; = vselect &lt;n x bool&gt; &lt;cond&gt;, &lt;n x &lt;ty&gt;&gt; &lt;val1&gt;, &lt;n x &lt;ty&gt;&gt; &lt;val2&gt; <i>; yields &lt;n x &lt;ty&gt;&gt;</i>
2491</pre>
2492
2493<h5>Overview:</h5>
2494
2495<p>
2496The '<tt>vselect</tt>' instruction chooses one value at each position
2497of a vector based on a condition.
2498</p>
2499
2500
2501<h5>Arguments:</h5>
2502
2503<p>
2504The '<tt>vselect</tt>' instruction requires a <a
2505href="#t_packed">packed</a> <tt>bool</tt> value indicating the
2506condition at each vector position, and two values of the same packed
2507type. All three operands must have the same length. The type of the
2508result is the same as the type of the two value operands.</p>
2509
2510<h5>Semantics:</h5>
2511
2512<p>
2513At each position where the <tt>bool</tt> vector is true, that position
2514of the result gets its value from the first value argument; otherwise,
2515it gets its value from the second value argument.
2516</p>
2517
2518<h5>Example:</h5>
2519
2520<pre>
2521 %X = vselect bool &lt;2 x bool&gt; &lt;bool true, bool false&gt;, &lt;2 x ubyte&gt; &lt;ubyte 17, ubyte 17&gt;,
2522 &lt;2 x ubyte&gt; &lt;ubyte 42, ubyte 42&gt; <i>; yields &lt;2 x ubyte&gt;:17, 42</i>
2523</pre>
2524</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002525
Robert Bocchino3a558662006-01-05 17:37:02 +00002526<!-- _______________________________________________________________________ -->
2527<div class="doc_subsubsection">
2528 <a name="i_extractelement">'<tt>extractelement</tt>' Instruction</a>
2529</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002530
Robert Bocchino3a558662006-01-05 17:37:02 +00002531<div class="doc_text">
2532
2533<h5>Syntax:</h5>
2534
2535<pre>
2536 &lt;result&gt; = extractelement &lt;n x &lt;ty&gt;&gt; &lt;val&gt;, uint &lt;idx&gt; <i>; yields &lt;ty&gt;</i>
2537</pre>
2538
2539<h5>Overview:</h5>
2540
2541<p>
2542The '<tt>extractelement</tt>' instruction extracts a single scalar
Robert Bocchino05ccd702006-01-15 20:48:27 +00002543element from a packed vector at a specified index.
Robert Bocchino3a558662006-01-05 17:37:02 +00002544</p>
2545
2546
2547<h5>Arguments:</h5>
2548
2549<p>
2550The first operand of an '<tt>extractelement</tt>' instruction is a
2551value of <a href="#t_packed">packed</a> type. The second operand is
2552an index indicating the position from which to extract the element.
2553The index may be a variable.</p>
2554
2555<h5>Semantics:</h5>
2556
2557<p>
2558The result is a scalar of the same type as the element type of
2559<tt>val</tt>. Its value is the value at position <tt>idx</tt> of
2560<tt>val</tt>. If <tt>idx</tt> exceeds the length of <tt>val</tt>, the
2561results are undefined.
2562</p>
2563
2564<h5>Example:</h5>
2565
2566<pre>
2567 %result = extractelement &lt;4 x int&gt; %vec, uint 0 <i>; yields int</i>
2568</pre>
2569</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002570
2571
Chris Lattner33ba0d92001-07-09 00:26:23 +00002572<!-- _______________________________________________________________________ -->
Chris Lattner2bff5242005-05-06 05:47:36 +00002573<div class="doc_subsubsection">
Robert Bocchino05ccd702006-01-15 20:48:27 +00002574 <a name="i_insertelement">'<tt>insertelement</tt>' Instruction</a>
2575</div>
2576
2577<div class="doc_text">
2578
2579<h5>Syntax:</h5>
2580
2581<pre>
2582 &lt;result&gt; = insertelement &lt;n x &lt;ty&gt;&gt; &lt;val&gt;, &lt;ty&gt; &lt;elt&gt, uint &lt;idx&gt; <i>; yields &lt;n x &lt;ty&gt;&gt;</i>
2583</pre>
2584
2585<h5>Overview:</h5>
2586
2587<p>
2588The '<tt>insertelement</tt>' instruction inserts a scalar
2589element into a packed vector at a specified index.
2590</p>
2591
2592
2593<h5>Arguments:</h5>
2594
2595<p>
2596The first operand of an '<tt>insertelement</tt>' instruction is a
2597value of <a href="#t_packed">packed</a> type. The second operand is a
2598scalar value whose type must equal the element type of the first
2599operand. The third operand is an index indicating the position at
2600which to insert the value. The index may be a variable.</p>
2601
2602<h5>Semantics:</h5>
2603
2604<p>
2605The result is a packed vector of the same type as <tt>val</tt>. Its
2606element values are those of <tt>val</tt> except at position
2607<tt>idx</tt>, where it gets the value <tt>elt</tt>. If <tt>idx</tt>
2608exceeds the length of <tt>val</tt>, the results are undefined.
2609</p>
2610
2611<h5>Example:</h5>
2612
2613<pre>
2614 %result = insertelement &lt;4 x int&gt; %vec, int 1, uint 0 <i>; yields &lt;4 x int&gt;</i>
2615</pre>
2616</div>
2617
Chris Lattnerc1989542006-04-08 00:13:41 +00002618<!-- _______________________________________________________________________ -->
2619<div class="doc_subsubsection">
2620 <a name="i_shufflevector">'<tt>shufflevector</tt>' Instruction</a>
2621</div>
2622
2623<div class="doc_text">
2624
2625<h5>Syntax:</h5>
2626
2627<pre>
2628 &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;n x uint&gt; &lt;mask&gt; <i>; yields &lt;n x &lt;ty&gt;&gt;</i>
2629</pre>
2630
2631<h5>Overview:</h5>
2632
2633<p>
2634The '<tt>shufflevector</tt>' instruction constructs a permutation of elements
2635from two input vectors, returning a vector of the same type.
2636</p>
2637
2638<h5>Arguments:</h5>
2639
2640<p>
2641The first two operands of a '<tt>shufflevector</tt>' instruction are vectors
2642with types that match each other and types that match the result of the
2643instruction. The third argument is a shuffle mask, which has the same number
2644of elements as the other vector type, but whose element type is always 'uint'.
2645</p>
2646
2647<p>
2648The shuffle mask operand is required to be a constant vector with either
2649constant integer or undef values.
2650</p>
2651
2652<h5>Semantics:</h5>
2653
2654<p>
2655The elements of the two input vectors are numbered from left to right across
2656both of the vectors. The shuffle mask operand specifies, for each element of
2657the result vector, which element of the two input registers the result element
2658gets. The element selector may be undef (meaning "don't care") and the second
2659operand may be undef if performing a shuffle from only one vector.
2660</p>
2661
2662<h5>Example:</h5>
2663
2664<pre>
2665 %result = shufflevector &lt;4 x int&gt; %v1, &lt;4 x int&gt; %v2, <4 x uint> <uint 0, uint 4, uint 1, uint 5> <i>; yields &lt;4 x int&gt;</i>
2666 %result = shufflevector &lt;4 x int&gt; %v1, &lt;4 x int&gt; undef, <4 x uint> <uint 0, uint 1, uint 2, uint 3> <i>; yields &lt;4 x int&gt;</i> - Identity shuffle.
2667</pre>
2668</div>
2669
Robert Bocchino05ccd702006-01-15 20:48:27 +00002670
2671<!-- _______________________________________________________________________ -->
2672<div class="doc_subsubsection">
Chris Lattner2bff5242005-05-06 05:47:36 +00002673 <a name="i_call">'<tt>call</tt>' Instruction</a>
2674</div>
2675
Misha Brukman9d0919f2003-11-08 01:05:38 +00002676<div class="doc_text">
Chris Lattner2bff5242005-05-06 05:47:36 +00002677
Chris Lattner00950542001-06-06 20:29:01 +00002678<h5>Syntax:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00002679<pre>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00002680 &lt;result&gt; = [tail] call [<a href="#callingconv">cconv</a>] &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)
Chris Lattner2bff5242005-05-06 05:47:36 +00002681</pre>
2682
Chris Lattner00950542001-06-06 20:29:01 +00002683<h5>Overview:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00002684
Misha Brukman9d0919f2003-11-08 01:05:38 +00002685<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00002686
Chris Lattner00950542001-06-06 20:29:01 +00002687<h5>Arguments:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00002688
Misha Brukman9d0919f2003-11-08 01:05:38 +00002689<p>This instruction requires several arguments:</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00002690
Chris Lattner6536cfe2002-05-06 22:08:29 +00002691<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00002692 <li>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00002693 <p>The optional "tail" marker indicates whether the callee function accesses
2694 any allocas or varargs in the caller. If the "tail" marker is present, the
Chris Lattner2bff5242005-05-06 05:47:36 +00002695 function call is eligible for tail call optimization. Note that calls may
2696 be marked "tail" even if they do not occur before a <a
2697 href="#i_ret"><tt>ret</tt></a> instruction.
Chris Lattner261efe92003-11-25 01:02:51 +00002698 </li>
2699 <li>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00002700 <p>The optional "cconv" marker indicates which <a href="callingconv">calling
2701 convention</a> the call should use. If none is specified, the call defaults
2702 to using C calling conventions.
2703 </li>
2704 <li>
Chris Lattner2bff5242005-05-06 05:47:36 +00002705 <p>'<tt>ty</tt>': shall be the signature of the pointer to function value
2706 being invoked. The argument types must match the types implied by this
John Criswellfc6b8952005-05-16 16:17:45 +00002707 signature. This type can be omitted if the function is not varargs and
2708 if the function type does not return a pointer to a function.</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00002709 </li>
2710 <li>
2711 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to
2712 be invoked. In most cases, this is a direct function invocation, but
2713 indirect <tt>call</tt>s are just as possible, calling an arbitrary pointer
John Criswellfc6b8952005-05-16 16:17:45 +00002714 to function value.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002715 </li>
2716 <li>
2717 <p>'<tt>function args</tt>': argument list whose types match the
Reid Spencera7e302a2005-05-01 22:22:57 +00002718 function signature argument types. All arguments must be of
2719 <a href="#t_firstclass">first class</a> type. If the function signature
2720 indicates the function accepts a variable number of arguments, the extra
2721 arguments can be specified.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002722 </li>
Chris Lattner6536cfe2002-05-06 22:08:29 +00002723</ol>
Chris Lattner2bff5242005-05-06 05:47:36 +00002724
Chris Lattner00950542001-06-06 20:29:01 +00002725<h5>Semantics:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00002726
Chris Lattner261efe92003-11-25 01:02:51 +00002727<p>The '<tt>call</tt>' instruction is used to cause control flow to
2728transfer to a specified function, with its incoming arguments bound to
2729the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
2730instruction in the called function, control flow continues with the
2731instruction after the function call, and the return value of the
2732function is bound to the result argument. This is a simpler case of
2733the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00002734
Chris Lattner00950542001-06-06 20:29:01 +00002735<h5>Example:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00002736
2737<pre>
2738 %retval = call int %test(int %argc)
2739 call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42);
2740 %X = tail call int %foo()
Chris Lattnerbad10ee2005-05-06 22:57:40 +00002741 %Y = tail call <a href="#callingconv">fastcc</a> int %foo()
Chris Lattner2bff5242005-05-06 05:47:36 +00002742</pre>
2743
Misha Brukman9d0919f2003-11-08 01:05:38 +00002744</div>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002745
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002746<!-- _______________________________________________________________________ -->
Chris Lattnere19d7a72004-09-27 21:51:25 +00002747<div class="doc_subsubsection">
Chris Lattnerfb6977d2006-01-13 23:26:01 +00002748 <a name="i_va_arg">'<tt>va_arg</tt>' Instruction</a>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002749</div>
2750
Misha Brukman9d0919f2003-11-08 01:05:38 +00002751<div class="doc_text">
Chris Lattnere19d7a72004-09-27 21:51:25 +00002752
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002753<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002754
2755<pre>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002756 &lt;resultval&gt; = va_arg &lt;va_list*&gt; &lt;arglist&gt;, &lt;argty&gt;
Chris Lattnere19d7a72004-09-27 21:51:25 +00002757</pre>
2758
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002759<h5>Overview:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002760
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002761<p>The '<tt>va_arg</tt>' instruction is used to access arguments passed through
Chris Lattnere19d7a72004-09-27 21:51:25 +00002762the "variable argument" area of a function call. It is used to implement the
2763<tt>va_arg</tt> macro in C.</p>
2764
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002765<h5>Arguments:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002766
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002767<p>This instruction takes a <tt>va_list*</tt> value and the type of
2768the argument. It returns a value of the specified argument type and
Jeff Cohen25d4f7e2005-11-11 02:15:27 +00002769increments the <tt>va_list</tt> to point to the next argument. Again, the
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002770actual type of <tt>va_list</tt> is target specific.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002771
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002772<h5>Semantics:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002773
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002774<p>The '<tt>va_arg</tt>' instruction loads an argument of the specified
2775type from the specified <tt>va_list</tt> and causes the
2776<tt>va_list</tt> to point to the next argument. For more information,
2777see the variable argument handling <a href="#int_varargs">Intrinsic
2778Functions</a>.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002779
2780<p>It is legal for this instruction to be called in a function which does not
2781take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002782function.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002783
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002784<p><tt>va_arg</tt> is an LLVM instruction instead of an <a
John Criswellfc6b8952005-05-16 16:17:45 +00002785href="#intrinsics">intrinsic function</a> because it takes a type as an
Chris Lattnere19d7a72004-09-27 21:51:25 +00002786argument.</p>
2787
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002788<h5>Example:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002789
2790<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
2791
Misha Brukman9d0919f2003-11-08 01:05:38 +00002792</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002793
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002794<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00002795<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
2796<!-- *********************************************************************** -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002797
Misha Brukman9d0919f2003-11-08 01:05:38 +00002798<div class="doc_text">
Chris Lattner33aec9e2004-02-12 17:01:32 +00002799
2800<p>LLVM supports the notion of an "intrinsic function". These functions have
John Criswellfc6b8952005-05-16 16:17:45 +00002801well known names and semantics and are required to follow certain
Chris Lattner33aec9e2004-02-12 17:01:32 +00002802restrictions. Overall, these instructions represent an extension mechanism for
2803the LLVM language that does not require changing all of the transformations in
2804LLVM to add to the language (or the bytecode reader/writer, the parser,
2805etc...).</p>
2806
John Criswellfc6b8952005-05-16 16:17:45 +00002807<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix. This
2808prefix is reserved in LLVM for intrinsic names; thus, functions may not be named
Chris Lattner33aec9e2004-02-12 17:01:32 +00002809this. Intrinsic functions must always be external functions: you cannot define
2810the body of intrinsic functions. Intrinsic functions may only be used in call
2811or invoke instructions: it is illegal to take the address of an intrinsic
2812function. Additionally, because intrinsic functions are part of the LLVM
2813language, it is required that they all be documented here if any are added.</p>
2814
2815
John Criswellfc6b8952005-05-16 16:17:45 +00002816<p>To learn how to add an intrinsic function, please see the <a
Chris Lattner590cff32005-05-11 03:35:57 +00002817href="ExtendingLLVM.html">Extending LLVM Guide</a>.
Chris Lattner33aec9e2004-02-12 17:01:32 +00002818</p>
2819
Misha Brukman9d0919f2003-11-08 01:05:38 +00002820</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002821
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002822<!-- ======================================================================= -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002823<div class="doc_subsection">
2824 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
2825</div>
2826
Misha Brukman9d0919f2003-11-08 01:05:38 +00002827<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00002828
Misha Brukman9d0919f2003-11-08 01:05:38 +00002829<p>Variable argument support is defined in LLVM with the <a
Chris Lattnerfb6977d2006-01-13 23:26:01 +00002830 href="#i_va_arg"><tt>va_arg</tt></a> instruction and these three
Chris Lattner261efe92003-11-25 01:02:51 +00002831intrinsic functions. These functions are related to the similarly
2832named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002833
Chris Lattner261efe92003-11-25 01:02:51 +00002834<p>All of these functions operate on arguments that use a
2835target-specific value type "<tt>va_list</tt>". The LLVM assembly
2836language reference manual does not define what this type is, so all
2837transformations should be prepared to handle intrinsics with any type
2838used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002839
Misha Brukman9d0919f2003-11-08 01:05:38 +00002840<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner261efe92003-11-25 01:02:51 +00002841instruction and the variable argument handling intrinsic functions are
2842used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002843
Chris Lattner33aec9e2004-02-12 17:01:32 +00002844<pre>
2845int %test(int %X, ...) {
2846 ; Initialize variable argument processing
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002847 %ap = alloca sbyte*
2848 call void %<a href="#i_va_start">llvm.va_start</a>(sbyte** %ap)
Chris Lattner33aec9e2004-02-12 17:01:32 +00002849
2850 ; Read a single integer argument
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002851 %tmp = va_arg sbyte** %ap, int
Chris Lattner33aec9e2004-02-12 17:01:32 +00002852
2853 ; Demonstrate usage of llvm.va_copy and llvm.va_end
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002854 %aq = alloca sbyte*
Andrew Lenharthd0a4c622005-06-22 20:38:11 +00002855 call void %<a href="#i_va_copy">llvm.va_copy</a>(sbyte** %aq, sbyte** %ap)
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002856 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte** %aq)
Chris Lattner33aec9e2004-02-12 17:01:32 +00002857
2858 ; Stop processing of arguments.
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002859 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte** %ap)
Chris Lattner33aec9e2004-02-12 17:01:32 +00002860 ret int %tmp
2861}
2862</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002863</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002864
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002865<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002866<div class="doc_subsubsection">
2867 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
2868</div>
2869
2870
Misha Brukman9d0919f2003-11-08 01:05:38 +00002871<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002872<h5>Syntax:</h5>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002873<pre> declare void %llvm.va_start(&lt;va_list&gt;* &lt;arglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002874<h5>Overview:</h5>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002875<P>The '<tt>llvm.va_start</tt>' intrinsic initializes
2876<tt>*&lt;arglist&gt;</tt> for subsequent use by <tt><a
2877href="#i_va_arg">va_arg</a></tt>.</p>
2878
2879<h5>Arguments:</h5>
2880
2881<P>The argument is a pointer to a <tt>va_list</tt> element to initialize.</p>
2882
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002883<h5>Semantics:</h5>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002884
2885<P>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
2886macro available in C. In a target-dependent way, it initializes the
2887<tt>va_list</tt> element the argument points to, so that the next call to
2888<tt>va_arg</tt> will produce the first variable argument passed to the function.
2889Unlike the C <tt>va_start</tt> macro, this intrinsic does not need to know the
2890last argument of the function, the compiler can figure that out.</p>
2891
Misha Brukman9d0919f2003-11-08 01:05:38 +00002892</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002893
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002894<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002895<div class="doc_subsubsection">
2896 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
2897</div>
2898
Misha Brukman9d0919f2003-11-08 01:05:38 +00002899<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002900<h5>Syntax:</h5>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002901<pre> declare void %llvm.va_end(&lt;va_list*&gt; &lt;arglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002902<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002903<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
2904which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
2905or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002906<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002907<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002908<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002909<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002910macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
2911Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
2912 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
2913with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002914</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002915
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002916<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002917<div class="doc_subsubsection">
2918 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
2919</div>
2920
Misha Brukman9d0919f2003-11-08 01:05:38 +00002921<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00002922
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002923<h5>Syntax:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002924
2925<pre>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002926 declare void %llvm.va_copy(&lt;va_list&gt;* &lt;destarglist&gt;,
Andrew Lenharthd0a4c622005-06-22 20:38:11 +00002927 &lt;va_list&gt;* &lt;srcarglist&gt;)
Chris Lattnerd7923912004-05-23 21:06:01 +00002928</pre>
2929
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002930<h5>Overview:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002931
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002932<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position from
2933the source argument list to the destination argument list.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002934
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002935<h5>Arguments:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002936
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002937<p>The first argument is a pointer to a <tt>va_list</tt> element to initialize.
Andrew Lenharthd0a4c622005-06-22 20:38:11 +00002938The second argument is a pointer to a <tt>va_list</tt> element to copy from.</p>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002939
Chris Lattnerd7923912004-05-23 21:06:01 +00002940
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002941<h5>Semantics:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002942
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002943<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt> macro
2944available in C. In a target-dependent way, it copies the source
2945<tt>va_list</tt> element into the destination list. This intrinsic is necessary
2946because the <tt><a href="i_va_begin">llvm.va_begin</a></tt> intrinsic may be
Chris Lattnerd7923912004-05-23 21:06:01 +00002947arbitrarily complex and require memory allocation, for example.</p>
2948
Misha Brukman9d0919f2003-11-08 01:05:38 +00002949</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002950
Chris Lattner33aec9e2004-02-12 17:01:32 +00002951<!-- ======================================================================= -->
2952<div class="doc_subsection">
Chris Lattnerd7923912004-05-23 21:06:01 +00002953 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
2954</div>
2955
2956<div class="doc_text">
2957
2958<p>
2959LLVM support for <a href="GarbageCollection.html">Accurate Garbage
2960Collection</a> requires the implementation and generation of these intrinsics.
2961These intrinsics allow identification of <a href="#i_gcroot">GC roots on the
2962stack</a>, as well as garbage collector implementations that require <a
2963href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers.
2964Front-ends for type-safe garbage collected languages should generate these
2965intrinsics to make use of the LLVM garbage collectors. For more details, see <a
2966href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
2967</p>
2968</div>
2969
2970<!-- _______________________________________________________________________ -->
2971<div class="doc_subsubsection">
2972 <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
2973</div>
2974
2975<div class="doc_text">
2976
2977<h5>Syntax:</h5>
2978
2979<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00002980 declare void %llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
Chris Lattnerd7923912004-05-23 21:06:01 +00002981</pre>
2982
2983<h5>Overview:</h5>
2984
John Criswell9e2485c2004-12-10 15:51:16 +00002985<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
Chris Lattnerd7923912004-05-23 21:06:01 +00002986the code generator, and allows some metadata to be associated with it.</p>
2987
2988<h5>Arguments:</h5>
2989
2990<p>The first argument specifies the address of a stack object that contains the
2991root pointer. The second pointer (which must be either a constant or a global
2992value address) contains the meta-data to be associated with the root.</p>
2993
2994<h5>Semantics:</h5>
2995
2996<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
2997location. At compile-time, the code generator generates information to allow
2998the runtime to find the pointer at GC safe points.
2999</p>
3000
3001</div>
3002
3003
3004<!-- _______________________________________________________________________ -->
3005<div class="doc_subsubsection">
3006 <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
3007</div>
3008
3009<div class="doc_text">
3010
3011<h5>Syntax:</h5>
3012
3013<pre>
Chris Lattner80626e92006-03-14 20:02:51 +00003014 declare sbyte* %llvm.gcread(sbyte* %ObjPtr, sbyte** %Ptr)
Chris Lattnerd7923912004-05-23 21:06:01 +00003015</pre>
3016
3017<h5>Overview:</h5>
3018
3019<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
3020locations, allowing garbage collector implementations that require read
3021barriers.</p>
3022
3023<h5>Arguments:</h5>
3024
Chris Lattner80626e92006-03-14 20:02:51 +00003025<p>The second argument is the address to read from, which should be an address
3026allocated from the garbage collector. The first object is a pointer to the
3027start of the referenced object, if needed by the language runtime (otherwise
3028null).</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00003029
3030<h5>Semantics:</h5>
3031
3032<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
3033instruction, but may be replaced with substantially more complex code by the
3034garbage collector runtime, as needed.</p>
3035
3036</div>
3037
3038
3039<!-- _______________________________________________________________________ -->
3040<div class="doc_subsubsection">
3041 <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
3042</div>
3043
3044<div class="doc_text">
3045
3046<h5>Syntax:</h5>
3047
3048<pre>
Chris Lattner80626e92006-03-14 20:02:51 +00003049 declare void %llvm.gcwrite(sbyte* %P1, sbyte* %Obj, sbyte** %P2)
Chris Lattnerd7923912004-05-23 21:06:01 +00003050</pre>
3051
3052<h5>Overview:</h5>
3053
3054<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
3055locations, allowing garbage collector implementations that require write
3056barriers (such as generational or reference counting collectors).</p>
3057
3058<h5>Arguments:</h5>
3059
Chris Lattner80626e92006-03-14 20:02:51 +00003060<p>The first argument is the reference to store, the second is the start of the
3061object to store it to, and the third is the address of the field of Obj to
3062store to. If the runtime does not require a pointer to the object, Obj may be
3063null.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00003064
3065<h5>Semantics:</h5>
3066
3067<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
3068instruction, but may be replaced with substantially more complex code by the
3069garbage collector runtime, as needed.</p>
3070
3071</div>
3072
3073
3074
3075<!-- ======================================================================= -->
3076<div class="doc_subsection">
Chris Lattner10610642004-02-14 04:08:35 +00003077 <a name="int_codegen">Code Generator Intrinsics</a>
3078</div>
3079
3080<div class="doc_text">
3081<p>
3082These intrinsics are provided by LLVM to expose special features that may only
3083be implemented with code generator support.
3084</p>
3085
3086</div>
3087
3088<!-- _______________________________________________________________________ -->
3089<div class="doc_subsubsection">
3090 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
3091</div>
3092
3093<div class="doc_text">
3094
3095<h5>Syntax:</h5>
3096<pre>
Chris Lattnerfcf39d42006-01-13 01:20:27 +00003097 declare sbyte *%llvm.returnaddress(uint &lt;level&gt;)
Chris Lattner10610642004-02-14 04:08:35 +00003098</pre>
3099
3100<h5>Overview:</h5>
3101
3102<p>
3103The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
3104indicating the return address of the current function or one of its callers.
3105</p>
3106
3107<h5>Arguments:</h5>
3108
3109<p>
3110The argument to this intrinsic indicates which function to return the address
3111for. Zero indicates the calling function, one indicates its caller, etc. The
3112argument is <b>required</b> to be a constant integer value.
3113</p>
3114
3115<h5>Semantics:</h5>
3116
3117<p>
3118The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
3119the return address of the specified call frame, or zero if it cannot be
3120identified. The value returned by this intrinsic is likely to be incorrect or 0
3121for arguments other than zero, so it should only be used for debugging purposes.
3122</p>
3123
3124<p>
3125Note that calling this intrinsic does not prevent function inlining or other
Chris Lattnerb40bb382005-03-07 20:30:51 +00003126aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner10610642004-02-14 04:08:35 +00003127source-language caller.
3128</p>
3129</div>
3130
3131
3132<!-- _______________________________________________________________________ -->
3133<div class="doc_subsubsection">
3134 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
3135</div>
3136
3137<div class="doc_text">
3138
3139<h5>Syntax:</h5>
3140<pre>
Chris Lattnerfcf39d42006-01-13 01:20:27 +00003141 declare sbyte *%llvm.frameaddress(uint &lt;level&gt;)
Chris Lattner10610642004-02-14 04:08:35 +00003142</pre>
3143
3144<h5>Overview:</h5>
3145
3146<p>
3147The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
3148pointer value for the specified stack frame.
3149</p>
3150
3151<h5>Arguments:</h5>
3152
3153<p>
3154The argument to this intrinsic indicates which function to return the frame
3155pointer for. Zero indicates the calling function, one indicates its caller,
3156etc. The argument is <b>required</b> to be a constant integer value.
3157</p>
3158
3159<h5>Semantics:</h5>
3160
3161<p>
3162The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
3163the frame address of the specified call frame, or zero if it cannot be
3164identified. The value returned by this intrinsic is likely to be incorrect or 0
3165for arguments other than zero, so it should only be used for debugging purposes.
3166</p>
3167
3168<p>
3169Note that calling this intrinsic does not prevent function inlining or other
Chris Lattnerb40bb382005-03-07 20:30:51 +00003170aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner10610642004-02-14 04:08:35 +00003171source-language caller.
3172</p>
3173</div>
3174
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00003175<!-- _______________________________________________________________________ -->
3176<div class="doc_subsubsection">
Chris Lattner57e1f392006-01-13 02:03:13 +00003177 <a name="i_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a>
3178</div>
3179
3180<div class="doc_text">
3181
3182<h5>Syntax:</h5>
3183<pre>
3184 declare sbyte *%llvm.stacksave()
3185</pre>
3186
3187<h5>Overview:</h5>
3188
3189<p>
3190The '<tt>llvm.stacksave</tt>' intrinsic is used to remember the current state of
3191the function stack, for use with <a href="#i_stackrestore">
3192<tt>llvm.stackrestore</tt></a>. This is useful for implementing language
3193features like scoped automatic variable sized arrays in C99.
3194</p>
3195
3196<h5>Semantics:</h5>
3197
3198<p>
3199This intrinsic returns a opaque pointer value that can be passed to <a
3200href="#i_stackrestore"><tt>llvm.stackrestore</tt></a>. When an
3201<tt>llvm.stackrestore</tt> intrinsic is executed with a value saved from
3202<tt>llvm.stacksave</tt>, it effectively restores the state of the stack to the
3203state it was in when the <tt>llvm.stacksave</tt> intrinsic executed. In
3204practice, this pops any <a href="#i_alloca">alloca</a> blocks from the stack
3205that were allocated after the <tt>llvm.stacksave</tt> was executed.
3206</p>
3207
3208</div>
3209
3210<!-- _______________________________________________________________________ -->
3211<div class="doc_subsubsection">
3212 <a name="i_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a>
3213</div>
3214
3215<div class="doc_text">
3216
3217<h5>Syntax:</h5>
3218<pre>
3219 declare void %llvm.stackrestore(sbyte* %ptr)
3220</pre>
3221
3222<h5>Overview:</h5>
3223
3224<p>
3225The '<tt>llvm.stackrestore</tt>' intrinsic is used to restore the state of
3226the function stack to the state it was in when the corresponding <a
3227href="#llvm.stacksave"><tt>llvm.stacksave</tt></a> intrinsic executed. This is
3228useful for implementing language features like scoped automatic variable sized
3229arrays in C99.
3230</p>
3231
3232<h5>Semantics:</h5>
3233
3234<p>
3235See the description for <a href="#i_stacksave"><tt>llvm.stacksave</tt></a>.
3236</p>
3237
3238</div>
3239
3240
3241<!-- _______________________________________________________________________ -->
3242<div class="doc_subsubsection">
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00003243 <a name="i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a>
3244</div>
3245
3246<div class="doc_text">
3247
3248<h5>Syntax:</h5>
3249<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00003250 declare void %llvm.prefetch(sbyte * &lt;address&gt;,
3251 uint &lt;rw&gt;, uint &lt;locality&gt;)
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00003252</pre>
3253
3254<h5>Overview:</h5>
3255
3256
3257<p>
3258The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to insert
John Criswellfc6b8952005-05-16 16:17:45 +00003259a prefetch instruction if supported; otherwise, it is a noop. Prefetches have
3260no
3261effect on the behavior of the program but can change its performance
Chris Lattner2a615362005-02-28 19:47:14 +00003262characteristics.
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00003263</p>
3264
3265<h5>Arguments:</h5>
3266
3267<p>
3268<tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier
3269determining if the fetch should be for a read (0) or write (1), and
3270<tt>locality</tt> is a temporal locality specifier ranging from (0) - no
Chris Lattneraeffb4a2005-03-07 20:31:38 +00003271locality, to (3) - extremely local keep in cache. The <tt>rw</tt> and
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00003272<tt>locality</tt> arguments must be constant integers.
3273</p>
3274
3275<h5>Semantics:</h5>
3276
3277<p>
3278This intrinsic does not modify the behavior of the program. In particular,
3279prefetches cannot trap and do not produce a value. On targets that support this
3280intrinsic, the prefetch can provide hints to the processor cache for better
3281performance.
3282</p>
3283
3284</div>
3285
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00003286<!-- _______________________________________________________________________ -->
3287<div class="doc_subsubsection">
3288 <a name="i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a>
3289</div>
3290
3291<div class="doc_text">
3292
3293<h5>Syntax:</h5>
3294<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00003295 declare void %llvm.pcmarker( uint &lt;id&gt; )
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00003296</pre>
3297
3298<h5>Overview:</h5>
3299
3300
3301<p>
John Criswellfc6b8952005-05-16 16:17:45 +00003302The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a Program Counter
3303(PC) in a region of
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00003304code to simulators and other tools. The method is target specific, but it is
3305expected that the marker will use exported symbols to transmit the PC of the marker.
Jeff Cohen25d4f7e2005-11-11 02:15:27 +00003306The marker makes no guarantees that it will remain with any specific instruction
Chris Lattnerd07c3f42005-11-15 06:07:55 +00003307after optimizations. It is possible that the presence of a marker will inhibit
Chris Lattnerb3e7afd2006-03-24 07:16:10 +00003308optimizations. The intended use is to be inserted after optimizations to allow
John Criswellfc6b8952005-05-16 16:17:45 +00003309correlations of simulation runs.
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00003310</p>
3311
3312<h5>Arguments:</h5>
3313
3314<p>
3315<tt>id</tt> is a numerical id identifying the marker.
3316</p>
3317
3318<h5>Semantics:</h5>
3319
3320<p>
3321This intrinsic does not modify the behavior of the program. Backends that do not
3322support this intrinisic may ignore it.
3323</p>
3324
3325</div>
3326
Andrew Lenharth51b8d542005-11-11 16:47:30 +00003327<!-- _______________________________________________________________________ -->
3328<div class="doc_subsubsection">
3329 <a name="i_readcyclecounter">'<tt>llvm.readcyclecounter</tt>' Intrinsic</a>
3330</div>
3331
3332<div class="doc_text">
3333
3334<h5>Syntax:</h5>
3335<pre>
3336 declare ulong %llvm.readcyclecounter( )
3337</pre>
3338
3339<h5>Overview:</h5>
3340
3341
3342<p>
3343The '<tt>llvm.readcyclecounter</tt>' intrinsic provides access to the cycle
3344counter register (or similar low latency, high accuracy clocks) on those targets
3345that support it. On X86, it should map to RDTSC. On Alpha, it should map to RPCC.
3346As the backing counters overflow quickly (on the order of 9 seconds on alpha), this
3347should only be used for small timings.
3348</p>
3349
3350<h5>Semantics:</h5>
3351
3352<p>
3353When directly supported, reading the cycle counter should not modify any memory.
3354Implementations are allowed to either return a application specific value or a
3355system wide value. On backends without support, this is lowered to a constant 0.
3356</p>
3357
3358</div>
3359
Chris Lattner10610642004-02-14 04:08:35 +00003360<!-- ======================================================================= -->
3361<div class="doc_subsection">
Chris Lattner33aec9e2004-02-12 17:01:32 +00003362 <a name="int_libc">Standard C Library Intrinsics</a>
3363</div>
3364
3365<div class="doc_text">
3366<p>
Chris Lattner10610642004-02-14 04:08:35 +00003367LLVM provides intrinsics for a few important standard C library functions.
3368These intrinsics allow source-language front-ends to pass information about the
3369alignment of the pointer arguments to the code generator, providing opportunity
3370for more efficient code generation.
Chris Lattner33aec9e2004-02-12 17:01:32 +00003371</p>
3372
3373</div>
3374
3375<!-- _______________________________________________________________________ -->
3376<div class="doc_subsubsection">
3377 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
3378</div>
3379
3380<div class="doc_text">
3381
3382<h5>Syntax:</h5>
3383<pre>
Chris Lattner5b310c32006-03-03 00:07:20 +00003384 declare void %llvm.memcpy.i32(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
3385 uint &lt;len&gt;, uint &lt;align&gt;)
3386 declare void %llvm.memcpy.i64(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
3387 ulong &lt;len&gt;, uint &lt;align&gt;)
Chris Lattner33aec9e2004-02-12 17:01:32 +00003388</pre>
3389
3390<h5>Overview:</h5>
3391
3392<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00003393The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source
Chris Lattner33aec9e2004-02-12 17:01:32 +00003394location to the destination location.
3395</p>
3396
3397<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00003398Note that, unlike the standard libc function, the <tt>llvm.memcpy.*</tt>
3399intrinsics do not return a value, and takes an extra alignment argument.
Chris Lattner33aec9e2004-02-12 17:01:32 +00003400</p>
3401
3402<h5>Arguments:</h5>
3403
3404<p>
3405The first argument is a pointer to the destination, the second is a pointer to
Chris Lattner5b310c32006-03-03 00:07:20 +00003406the source. The third argument is an integer argument
Chris Lattner33aec9e2004-02-12 17:01:32 +00003407specifying the number of bytes to copy, and the fourth argument is the alignment
3408of the source and destination locations.
3409</p>
3410
Chris Lattner3301ced2004-02-12 21:18:15 +00003411<p>
3412If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattnerf0afc2c2006-03-04 00:02:10 +00003413the caller guarantees that both the source and destination pointers are aligned
3414to that boundary.
Chris Lattner3301ced2004-02-12 21:18:15 +00003415</p>
3416
Chris Lattner33aec9e2004-02-12 17:01:32 +00003417<h5>Semantics:</h5>
3418
3419<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00003420The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source
Chris Lattner33aec9e2004-02-12 17:01:32 +00003421location to the destination location, which are not allowed to overlap. It
3422copies "len" bytes of memory over. If the argument is known to be aligned to
3423some boundary, this can be specified as the fourth argument, otherwise it should
3424be set to 0 or 1.
3425</p>
3426</div>
3427
3428
Chris Lattner0eb51b42004-02-12 18:10:10 +00003429<!-- _______________________________________________________________________ -->
3430<div class="doc_subsubsection">
3431 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
3432</div>
3433
3434<div class="doc_text">
3435
3436<h5>Syntax:</h5>
3437<pre>
Chris Lattner5b310c32006-03-03 00:07:20 +00003438 declare void %llvm.memmove.i32(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
3439 uint &lt;len&gt;, uint &lt;align&gt;)
3440 declare void %llvm.memmove.i64(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
3441 ulong &lt;len&gt;, uint &lt;align&gt;)
Chris Lattner0eb51b42004-02-12 18:10:10 +00003442</pre>
3443
3444<h5>Overview:</h5>
3445
3446<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00003447The '<tt>llvm.memmove.*</tt>' intrinsics move a block of memory from the source
3448location to the destination location. It is similar to the
3449'<tt>llvm.memcmp</tt>' intrinsic but allows the two memory locations to overlap.
Chris Lattner0eb51b42004-02-12 18:10:10 +00003450</p>
3451
3452<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00003453Note that, unlike the standard libc function, the <tt>llvm.memmove.*</tt>
3454intrinsics do not return a value, and takes an extra alignment argument.
Chris Lattner0eb51b42004-02-12 18:10:10 +00003455</p>
3456
3457<h5>Arguments:</h5>
3458
3459<p>
3460The first argument is a pointer to the destination, the second is a pointer to
Chris Lattner5b310c32006-03-03 00:07:20 +00003461the source. The third argument is an integer argument
Chris Lattner0eb51b42004-02-12 18:10:10 +00003462specifying the number of bytes to copy, and the fourth argument is the alignment
3463of the source and destination locations.
3464</p>
3465
Chris Lattner3301ced2004-02-12 21:18:15 +00003466<p>
3467If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattnerf0afc2c2006-03-04 00:02:10 +00003468the caller guarantees that the source and destination pointers are aligned to
3469that boundary.
Chris Lattner3301ced2004-02-12 21:18:15 +00003470</p>
3471
Chris Lattner0eb51b42004-02-12 18:10:10 +00003472<h5>Semantics:</h5>
3473
3474<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00003475The '<tt>llvm.memmove.*</tt>' intrinsics copy a block of memory from the source
Chris Lattner0eb51b42004-02-12 18:10:10 +00003476location to the destination location, which may overlap. It
3477copies "len" bytes of memory over. If the argument is known to be aligned to
3478some boundary, this can be specified as the fourth argument, otherwise it should
3479be set to 0 or 1.
3480</p>
3481</div>
3482
Chris Lattner8ff75902004-01-06 05:31:32 +00003483
Chris Lattner10610642004-02-14 04:08:35 +00003484<!-- _______________________________________________________________________ -->
3485<div class="doc_subsubsection">
Chris Lattner5b310c32006-03-03 00:07:20 +00003486 <a name="i_memset">'<tt>llvm.memset.*</tt>' Intrinsics</a>
Chris Lattner10610642004-02-14 04:08:35 +00003487</div>
3488
3489<div class="doc_text">
3490
3491<h5>Syntax:</h5>
3492<pre>
Chris Lattner5b310c32006-03-03 00:07:20 +00003493 declare void %llvm.memset.i32(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
3494 uint &lt;len&gt;, uint &lt;align&gt;)
3495 declare void %llvm.memset.i64(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
3496 ulong &lt;len&gt;, uint &lt;align&gt;)
Chris Lattner10610642004-02-14 04:08:35 +00003497</pre>
3498
3499<h5>Overview:</h5>
3500
3501<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00003502The '<tt>llvm.memset.*</tt>' intrinsics fill a block of memory with a particular
Chris Lattner10610642004-02-14 04:08:35 +00003503byte value.
3504</p>
3505
3506<p>
3507Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
3508does not return a value, and takes an extra alignment argument.
3509</p>
3510
3511<h5>Arguments:</h5>
3512
3513<p>
3514The first argument is a pointer to the destination to fill, the second is the
Chris Lattner5b310c32006-03-03 00:07:20 +00003515byte value to fill it with, the third argument is an integer
Chris Lattner10610642004-02-14 04:08:35 +00003516argument specifying the number of bytes to fill, and the fourth argument is the
3517known alignment of destination location.
3518</p>
3519
3520<p>
3521If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattnerf0afc2c2006-03-04 00:02:10 +00003522the caller guarantees that the destination pointer is aligned to that boundary.
Chris Lattner10610642004-02-14 04:08:35 +00003523</p>
3524
3525<h5>Semantics:</h5>
3526
3527<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00003528The '<tt>llvm.memset.*</tt>' intrinsics fill "len" bytes of memory starting at
3529the
Chris Lattner10610642004-02-14 04:08:35 +00003530destination location. If the argument is known to be aligned to some boundary,
3531this can be specified as the fourth argument, otherwise it should be set to 0 or
35321.
3533</p>
3534</div>
3535
3536
Chris Lattner32006282004-06-11 02:28:03 +00003537<!-- _______________________________________________________________________ -->
3538<div class="doc_subsubsection">
Reid Spencer0b118202006-01-16 21:12:35 +00003539 <a name="i_isunordered">'<tt>llvm.isunordered.*</tt>' Intrinsic</a>
Alkis Evlogimenos26bbe932004-06-13 01:16:15 +00003540</div>
3541
3542<div class="doc_text">
3543
3544<h5>Syntax:</h5>
3545<pre>
Reid Spencer0b118202006-01-16 21:12:35 +00003546 declare bool %llvm.isunordered.f32(float Val1, float Val2)
3547 declare bool %llvm.isunordered.f64(double Val1, double Val2)
Alkis Evlogimenos26bbe932004-06-13 01:16:15 +00003548</pre>
3549
3550<h5>Overview:</h5>
3551
3552<p>
Reid Spencer0b118202006-01-16 21:12:35 +00003553The '<tt>llvm.isunordered</tt>' intrinsics return true if either or both of the
Alkis Evlogimenos26bbe932004-06-13 01:16:15 +00003554specified floating point values is a NAN.
3555</p>
3556
3557<h5>Arguments:</h5>
3558
3559<p>
3560The arguments are floating point numbers of the same type.
3561</p>
3562
3563<h5>Semantics:</h5>
3564
3565<p>
3566If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise
3567false.
3568</p>
3569</div>
3570
3571
Chris Lattnera4d74142005-07-21 01:29:16 +00003572<!-- _______________________________________________________________________ -->
3573<div class="doc_subsubsection">
Chris Lattnerec6cb612006-01-16 22:38:59 +00003574 <a name="i_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a>
Chris Lattnera4d74142005-07-21 01:29:16 +00003575</div>
3576
3577<div class="doc_text">
3578
3579<h5>Syntax:</h5>
3580<pre>
Reid Spencer0b118202006-01-16 21:12:35 +00003581 declare double %llvm.sqrt.f32(float Val)
3582 declare double %llvm.sqrt.f64(double Val)
Chris Lattnera4d74142005-07-21 01:29:16 +00003583</pre>
3584
3585<h5>Overview:</h5>
3586
3587<p>
Reid Spencer0b118202006-01-16 21:12:35 +00003588The '<tt>llvm.sqrt</tt>' intrinsics return the sqrt of the specified operand,
Chris Lattnera4d74142005-07-21 01:29:16 +00003589returning the same value as the libm '<tt>sqrt</tt>' function would. Unlike
3590<tt>sqrt</tt> in libm, however, <tt>llvm.sqrt</tt> has undefined behavior for
3591negative numbers (which allows for better optimization).
3592</p>
3593
3594<h5>Arguments:</h5>
3595
3596<p>
3597The argument and return value are floating point numbers of the same type.
3598</p>
3599
3600<h5>Semantics:</h5>
3601
3602<p>
3603This function returns the sqrt of the specified operand if it is a positive
3604floating point number.
3605</p>
3606</div>
3607
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003608<!-- ======================================================================= -->
3609<div class="doc_subsection">
Nate Begeman7e36c472006-01-13 23:26:38 +00003610 <a name="int_manip">Bit Manipulation Intrinsics</a>
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003611</div>
3612
3613<div class="doc_text">
3614<p>
Nate Begeman7e36c472006-01-13 23:26:38 +00003615LLVM provides intrinsics for a few important bit manipulation operations.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003616These allow efficient code generation for some algorithms.
3617</p>
3618
3619</div>
3620
3621<!-- _______________________________________________________________________ -->
3622<div class="doc_subsubsection">
Nate Begeman7e36c472006-01-13 23:26:38 +00003623 <a name="i_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a>
3624</div>
3625
3626<div class="doc_text">
3627
3628<h5>Syntax:</h5>
3629<pre>
Chris Lattnerec6cb612006-01-16 22:38:59 +00003630 declare ushort %llvm.bswap.i16(ushort &lt;id&gt;)
3631 declare uint %llvm.bswap.i32(uint &lt;id&gt;)
3632 declare ulong %llvm.bswap.i64(ulong &lt;id&gt;)
Nate Begeman7e36c472006-01-13 23:26:38 +00003633</pre>
3634
3635<h5>Overview:</h5>
3636
3637<p>
3638The '<tt>llvm.bwsap</tt>' family of intrinsics is used to byteswap a 16, 32 or
363964 bit quantity. These are useful for performing operations on data that is not
3640in the target's native byte order.
3641</p>
3642
3643<h5>Semantics:</h5>
3644
3645<p>
Chris Lattnerec6cb612006-01-16 22:38:59 +00003646The <tt>llvm.bswap.16</tt> intrinsic returns a ushort value that has the high and low
3647byte of the input ushort swapped. Similarly, the <tt>llvm.bswap.i32</tt> intrinsic
Nate Begeman7e36c472006-01-13 23:26:38 +00003648returns a uint value that has the four bytes of the input uint swapped, so that
3649if the input bytes are numbered 0, 1, 2, 3 then the returned uint will have its
Chris Lattnerec6cb612006-01-16 22:38:59 +00003650bytes in 3, 2, 1, 0 order. The <tt>llvm.bswap.i64</tt> intrinsic extends this concept
Nate Begeman7e36c472006-01-13 23:26:38 +00003651to 64 bits.
3652</p>
3653
3654</div>
3655
3656<!-- _______________________________________________________________________ -->
3657<div class="doc_subsubsection">
Reid Spencer0b118202006-01-16 21:12:35 +00003658 <a name="int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic</a>
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003659</div>
3660
3661<div class="doc_text">
3662
3663<h5>Syntax:</h5>
3664<pre>
Chris Lattnerec6cb612006-01-16 22:38:59 +00003665 declare ubyte %llvm.ctpop.i8 (ubyte &lt;src&gt;)
3666 declare ushort %llvm.ctpop.i16(ushort &lt;src&gt;)
3667 declare uint %llvm.ctpop.i32(uint &lt;src&gt;)
3668 declare ulong %llvm.ctpop.i64(ulong &lt;src&gt;)
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003669</pre>
3670
3671<h5>Overview:</h5>
3672
3673<p>
Chris Lattnerec6cb612006-01-16 22:38:59 +00003674The '<tt>llvm.ctpop</tt>' family of intrinsics counts the number of bits set in a
3675value.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003676</p>
3677
3678<h5>Arguments:</h5>
3679
3680<p>
Chris Lattnercfe6b372005-05-07 01:46:40 +00003681The only argument is the value to be counted. The argument may be of any
Chris Lattnerec6cb612006-01-16 22:38:59 +00003682unsigned integer type. The return type must match the argument type.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003683</p>
3684
3685<h5>Semantics:</h5>
3686
3687<p>
3688The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable.
3689</p>
3690</div>
3691
3692<!-- _______________________________________________________________________ -->
3693<div class="doc_subsubsection">
Chris Lattner8a886be2006-01-16 22:34:14 +00003694 <a name="int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic</a>
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003695</div>
3696
3697<div class="doc_text">
3698
3699<h5>Syntax:</h5>
3700<pre>
Chris Lattnerec6cb612006-01-16 22:38:59 +00003701 declare ubyte %llvm.ctlz.i8 (ubyte &lt;src&gt;)
3702 declare ushort %llvm.ctlz.i16(ushort &lt;src&gt;)
3703 declare uint %llvm.ctlz.i32(uint &lt;src&gt;)
3704 declare ulong %llvm.ctlz.i64(ulong &lt;src&gt;)
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003705</pre>
3706
3707<h5>Overview:</h5>
3708
3709<p>
Reid Spencer0b118202006-01-16 21:12:35 +00003710The '<tt>llvm.ctlz</tt>' family of intrinsic functions counts the number of
3711leading zeros in a variable.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003712</p>
3713
3714<h5>Arguments:</h5>
3715
3716<p>
Chris Lattnercfe6b372005-05-07 01:46:40 +00003717The only argument is the value to be counted. The argument may be of any
Chris Lattnerec6cb612006-01-16 22:38:59 +00003718unsigned integer type. The return type must match the argument type.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003719</p>
3720
3721<h5>Semantics:</h5>
3722
3723<p>
Chris Lattnereff29ab2005-05-15 19:39:26 +00003724The '<tt>llvm.ctlz</tt>' intrinsic counts the leading (most significant) zeros
3725in a variable. If the src == 0 then the result is the size in bits of the type
3726of src. For example, <tt>llvm.cttz(int 2) = 30</tt>.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003727</p>
3728</div>
Chris Lattner32006282004-06-11 02:28:03 +00003729
3730
Chris Lattnereff29ab2005-05-15 19:39:26 +00003731
3732<!-- _______________________________________________________________________ -->
3733<div class="doc_subsubsection">
Chris Lattner8a886be2006-01-16 22:34:14 +00003734 <a name="int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic</a>
Chris Lattnereff29ab2005-05-15 19:39:26 +00003735</div>
3736
3737<div class="doc_text">
3738
3739<h5>Syntax:</h5>
3740<pre>
Chris Lattnerec6cb612006-01-16 22:38:59 +00003741 declare ubyte %llvm.cttz.i8 (ubyte &lt;src&gt;)
3742 declare ushort %llvm.cttz.i16(ushort &lt;src&gt;)
3743 declare uint %llvm.cttz.i32(uint &lt;src&gt;)
3744 declare ulong %llvm.cttz.i64(ulong &lt;src&gt;)
Chris Lattnereff29ab2005-05-15 19:39:26 +00003745</pre>
3746
3747<h5>Overview:</h5>
3748
3749<p>
Reid Spencer0b118202006-01-16 21:12:35 +00003750The '<tt>llvm.cttz</tt>' family of intrinsic functions counts the number of
3751trailing zeros.
Chris Lattnereff29ab2005-05-15 19:39:26 +00003752</p>
3753
3754<h5>Arguments:</h5>
3755
3756<p>
3757The only argument is the value to be counted. The argument may be of any
Chris Lattnerec6cb612006-01-16 22:38:59 +00003758unsigned integer type. The return type must match the argument type.
Chris Lattnereff29ab2005-05-15 19:39:26 +00003759</p>
3760
3761<h5>Semantics:</h5>
3762
3763<p>
3764The '<tt>llvm.cttz</tt>' intrinsic counts the trailing (least significant) zeros
3765in a variable. If the src == 0 then the result is the size in bits of the type
3766of src. For example, <tt>llvm.cttz(2) = 1</tt>.
3767</p>
3768</div>
3769
Chris Lattner8ff75902004-01-06 05:31:32 +00003770<!-- ======================================================================= -->
3771<div class="doc_subsection">
3772 <a name="int_debugger">Debugger Intrinsics</a>
3773</div>
3774
3775<div class="doc_text">
3776<p>
3777The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
3778are described in the <a
3779href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
3780Debugging</a> document.
3781</p>
3782</div>
3783
3784
Chris Lattner00950542001-06-06 20:29:01 +00003785<!-- *********************************************************************** -->
Chris Lattner00950542001-06-06 20:29:01 +00003786<hr>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00003787<address>
3788 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
3789 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
3790 <a href="http://validator.w3.org/check/referer"><img
3791 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
3792
3793 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
Reid Spencer05fe4b02006-03-14 05:39:39 +00003794 <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00003795 Last modified: $Date$
3796</address>
Misha Brukman9d0919f2003-11-08 01:05:38 +00003797</body>
3798</html>