blob: df5cd9f9af249a15b5b07ad02401fecfbf2bc3c4 [file] [log] [blame]
Misha Brukmanc501f552004-03-01 17:47:27 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
Misha Brukman76307852003-11-08 01:05:38 +00003<html>
4<head>
5 <title>LLVM Assembly Language Reference Manual</title>
Reid Spencercb84e432004-08-26 20:44:00 +00006 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7 <meta name="author" content="Chris Lattner">
8 <meta name="description"
9 content="LLVM Assembly Language Reference Manual.">
Misha Brukman76307852003-11-08 01:05:38 +000010 <link rel="stylesheet" href="llvm.css" type="text/css">
11</head>
Chris Lattner757528b0b2004-05-23 21:06:01 +000012
Misha Brukman76307852003-11-08 01:05:38 +000013<body>
Chris Lattner757528b0b2004-05-23 21:06:01 +000014
Chris Lattner48b383b02003-11-25 01:02:51 +000015<div class="doc_title"> LLVM Language Reference Manual </div>
Chris Lattner2f7c9632001-06-06 20:29:01 +000016<ol>
Misha Brukman76307852003-11-08 01:05:38 +000017 <li><a href="#abstract">Abstract</a></li>
18 <li><a href="#introduction">Introduction</a></li>
19 <li><a href="#identifiers">Identifiers</a></li>
Chris Lattner6af02f32004-12-09 16:11:40 +000020 <li><a href="#highlevel">High Level Structure</a>
21 <ol>
22 <li><a href="#modulestructure">Module Structure</a></li>
Chris Lattnerd79749a2004-12-09 16:36:40 +000023 <li><a href="#linkage">Linkage Types</a></li>
Chris Lattner6af02f32004-12-09 16:11:40 +000024 <li><a href="#globalvars">Global Variables</a></li>
25 <li><a href="#functionstructure">Function Structure</a></li>
26 </ol>
27 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000028 <li><a href="#typesystem">Type System</a>
29 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000030 <li><a href="#t_primitive">Primitive Types</a>
31 <ol>
Misha Brukman76307852003-11-08 01:05:38 +000032 <li><a href="#t_classifications">Type Classifications</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000033 </ol>
34 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000035 <li><a href="#t_derived">Derived Types</a>
36 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000037 <li><a href="#t_array">Array Type</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000038 <li><a href="#t_function">Function Type</a></li>
39 <li><a href="#t_pointer">Pointer Type</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000040 <li><a href="#t_struct">Structure Type</a></li>
Chris Lattnerc8cb6952004-08-12 19:12:28 +000041 <li><a href="#t_packed">Packed Type</a></li>
Chris Lattner37b6b092005-04-25 17:34:15 +000042 <li><a href="#t_opaque">Opaque Type</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000043 </ol>
44 </li>
45 </ol>
46 </li>
Chris Lattner6af02f32004-12-09 16:11:40 +000047 <li><a href="#constants">Constants</a>
Chris Lattner74d3f822004-12-09 17:30:23 +000048 <ol>
49 <li><a href="#simpleconstants">Simple Constants</a>
50 <li><a href="#aggregateconstants">Aggregate Constants</a>
51 <li><a href="#globalconstants">Global Variable and Function Addresses</a>
52 <li><a href="#undefvalues">Undefined Values</a>
53 <li><a href="#constantexprs">Constant Expressions</a>
54 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000055 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000056 <li><a href="#instref">Instruction Reference</a>
57 <ol>
58 <li><a href="#terminators">Terminator Instructions</a>
59 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000060 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
61 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000062 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
63 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000064 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
Chris Lattner08b7d5b2004-10-16 18:04:13 +000065 <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000066 </ol>
67 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000068 <li><a href="#binaryops">Binary Operations</a>
69 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000070 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
71 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
72 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
73 <li><a href="#i_div">'<tt>div</tt>' Instruction</a></li>
74 <li><a href="#i_rem">'<tt>rem</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000075 <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000076 </ol>
77 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000078 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
79 <ol>
Misha Brukman76307852003-11-08 01:05:38 +000080 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000081 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000082 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
83 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
84 <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000085 </ol>
86 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000087 <li><a href="#memoryops">Memory Access Operations</a>
88 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000089 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
90 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
91 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
92 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
93 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
94 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
95 </ol>
96 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000097 <li><a href="#otherops">Other Operations</a>
98 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000099 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +0000100 <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li>
Chris Lattnerb53c28d2004-03-12 05:50:16 +0000101 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000102 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +0000103 <li><a href="#i_vanext">'<tt>vanext</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000104 <li><a href="#i_vaarg">'<tt>vaarg</tt>' Instruction</a></li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000105 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000106 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000107 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000108 </li>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +0000109 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +0000110 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000111 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
112 <ol>
113 <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
114 <li><a href="#i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
115 <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
116 </ol>
117 </li>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000118 <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
119 <ol>
120 <li><a href="#i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li>
121 <li><a href="#i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li>
122 <li><a href="#i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li>
123 </ol>
124 </li>
Chris Lattner3649c3a2004-02-14 04:08:35 +0000125 <li><a href="#int_codegen">Code Generator Intrinsics</a>
126 <ol>
127 <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
128 <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
Chris Lattnerc8a2c222005-02-28 19:24:19 +0000129 <li><a href="#i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a></li>
Andrew Lenharthb4427912005-03-28 20:05:49 +0000130 <li><a href="#i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a></li>
John Criswellaa1c3c12004-04-09 16:43:20 +0000131 </ol>
132 </li>
133 <li><a href="#int_os">Operating System Intrinsics</a>
134 <ol>
Chris Lattner3b4f4372004-06-11 02:28:03 +0000135 <li><a href="#i_readport">'<tt>llvm.readport</tt>' Intrinsic</a></li>
136 <li><a href="#i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a></li>
John Criswella4501222004-04-12 15:02:16 +0000137 <li><a href="#i_readio">'<tt>llvm.readio</tt>' Intrinsic</a></li>
138 <li><a href="#i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a></li>
Chris Lattner3649c3a2004-02-14 04:08:35 +0000139 </ol>
Chris Lattnerfee11462004-02-12 17:01:32 +0000140 <li><a href="#int_libc">Standard C Library Intrinsics</a>
141 <ol>
142 <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li>
Chris Lattnerf30152e2004-02-12 18:10:10 +0000143 <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li>
Chris Lattner3649c3a2004-02-14 04:08:35 +0000144 <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li>
Alkis Evlogimenos9d740622004-06-12 19:19:14 +0000145 <li><a href="#i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a></li>
Chris Lattnerfee11462004-02-12 17:01:32 +0000146 </ol>
147 </li>
Andrew Lenharth1d463522005-05-03 18:01:48 +0000148 <li><a href="#int_count">Bit counting Intrinsics</a>
149 <ol>
150 <li><a href="#int_ctpop">'<tt>llvm.ctpop</tt>' Intrinsic </a></li>
151 <li><a href="#int_cttz">'<tt>llvm.cttz</tt>' Intrinsic </a></li>
152 <li><a href="#int_ctlz">'<tt>llvm.ctlz</tt>' Intrinsic </a></li>
153 </ol>
154 </li>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000155 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000156 </ol>
157 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000158</ol>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000159
160<div class="doc_author">
161 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
162 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
Misha Brukman76307852003-11-08 01:05:38 +0000163</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000164
Chris Lattner2f7c9632001-06-06 20:29:01 +0000165<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000166<div class="doc_section"> <a name="abstract">Abstract </a></div>
167<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000168
Misha Brukman76307852003-11-08 01:05:38 +0000169<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000170<p>This document is a reference manual for the LLVM assembly language.
171LLVM is an SSA based representation that provides type safety,
172low-level operations, flexibility, and the capability of representing
173'all' high-level languages cleanly. It is the common code
174representation used throughout all phases of the LLVM compilation
175strategy.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000176</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000177
Chris Lattner2f7c9632001-06-06 20:29:01 +0000178<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000179<div class="doc_section"> <a name="introduction">Introduction</a> </div>
180<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000181
Misha Brukman76307852003-11-08 01:05:38 +0000182<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000183
Chris Lattner48b383b02003-11-25 01:02:51 +0000184<p>The LLVM code representation is designed to be used in three
185different forms: as an in-memory compiler IR, as an on-disk bytecode
186representation (suitable for fast loading by a Just-In-Time compiler),
187and as a human readable assembly language representation. This allows
188LLVM to provide a powerful intermediate representation for efficient
189compiler transformations and analysis, while providing a natural means
190to debug and visualize the transformations. The three different forms
191of LLVM are all equivalent. This document describes the human readable
192representation and notation.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000193
Chris Lattner48b383b02003-11-25 01:02:51 +0000194<p>The LLVM representation aims to be a light-weight and low-level
195while being expressive, typed, and extensible at the same time. It
196aims to be a "universal IR" of sorts, by being at a low enough level
197that high-level ideas may be cleanly mapped to it (similar to how
198microprocessors are "universal IR's", allowing many source languages to
199be mapped to them). By providing type information, LLVM can be used as
200the target of optimizations: for example, through pointer analysis, it
201can be proven that a C automatic variable is never accessed outside of
202the current function... allowing it to be promoted to a simple SSA
203value instead of a memory location.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000204
Misha Brukman76307852003-11-08 01:05:38 +0000205</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000206
Chris Lattner2f7c9632001-06-06 20:29:01 +0000207<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000208<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000209
Misha Brukman76307852003-11-08 01:05:38 +0000210<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000211
Chris Lattner48b383b02003-11-25 01:02:51 +0000212<p>It is important to note that this document describes 'well formed'
213LLVM assembly language. There is a difference between what the parser
214accepts and what is considered 'well formed'. For example, the
215following instruction is syntactically okay, but not well formed:</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000216
217<pre>
218 %x = <a href="#i_add">add</a> int 1, %x
219</pre>
220
Chris Lattner48b383b02003-11-25 01:02:51 +0000221<p>...because the definition of <tt>%x</tt> does not dominate all of
222its uses. The LLVM infrastructure provides a verification pass that may
223be used to verify that an LLVM module is well formed. This pass is
224automatically run by the parser after parsing input assembly, and by
225the optimizer before it outputs bytecode. The violations pointed out
226by the verifier pass indicate bugs in transformation passes or input to
227the parser.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000228
Chris Lattner48b383b02003-11-25 01:02:51 +0000229<!-- Describe the typesetting conventions here. --> </div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000230
Chris Lattner2f7c9632001-06-06 20:29:01 +0000231<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000232<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000233<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000234
Misha Brukman76307852003-11-08 01:05:38 +0000235<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000236
Chris Lattner48b383b02003-11-25 01:02:51 +0000237<p>LLVM uses three different forms of identifiers, for different
238purposes:</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000239
Chris Lattner2f7c9632001-06-06 20:29:01 +0000240<ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000241 <li>Named values are represented as a string of characters with a '%' prefix.
242 For example, %foo, %DivisionByZero, %a.really.long.identifier. The actual
243 regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
244 Identifiers which require other characters in their names can be surrounded
245 with quotes. In this way, anything except a <tt>"</tt> character can be used
246 in a name.</li>
247
248 <li>Unnamed values are represented as an unsigned numeric value with a '%'
249 prefix. For example, %12, %2, %44.</li>
250
Reid Spencer8f08d802004-12-09 18:02:53 +0000251 <li>Constants, which are described in a <a href="#constants">section about
252 constants</a>, below.</li>
Misha Brukman76307852003-11-08 01:05:38 +0000253</ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000254
255<p>LLVM requires that values start with a '%' sign for two reasons: Compilers
256don't need to worry about name clashes with reserved words, and the set of
257reserved words may be expanded in the future without penalty. Additionally,
258unnamed identifiers allow a compiler to quickly come up with a temporary
259variable without having to avoid symbol table conflicts.</p>
260
Chris Lattner48b383b02003-11-25 01:02:51 +0000261<p>Reserved words in LLVM are very similar to reserved words in other
262languages. There are keywords for different opcodes ('<tt><a
Chris Lattnerd79749a2004-12-09 16:36:40 +0000263href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
264href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
265href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>', etc...),
266and others. These reserved words cannot conflict with variable names, because
267none of them start with a '%' character.</p>
268
269<p>Here is an example of LLVM code to multiply the integer variable
270'<tt>%X</tt>' by 8:</p>
271
Misha Brukman76307852003-11-08 01:05:38 +0000272<p>The easy way:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000273
274<pre>
275 %result = <a href="#i_mul">mul</a> uint %X, 8
276</pre>
277
Misha Brukman76307852003-11-08 01:05:38 +0000278<p>After strength reduction:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000279
280<pre>
281 %result = <a href="#i_shl">shl</a> uint %X, ubyte 3
282</pre>
283
Misha Brukman76307852003-11-08 01:05:38 +0000284<p>And the hard way:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000285
286<pre>
287 <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
288 <a href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
289 %result = <a href="#i_add">add</a> uint %1, %1
290</pre>
291
Chris Lattner48b383b02003-11-25 01:02:51 +0000292<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
293important lexical features of LLVM:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000294
Chris Lattner2f7c9632001-06-06 20:29:01 +0000295<ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000296
297 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
298 line.</li>
299
300 <li>Unnamed temporaries are created when the result of a computation is not
301 assigned to a named value.</li>
302
Misha Brukman76307852003-11-08 01:05:38 +0000303 <li>Unnamed temporaries are numbered sequentially</li>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000304
Misha Brukman76307852003-11-08 01:05:38 +0000305</ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000306
307<p>...and it also show a convention that we follow in this document. When
308demonstrating instructions, we will follow an instruction with a comment that
309defines the type and name of value produced. Comments are shown in italic
310text.</p>
311
Misha Brukman76307852003-11-08 01:05:38 +0000312</div>
Chris Lattner6af02f32004-12-09 16:11:40 +0000313
314<!-- *********************************************************************** -->
315<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
316<!-- *********************************************************************** -->
317
318<!-- ======================================================================= -->
319<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
320</div>
321
322<div class="doc_text">
323
324<p>LLVM programs are composed of "Module"s, each of which is a
325translation unit of the input programs. Each module consists of
326functions, global variables, and symbol table entries. Modules may be
327combined together with the LLVM linker, which merges function (and
328global variable) definitions, resolves forward declarations, and merges
329symbol table entries. Here is an example of the "hello world" module:</p>
330
331<pre><i>; Declare the string constant as a global constant...</i>
332<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
333 href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00" <i>; [13 x sbyte]*</i>
334
335<i>; External declaration of the puts function</i>
336<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
337
338<i>; Definition of main function</i>
339int %main() { <i>; int()* </i>
340 <i>; Convert [13x sbyte]* to sbyte *...</i>
341 %cast210 = <a
342 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
343
344 <i>; Call puts function to write out the string to stdout...</i>
345 <a
346 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
347 <a
348 href="#i_ret">ret</a> int 0<br>}<br></pre>
349
350<p>This example is made up of a <a href="#globalvars">global variable</a>
351named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
352function, and a <a href="#functionstructure">function definition</a>
353for "<tt>main</tt>".</p>
354
Chris Lattnerd79749a2004-12-09 16:36:40 +0000355<p>In general, a module is made up of a list of global values,
356where both functions and global variables are global values. Global values are
357represented by a pointer to a memory location (in this case, a pointer to an
358array of char, and a pointer to a function), and have one of the following <a
359href="#linkage">linkage types</a>.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000360
Chris Lattnerd79749a2004-12-09 16:36:40 +0000361</div>
362
363<!-- ======================================================================= -->
364<div class="doc_subsection">
365 <a name="linkage">Linkage Types</a>
366</div>
367
368<div class="doc_text">
369
370<p>
371All Global Variables and Functions have one of the following types of linkage:
372</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000373
374<dl>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000375
Chris Lattner6af02f32004-12-09 16:11:40 +0000376 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000377
378 <dd>Global values with internal linkage are only directly accessible by
379 objects in the current module. In particular, linking code into a module with
380 an internal global value may cause the internal to be renamed as necessary to
381 avoid collisions. Because the symbol is internal to the module, all
382 references can be updated. This corresponds to the notion of the
383 '<tt>static</tt>' keyword in C, or the idea of "anonymous namespaces" in C++.
Chris Lattner6af02f32004-12-09 16:11:40 +0000384 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000385
Chris Lattner6af02f32004-12-09 16:11:40 +0000386 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000387
388 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt> linkage, with
389 the twist that linking together two modules defining the same
390 <tt>linkonce</tt> globals will cause one of the globals to be discarded. This
391 is typically used to implement inline functions. Unreferenced
392 <tt>linkonce</tt> globals are allowed to be discarded.
Chris Lattner6af02f32004-12-09 16:11:40 +0000393 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000394
Chris Lattner6af02f32004-12-09 16:11:40 +0000395 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000396
397 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage,
398 except that unreferenced <tt>weak</tt> globals may not be discarded. This is
399 used to implement constructs in C such as "<tt>int X;</tt>" at global scope.
Chris Lattner6af02f32004-12-09 16:11:40 +0000400 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000401
Chris Lattner6af02f32004-12-09 16:11:40 +0000402 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000403
404 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
405 pointer to array type. When two global variables with appending linkage are
406 linked together, the two global arrays are appended together. This is the
407 LLVM, typesafe, equivalent of having the system linker append together
408 "sections" with identical names when .o files are linked.
Chris Lattner6af02f32004-12-09 16:11:40 +0000409 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000410
Chris Lattner6af02f32004-12-09 16:11:40 +0000411 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000412
413 <dd>If none of the above identifiers are used, the global is externally
414 visible, meaning that it participates in linkage and can be used to resolve
415 external symbol references.
Chris Lattner6af02f32004-12-09 16:11:40 +0000416 </dd>
417</dl>
418
Chris Lattner6af02f32004-12-09 16:11:40 +0000419<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
420variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
421variable and was linked with this one, one of the two would be renamed,
422preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
423external (i.e., lacking any linkage declarations), they are accessible
424outside of the current module. It is illegal for a function <i>declaration</i>
425to have any linkage type other than "externally visible".</a></p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000426
Chris Lattner6af02f32004-12-09 16:11:40 +0000427</div>
428
429<!-- ======================================================================= -->
430<div class="doc_subsection">
431 <a name="globalvars">Global Variables</a>
432</div>
433
434<div class="doc_text">
435
Chris Lattner5d5aede2005-02-12 19:30:21 +0000436<p>Global variables define regions of memory allocated at compilation time
437instead of run-time. Global variables may optionally be initialized. A
438variable may be defined as a global "constant", which indicates that the
439contents of the variable will <b>never</b> be modified (enabling better
440optimization, allowing the global data to be placed in the read-only section of
441an executable, etc). Note that variables that need runtime initialization
442cannot be marked "constant", as there is a store to the variable.</p>
443
444<p>
445LLVM explicitly allows <em>declarations</em> of global variables to be marked
446constant, even if the final definition of the global is not. This capability
447can be used to enable slightly better optimization of the program, but requires
448the language definition to guarantee that optimizations based on the
449'constantness' are valid for the translation units that do not include the
450definition.
451</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000452
453<p>As SSA values, global variables define pointer values that are in
454scope (i.e. they dominate) all basic blocks in the program. Global
455variables always define a pointer to their "content" type because they
456describe a region of memory, and all memory objects in LLVM are
457accessed through pointers.</p>
458
459</div>
460
461
462<!-- ======================================================================= -->
463<div class="doc_subsection">
464 <a name="functionstructure">Functions</a>
465</div>
466
467<div class="doc_text">
468
469<p>LLVM function definitions are composed of a (possibly empty) argument list,
470an opening curly brace, a list of basic blocks, and a closing curly brace. LLVM
471function declarations are defined with the "<tt>declare</tt>" keyword, a
472function name, and a function signature.</p>
473
474<p>A function definition contains a list of basic blocks, forming the CFG for
475the function. Each basic block may optionally start with a label (giving the
476basic block a symbol table entry), contains a list of instructions, and ends
477with a <a href="#terminators">terminator</a> instruction (such as a branch or
478function return).</p>
479
480<p>The first basic block in program is special in two ways: it is immediately
481executed on entrance to the function, and it is not allowed to have predecessor
482basic blocks (i.e. there can not be any branches to the entry block of a
483function). Because the block can have no predecessors, it also cannot have any
484<a href="#i_phi">PHI nodes</a>.</p>
485
486<p>LLVM functions are identified by their name and type signature. Hence, two
487functions with the same name but different parameter lists or return values are
Chris Lattner455fc8c2005-03-07 22:13:59 +0000488considered different functions, and LLVM will resolve references to each
Chris Lattner6af02f32004-12-09 16:11:40 +0000489appropriately.</p>
490
491</div>
492
493
494
Chris Lattner2f7c9632001-06-06 20:29:01 +0000495<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000496<div class="doc_section"> <a name="typesystem">Type System</a> </div>
497<!-- *********************************************************************** -->
Chris Lattner6af02f32004-12-09 16:11:40 +0000498
Misha Brukman76307852003-11-08 01:05:38 +0000499<div class="doc_text">
Chris Lattner6af02f32004-12-09 16:11:40 +0000500
Misha Brukman76307852003-11-08 01:05:38 +0000501<p>The LLVM type system is one of the most important features of the
Chris Lattner48b383b02003-11-25 01:02:51 +0000502intermediate representation. Being typed enables a number of
503optimizations to be performed on the IR directly, without having to do
504extra analyses on the side before the transformation. A strong type
505system makes it easier to read the generated code and enables novel
506analyses and transformations that are not feasible to perform on normal
507three address code representations.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000508
509</div>
510
Chris Lattner2f7c9632001-06-06 20:29:01 +0000511<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000512<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000513<div class="doc_text">
John Criswell417228d2004-04-09 16:48:45 +0000514<p>The primitive types are the fundamental building blocks of the LLVM
Chris Lattner455fc8c2005-03-07 22:13:59 +0000515system. The current set of primitive types is as follows:</p>
Misha Brukmanc501f552004-03-01 17:47:27 +0000516
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000517<table class="layout">
518 <tr class="layout">
519 <td class="left">
520 <table>
Chris Lattner48b383b02003-11-25 01:02:51 +0000521 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000522 <tr><th>Type</th><th>Description</th></tr>
523 <tr><td><tt>void</tt></td><td>No value</td></tr>
Misha Brukman36c6bc12005-04-22 18:02:52 +0000524 <tr><td><tt>ubyte</tt></td><td>Unsigned 8-bit value</td></tr>
525 <tr><td><tt>ushort</tt></td><td>Unsigned 16-bit value</td></tr>
526 <tr><td><tt>uint</tt></td><td>Unsigned 32-bit value</td></tr>
527 <tr><td><tt>ulong</tt></td><td>Unsigned 64-bit value</td></tr>
528 <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000529 <tr><td><tt>label</tt></td><td>Branch destination</td></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000530 </tbody>
531 </table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000532 </td>
533 <td class="right">
534 <table>
Chris Lattner48b383b02003-11-25 01:02:51 +0000535 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000536 <tr><th>Type</th><th>Description</th></tr>
537 <tr><td><tt>bool</tt></td><td>True or False value</td></tr>
Misha Brukman36c6bc12005-04-22 18:02:52 +0000538 <tr><td><tt>sbyte</tt></td><td>Signed 8-bit value</td></tr>
539 <tr><td><tt>short</tt></td><td>Signed 16-bit value</td></tr>
540 <tr><td><tt>int</tt></td><td>Signed 32-bit value</td></tr>
541 <tr><td><tt>long</tt></td><td>Signed 64-bit value</td></tr>
542 <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000543 </tbody>
544 </table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000545 </td>
546 </tr>
Misha Brukman76307852003-11-08 01:05:38 +0000547</table>
Misha Brukman76307852003-11-08 01:05:38 +0000548</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000549
Chris Lattner2f7c9632001-06-06 20:29:01 +0000550<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000551<div class="doc_subsubsection"> <a name="t_classifications">Type
552Classifications</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000553<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000554<p>These different primitive types fall into a few useful
555classifications:</p>
Misha Brukmanc501f552004-03-01 17:47:27 +0000556
557<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +0000558 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000559 <tr><th>Classification</th><th>Types</th></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000560 <tr>
561 <td><a name="t_signed">signed</a></td>
562 <td><tt>sbyte, short, int, long, float, double</tt></td>
563 </tr>
564 <tr>
565 <td><a name="t_unsigned">unsigned</a></td>
566 <td><tt>ubyte, ushort, uint, ulong</tt></td>
567 </tr>
568 <tr>
569 <td><a name="t_integer">integer</a></td>
570 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
571 </tr>
572 <tr>
573 <td><a name="t_integral">integral</a></td>
Misha Brukman20f9a622004-08-12 20:16:08 +0000574 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt>
575 </td>
Chris Lattner48b383b02003-11-25 01:02:51 +0000576 </tr>
577 <tr>
578 <td><a name="t_floating">floating point</a></td>
579 <td><tt>float, double</tt></td>
580 </tr>
581 <tr>
582 <td><a name="t_firstclass">first class</a></td>
Misha Brukman20f9a622004-08-12 20:16:08 +0000583 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long,<br>
584 float, double, <a href="#t_pointer">pointer</a>,
585 <a href="#t_packed">packed</a></tt></td>
Chris Lattner48b383b02003-11-25 01:02:51 +0000586 </tr>
587 </tbody>
Misha Brukman76307852003-11-08 01:05:38 +0000588</table>
Misha Brukmanc501f552004-03-01 17:47:27 +0000589
Chris Lattner48b383b02003-11-25 01:02:51 +0000590<p>The <a href="#t_firstclass">first class</a> types are perhaps the
591most important. Values of these types are the only ones which can be
592produced by instructions, passed as arguments, or used as operands to
593instructions. This means that all structures and arrays must be
594manipulated either by pointer or by component.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000595</div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000596
Chris Lattner2f7c9632001-06-06 20:29:01 +0000597<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000598<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000599
Misha Brukman76307852003-11-08 01:05:38 +0000600<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +0000601
Chris Lattner48b383b02003-11-25 01:02:51 +0000602<p>The real power in LLVM comes from the derived types in the system.
603This is what allows a programmer to represent arrays, functions,
604pointers, and other useful types. Note that these derived types may be
605recursive: For example, it is possible to have a two dimensional array.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000606
Misha Brukman76307852003-11-08 01:05:38 +0000607</div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000608
Chris Lattner2f7c9632001-06-06 20:29:01 +0000609<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000610<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000611
Misha Brukman76307852003-11-08 01:05:38 +0000612<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +0000613
Chris Lattner2f7c9632001-06-06 20:29:01 +0000614<h5>Overview:</h5>
Chris Lattner74d3f822004-12-09 17:30:23 +0000615
Misha Brukman76307852003-11-08 01:05:38 +0000616<p>The array type is a very simple derived type that arranges elements
Chris Lattner48b383b02003-11-25 01:02:51 +0000617sequentially in memory. The array type requires a size (number of
618elements) and an underlying data type.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000619
Chris Lattner590645f2002-04-14 06:13:44 +0000620<h5>Syntax:</h5>
Chris Lattner74d3f822004-12-09 17:30:23 +0000621
622<pre>
623 [&lt;# elements&gt; x &lt;elementtype&gt;]
624</pre>
625
Chris Lattner48b383b02003-11-25 01:02:51 +0000626<p>The number of elements is a constant integer value, elementtype may
627be any type with a size.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000628
Chris Lattner590645f2002-04-14 06:13:44 +0000629<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000630<table class="layout">
631 <tr class="layout">
632 <td class="left">
633 <tt>[40 x int ]</tt><br/>
634 <tt>[41 x int ]</tt><br/>
635 <tt>[40 x uint]</tt><br/>
636 </td>
637 <td class="left">
638 Array of 40 integer values.<br/>
639 Array of 41 integer values.<br/>
640 Array of 40 unsigned integer values.<br/>
641 </td>
642 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000643</table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000644<p>Here are some examples of multidimensional arrays:</p>
645<table class="layout">
646 <tr class="layout">
647 <td class="left">
648 <tt>[3 x [4 x int]]</tt><br/>
649 <tt>[12 x [10 x float]]</tt><br/>
650 <tt>[2 x [3 x [4 x uint]]]</tt><br/>
651 </td>
652 <td class="left">
653 3x4 array integer values.<br/>
654 12x10 array of single precision floating point values.<br/>
655 2x3x4 array of unsigned integer values.<br/>
656 </td>
657 </tr>
658</table>
Misha Brukman76307852003-11-08 01:05:38 +0000659</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000660
Chris Lattner2f7c9632001-06-06 20:29:01 +0000661<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000662<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000663<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000664<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000665<p>The function type can be thought of as a function signature. It
666consists of a return type and a list of formal parameter types.
John Criswella0d50d22003-11-25 21:45:46 +0000667Function types are usually used to build virtual function tables
Chris Lattner48b383b02003-11-25 01:02:51 +0000668(which are structures of pointers to functions), for indirect function
669calls, and when defining a function.</p>
John Criswella0d50d22003-11-25 21:45:46 +0000670<p>
671The return type of a function type cannot be an aggregate type.
672</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000673<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000674<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
Misha Brukman20f9a622004-08-12 20:16:08 +0000675<p>Where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
676specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner5ed60612003-09-03 00:41:47 +0000677which indicates that the function takes a variable number of arguments.
678Variable argument functions can access their arguments with the <a
Chris Lattner48b383b02003-11-25 01:02:51 +0000679 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000680<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000681<table class="layout">
682 <tr class="layout">
683 <td class="left">
684 <tt>int (int)</tt> <br/>
685 <tt>float (int, int *) *</tt><br/>
686 <tt>int (sbyte *, ...)</tt><br/>
687 </td>
688 <td class="left">
689 function taking an <tt>int</tt>, returning an <tt>int</tt><br/>
690 <a href="#t_pointer">Pointer</a> to a function that takes an
Misha Brukman20f9a622004-08-12 20:16:08 +0000691 <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000692 returning <tt>float</tt>.<br/>
693 A vararg function that takes at least one <a href="#t_pointer">pointer</a>
694 to <tt>sbyte</tt> (signed char in C), which returns an integer. This is
695 the signature for <tt>printf</tt> in LLVM.<br/>
696 </td>
697 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000698</table>
Misha Brukmanc501f552004-03-01 17:47:27 +0000699
Misha Brukman76307852003-11-08 01:05:38 +0000700</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000701<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000702<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000703<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000704<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000705<p>The structure type is used to represent a collection of data members
706together in memory. The packing of the field types is defined to match
707the ABI of the underlying processor. The elements of a structure may
708be any type that has a size.</p>
709<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
710and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
711field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
712instruction.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000713<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000714<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000715<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000716<table class="layout">
717 <tr class="layout">
718 <td class="left">
719 <tt>{ int, int, int }</tt><br/>
720 <tt>{ float, int (int) * }</tt><br/>
721 </td>
722 <td class="left">
723 a triple of three <tt>int</tt> values<br/>
724 A pair, where the first element is a <tt>float</tt> and the second element
725 is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a>
726 that takes an <tt>int</tt>, returning an <tt>int</tt>.<br/>
727 </td>
728 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000729</table>
Misha Brukman76307852003-11-08 01:05:38 +0000730</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000731
Chris Lattner2f7c9632001-06-06 20:29:01 +0000732<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000733<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000734<div class="doc_text">
Chris Lattner590645f2002-04-14 06:13:44 +0000735<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000736<p>As in many languages, the pointer type represents a pointer or
737reference to another object, which must live in memory.</p>
Chris Lattner590645f2002-04-14 06:13:44 +0000738<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000739<pre> &lt;type&gt; *<br></pre>
Chris Lattner590645f2002-04-14 06:13:44 +0000740<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000741<table class="layout">
742 <tr class="layout">
743 <td class="left">
744 <tt>[4x int]*</tt><br/>
745 <tt>int (int *) *</tt><br/>
746 </td>
747 <td class="left">
748 A <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of
749 four <tt>int</tt> values<br/>
750 A <a href="#t_pointer">pointer</a> to a <a
Chris Lattner16fb0032005-02-19 02:22:14 +0000751 href="#t_function">function</a> that takes an <tt>int*</tt>, returning an
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000752 <tt>int</tt>.<br/>
753 </td>
754 </tr>
Misha Brukman76307852003-11-08 01:05:38 +0000755</table>
Misha Brukman76307852003-11-08 01:05:38 +0000756</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000757
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000758<!-- _______________________________________________________________________ -->
759<div class="doc_subsubsection"> <a name="t_packed">Packed Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000760<div class="doc_text">
Chris Lattner37b6b092005-04-25 17:34:15 +0000761
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000762<h5>Overview:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +0000763
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000764<p>A packed type is a simple derived type that represents a vector
765of elements. Packed types are used when multiple primitive data
766are operated in parallel using a single instruction (SIMD).
767A packed type requires a size (number of
768elements) and an underlying primitive data type. Packed types are
769considered <a href="#t_firstclass">first class</a>.</p>
Chris Lattner37b6b092005-04-25 17:34:15 +0000770
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000771<h5>Syntax:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +0000772
773<pre>
774 &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;
775</pre>
776
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000777<p>The number of elements is a constant integer value, elementtype may
778be any integral or floating point type.</p>
Chris Lattner37b6b092005-04-25 17:34:15 +0000779
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000780<h5>Examples:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +0000781
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000782<table class="layout">
783 <tr class="layout">
784 <td class="left">
785 <tt>&lt;4 x int&gt;</tt><br/>
786 <tt>&lt;8 x float&gt;</tt><br/>
787 <tt>&lt;2 x uint&gt;</tt><br/>
788 </td>
789 <td class="left">
790 Packed vector of 4 integer values.<br/>
791 Packed vector of 8 floating-point values.<br/>
792 Packed vector of 2 unsigned integer values.<br/>
793 </td>
794 </tr>
795</table>
Misha Brukman76307852003-11-08 01:05:38 +0000796</div>
797
Chris Lattner37b6b092005-04-25 17:34:15 +0000798<!-- _______________________________________________________________________ -->
799<div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div>
800<div class="doc_text">
801
802<h5>Overview:</h5>
803
804<p>Opaque types are used to represent unknown types in the system. This
805corresponds (for example) to the C notion of a foward declared structure type.
806In LLVM, opaque types can eventually be resolved to any type (not just a
807structure type).</p>
808
809<h5>Syntax:</h5>
810
811<pre>
812 opaque
813</pre>
814
815<h5>Examples:</h5>
816
817<table class="layout">
818 <tr class="layout">
819 <td class="left">
820 <tt>opaque</tt>
821 </td>
822 <td class="left">
823 An opaque type.<br/>
824 </td>
825 </tr>
826</table>
827</div>
828
829
Chris Lattner74d3f822004-12-09 17:30:23 +0000830<!-- *********************************************************************** -->
831<div class="doc_section"> <a name="constants">Constants</a> </div>
832<!-- *********************************************************************** -->
833
834<div class="doc_text">
835
836<p>LLVM has several different basic types of constants. This section describes
837them all and their syntax.</p>
838
839</div>
840
841<!-- ======================================================================= -->
Reid Spencer8f08d802004-12-09 18:02:53 +0000842<div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000843
844<div class="doc_text">
845
846<dl>
847 <dt><b>Boolean constants</b></dt>
848
849 <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
850 constants of the <tt><a href="#t_primitive">bool</a></tt> type.
851 </dd>
852
853 <dt><b>Integer constants</b></dt>
854
Reid Spencer8f08d802004-12-09 18:02:53 +0000855 <dd>Standard integers (such as '4') are constants of the <a
Chris Lattner74d3f822004-12-09 17:30:23 +0000856 href="#t_integer">integer</a> type. Negative numbers may be used with signed
857 integer types.
858 </dd>
859
860 <dt><b>Floating point constants</b></dt>
861
862 <dd>Floating point constants use standard decimal notation (e.g. 123.421),
863 exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
Reid Spencer8f08d802004-12-09 18:02:53 +0000864 notation. Floating point constants have an optional hexadecimal
Chris Lattner74d3f822004-12-09 17:30:23 +0000865 notation (see below). Floating point constants must have a <a
866 href="#t_floating">floating point</a> type. </dd>
867
868 <dt><b>Null pointer constants</b></dt>
869
John Criswelldfe6a862004-12-10 15:51:16 +0000870 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
Chris Lattner74d3f822004-12-09 17:30:23 +0000871 and must be of <a href="#t_pointer">pointer type</a>.</dd>
872
873</dl>
874
John Criswelldfe6a862004-12-10 15:51:16 +0000875<p>The one non-intuitive notation for constants is the optional hexadecimal form
Chris Lattner74d3f822004-12-09 17:30:23 +0000876of floating point constants. For example, the form '<tt>double
8770x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
8784.5e+15</tt>'. The only time hexadecimal floating point constants are required
Reid Spencer8f08d802004-12-09 18:02:53 +0000879(and the only time that they are generated by the disassembler) is when a
880floating point constant must be emitted but it cannot be represented as a
881decimal floating point number. For example, NaN's, infinities, and other
882special values are represented in their IEEE hexadecimal format so that
883assembly and disassembly do not cause any bits to change in the constants.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000884
885</div>
886
887<!-- ======================================================================= -->
888<div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a>
889</div>
890
891<div class="doc_text">
Chris Lattner455fc8c2005-03-07 22:13:59 +0000892<p>Aggregate constants arise from aggregation of simple constants
893and smaller aggregate constants.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000894
895<dl>
896 <dt><b>Structure constants</b></dt>
897
898 <dd>Structure constants are represented with notation similar to structure
899 type definitions (a comma separated list of elements, surrounded by braces
Chris Lattner455fc8c2005-03-07 22:13:59 +0000900 (<tt>{}</tt>)). For example: "<tt>{ int 4, float 17.0, int* %G }</tt>",
901 where "<tt>%G</tt>" is declared as "<tt>%G = external global int</tt>". Structure constants
902 must have <a href="#t_struct">structure type</a>, and the number and
Chris Lattner74d3f822004-12-09 17:30:23 +0000903 types of elements must match those specified by the type.
904 </dd>
905
906 <dt><b>Array constants</b></dt>
907
908 <dd>Array constants are represented with notation similar to array type
909 definitions (a comma separated list of elements, surrounded by square brackets
John Criswelldfe6a862004-12-10 15:51:16 +0000910 (<tt>[]</tt>)). For example: "<tt>[ int 42, int 11, int 74 ]</tt>". Array
Chris Lattner74d3f822004-12-09 17:30:23 +0000911 constants must have <a href="#t_array">array type</a>, and the number and
912 types of elements must match those specified by the type.
913 </dd>
914
915 <dt><b>Packed constants</b></dt>
916
917 <dd>Packed constants are represented with notation similar to packed type
918 definitions (a comma separated list of elements, surrounded by
John Criswelldfe6a862004-12-10 15:51:16 +0000919 less-than/greater-than's (<tt>&lt;&gt;</tt>)). For example: "<tt>&lt; int 42,
Chris Lattner74d3f822004-12-09 17:30:23 +0000920 int 11, int 74, int 100 &gt;</tt>". Packed constants must have <a
921 href="#t_packed">packed type</a>, and the number and types of elements must
922 match those specified by the type.
923 </dd>
924
925 <dt><b>Zero initialization</b></dt>
926
927 <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
928 value to zero of <em>any</em> type, including scalar and aggregate types.
929 This is often used to avoid having to print large zero initializers (e.g. for
930 large arrays), and is always exactly equivalent to using explicit zero
931 initializers.
932 </dd>
933</dl>
934
935</div>
936
937<!-- ======================================================================= -->
938<div class="doc_subsection">
939 <a name="globalconstants">Global Variable and Function Addresses</a>
940</div>
941
942<div class="doc_text">
943
944<p>The addresses of <a href="#globalvars">global variables</a> and <a
945href="#functionstructure">functions</a> are always implicitly valid (link-time)
John Criswelldfe6a862004-12-10 15:51:16 +0000946constants. These constants are explicitly referenced when the <a
947href="#identifiers">identifier for the global</a> is used and always have <a
Chris Lattner74d3f822004-12-09 17:30:23 +0000948href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
949file:</p>
950
951<pre>
952 %X = global int 17
953 %Y = global int 42
954 %Z = global [2 x int*] [ int* %X, int* %Y ]
955</pre>
956
957</div>
958
959<!-- ======================================================================= -->
Reid Spencer641f5c92004-12-09 18:13:12 +0000960<div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000961<div class="doc_text">
Reid Spencer641f5c92004-12-09 18:13:12 +0000962 <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has
963 no specific value. Undefined values may be of any type, and be used anywhere
964 a constant is permitted.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000965
Reid Spencer641f5c92004-12-09 18:13:12 +0000966 <p>Undefined values indicate to the compiler that the program is well defined
967 no matter what value is used, giving the compiler more freedom to optimize.
968 </p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000969</div>
970
971<!-- ======================================================================= -->
972<div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
973</div>
974
975<div class="doc_text">
976
977<p>Constant expressions are used to allow expressions involving other constants
978to be used as constants. Constant expressions may be of any <a
979href="#t_firstclass">first class</a> type, and may involve any LLVM operation
980that does not have side effects (e.g. load and call are not supported). The
981following is the syntax for constant expressions:</p>
982
983<dl>
984 <dt><b><tt>cast ( CST to TYPE )</tt></b></dt>
985
986 <dd>Cast a constant to another type.</dd>
987
988 <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
989
990 <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
991 constants. As with the <a href="#i_getelementptr">getelementptr</a>
992 instruction, the index list may have zero or more indexes, which are required
993 to make sense for the type of "CSTPTR".</dd>
994
995 <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
996
Reid Spencer641f5c92004-12-09 18:13:12 +0000997 <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
998 be any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise
Chris Lattner74d3f822004-12-09 17:30:23 +0000999 binary</a> operations. The constraints on operands are the same as those for
1000 the corresponding instruction (e.g. no bitwise operations on floating point
1001 are allowed).</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001002</dl>
Chris Lattner74d3f822004-12-09 17:30:23 +00001003</div>
Chris Lattnerb1652612004-03-08 16:49:10 +00001004
Chris Lattner2f7c9632001-06-06 20:29:01 +00001005<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001006<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
1007<!-- *********************************************************************** -->
Chris Lattner74d3f822004-12-09 17:30:23 +00001008
Misha Brukman76307852003-11-08 01:05:38 +00001009<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00001010
Chris Lattner48b383b02003-11-25 01:02:51 +00001011<p>The LLVM instruction set consists of several different
1012classifications of instructions: <a href="#terminators">terminator
1013instructions</a>, <a href="#binaryops">binary instructions</a>, <a
1014 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
1015instructions</a>.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001016
Misha Brukman76307852003-11-08 01:05:38 +00001017</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001018
Chris Lattner2f7c9632001-06-06 20:29:01 +00001019<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001020<div class="doc_subsection"> <a name="terminators">Terminator
1021Instructions</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001022
Misha Brukman76307852003-11-08 01:05:38 +00001023<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00001024
Chris Lattner48b383b02003-11-25 01:02:51 +00001025<p>As mentioned <a href="#functionstructure">previously</a>, every
1026basic block in a program ends with a "Terminator" instruction, which
1027indicates which block should be executed after the current block is
1028finished. These terminator instructions typically yield a '<tt>void</tt>'
1029value: they produce control flow, not values (the one exception being
1030the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
John Criswelldfe6a862004-12-10 15:51:16 +00001031<p>There are six different terminator instructions: the '<a
Chris Lattner48b383b02003-11-25 01:02:51 +00001032 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
1033instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001034the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
1035 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
1036 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001037
Misha Brukman76307852003-11-08 01:05:38 +00001038</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001039
Chris Lattner2f7c9632001-06-06 20:29:01 +00001040<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001041<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
1042Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001043<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001044<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001045<pre> ret &lt;type&gt; &lt;value&gt; <i>; Return a value from a non-void function</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001046 ret void <i>; Return from void function</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001047</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001048<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001049<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
1050value) from a function, back to the caller.</p>
John Criswell417228d2004-04-09 16:48:45 +00001051<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner48b383b02003-11-25 01:02:51 +00001052returns a value and then causes control flow, and one that just causes
1053control flow to occur.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001054<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001055<p>The '<tt>ret</tt>' instruction may return any '<a
1056 href="#t_firstclass">first class</a>' type. Notice that a function is
1057not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
1058instruction inside of the function that returns a value that does not
1059match the return type of the function.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001060<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001061<p>When the '<tt>ret</tt>' instruction is executed, control flow
1062returns back to the calling function's context. If the caller is a "<a
John Criswell40db33f2004-06-25 15:16:57 +00001063 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner48b383b02003-11-25 01:02:51 +00001064the instruction after the call. If the caller was an "<a
1065 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
1066at the beginning "normal" of the destination block. If the instruction
1067returns a value, that value shall set the call or invoke instruction's
1068return value.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001069<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001070<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001071 ret void <i>; Return from a void function</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001072</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001073</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001074<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001075<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001076<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001077<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001078<pre> br bool &lt;cond&gt;, label &lt;iftrue&gt;, label &lt;iffalse&gt;<br> br label &lt;dest&gt; <i>; Unconditional branch</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001079</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001080<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001081<p>The '<tt>br</tt>' instruction is used to cause control flow to
1082transfer to a different basic block in the current function. There are
1083two forms of this instruction, corresponding to a conditional branch
1084and an unconditional branch.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001085<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001086<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
1087single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
1088unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
1089value as a target.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001090<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001091<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
1092argument is evaluated. If the value is <tt>true</tt>, control flows
1093to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
1094control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001095<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001096<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
1097 href="#i_ret">ret</a> int 1<br>IfUnequal:<br> <a href="#i_ret">ret</a> int 0<br></pre>
Misha Brukman76307852003-11-08 01:05:38 +00001098</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001099<!-- _______________________________________________________________________ -->
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001100<div class="doc_subsubsection">
1101 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
1102</div>
1103
Misha Brukman76307852003-11-08 01:05:38 +00001104<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001105<h5>Syntax:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001106
1107<pre>
1108 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
1109</pre>
1110
Chris Lattner2f7c9632001-06-06 20:29:01 +00001111<h5>Overview:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001112
1113<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
1114several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman76307852003-11-08 01:05:38 +00001115instruction, allowing a branch to occur to one of many possible
1116destinations.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001117
1118
Chris Lattner2f7c9632001-06-06 20:29:01 +00001119<h5>Arguments:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001120
1121<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
1122comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
1123an array of pairs of comparison value constants and '<tt>label</tt>'s. The
1124table is not allowed to contain duplicate constant entries.</p>
1125
Chris Lattner2f7c9632001-06-06 20:29:01 +00001126<h5>Semantics:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001127
Chris Lattner48b383b02003-11-25 01:02:51 +00001128<p>The <tt>switch</tt> instruction specifies a table of values and
1129destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswellbcbb18c2004-06-25 16:05:06 +00001130table is searched for the given value. If the value is found, control flow is
1131transfered to the corresponding destination; otherwise, control flow is
1132transfered to the default destination.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001133
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001134<h5>Implementation:</h5>
1135
1136<p>Depending on properties of the target machine and the particular
1137<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswellbcbb18c2004-06-25 16:05:06 +00001138ways. For example, it could be generated as a series of chained conditional
1139branches or with a lookup table.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001140
1141<h5>Example:</h5>
1142
1143<pre>
1144 <i>; Emulate a conditional br instruction</i>
1145 %Val = <a href="#i_cast">cast</a> bool %value to int
1146 switch int %Val, label %truedest [int 0, label %falsedest ]
1147
1148 <i>; Emulate an unconditional br instruction</i>
1149 switch uint 0, label %dest [ ]
1150
1151 <i>; Implement a jump table:</i>
1152 switch uint %val, label %otherwise [ uint 0, label %onzero
1153 uint 1, label %onone
1154 uint 2, label %ontwo ]
Chris Lattner2f7c9632001-06-06 20:29:01 +00001155</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001156</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001157<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001158<div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>'
1159Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001160<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001161<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001162<pre> &lt;result&gt; = invoke &lt;ptr to function ty&gt; %&lt;function ptr val&gt;(&lt;function args&gt;)<br> to label &lt;normal label&gt; except label &lt;exception label&gt;<br></pre>
Chris Lattnera8292f32002-05-06 22:08:29 +00001163<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001164<p>The '<tt>invoke</tt>' instruction causes control to transfer to a
1165specified function, with the possibility of control flow transfer to
1166either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>.
1167If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>"
1168instruction, control flow will return to the "normal" label. If the
1169callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
1170instruction, control is interrupted, and continued at the dynamically
1171nearest "except" label.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001172<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001173<p>This instruction requires several arguments:</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001174<ol>
Chris Lattner48b383b02003-11-25 01:02:51 +00001175 <li>'<tt>ptr to function ty</tt>': shall be the signature of the
1176pointer to function value being invoked. In most cases, this is a
1177direct function invocation, but indirect <tt>invoke</tt>s are just as
1178possible, branching off an arbitrary pointer to function value. </li>
1179 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer
1180to a function to be invoked. </li>
1181 <li>'<tt>function args</tt>': argument list whose types match the
1182function signature argument types. If the function signature indicates
1183the function accepts a variable number of arguments, the extra
1184arguments can be specified. </li>
1185 <li>'<tt>normal label</tt>': the label reached when the called
1186function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
1187 <li>'<tt>exception label</tt>': the label reached when a callee
1188returns with the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001189</ol>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001190<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001191<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner48b383b02003-11-25 01:02:51 +00001192 href="#i_call">call</a></tt>' instruction in most regards. The
1193primary difference is that it establishes an association with a label,
1194which is used by the runtime library to unwind the stack.</p>
1195<p>This instruction is used in languages with destructors to ensure
1196that proper cleanup is performed in the case of either a <tt>longjmp</tt>
1197or a thrown exception. Additionally, this is important for
1198implementation of '<tt>catch</tt>' clauses in high-level languages that
1199support them.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001200<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001201<pre> %retval = invoke int %Test(int 15)<br> to label %Continue<br> except label %TestCleanup <i>; {int}:retval set</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001202</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001203</div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001204
1205
Chris Lattner5ed60612003-09-03 00:41:47 +00001206<!-- _______________________________________________________________________ -->
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001207
Chris Lattner48b383b02003-11-25 01:02:51 +00001208<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
1209Instruction</a> </div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001210
Misha Brukman76307852003-11-08 01:05:38 +00001211<div class="doc_text">
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001212
Chris Lattner5ed60612003-09-03 00:41:47 +00001213<h5>Syntax:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001214<pre>
1215 unwind
1216</pre>
1217
Chris Lattner5ed60612003-09-03 00:41:47 +00001218<h5>Overview:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001219
1220<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
1221at the first callee in the dynamic call stack which used an <a
1222href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
1223primarily used to implement exception handling.</p>
1224
Chris Lattner5ed60612003-09-03 00:41:47 +00001225<h5>Semantics:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001226
1227<p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to
1228immediately halt. The dynamic call stack is then searched for the first <a
1229href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
1230execution continues at the "exceptional" destination block specified by the
1231<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
1232dynamic call chain, undefined behavior results.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001233</div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001234
1235<!-- _______________________________________________________________________ -->
1236
1237<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
1238Instruction</a> </div>
1239
1240<div class="doc_text">
1241
1242<h5>Syntax:</h5>
1243<pre>
1244 unreachable
1245</pre>
1246
1247<h5>Overview:</h5>
1248
1249<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
1250instruction is used to inform the optimizer that a particular portion of the
1251code is not reachable. This can be used to indicate that the code after a
1252no-return function cannot be reached, and other facts.</p>
1253
1254<h5>Semantics:</h5>
1255
1256<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
1257</div>
1258
1259
1260
Chris Lattner2f7c9632001-06-06 20:29:01 +00001261<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001262<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001263<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +00001264<p>Binary operators are used to do most of the computation in a
1265program. They require two operands, execute an operation on them, and
John Criswelldfe6a862004-12-10 15:51:16 +00001266produce a single value. The operands might represent
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001267multiple data, as is the case with the <a href="#t_packed">packed</a> data type.
1268The result value of a binary operator is not
Chris Lattner48b383b02003-11-25 01:02:51 +00001269necessarily the same type as its operands.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001270<p>There are several different binary operators:</p>
Misha Brukman76307852003-11-08 01:05:38 +00001271</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001272<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001273<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
1274Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001275<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001276<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001277<pre> &lt;result&gt; = add &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001278</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001279<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001280<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001281<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001282<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001283 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
1284 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1285Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001286<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001287<p>The value produced is the integer or floating point sum of the two
1288operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001289<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001290<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001291</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001292</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001293<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001294<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
1295Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001296<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001297<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001298<pre> &lt;result&gt; = sub &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001299</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001300<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001301<p>The '<tt>sub</tt>' instruction returns the difference of its two
1302operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001303<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
1304instruction present in most other intermediate representations.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001305<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001306<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001307 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001308values.
1309This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1310Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001311<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001312<p>The value produced is the integer or floating point difference of
1313the two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001314<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001315<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001316 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
1317</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001318</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001319<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001320<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
1321Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001322<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001323<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001324<pre> &lt;result&gt; = mul &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001325</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001326<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001327<p>The '<tt>mul</tt>' instruction returns the product of its two
1328operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001329<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001330<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001331 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001332values.
1333This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1334Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001335<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001336<p>The value produced is the integer or floating point product of the
Misha Brukman76307852003-11-08 01:05:38 +00001337two operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001338<p>There is no signed vs unsigned multiplication. The appropriate
1339action is taken based on the type of the operand.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001340<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001341<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001342</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001343</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001344<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001345<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
1346Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001347<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001348<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001349<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1350</pre>
1351<h5>Overview:</h5>
1352<p>The '<tt>div</tt>' instruction returns the quotient of its two
1353operands.</p>
1354<h5>Arguments:</h5>
1355<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
1356 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001357values.
1358This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1359Both arguments must have identical types.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001360<h5>Semantics:</h5>
1361<p>The value produced is the integer or floating point quotient of the
1362two operands.</p>
1363<h5>Example:</h5>
1364<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
1365</pre>
1366</div>
1367<!-- _______________________________________________________________________ -->
1368<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
1369Instruction</a> </div>
1370<div class="doc_text">
1371<h5>Syntax:</h5>
1372<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1373</pre>
1374<h5>Overview:</h5>
1375<p>The '<tt>rem</tt>' instruction returns the remainder from the
1376division of its two operands.</p>
1377<h5>Arguments:</h5>
1378<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1379 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001380values.
1381This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1382Both arguments must have identical types.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001383<h5>Semantics:</h5>
1384<p>This returns the <i>remainder</i> of a division (where the result
1385has the same sign as the divisor), not the <i>modulus</i> (where the
1386result has the same sign as the dividend) of a value. For more
1387information about the difference, see: <a
1388 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1389Math Forum</a>.</p>
1390<h5>Example:</h5>
1391<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1392</pre>
1393</div>
1394<!-- _______________________________________________________________________ -->
1395<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1396Instructions</a> </div>
1397<div class="doc_text">
1398<h5>Syntax:</h5>
1399<pre> &lt;result&gt; = seteq &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001400 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1401 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1402 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1403 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1404 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1405</pre>
Chris Lattner48b383b02003-11-25 01:02:51 +00001406<h5>Overview:</h5>
1407<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1408value based on a comparison of their two operands.</p>
1409<h5>Arguments:</h5>
1410<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1411be of <a href="#t_firstclass">first class</a> type (it is not possible
1412to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1413or '<tt>void</tt>' values, etc...). Both arguments must have identical
1414types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001415<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001416<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1417value if both operands are equal.<br>
1418The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1419value if both operands are unequal.<br>
1420The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1421value if the first operand is less than the second operand.<br>
1422The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1423value if the first operand is greater than the second operand.<br>
1424The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1425value if the first operand is less than or equal to the second operand.<br>
1426The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1427value if the first operand is greater than or equal to the second
1428operand.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001429<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001430<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001431 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
1432 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1433 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1434 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1435 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1436</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001437</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001438<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001439<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1440Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001441<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +00001442<p>Bitwise binary operators are used to do various forms of
1443bit-twiddling in a program. They are generally very efficient
John Criswelldfe6a862004-12-10 15:51:16 +00001444instructions and can commonly be strength reduced from other
Chris Lattner48b383b02003-11-25 01:02:51 +00001445instructions. They require two operands, execute an operation on them,
1446and produce a single value. The resulting value of the bitwise binary
1447operators is always the same type as its first operand.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001448</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001449<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001450<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1451Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001452<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001453<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001454<pre> &lt;result&gt; = and &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001455</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001456<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001457<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1458its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001459<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001460<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001461 href="#t_integral">integral</a> values. Both arguments must have
1462identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001463<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001464<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001465<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00001466<div style="align: center">
Misha Brukman76307852003-11-08 01:05:38 +00001467<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +00001468 <tbody>
1469 <tr>
1470 <td>In0</td>
1471 <td>In1</td>
1472 <td>Out</td>
1473 </tr>
1474 <tr>
1475 <td>0</td>
1476 <td>0</td>
1477 <td>0</td>
1478 </tr>
1479 <tr>
1480 <td>0</td>
1481 <td>1</td>
1482 <td>0</td>
1483 </tr>
1484 <tr>
1485 <td>1</td>
1486 <td>0</td>
1487 <td>0</td>
1488 </tr>
1489 <tr>
1490 <td>1</td>
1491 <td>1</td>
1492 <td>1</td>
1493 </tr>
1494 </tbody>
1495</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001496</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001497<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001498<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001499 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1500 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1501</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001502</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001503<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001504<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001505<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001506<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001507<pre> &lt;result&gt; = or &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001508</pre>
Chris Lattner48b383b02003-11-25 01:02:51 +00001509<h5>Overview:</h5>
1510<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1511or of its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001512<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001513<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001514 href="#t_integral">integral</a> values. Both arguments must have
1515identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001516<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001517<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001518<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00001519<div style="align: center">
Chris Lattner48b383b02003-11-25 01:02:51 +00001520<table border="1" cellspacing="0" cellpadding="4">
1521 <tbody>
1522 <tr>
1523 <td>In0</td>
1524 <td>In1</td>
1525 <td>Out</td>
1526 </tr>
1527 <tr>
1528 <td>0</td>
1529 <td>0</td>
1530 <td>0</td>
1531 </tr>
1532 <tr>
1533 <td>0</td>
1534 <td>1</td>
1535 <td>1</td>
1536 </tr>
1537 <tr>
1538 <td>1</td>
1539 <td>0</td>
1540 <td>1</td>
1541 </tr>
1542 <tr>
1543 <td>1</td>
1544 <td>1</td>
1545 <td>1</td>
1546 </tr>
1547 </tbody>
1548</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001549</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001550<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001551<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001552 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1553 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1554</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001555</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001556<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001557<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1558Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001559<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001560<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001561<pre> &lt;result&gt; = xor &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001562</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001563<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001564<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1565or of its two operands. The <tt>xor</tt> is used to implement the
1566"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001567<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001568<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001569 href="#t_integral">integral</a> values. Both arguments must have
1570identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001571<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001572<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001573<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00001574<div style="align: center">
Chris Lattner48b383b02003-11-25 01:02:51 +00001575<table border="1" cellspacing="0" cellpadding="4">
1576 <tbody>
1577 <tr>
1578 <td>In0</td>
1579 <td>In1</td>
1580 <td>Out</td>
1581 </tr>
1582 <tr>
1583 <td>0</td>
1584 <td>0</td>
1585 <td>0</td>
1586 </tr>
1587 <tr>
1588 <td>0</td>
1589 <td>1</td>
1590 <td>1</td>
1591 </tr>
1592 <tr>
1593 <td>1</td>
1594 <td>0</td>
1595 <td>1</td>
1596 </tr>
1597 <tr>
1598 <td>1</td>
1599 <td>1</td>
1600 <td>0</td>
1601 </tr>
1602 </tbody>
1603</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001604</div>
Chris Lattner48b383b02003-11-25 01:02:51 +00001605<p> </p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001606<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001607<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001608 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1609 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner5ed60612003-09-03 00:41:47 +00001610 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001611</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001612</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001613<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001614<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1615Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001616<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001617<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001618<pre> &lt;result&gt; = shl &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001619</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001620<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001621<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1622the left a specified number of bits.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001623<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001624<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001625 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1626type.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001627<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001628<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001629<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001630<pre> &lt;result&gt; = shl int 4, ubyte %var <i>; yields {int}:result = 4 &lt;&lt; %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001631 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1632 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1633</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001634</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001635<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001636<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1637Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001638<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001639<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001640<pre> &lt;result&gt; = shr &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001641</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001642<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001643<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1644the right a specified number of bits.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001645<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001646<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001647 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1648type.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001649<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001650<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1651most significant bit is duplicated in the newly free'd bit positions.
1652If the first argument is unsigned, zero bits shall fill the empty
1653positions.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001654<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001655<pre> &lt;result&gt; = shr int 4, ubyte %var <i>; yields {int}:result = 4 &gt;&gt; %var</i>
Chris Lattner33426d92003-06-18 21:30:51 +00001656 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001657 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner33426d92003-06-18 21:30:51 +00001658 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1659 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001660</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001661</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001662<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001663<div class="doc_subsection"> <a name="memoryops">Memory Access
1664Operations</a></div>
Misha Brukman76307852003-11-08 01:05:38 +00001665<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +00001666<p>A key design point of an SSA-based representation is how it
1667represents memory. In LLVM, no memory locations are in SSA form, which
1668makes things very simple. This section describes how to read, write,
John Criswelldfe6a862004-12-10 15:51:16 +00001669allocate, and free memory in LLVM.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001670</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001671<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001672<div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>'
1673Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001674<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001675<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001676<pre> &lt;result&gt; = malloc &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001677 &lt;result&gt; = malloc &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001678</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001679<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001680<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1681heap and returns a pointer to it.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001682<h5>Arguments:</h5>
John Criswella92e5862004-02-24 16:13:56 +00001683<p>The '<tt>malloc</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1684bytes of memory from the operating system and returns a pointer of the
Chris Lattner48b383b02003-11-25 01:02:51 +00001685appropriate type to the program. The second form of the instruction is
1686a shorter version of the first instruction that defaults to allocating
1687one element.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001688<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001689<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001690<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1691a pointer is returned.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001692<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001693<pre> %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
Misha Brukman76307852003-11-08 01:05:38 +00001694
Chris Lattner48b383b02003-11-25 01:02:51 +00001695 %size = <a
1696 href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001697 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1698 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001699</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001700</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001701<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001702<div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>'
1703Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001704<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001705<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001706<pre> free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001707</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001708<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001709<p>The '<tt>free</tt>' instruction returns memory back to the unused
1710memory heap, to be reallocated in the future.</p>
1711<p> </p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001712<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001713<p>'<tt>value</tt>' shall be a pointer value that points to a value
1714that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1715instruction.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001716<h5>Semantics:</h5>
John Criswelldfe6a862004-12-10 15:51:16 +00001717<p>Access to the memory pointed to by the pointer is no longer defined
Chris Lattner48b383b02003-11-25 01:02:51 +00001718after this instruction executes.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001719<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001720<pre> %array = <a href="#i_malloc">malloc</a> [4 x ubyte] <i>; yields {[4 x ubyte]*}:array</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001721 free [4 x ubyte]* %array
1722</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001723</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001724<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001725<div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>'
1726Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001727<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001728<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001729<pre> &lt;result&gt; = alloca &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001730 &lt;result&gt; = alloca &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001731</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001732<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001733<p>The '<tt>alloca</tt>' instruction allocates memory on the current
1734stack frame of the procedure that is live until the current function
1735returns to its caller.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001736<h5>Arguments:</h5>
John Criswelldfe6a862004-12-10 15:51:16 +00001737<p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00001738bytes of memory on the runtime stack, returning a pointer of the
1739appropriate type to the program. The second form of the instruction is
1740a shorter version of the first that defaults to allocating one element.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001741<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001742<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001743<p>Memory is allocated, a pointer is returned. '<tt>alloca</tt>'d
1744memory is automatically released when the function returns. The '<tt>alloca</tt>'
1745instruction is commonly used to represent automatic variables that must
1746have an address available. When the function returns (either with the <tt><a
1747 href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt>
Misha Brukman76307852003-11-08 01:05:38 +00001748instructions), the memory is reclaimed.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001749<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001750<pre> %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001751 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001752</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001753</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001754<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001755<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1756Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001757<div class="doc_text">
Chris Lattner095735d2002-05-06 03:03:22 +00001758<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001759<pre> &lt;result&gt; = load &lt;ty&gt;* &lt;pointer&gt;<br> &lt;result&gt; = volatile load &lt;ty&gt;* &lt;pointer&gt;<br></pre>
Chris Lattner095735d2002-05-06 03:03:22 +00001760<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001761<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00001762<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001763<p>The argument to the '<tt>load</tt>' instruction specifies the memory
1764address to load from. The pointer must point to a <a
Chris Lattner10ee9652004-06-03 22:57:15 +00001765 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
Chris Lattner48b383b02003-11-25 01:02:51 +00001766marked as <tt>volatile</tt> then the optimizer is not allowed to modify
1767the number or order of execution of this <tt>load</tt> with other
1768volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1769instructions. </p>
Chris Lattner095735d2002-05-06 03:03:22 +00001770<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001771<p>The location of memory pointed to is loaded.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00001772<h5>Examples:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001773<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1774 <a
1775 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner095735d2002-05-06 03:03:22 +00001776 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1777</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001778</div>
Chris Lattner095735d2002-05-06 03:03:22 +00001779<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001780<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1781Instruction</a> </div>
Chris Lattner095735d2002-05-06 03:03:22 +00001782<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001783<pre> store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt; <i>; yields {void}</i>
Chris Lattner12d456c2003-09-08 18:27:49 +00001784 volatile store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt; <i>; yields {void}</i>
Chris Lattner095735d2002-05-06 03:03:22 +00001785</pre>
Chris Lattner095735d2002-05-06 03:03:22 +00001786<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001787<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00001788<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001789<p>There are two arguments to the '<tt>store</tt>' instruction: a value
1790to store and an address to store it into. The type of the '<tt>&lt;pointer&gt;</tt>'
1791operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
1792operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the
1793optimizer is not allowed to modify the number or order of execution of
1794this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1795 href="#i_store">store</a></tt> instructions.</p>
1796<h5>Semantics:</h5>
1797<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
1798at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00001799<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001800<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1801 <a
1802 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner095735d2002-05-06 03:03:22 +00001803 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1804</pre>
Chris Lattner095735d2002-05-06 03:03:22 +00001805<!-- _______________________________________________________________________ -->
Chris Lattner33fd7022004-04-05 01:30:49 +00001806<div class="doc_subsubsection">
1807 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
1808</div>
1809
Misha Brukman76307852003-11-08 01:05:38 +00001810<div class="doc_text">
Chris Lattner590645f2002-04-14 06:13:44 +00001811<h5>Syntax:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00001812<pre>
1813 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
1814</pre>
1815
Chris Lattner590645f2002-04-14 06:13:44 +00001816<h5>Overview:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00001817
1818<p>
1819The '<tt>getelementptr</tt>' instruction is used to get the address of a
1820subelement of an aggregate data structure.</p>
1821
Chris Lattner590645f2002-04-14 06:13:44 +00001822<h5>Arguments:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00001823
1824<p>This instruction takes a list of integer constants that indicate what
1825elements of the aggregate object to index to. The actual types of the arguments
1826provided depend on the type of the first pointer argument. The
1827'<tt>getelementptr</tt>' instruction is used to index down through the type
1828levels of a structure. When indexing into a structure, only <tt>uint</tt>
1829integer constants are allowed. When indexing into an array or pointer
1830<tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
1831
Chris Lattner48b383b02003-11-25 01:02:51 +00001832<p>For example, let's consider a C code fragment and how it gets
1833compiled to LLVM:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00001834
1835<pre>
1836 struct RT {
1837 char A;
1838 int B[10][20];
1839 char C;
1840 };
1841 struct ST {
1842 int X;
1843 double Y;
1844 struct RT Z;
1845 };
1846
1847 int *foo(struct ST *s) {
1848 return &amp;s[1].Z.B[5][13];
1849 }
1850</pre>
1851
Misha Brukman76307852003-11-08 01:05:38 +00001852<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00001853
1854<pre>
1855 %RT = type { sbyte, [10 x [20 x int]], sbyte }
1856 %ST = type { int, double, %RT }
1857
Brian Gaeke317ef962004-07-02 21:08:14 +00001858 implementation
1859
1860 int* %foo(%ST* %s) {
1861 entry:
1862 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13
Chris Lattner33fd7022004-04-05 01:30:49 +00001863 ret int* %reg
1864 }
1865</pre>
1866
Chris Lattner590645f2002-04-14 06:13:44 +00001867<h5>Semantics:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00001868
1869<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
Chris Lattner10ee9652004-06-03 22:57:15 +00001870on the pointer type that is being index into. <a href="#t_pointer">Pointer</a>
1871and <a href="#t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
1872<tt>ulong</tt>, or <tt>long</tt> values, and <a href="#t_struct">structure</a>
Chris Lattner33fd7022004-04-05 01:30:49 +00001873types require <tt>uint</tt> <b>constants</b>.</p>
1874
Misha Brukman76307852003-11-08 01:05:38 +00001875<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattner33fd7022004-04-05 01:30:49 +00001876type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
1877}</tt>' type, a structure. The second index indexes into the third element of
1878the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
1879sbyte }</tt>' type, another structure. The third index indexes into the second
1880element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
1881array. The two dimensions of the array are subscripted into, yielding an
1882'<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction return a pointer
1883to this element, thus computing a value of '<tt>int*</tt>' type.</p>
1884
Chris Lattner48b383b02003-11-25 01:02:51 +00001885<p>Note that it is perfectly legal to index partially through a
1886structure, returning a pointer to an inner element. Because of this,
1887the LLVM code for the given testcase is equivalent to:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00001888
1889<pre>
Chris Lattner455fc8c2005-03-07 22:13:59 +00001890 int* %foo(%ST* %s) {
Chris Lattner33fd7022004-04-05 01:30:49 +00001891 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
1892 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
1893 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
1894 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
1895 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
1896 ret int* %t5
1897 }
Chris Lattnera8292f32002-05-06 22:08:29 +00001898</pre>
Chris Lattner590645f2002-04-14 06:13:44 +00001899<h5>Example:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00001900<pre>
1901 <i>; yields [12 x ubyte]*:aptr</i>
1902 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
1903</pre>
1904
1905</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001906<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001907<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001908<div class="doc_text">
John Criswell417228d2004-04-09 16:48:45 +00001909<p>The instructions in this category are the "miscellaneous"
Chris Lattner48b383b02003-11-25 01:02:51 +00001910instructions, which defy better classification.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001911</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001912<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001913<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
1914Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001915<div class="doc_text">
Chris Lattner70de6632001-07-09 00:26:23 +00001916<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001917<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner70de6632001-07-09 00:26:23 +00001918<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001919<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
1920the SSA graph representing the function.</p>
Chris Lattner70de6632001-07-09 00:26:23 +00001921<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001922<p>The type of the incoming values are specified with the first type
1923field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
1924as arguments, with one pair for each predecessor basic block of the
1925current block. Only values of <a href="#t_firstclass">first class</a>
1926type may be used as the value arguments to the PHI node. Only labels
1927may be used as the label arguments.</p>
1928<p>There must be no non-phi instructions between the start of a basic
1929block and the PHI instructions: i.e. PHI instructions must be first in
1930a basic block.</p>
Chris Lattner70de6632001-07-09 00:26:23 +00001931<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001932<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
1933value specified by the parameter, depending on which basic block we
1934came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattnera8292f32002-05-06 22:08:29 +00001935<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001936<pre>Loop: ; Infinite loop that counts from 0 on up...<br> %indvar = phi uint [ 0, %LoopHeader ], [ %nextindvar, %Loop ]<br> %nextindvar = add uint %indvar, 1<br> br label %Loop<br></pre>
Misha Brukman76307852003-11-08 01:05:38 +00001937</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001938
Chris Lattnera8292f32002-05-06 22:08:29 +00001939<!-- _______________________________________________________________________ -->
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001940<div class="doc_subsubsection">
1941 <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
1942</div>
1943
Misha Brukman76307852003-11-08 01:05:38 +00001944<div class="doc_text">
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001945
Chris Lattnera8292f32002-05-06 22:08:29 +00001946<h5>Syntax:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001947
1948<pre>
1949 &lt;result&gt; = cast &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Chris Lattnera8292f32002-05-06 22:08:29 +00001950</pre>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001951
Chris Lattnera8292f32002-05-06 22:08:29 +00001952<h5>Overview:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001953
1954<p>
1955The '<tt>cast</tt>' instruction is used as the primitive means to convert
1956integers to floating point, change data type sizes, and break type safety (by
1957casting pointers).
1958</p>
1959
1960
Chris Lattnera8292f32002-05-06 22:08:29 +00001961<h5>Arguments:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001962
1963<p>
1964The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
1965class value, and a type to cast it to, which must also be a <a
1966href="#t_firstclass">first class</a> type.
1967</p>
1968
Chris Lattnera8292f32002-05-06 22:08:29 +00001969<h5>Semantics:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001970
1971<p>
1972This instruction follows the C rules for explicit casts when determining how the
1973data being cast must change to fit in its new container.
1974</p>
1975
1976<p>
1977When casting to bool, any value that would be considered true in the context of
1978a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
1979all else are '<tt>false</tt>'.
1980</p>
1981
1982<p>
1983When extending an integral value from a type of one signness to another (for
1984example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
1985<b>source</b> value is signed, and zero-extended if the source value is
1986unsigned. <tt>bool</tt> values are always zero extended into either zero or
1987one.
1988</p>
1989
Chris Lattner70de6632001-07-09 00:26:23 +00001990<h5>Example:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001991
1992<pre>
1993 %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattnerd8f8ede2002-06-25 18:03:17 +00001994 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner70de6632001-07-09 00:26:23 +00001995</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001996</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001997
1998<!-- _______________________________________________________________________ -->
1999<div class="doc_subsubsection">
2000 <a name="i_select">'<tt>select</tt>' Instruction</a>
2001</div>
2002
2003<div class="doc_text">
2004
2005<h5>Syntax:</h5>
2006
2007<pre>
2008 &lt;result&gt; = select bool &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
2009</pre>
2010
2011<h5>Overview:</h5>
2012
2013<p>
2014The '<tt>select</tt>' instruction is used to choose one value based on a
2015condition, without branching.
2016</p>
2017
2018
2019<h5>Arguments:</h5>
2020
2021<p>
2022The '<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.
2023</p>
2024
2025<h5>Semantics:</h5>
2026
2027<p>
2028If the boolean condition evaluates to true, the instruction returns the first
2029value argument, otherwise it returns the second value argument.
2030</p>
2031
2032<h5>Example:</h5>
2033
2034<pre>
2035 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
2036</pre>
2037</div>
2038
2039
2040
2041
2042
Chris Lattner70de6632001-07-09 00:26:23 +00002043<!-- _______________________________________________________________________ -->
Chris Lattnere23c1392005-05-06 05:47:36 +00002044<div class="doc_subsubsection">
2045 <a name="i_call">'<tt>call</tt>' Instruction</a>
2046</div>
2047
Misha Brukman76307852003-11-08 01:05:38 +00002048<div class="doc_text">
Chris Lattnere23c1392005-05-06 05:47:36 +00002049
Chris Lattner2f7c9632001-06-06 20:29:01 +00002050<h5>Syntax:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00002051<pre>
2052 &lt;result&gt; = [tail] call &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)
2053</pre>
2054
Chris Lattner2f7c9632001-06-06 20:29:01 +00002055<h5>Overview:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00002056
Misha Brukman76307852003-11-08 01:05:38 +00002057<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00002058
Chris Lattner2f7c9632001-06-06 20:29:01 +00002059<h5>Arguments:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00002060
Misha Brukman76307852003-11-08 01:05:38 +00002061<p>This instruction requires several arguments:</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00002062
Chris Lattnera8292f32002-05-06 22:08:29 +00002063<ol>
Chris Lattner48b383b02003-11-25 01:02:51 +00002064 <li>
Chris Lattnere23c1392005-05-06 05:47:36 +00002065 <p>The "tail" marker indicates whether the callee function accesses any
2066 allocas or varargs in the caller. If the "tail" marker is present, the
2067 function call is eligible for tail call optimization. Note that calls may
2068 be marked "tail" even if they do not occur before a <a
2069 href="#i_ret"><tt>ret</tt></a> instruction.
Chris Lattner48b383b02003-11-25 01:02:51 +00002070 </li>
2071 <li>
Chris Lattnere23c1392005-05-06 05:47:36 +00002072 <p>'<tt>ty</tt>': shall be the signature of the pointer to function value
2073 being invoked. The argument types must match the types implied by this
2074 signature.</p>
2075 </li>
2076 <li>
2077 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to
2078 be invoked. In most cases, this is a direct function invocation, but
2079 indirect <tt>call</tt>s are just as possible, calling an arbitrary pointer
2080 to function values.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002081 </li>
2082 <li>
2083 <p>'<tt>function args</tt>': argument list whose types match the
Reid Spencerd845d162005-05-01 22:22:57 +00002084 function signature argument types. All arguments must be of
2085 <a href="#t_firstclass">first class</a> type. If the function signature
2086 indicates the function accepts a variable number of arguments, the extra
2087 arguments can be specified.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002088 </li>
Chris Lattnera8292f32002-05-06 22:08:29 +00002089</ol>
Chris Lattnere23c1392005-05-06 05:47:36 +00002090
Chris Lattner2f7c9632001-06-06 20:29:01 +00002091<h5>Semantics:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00002092
Chris Lattner48b383b02003-11-25 01:02:51 +00002093<p>The '<tt>call</tt>' instruction is used to cause control flow to
2094transfer to a specified function, with its incoming arguments bound to
2095the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
2096instruction in the called function, control flow continues with the
2097instruction after the function call, and the return value of the
2098function is bound to the result argument. This is a simpler case of
2099the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00002100
Chris Lattner2f7c9632001-06-06 20:29:01 +00002101<h5>Example:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00002102
2103<pre>
2104 %retval = call int %test(int %argc)
2105 call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42);
2106 %X = tail call int %foo()
2107</pre>
2108
Misha Brukman76307852003-11-08 01:05:38 +00002109</div>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002110
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002111<!-- _______________________________________________________________________ -->
Chris Lattner6a4a0492004-09-27 21:51:25 +00002112<div class="doc_subsubsection">
2113 <a name="i_vanext">'<tt>vanext</tt>' Instruction</a>
2114</div>
2115
Misha Brukman76307852003-11-08 01:05:38 +00002116<div class="doc_text">
Chris Lattner6a4a0492004-09-27 21:51:25 +00002117
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002118<h5>Syntax:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002119
2120<pre>
2121 &lt;resultarglist&gt; = vanext &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;
2122</pre>
2123
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002124<h5>Overview:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002125
Chris Lattner48b383b02003-11-25 01:02:51 +00002126<p>The '<tt>vanext</tt>' instruction is used to access arguments passed
2127through the "variable argument" area of a function call. It is used to
2128implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002129
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002130<h5>Arguments:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002131
2132<p>This instruction takes a <tt>va_list</tt> value and the type of the
2133argument. It returns another <tt>va_list</tt>. The actual type of
2134<tt>va_list</tt> may be defined differently for different targets. Most targets
2135use a <tt>va_list</tt> type of <tt>sbyte*</tt> or some other pointer type.</p>
2136
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002137<h5>Semantics:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002138
2139<p>The '<tt>vanext</tt>' instruction advances the specified <tt>va_list</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00002140past an argument of the specified type. In conjunction with the <a
2141 href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement
2142the <tt>va_arg</tt> macro available in C. For more information, see
2143the variable argument handling <a href="#int_varargs">Intrinsic
2144Functions</a>.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002145
Chris Lattner48b383b02003-11-25 01:02:51 +00002146<p>It is legal for this instruction to be called in a function which
2147does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman76307852003-11-08 01:05:38 +00002148function.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002149
Misha Brukman76307852003-11-08 01:05:38 +00002150<p><tt>vanext</tt> is an LLVM instruction instead of an <a
Chris Lattner6a4a0492004-09-27 21:51:25 +00002151href="#intrinsics">intrinsic function</a> because it takes a type as an
2152argument. The type refers to the current argument in the <tt>va_list</tt>, it
2153tells the compiler how far on the stack it needs to advance to find the next
2154argument</p>
2155
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002156<h5>Example:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002157
Chris Lattner48b383b02003-11-25 01:02:51 +00002158<p>See the <a href="#int_varargs">variable argument processing</a>
2159section.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002160
Misha Brukman76307852003-11-08 01:05:38 +00002161</div>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002162
Chris Lattner26ca62e2003-10-18 05:51:36 +00002163<!-- _______________________________________________________________________ -->
Chris Lattner6a4a0492004-09-27 21:51:25 +00002164<div class="doc_subsubsection">
2165 <a name="i_vaarg">'<tt>vaarg</tt>' Instruction</a>
2166</div>
2167
Misha Brukman76307852003-11-08 01:05:38 +00002168<div class="doc_text">
Chris Lattner6a4a0492004-09-27 21:51:25 +00002169
Chris Lattner26ca62e2003-10-18 05:51:36 +00002170<h5>Syntax:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002171
2172<pre>
2173 &lt;resultval&gt; = vaarg &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;
2174</pre>
2175
Chris Lattner26ca62e2003-10-18 05:51:36 +00002176<h5>Overview:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002177
2178<p>The '<tt>vaarg</tt>' instruction is used to access arguments passed through
2179the "variable argument" area of a function call. It is used to implement the
2180<tt>va_arg</tt> macro in C.</p>
2181
Chris Lattner26ca62e2003-10-18 05:51:36 +00002182<h5>Arguments:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002183
2184<p>This instruction takes a <tt>va_list</tt> value and the type of the
2185argument. It returns a value of the specified argument type. Again, the actual
2186type of <tt>va_list</tt> is target specific.</p>
2187
Chris Lattner26ca62e2003-10-18 05:51:36 +00002188<h5>Semantics:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002189
2190<p>The '<tt>vaarg</tt>' instruction loads an argument of the specified type from
2191the specified <tt>va_list</tt>. In conjunction with the <a
2192href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to implement the
2193<tt>va_arg</tt> macro available in C. For more information, see the variable
2194argument handling <a href="#int_varargs">Intrinsic Functions</a>.</p>
2195
2196<p>It is legal for this instruction to be called in a function which does not
2197take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman76307852003-11-08 01:05:38 +00002198function.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002199
Misha Brukman76307852003-11-08 01:05:38 +00002200<p><tt>vaarg</tt> is an LLVM instruction instead of an <a
Chris Lattner6a4a0492004-09-27 21:51:25 +00002201href="#intrinsics">intrinsic function</a> because it takes an type as an
2202argument.</p>
2203
Chris Lattner26ca62e2003-10-18 05:51:36 +00002204<h5>Example:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002205
2206<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
2207
Misha Brukman76307852003-11-08 01:05:38 +00002208</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002209
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002210<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002211<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
2212<!-- *********************************************************************** -->
Chris Lattner941515c2004-01-06 05:31:32 +00002213
Misha Brukman76307852003-11-08 01:05:38 +00002214<div class="doc_text">
Chris Lattnerfee11462004-02-12 17:01:32 +00002215
2216<p>LLVM supports the notion of an "intrinsic function". These functions have
2217well known names and semantics, and are required to follow certain
2218restrictions. Overall, these instructions represent an extension mechanism for
2219the LLVM language that does not require changing all of the transformations in
2220LLVM to add to the language (or the bytecode reader/writer, the parser,
2221etc...).</p>
2222
2223<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix, this
2224prefix is reserved in LLVM for intrinsic names, thus functions may not be named
2225this. Intrinsic functions must always be external functions: you cannot define
2226the body of intrinsic functions. Intrinsic functions may only be used in call
2227or invoke instructions: it is illegal to take the address of an intrinsic
2228function. Additionally, because intrinsic functions are part of the LLVM
2229language, it is required that they all be documented here if any are added.</p>
2230
2231
2232<p>
2233Adding an intrinsic to LLVM is straight-forward if it is possible to express the
2234concept in LLVM directly (ie, code generator support is not _required_). To do
2235this, extend the default implementation of the IntrinsicLowering class to handle
2236the intrinsic. Code generators use this class to lower intrinsics they do not
2237understand to raw LLVM instructions that they do.
2238</p>
2239
Misha Brukman76307852003-11-08 01:05:38 +00002240</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002241
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002242<!-- ======================================================================= -->
Chris Lattner941515c2004-01-06 05:31:32 +00002243<div class="doc_subsection">
2244 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
2245</div>
2246
Misha Brukman76307852003-11-08 01:05:38 +00002247<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +00002248
Misha Brukman76307852003-11-08 01:05:38 +00002249<p>Variable argument support is defined in LLVM with the <a
Chris Lattner48b383b02003-11-25 01:02:51 +00002250 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
2251intrinsic functions. These functions are related to the similarly
2252named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002253
Chris Lattner48b383b02003-11-25 01:02:51 +00002254<p>All of these functions operate on arguments that use a
2255target-specific value type "<tt>va_list</tt>". The LLVM assembly
2256language reference manual does not define what this type is, so all
2257transformations should be prepared to handle intrinsics with any type
2258used.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002259
Misha Brukman76307852003-11-08 01:05:38 +00002260<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner48b383b02003-11-25 01:02:51 +00002261instruction and the variable argument handling intrinsic functions are
2262used.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002263
Chris Lattnerfee11462004-02-12 17:01:32 +00002264<pre>
2265int %test(int %X, ...) {
2266 ; Initialize variable argument processing
2267 %ap = call sbyte* %<a href="#i_va_start">llvm.va_start</a>()
2268
2269 ; Read a single integer argument
2270 %tmp = vaarg sbyte* %ap, int
2271
2272 ; Advance to the next argument
2273 %ap2 = vanext sbyte* %ap, int
2274
2275 ; Demonstrate usage of llvm.va_copy and llvm.va_end
2276 %aq = call sbyte* %<a href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2)
2277 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %aq)
2278
2279 ; Stop processing of arguments.
2280 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %ap2)
2281 ret int %tmp
2282}
2283</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002284</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002285
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002286<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00002287<div class="doc_subsubsection">
2288 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
2289</div>
2290
2291
Misha Brukman76307852003-11-08 01:05:38 +00002292<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002293<h5>Syntax:</h5>
Reid Spencer7821d062005-04-26 20:50:44 +00002294<pre> declare &lt;va_list&gt; %llvm.va_start()<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002295<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002296<p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt>&lt;arglist&gt;</tt>
2297for subsequent use by the variable argument intrinsics.</p>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002298<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002299<p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00002300macro available in C. In a target-dependent way, it initializes and
2301returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt>
2302will produce the first variable argument passed to the function. Unlike
2303the C <tt>va_start</tt> macro, this intrinsic does not need to know the
2304last argument of the function, the compiler can figure that out.</p>
2305<p>Note that this intrinsic function is only legal to be called from
2306within the body of a variable argument function.</p>
Misha Brukman76307852003-11-08 01:05:38 +00002307</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002308
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002309<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00002310<div class="doc_subsubsection">
2311 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
2312</div>
2313
Misha Brukman76307852003-11-08 01:05:38 +00002314<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002315<h5>Syntax:</h5>
Reid Spencer7821d062005-04-26 20:50:44 +00002316<pre> declare void %llvm.va_end(&lt;va_list&gt; &lt;arglist&gt;)<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002317<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002318<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
2319which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
2320or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002321<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002322<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002323<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002324<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00002325macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
2326Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
2327 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
2328with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman76307852003-11-08 01:05:38 +00002329</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002330
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002331<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00002332<div class="doc_subsubsection">
2333 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
2334</div>
2335
Misha Brukman76307852003-11-08 01:05:38 +00002336<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +00002337
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002338<h5>Syntax:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002339
2340<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002341 declare &lt;va_list&gt; %llvm.va_copy(&lt;va_list&gt; &lt;destarglist&gt;)
Chris Lattner757528b0b2004-05-23 21:06:01 +00002342</pre>
2343
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002344<h5>Overview:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002345
2346<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position
2347from the source argument list to the destination argument list.</p>
2348
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002349<h5>Arguments:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002350
Misha Brukman76307852003-11-08 01:05:38 +00002351<p>The argument is the <tt>va_list</tt> to copy.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002352
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002353<h5>Semantics:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002354
Misha Brukman76307852003-11-08 01:05:38 +00002355<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002356macro available in C. In a target-dependent way, it copies the source
2357<tt>va_list</tt> element into the returned list. This intrinsic is necessary
Chris Lattner53e5e2a2004-06-21 22:52:48 +00002358because the <tt><a href="#i_va_start">llvm.va_start</a></tt> intrinsic may be
Chris Lattner757528b0b2004-05-23 21:06:01 +00002359arbitrarily complex and require memory allocation, for example.</p>
2360
Misha Brukman76307852003-11-08 01:05:38 +00002361</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002362
Chris Lattnerfee11462004-02-12 17:01:32 +00002363<!-- ======================================================================= -->
2364<div class="doc_subsection">
Chris Lattner757528b0b2004-05-23 21:06:01 +00002365 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
2366</div>
2367
2368<div class="doc_text">
2369
2370<p>
2371LLVM support for <a href="GarbageCollection.html">Accurate Garbage
2372Collection</a> requires the implementation and generation of these intrinsics.
2373These intrinsics allow identification of <a href="#i_gcroot">GC roots on the
2374stack</a>, as well as garbage collector implementations that require <a
2375href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers.
2376Front-ends for type-safe garbage collected languages should generate these
2377intrinsics to make use of the LLVM garbage collectors. For more details, see <a
2378href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
2379</p>
2380</div>
2381
2382<!-- _______________________________________________________________________ -->
2383<div class="doc_subsubsection">
2384 <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
2385</div>
2386
2387<div class="doc_text">
2388
2389<h5>Syntax:</h5>
2390
2391<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002392 declare void %llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
Chris Lattner757528b0b2004-05-23 21:06:01 +00002393</pre>
2394
2395<h5>Overview:</h5>
2396
John Criswelldfe6a862004-12-10 15:51:16 +00002397<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
Chris Lattner757528b0b2004-05-23 21:06:01 +00002398the code generator, and allows some metadata to be associated with it.</p>
2399
2400<h5>Arguments:</h5>
2401
2402<p>The first argument specifies the address of a stack object that contains the
2403root pointer. The second pointer (which must be either a constant or a global
2404value address) contains the meta-data to be associated with the root.</p>
2405
2406<h5>Semantics:</h5>
2407
2408<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
2409location. At compile-time, the code generator generates information to allow
2410the runtime to find the pointer at GC safe points.
2411</p>
2412
2413</div>
2414
2415
2416<!-- _______________________________________________________________________ -->
2417<div class="doc_subsubsection">
2418 <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
2419</div>
2420
2421<div class="doc_text">
2422
2423<h5>Syntax:</h5>
2424
2425<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002426 declare sbyte* %llvm.gcread(sbyte** %Ptr)
Chris Lattner757528b0b2004-05-23 21:06:01 +00002427</pre>
2428
2429<h5>Overview:</h5>
2430
2431<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
2432locations, allowing garbage collector implementations that require read
2433barriers.</p>
2434
2435<h5>Arguments:</h5>
2436
2437<p>The argument is the address to read from, which should be an address
2438allocated from the garbage collector.</p>
2439
2440<h5>Semantics:</h5>
2441
2442<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
2443instruction, but may be replaced with substantially more complex code by the
2444garbage collector runtime, as needed.</p>
2445
2446</div>
2447
2448
2449<!-- _______________________________________________________________________ -->
2450<div class="doc_subsubsection">
2451 <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
2452</div>
2453
2454<div class="doc_text">
2455
2456<h5>Syntax:</h5>
2457
2458<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002459 declare void %llvm.gcwrite(sbyte* %P1, sbyte** %P2)
Chris Lattner757528b0b2004-05-23 21:06:01 +00002460</pre>
2461
2462<h5>Overview:</h5>
2463
2464<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
2465locations, allowing garbage collector implementations that require write
2466barriers (such as generational or reference counting collectors).</p>
2467
2468<h5>Arguments:</h5>
2469
2470<p>The first argument is the reference to store, and the second is the heap
2471location to store to.</p>
2472
2473<h5>Semantics:</h5>
2474
2475<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
2476instruction, but may be replaced with substantially more complex code by the
2477garbage collector runtime, as needed.</p>
2478
2479</div>
2480
2481
2482
2483<!-- ======================================================================= -->
2484<div class="doc_subsection">
Chris Lattner3649c3a2004-02-14 04:08:35 +00002485 <a name="int_codegen">Code Generator Intrinsics</a>
2486</div>
2487
2488<div class="doc_text">
2489<p>
2490These intrinsics are provided by LLVM to expose special features that may only
2491be implemented with code generator support.
2492</p>
2493
2494</div>
2495
2496<!-- _______________________________________________________________________ -->
2497<div class="doc_subsubsection">
2498 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
2499</div>
2500
2501<div class="doc_text">
2502
2503<h5>Syntax:</h5>
2504<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002505 declare void* %llvm.returnaddress(uint &lt;level&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00002506</pre>
2507
2508<h5>Overview:</h5>
2509
2510<p>
2511The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
2512indicating the return address of the current function or one of its callers.
2513</p>
2514
2515<h5>Arguments:</h5>
2516
2517<p>
2518The argument to this intrinsic indicates which function to return the address
2519for. Zero indicates the calling function, one indicates its caller, etc. The
2520argument is <b>required</b> to be a constant integer value.
2521</p>
2522
2523<h5>Semantics:</h5>
2524
2525<p>
2526The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
2527the return address of the specified call frame, or zero if it cannot be
2528identified. The value returned by this intrinsic is likely to be incorrect or 0
2529for arguments other than zero, so it should only be used for debugging purposes.
2530</p>
2531
2532<p>
2533Note that calling this intrinsic does not prevent function inlining or other
Chris Lattner2e6eb5f2005-03-07 20:30:51 +00002534aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner3649c3a2004-02-14 04:08:35 +00002535source-language caller.
2536</p>
2537</div>
2538
2539
2540<!-- _______________________________________________________________________ -->
2541<div class="doc_subsubsection">
2542 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
2543</div>
2544
2545<div class="doc_text">
2546
2547<h5>Syntax:</h5>
2548<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002549 declare void* %llvm.frameaddress(uint &lt;level&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00002550</pre>
2551
2552<h5>Overview:</h5>
2553
2554<p>
2555The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
2556pointer value for the specified stack frame.
2557</p>
2558
2559<h5>Arguments:</h5>
2560
2561<p>
2562The argument to this intrinsic indicates which function to return the frame
2563pointer for. Zero indicates the calling function, one indicates its caller,
2564etc. The argument is <b>required</b> to be a constant integer value.
2565</p>
2566
2567<h5>Semantics:</h5>
2568
2569<p>
2570The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
2571the frame address of the specified call frame, or zero if it cannot be
2572identified. The value returned by this intrinsic is likely to be incorrect or 0
2573for arguments other than zero, so it should only be used for debugging purposes.
2574</p>
2575
2576<p>
2577Note that calling this intrinsic does not prevent function inlining or other
Chris Lattner2e6eb5f2005-03-07 20:30:51 +00002578aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner3649c3a2004-02-14 04:08:35 +00002579source-language caller.
2580</p>
2581</div>
2582
Chris Lattnerc8a2c222005-02-28 19:24:19 +00002583<!-- _______________________________________________________________________ -->
2584<div class="doc_subsubsection">
2585 <a name="i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a>
2586</div>
2587
2588<div class="doc_text">
2589
2590<h5>Syntax:</h5>
2591<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002592 declare void %llvm.prefetch(sbyte * &lt;address&gt;,
2593 uint &lt;rw&gt;, uint &lt;locality&gt;)
Chris Lattnerc8a2c222005-02-28 19:24:19 +00002594</pre>
2595
2596<h5>Overview:</h5>
2597
2598
2599<p>
2600The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to insert
2601a prefetch instruction if supported, otherwise it is a noop. Prefetches have no
Chris Lattnerff851072005-02-28 19:47:14 +00002602effect on the behavior of the program, but can change its performance
2603characteristics.
Chris Lattnerc8a2c222005-02-28 19:24:19 +00002604</p>
2605
2606<h5>Arguments:</h5>
2607
2608<p>
2609<tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier
2610determining if the fetch should be for a read (0) or write (1), and
2611<tt>locality</tt> is a temporal locality specifier ranging from (0) - no
Chris Lattnerd3e641c2005-03-07 20:31:38 +00002612locality, to (3) - extremely local keep in cache. The <tt>rw</tt> and
Chris Lattnerc8a2c222005-02-28 19:24:19 +00002613<tt>locality</tt> arguments must be constant integers.
2614</p>
2615
2616<h5>Semantics:</h5>
2617
2618<p>
2619This intrinsic does not modify the behavior of the program. In particular,
2620prefetches cannot trap and do not produce a value. On targets that support this
2621intrinsic, the prefetch can provide hints to the processor cache for better
2622performance.
2623</p>
2624
2625</div>
2626
Andrew Lenharthb4427912005-03-28 20:05:49 +00002627<!-- _______________________________________________________________________ -->
2628<div class="doc_subsubsection">
2629 <a name="i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a>
2630</div>
2631
2632<div class="doc_text">
2633
2634<h5>Syntax:</h5>
2635<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002636 declare void %llvm.pcmarker( uint &lt;id&gt; )
Andrew Lenharthb4427912005-03-28 20:05:49 +00002637</pre>
2638
2639<h5>Overview:</h5>
2640
2641
2642<p>
2643The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a PC in a region of
2644code to simulators and other tools. The method is target specific, but it is
2645expected that the marker will use exported symbols to transmit the PC of the marker.
2646The marker makes no guaranties that it will remain with any specific instruction
2647after optimizations. It is possible that the presense of a marker will inhibit
2648optimizations. The intended use is to be inserted after optmizations to allow
2649corrolations of simulation runs.
2650</p>
2651
2652<h5>Arguments:</h5>
2653
2654<p>
2655<tt>id</tt> is a numerical id identifying the marker.
2656</p>
2657
2658<h5>Semantics:</h5>
2659
2660<p>
2661This intrinsic does not modify the behavior of the program. Backends that do not
2662support this intrinisic may ignore it.
2663</p>
2664
2665</div>
2666
Chris Lattnerc8a2c222005-02-28 19:24:19 +00002667
John Criswellaa1c3c12004-04-09 16:43:20 +00002668<!-- ======================================================================= -->
2669<div class="doc_subsection">
2670 <a name="int_os">Operating System Intrinsics</a>
2671</div>
2672
2673<div class="doc_text">
2674<p>
2675These intrinsics are provided by LLVM to support the implementation of
2676operating system level code.
2677</p>
2678
2679</div>
John Criswella4501222004-04-12 15:02:16 +00002680
John Criswell508b93c2004-04-09 15:23:37 +00002681<!-- _______________________________________________________________________ -->
2682<div class="doc_subsubsection">
2683 <a name="i_readport">'<tt>llvm.readport</tt>' Intrinsic</a>
2684</div>
2685
2686<div class="doc_text">
2687
2688<h5>Syntax:</h5>
2689<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002690 declare &lt;integer type&gt; %llvm.readport (&lt;integer type&gt; &lt;address&gt;)
John Criswell508b93c2004-04-09 15:23:37 +00002691</pre>
2692
2693<h5>Overview:</h5>
2694
2695<p>
John Criswellaa1c3c12004-04-09 16:43:20 +00002696The '<tt>llvm.readport</tt>' intrinsic reads data from the specified hardware
2697I/O port.
John Criswell508b93c2004-04-09 15:23:37 +00002698</p>
2699
2700<h5>Arguments:</h5>
2701
2702<p>
John Criswellaa1c3c12004-04-09 16:43:20 +00002703The argument to this intrinsic indicates the hardware I/O address from which
2704to read the data. The address is in the hardware I/O address namespace (as
2705opposed to being a memory location for memory mapped I/O).
John Criswell508b93c2004-04-09 15:23:37 +00002706</p>
2707
2708<h5>Semantics:</h5>
2709
2710<p>
John Criswellaa1c3c12004-04-09 16:43:20 +00002711The '<tt>llvm.readport</tt>' intrinsic reads data from the hardware I/O port
2712specified by <i>address</i> and returns the value. The address and return
2713value must be integers, but the size is dependent upon the platform upon which
2714the program is code generated. For example, on x86, the address must be an
Misha Brukman36c6bc12005-04-22 18:02:52 +00002715unsigned 16-bit value, and the return value must be 8, 16, or 32 bits.
John Criswell508b93c2004-04-09 15:23:37 +00002716</p>
2717
2718</div>
2719
2720<!-- _______________________________________________________________________ -->
2721<div class="doc_subsubsection">
2722 <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a>
2723</div>
2724
2725<div class="doc_text">
2726
2727<h5>Syntax:</h5>
2728<pre>
Chris Lattner74d3f822004-12-09 17:30:23 +00002729 call void (&lt;integer type&gt;, &lt;integer type&gt;)*
2730 %llvm.writeport (&lt;integer type&gt; &lt;value&gt;,
2731 &lt;integer type&gt; &lt;address&gt;)
John Criswell508b93c2004-04-09 15:23:37 +00002732</pre>
2733
2734<h5>Overview:</h5>
2735
2736<p>
John Criswellaa1c3c12004-04-09 16:43:20 +00002737The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified hardware
2738I/O port.
John Criswell508b93c2004-04-09 15:23:37 +00002739</p>
2740
2741<h5>Arguments:</h5>
2742
2743<p>
John Criswell7a576472004-04-12 16:33:19 +00002744The first argument is the value to write to the I/O port.
John Criswell508b93c2004-04-09 15:23:37 +00002745</p>
2746
2747<p>
John Criswell7a576472004-04-12 16:33:19 +00002748The second argument indicates the hardware I/O address to which data should be
2749written. The address is in the hardware I/O address namespace (as opposed to
2750being a memory location for memory mapped I/O).
John Criswell508b93c2004-04-09 15:23:37 +00002751</p>
2752
2753<h5>Semantics:</h5>
2754
2755<p>
2756The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port
2757specified by <i>address</i>. The address and value must be integers, but the
2758size is dependent upon the platform upon which the program is code generated.
Misha Brukman36c6bc12005-04-22 18:02:52 +00002759For example, on x86, the address must be an unsigned 16-bit value, and the
John Criswellaa1c3c12004-04-09 16:43:20 +00002760value written must be 8, 16, or 32 bits in length.
John Criswell508b93c2004-04-09 15:23:37 +00002761</p>
2762
2763</div>
Chris Lattner3649c3a2004-02-14 04:08:35 +00002764
John Criswella4501222004-04-12 15:02:16 +00002765<!-- _______________________________________________________________________ -->
2766<div class="doc_subsubsection">
2767 <a name="i_readio">'<tt>llvm.readio</tt>' Intrinsic</a>
2768</div>
2769
2770<div class="doc_text">
2771
2772<h5>Syntax:</h5>
2773<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002774 declare &lt;result&gt; %llvm.readio (&lt;ty&gt; * &lt;pointer&gt;)
John Criswella4501222004-04-12 15:02:16 +00002775</pre>
2776
2777<h5>Overview:</h5>
2778
2779<p>
2780The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
2781address.
2782</p>
2783
2784<h5>Arguments:</h5>
2785
2786<p>
John Criswell7a576472004-04-12 16:33:19 +00002787The argument to this intrinsic is a pointer indicating the memory address from
2788which to read the data. The data must be a
2789<a href="#t_firstclass">first class</a> type.
John Criswella4501222004-04-12 15:02:16 +00002790</p>
2791
2792<h5>Semantics:</h5>
2793
2794<p>
2795The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
John Criswell7a576472004-04-12 16:33:19 +00002796location specified by <i>pointer</i> and returns the value. The argument must
2797be a pointer, and the return value must be a
2798<a href="#t_firstclass">first class</a> type. However, certain architectures
Misha Brukman36c6bc12005-04-22 18:02:52 +00002799may not support I/O on all first class types. For example, 32-bit processors
John Criswell7a576472004-04-12 16:33:19 +00002800may only support I/O on data types that are 32 bits or less.
John Criswella4501222004-04-12 15:02:16 +00002801</p>
2802
2803<p>
John Criswell7a576472004-04-12 16:33:19 +00002804This intrinsic enforces an in-order memory model for llvm.readio and
2805llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2806scheduled processors may execute loads and stores out of order, re-ordering at
2807run time accesses to memory mapped I/O registers. Using these intrinsics
2808ensures that accesses to memory mapped I/O registers occur in program order.
John Criswella4501222004-04-12 15:02:16 +00002809</p>
2810
2811</div>
2812
2813<!-- _______________________________________________________________________ -->
2814<div class="doc_subsubsection">
2815 <a name="i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a>
2816</div>
2817
2818<div class="doc_text">
2819
2820<h5>Syntax:</h5>
2821<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002822 declare void %llvm.writeio (&lt;ty1&gt; &lt;value&gt;, &lt;ty2&gt; * &lt;pointer&gt;)
John Criswella4501222004-04-12 15:02:16 +00002823</pre>
2824
2825<h5>Overview:</h5>
2826
2827<p>
2828The '<tt>llvm.writeio</tt>' intrinsic writes data to the specified memory
2829mapped I/O address.
2830</p>
2831
2832<h5>Arguments:</h5>
2833
2834<p>
John Criswell7a576472004-04-12 16:33:19 +00002835The first argument is the value to write to the memory mapped I/O location.
2836The second argument is a pointer indicating the memory address to which the
2837data should be written.
John Criswella4501222004-04-12 15:02:16 +00002838</p>
2839
2840<h5>Semantics:</h5>
2841
2842<p>
2843The '<tt>llvm.writeio</tt>' intrinsic writes <i>value</i> to the memory mapped
John Criswell7a576472004-04-12 16:33:19 +00002844I/O address specified by <i>pointer</i>. The value must be a
2845<a href="#t_firstclass">first class</a> type. However, certain architectures
Misha Brukman36c6bc12005-04-22 18:02:52 +00002846may not support I/O on all first class types. For example, 32-bit processors
John Criswell7a576472004-04-12 16:33:19 +00002847may only support I/O on data types that are 32 bits or less.
John Criswella4501222004-04-12 15:02:16 +00002848</p>
2849
2850<p>
John Criswell7a576472004-04-12 16:33:19 +00002851This intrinsic enforces an in-order memory model for llvm.readio and
2852llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2853scheduled processors may execute loads and stores out of order, re-ordering at
2854run time accesses to memory mapped I/O registers. Using these intrinsics
2855ensures that accesses to memory mapped I/O registers occur in program order.
John Criswella4501222004-04-12 15:02:16 +00002856</p>
2857
2858</div>
2859
Chris Lattner3649c3a2004-02-14 04:08:35 +00002860<!-- ======================================================================= -->
2861<div class="doc_subsection">
Chris Lattnerfee11462004-02-12 17:01:32 +00002862 <a name="int_libc">Standard C Library Intrinsics</a>
2863</div>
2864
2865<div class="doc_text">
2866<p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00002867LLVM provides intrinsics for a few important standard C library functions.
2868These intrinsics allow source-language front-ends to pass information about the
2869alignment of the pointer arguments to the code generator, providing opportunity
2870for more efficient code generation.
Chris Lattnerfee11462004-02-12 17:01:32 +00002871</p>
2872
2873</div>
2874
2875<!-- _______________________________________________________________________ -->
2876<div class="doc_subsubsection">
2877 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
2878</div>
2879
2880<div class="doc_text">
2881
2882<h5>Syntax:</h5>
2883<pre>
Reid Spencercf669d82005-04-26 20:41:16 +00002884 declare void %llvm.memcpy(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2885 uint &lt;len&gt;, uint &lt;align&gt;)
Chris Lattnerfee11462004-02-12 17:01:32 +00002886</pre>
2887
2888<h5>Overview:</h5>
2889
2890<p>
2891The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2892location to the destination location.
2893</p>
2894
2895<p>
2896Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
2897does not return a value, and takes an extra alignment argument.
2898</p>
2899
2900<h5>Arguments:</h5>
2901
2902<p>
2903The first argument is a pointer to the destination, the second is a pointer to
2904the source. The third argument is an (arbitrarily sized) integer argument
2905specifying the number of bytes to copy, and the fourth argument is the alignment
2906of the source and destination locations.
2907</p>
2908
Chris Lattner4c67c482004-02-12 21:18:15 +00002909<p>
2910If the call to this intrinisic has an alignment value that is not 0 or 1, then
2911the caller guarantees that the size of the copy is a multiple of the alignment
2912and that both the source and destination pointers are aligned to that boundary.
2913</p>
2914
Chris Lattnerfee11462004-02-12 17:01:32 +00002915<h5>Semantics:</h5>
2916
2917<p>
2918The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2919location to the destination location, which are not allowed to overlap. It
2920copies "len" bytes of memory over. If the argument is known to be aligned to
2921some boundary, this can be specified as the fourth argument, otherwise it should
2922be set to 0 or 1.
2923</p>
2924</div>
2925
2926
Chris Lattnerf30152e2004-02-12 18:10:10 +00002927<!-- _______________________________________________________________________ -->
2928<div class="doc_subsubsection">
2929 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
2930</div>
2931
2932<div class="doc_text">
2933
2934<h5>Syntax:</h5>
2935<pre>
Reid Spencercf669d82005-04-26 20:41:16 +00002936 declare void %llvm.memmove(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2937 uint &lt;len&gt;, uint &lt;align&gt;)
Chris Lattnerf30152e2004-02-12 18:10:10 +00002938</pre>
2939
2940<h5>Overview:</h5>
2941
2942<p>
2943The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
2944location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>'
2945intrinsic but allows the two memory locations to overlap.
2946</p>
2947
2948<p>
2949Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
2950does not return a value, and takes an extra alignment argument.
2951</p>
2952
2953<h5>Arguments:</h5>
2954
2955<p>
2956The first argument is a pointer to the destination, the second is a pointer to
2957the source. The third argument is an (arbitrarily sized) integer argument
2958specifying the number of bytes to copy, and the fourth argument is the alignment
2959of the source and destination locations.
2960</p>
2961
Chris Lattner4c67c482004-02-12 21:18:15 +00002962<p>
2963If the call to this intrinisic has an alignment value that is not 0 or 1, then
2964the caller guarantees that the size of the copy is a multiple of the alignment
2965and that both the source and destination pointers are aligned to that boundary.
2966</p>
2967
Chris Lattnerf30152e2004-02-12 18:10:10 +00002968<h5>Semantics:</h5>
2969
2970<p>
2971The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
2972location to the destination location, which may overlap. It
2973copies "len" bytes of memory over. If the argument is known to be aligned to
2974some boundary, this can be specified as the fourth argument, otherwise it should
2975be set to 0 or 1.
2976</p>
2977</div>
2978
Chris Lattner941515c2004-01-06 05:31:32 +00002979
Chris Lattner3649c3a2004-02-14 04:08:35 +00002980<!-- _______________________________________________________________________ -->
2981<div class="doc_subsubsection">
2982 <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a>
2983</div>
2984
2985<div class="doc_text">
2986
2987<h5>Syntax:</h5>
2988<pre>
Reid Spencercf669d82005-04-26 20:41:16 +00002989 declare void %llvm.memset(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
2990 uint &lt;len&gt;, uint &lt;align&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00002991</pre>
2992
2993<h5>Overview:</h5>
2994
2995<p>
2996The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular
2997byte value.
2998</p>
2999
3000<p>
3001Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
3002does not return a value, and takes an extra alignment argument.
3003</p>
3004
3005<h5>Arguments:</h5>
3006
3007<p>
3008The first argument is a pointer to the destination to fill, the second is the
3009byte value to fill it with, the third argument is an (arbitrarily sized) integer
3010argument specifying the number of bytes to fill, and the fourth argument is the
3011known alignment of destination location.
3012</p>
3013
3014<p>
3015If the call to this intrinisic has an alignment value that is not 0 or 1, then
3016the caller guarantees that the size of the copy is a multiple of the alignment
3017and that the destination pointer is aligned to that boundary.
3018</p>
3019
3020<h5>Semantics:</h5>
3021
3022<p>
3023The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the
3024destination location. If the argument is known to be aligned to some boundary,
3025this can be specified as the fourth argument, otherwise it should be set to 0 or
30261.
3027</p>
3028</div>
3029
3030
Chris Lattner3b4f4372004-06-11 02:28:03 +00003031<!-- _______________________________________________________________________ -->
3032<div class="doc_subsubsection">
Alkis Evlogimenos0fa39232004-06-13 01:16:15 +00003033 <a name="i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a>
3034</div>
3035
3036<div class="doc_text">
3037
3038<h5>Syntax:</h5>
3039<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00003040 declare bool %llvm.isunordered(&lt;float or double&gt; Val1, &lt;float or double&gt; Val2)
Alkis Evlogimenos0fa39232004-06-13 01:16:15 +00003041</pre>
3042
3043<h5>Overview:</h5>
3044
3045<p>
3046The '<tt>llvm.isunordered</tt>' intrinsic returns true if either or both of the
3047specified floating point values is a NAN.
3048</p>
3049
3050<h5>Arguments:</h5>
3051
3052<p>
3053The arguments are floating point numbers of the same type.
3054</p>
3055
3056<h5>Semantics:</h5>
3057
3058<p>
3059If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise
3060false.
3061</p>
3062</div>
3063
3064
Andrew Lenharth1d463522005-05-03 18:01:48 +00003065<!-- ======================================================================= -->
3066<div class="doc_subsection">
3067 <a name="int_count">Bit Counting Intrinsics</a>
3068</div>
3069
3070<div class="doc_text">
3071<p>
3072LLVM provides intrinsics for a few important bit counting operations.
3073These allow efficient code generation for some algorithms.
3074</p>
3075
3076</div>
3077
3078<!-- _______________________________________________________________________ -->
3079<div class="doc_subsubsection">
3080 <a name="int_ctpop">'<tt>llvm.ctpop</tt>' Intrinsic</a>
3081</div>
3082
3083<div class="doc_text">
3084
3085<h5>Syntax:</h5>
3086<pre>
3087 declare int %llvm.ctpop(int &lt;src&gt;)
3088
3089</pre>
3090
3091<h5>Overview:</h5>
3092
3093<p>
3094The '<tt>llvm.ctpop</tt>' intrinsic counts the number of ones in a variable.
3095</p>
3096
3097<h5>Arguments:</h5>
3098
3099<p>
Andrew Lenharth5be6f132005-05-04 14:58:31 +00003100The only argument is the value to be counted. The argument may be of any integer type.
Andrew Lenharth1d463522005-05-03 18:01:48 +00003101</p>
3102
3103<h5>Semantics:</h5>
3104
3105<p>
3106The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable.
3107</p>
3108</div>
3109
3110<!-- _______________________________________________________________________ -->
3111<div class="doc_subsubsection">
3112 <a name="int_cttz">'<tt>llvm.cttz</tt>' Intrinsic</a>
3113</div>
3114
3115<div class="doc_text">
3116
3117<h5>Syntax:</h5>
3118<pre>
3119 declare int %llvm.cttz(int &lt;src&gt;)
3120
3121</pre>
3122
3123<h5>Overview:</h5>
3124
3125<p>
3126The '<tt>llvm.cttz</tt>' intrinsic counts the number of trailing zeros.
3127</p>
3128
3129<h5>Arguments:</h5>
3130
3131<p>
Andrew Lenharth5be6f132005-05-04 14:58:31 +00003132The only argument is the value to be counted. The argument may be of any integer type.
Andrew Lenharth1d463522005-05-03 18:01:48 +00003133</p>
3134
3135<h5>Semantics:</h5>
3136
3137<p>
3138The '<tt>llvm.cttz</tt>' intrinsic counts the trailing zeros in a variable. If the src == 0
3139then the result is the size in bits of the type of src.
3140</p>
3141</div>
3142
3143<!-- _______________________________________________________________________ -->
3144<div class="doc_subsubsection">
3145 <a name="int_ctlz">'<tt>llvm.ctlz</tt>' Intrinsic</a>
3146</div>
3147
3148<div class="doc_text">
3149
3150<h5>Syntax:</h5>
3151<pre>
3152 declare int %llvm.ctlz(int &lt;src&gt;)
3153
3154</pre>
3155
3156<h5>Overview:</h5>
3157
3158<p>
3159The '<tt>llvm.ctlz</tt>' intrinsic counts the number of leading zeros in a variable.
3160</p>
3161
3162<h5>Arguments:</h5>
3163
3164<p>
Andrew Lenharth5be6f132005-05-04 14:58:31 +00003165The only argument is the value to be counted. The argument may be of any integer type.
Andrew Lenharth1d463522005-05-03 18:01:48 +00003166</p>
3167
3168<h5>Semantics:</h5>
3169
3170<p>
3171The '<tt>llvm.ctlz</tt>' intrinsic counts the leading zeros in a variable. If the src == 0
3172then the result is the size in bits of the type of src.
3173</p>
3174</div>
Chris Lattner3b4f4372004-06-11 02:28:03 +00003175
3176
Chris Lattner941515c2004-01-06 05:31:32 +00003177<!-- ======================================================================= -->
3178<div class="doc_subsection">
3179 <a name="int_debugger">Debugger Intrinsics</a>
3180</div>
3181
3182<div class="doc_text">
3183<p>
3184The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
3185are described in the <a
3186href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
3187Debugging</a> document.
3188</p>
3189</div>
3190
3191
Chris Lattner2f7c9632001-06-06 20:29:01 +00003192<!-- *********************************************************************** -->
Chris Lattner2f7c9632001-06-06 20:29:01 +00003193<hr>
Misha Brukmanc501f552004-03-01 17:47:27 +00003194<address>
3195 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
3196 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
3197 <a href="http://validator.w3.org/check/referer"><img
3198 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
3199
3200 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
3201 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
3202 Last modified: $Date$
3203</address>
Misha Brukman76307852003-11-08 01:05:38 +00003204</body>
3205</html>