blob: f3f82d9d212a19a98e7971755a0ab5728332d613 [file] [log] [blame]
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
Misha Brukman9d0919f2003-11-08 01:05:38 +00003<html>
4<head>
5 <title>LLVM Assembly Language Reference Manual</title>
Reid Spencer3921c742004-08-26 20:44:00 +00006 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7 <meta name="author" content="Chris Lattner">
8 <meta name="description"
9 content="LLVM Assembly Language Reference Manual.">
Misha Brukman9d0919f2003-11-08 01:05:38 +000010 <link rel="stylesheet" href="llvm.css" type="text/css">
11</head>
Chris Lattnerd7923912004-05-23 21:06:01 +000012
Misha Brukman9d0919f2003-11-08 01:05:38 +000013<body>
Chris Lattnerd7923912004-05-23 21:06:01 +000014
Chris Lattner261efe92003-11-25 01:02:51 +000015<div class="doc_title"> LLVM Language Reference Manual </div>
Chris Lattner00950542001-06-06 20:29:01 +000016<ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000017 <li><a href="#abstract">Abstract</a></li>
18 <li><a href="#introduction">Introduction</a></li>
19 <li><a href="#identifiers">Identifiers</a></li>
Chris Lattnerfa730212004-12-09 16:11:40 +000020 <li><a href="#highlevel">High Level Structure</a>
21 <ol>
22 <li><a href="#modulestructure">Module Structure</a></li>
Chris Lattnere5d947b2004-12-09 16:36:40 +000023 <li><a href="#linkage">Linkage Types</a></li>
Chris Lattnerbad10ee2005-05-06 22:57:40 +000024 <li><a href="#callingconv">Calling Conventions</a></li>
Chris Lattnerfa730212004-12-09 16:11:40 +000025 <li><a href="#globalvars">Global Variables</a></li>
26 <li><a href="#functionstructure">Function Structure</a></li>
27 </ol>
28 </li>
Chris Lattner00950542001-06-06 20:29:01 +000029 <li><a href="#typesystem">Type System</a>
30 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000031 <li><a href="#t_primitive">Primitive Types</a>
32 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000033 <li><a href="#t_classifications">Type Classifications</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000034 </ol>
35 </li>
Chris Lattner00950542001-06-06 20:29:01 +000036 <li><a href="#t_derived">Derived Types</a>
37 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000038 <li><a href="#t_array">Array Type</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000039 <li><a href="#t_function">Function Type</a></li>
40 <li><a href="#t_pointer">Pointer Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000041 <li><a href="#t_struct">Structure Type</a></li>
Chris Lattnera58561b2004-08-12 19:12:28 +000042 <li><a href="#t_packed">Packed Type</a></li>
Chris Lattner69c11bb2005-04-25 17:34:15 +000043 <li><a href="#t_opaque">Opaque Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000044 </ol>
45 </li>
46 </ol>
47 </li>
Chris Lattnerfa730212004-12-09 16:11:40 +000048 <li><a href="#constants">Constants</a>
Chris Lattnerc3f59762004-12-09 17:30:23 +000049 <ol>
50 <li><a href="#simpleconstants">Simple Constants</a>
51 <li><a href="#aggregateconstants">Aggregate Constants</a>
52 <li><a href="#globalconstants">Global Variable and Function Addresses</a>
53 <li><a href="#undefvalues">Undefined Values</a>
54 <li><a href="#constantexprs">Constant Expressions</a>
55 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +000056 </li>
Chris Lattner00950542001-06-06 20:29:01 +000057 <li><a href="#instref">Instruction Reference</a>
58 <ol>
59 <li><a href="#terminators">Terminator Instructions</a>
60 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000061 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
62 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000063 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
64 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000065 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
Chris Lattner35eca582004-10-16 18:04:13 +000066 <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000067 </ol>
68 </li>
Chris Lattner00950542001-06-06 20:29:01 +000069 <li><a href="#binaryops">Binary Operations</a>
70 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000071 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
72 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
73 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
74 <li><a href="#i_div">'<tt>div</tt>' Instruction</a></li>
75 <li><a href="#i_rem">'<tt>rem</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000076 <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000077 </ol>
78 </li>
Chris Lattner00950542001-06-06 20:29:01 +000079 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
80 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000081 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000082 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000083 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
84 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
85 <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000086 </ol>
87 </li>
Chris Lattner00950542001-06-06 20:29:01 +000088 <li><a href="#memoryops">Memory Access Operations</a>
89 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000090 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
91 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
92 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
93 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
94 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
95 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
96 </ol>
97 </li>
Chris Lattner00950542001-06-06 20:29:01 +000098 <li><a href="#otherops">Other Operations</a>
99 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000100 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000101 <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li>
Chris Lattnercc37aae2004-03-12 05:50:16 +0000102 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Robert Bocchino3a558662006-01-05 17:37:02 +0000103 <li><a href="#i_extractelement">'<tt>extractelement</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000104 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Chris Lattnerfb6977d2006-01-13 23:26:01 +0000105 <li><a href="#i_va_arg">'<tt>va_arg</tt>' Instruction</a></li>
Chris Lattner00950542001-06-06 20:29:01 +0000106 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000107 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000108 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000109 </li>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +0000110 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +0000111 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000112 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
113 <ol>
114 <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
115 <li><a href="#i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
116 <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
117 </ol>
118 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000119 <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
120 <ol>
121 <li><a href="#i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li>
122 <li><a href="#i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li>
123 <li><a href="#i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li>
124 </ol>
125 </li>
Chris Lattner10610642004-02-14 04:08:35 +0000126 <li><a href="#int_codegen">Code Generator Intrinsics</a>
127 <ol>
128 <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
129 <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
Chris Lattner57e1f392006-01-13 02:03:13 +0000130 <li><a href="#i_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a></li>
131 <li><a href="#i_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a></li>
Chris Lattner9a9d7ac2005-02-28 19:24:19 +0000132 <li><a href="#i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a></li>
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +0000133 <li><a href="#i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a></li>
Andrew Lenharth51b8d542005-11-11 16:47:30 +0000134 <li><a href="#i_readcyclecounter"><tt>llvm.readcyclecounter</tt>' Intrinsic</a></li>
John Criswell7123e272004-04-09 16:43:20 +0000135 </ol>
136 </li>
137 <li><a href="#int_os">Operating System Intrinsics</a>
138 <ol>
Chris Lattner32006282004-06-11 02:28:03 +0000139 <li><a href="#i_readport">'<tt>llvm.readport</tt>' Intrinsic</a></li>
140 <li><a href="#i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a></li>
John Criswell183402a2004-04-12 15:02:16 +0000141 <li><a href="#i_readio">'<tt>llvm.readio</tt>' Intrinsic</a></li>
142 <li><a href="#i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000143 </ol>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000144 <li><a href="#int_libc">Standard C Library Intrinsics</a>
145 <ol>
146 <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li>
Chris Lattner0eb51b42004-02-12 18:10:10 +0000147 <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000148 <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li>
Alkis Evlogimenos96853722004-06-12 19:19:14 +0000149 <li><a href="#i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a></li>
Chris Lattnera4d74142005-07-21 01:29:16 +0000150 <li><a href="#i_sqrt">'<tt>llvm.sqrt</tt>' Intrinsic</a></li>
151
Chris Lattner33aec9e2004-02-12 17:01:32 +0000152 </ol>
153 </li>
Nate Begeman7e36c472006-01-13 23:26:38 +0000154 <li><a href="#int_manip">Bit Manipulation Intrinsics</a>
Andrew Lenharthec370fd2005-05-03 18:01:48 +0000155 <ol>
Nate Begeman7e36c472006-01-13 23:26:38 +0000156 <li><a href="#i_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a></li>
Andrew Lenharthec370fd2005-05-03 18:01:48 +0000157 <li><a href="#int_ctpop">'<tt>llvm.ctpop</tt>' Intrinsic </a></li>
Andrew Lenharthec370fd2005-05-03 18:01:48 +0000158 <li><a href="#int_ctlz">'<tt>llvm.ctlz</tt>' Intrinsic </a></li>
Chris Lattnereff29ab2005-05-15 19:39:26 +0000159 <li><a href="#int_cttz">'<tt>llvm.cttz</tt>' Intrinsic </a></li>
Andrew Lenharthec370fd2005-05-03 18:01:48 +0000160 </ol>
161 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000162 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000163 </ol>
164 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000165</ol>
Chris Lattnerd7923912004-05-23 21:06:01 +0000166
167<div class="doc_author">
168 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
169 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000170</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000171
Chris Lattner00950542001-06-06 20:29:01 +0000172<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000173<div class="doc_section"> <a name="abstract">Abstract </a></div>
174<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000175
Misha Brukman9d0919f2003-11-08 01:05:38 +0000176<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000177<p>This document is a reference manual for the LLVM assembly language.
178LLVM is an SSA based representation that provides type safety,
179low-level operations, flexibility, and the capability of representing
180'all' high-level languages cleanly. It is the common code
181representation used throughout all phases of the LLVM compilation
182strategy.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000183</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000184
Chris Lattner00950542001-06-06 20:29:01 +0000185<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000186<div class="doc_section"> <a name="introduction">Introduction</a> </div>
187<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000188
Misha Brukman9d0919f2003-11-08 01:05:38 +0000189<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000190
Chris Lattner261efe92003-11-25 01:02:51 +0000191<p>The LLVM code representation is designed to be used in three
192different forms: as an in-memory compiler IR, as an on-disk bytecode
193representation (suitable for fast loading by a Just-In-Time compiler),
194and as a human readable assembly language representation. This allows
195LLVM to provide a powerful intermediate representation for efficient
196compiler transformations and analysis, while providing a natural means
197to debug and visualize the transformations. The three different forms
198of LLVM are all equivalent. This document describes the human readable
199representation and notation.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000200
John Criswellc1f786c2005-05-13 22:25:59 +0000201<p>The LLVM representation aims to be light-weight and low-level
Chris Lattner261efe92003-11-25 01:02:51 +0000202while being expressive, typed, and extensible at the same time. It
203aims to be a "universal IR" of sorts, by being at a low enough level
204that high-level ideas may be cleanly mapped to it (similar to how
205microprocessors are "universal IR's", allowing many source languages to
206be mapped to them). By providing type information, LLVM can be used as
207the target of optimizations: for example, through pointer analysis, it
208can be proven that a C automatic variable is never accessed outside of
209the current function... allowing it to be promoted to a simple SSA
210value instead of a memory location.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000211
Misha Brukman9d0919f2003-11-08 01:05:38 +0000212</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000213
Chris Lattner00950542001-06-06 20:29:01 +0000214<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000215<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000216
Misha Brukman9d0919f2003-11-08 01:05:38 +0000217<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000218
Chris Lattner261efe92003-11-25 01:02:51 +0000219<p>It is important to note that this document describes 'well formed'
220LLVM assembly language. There is a difference between what the parser
221accepts and what is considered 'well formed'. For example, the
222following instruction is syntactically okay, but not well formed:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000223
224<pre>
225 %x = <a href="#i_add">add</a> int 1, %x
226</pre>
227
Chris Lattner261efe92003-11-25 01:02:51 +0000228<p>...because the definition of <tt>%x</tt> does not dominate all of
229its uses. The LLVM infrastructure provides a verification pass that may
230be used to verify that an LLVM module is well formed. This pass is
John Criswellc1f786c2005-05-13 22:25:59 +0000231automatically run by the parser after parsing input assembly and by
Chris Lattner261efe92003-11-25 01:02:51 +0000232the optimizer before it outputs bytecode. The violations pointed out
233by the verifier pass indicate bugs in transformation passes or input to
234the parser.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000235
Chris Lattner261efe92003-11-25 01:02:51 +0000236<!-- Describe the typesetting conventions here. --> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000237
Chris Lattner00950542001-06-06 20:29:01 +0000238<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000239<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000240<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000241
Misha Brukman9d0919f2003-11-08 01:05:38 +0000242<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000243
Chris Lattner261efe92003-11-25 01:02:51 +0000244<p>LLVM uses three different forms of identifiers, for different
245purposes:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000246
Chris Lattner00950542001-06-06 20:29:01 +0000247<ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000248 <li>Named values are represented as a string of characters with a '%' prefix.
249 For example, %foo, %DivisionByZero, %a.really.long.identifier. The actual
250 regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
251 Identifiers which require other characters in their names can be surrounded
252 with quotes. In this way, anything except a <tt>"</tt> character can be used
253 in a name.</li>
254
255 <li>Unnamed values are represented as an unsigned numeric value with a '%'
256 prefix. For example, %12, %2, %44.</li>
257
Reid Spencercc16dc32004-12-09 18:02:53 +0000258 <li>Constants, which are described in a <a href="#constants">section about
259 constants</a>, below.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000260</ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000261
262<p>LLVM requires that values start with a '%' sign for two reasons: Compilers
263don't need to worry about name clashes with reserved words, and the set of
264reserved words may be expanded in the future without penalty. Additionally,
265unnamed identifiers allow a compiler to quickly come up with a temporary
266variable without having to avoid symbol table conflicts.</p>
267
Chris Lattner261efe92003-11-25 01:02:51 +0000268<p>Reserved words in LLVM are very similar to reserved words in other
269languages. There are keywords for different opcodes ('<tt><a
Chris Lattnere5d947b2004-12-09 16:36:40 +0000270href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
271href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
272href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>', etc...),
273and others. These reserved words cannot conflict with variable names, because
274none of them start with a '%' character.</p>
275
276<p>Here is an example of LLVM code to multiply the integer variable
277'<tt>%X</tt>' by 8:</p>
278
Misha Brukman9d0919f2003-11-08 01:05:38 +0000279<p>The easy way:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000280
281<pre>
282 %result = <a href="#i_mul">mul</a> uint %X, 8
283</pre>
284
Misha Brukman9d0919f2003-11-08 01:05:38 +0000285<p>After strength reduction:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000286
287<pre>
288 %result = <a href="#i_shl">shl</a> uint %X, ubyte 3
289</pre>
290
Misha Brukman9d0919f2003-11-08 01:05:38 +0000291<p>And the hard way:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000292
293<pre>
294 <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
295 <a href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
296 %result = <a href="#i_add">add</a> uint %1, %1
297</pre>
298
Chris Lattner261efe92003-11-25 01:02:51 +0000299<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
300important lexical features of LLVM:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000301
Chris Lattner00950542001-06-06 20:29:01 +0000302<ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000303
304 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
305 line.</li>
306
307 <li>Unnamed temporaries are created when the result of a computation is not
308 assigned to a named value.</li>
309
Misha Brukman9d0919f2003-11-08 01:05:38 +0000310 <li>Unnamed temporaries are numbered sequentially</li>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000311
Misha Brukman9d0919f2003-11-08 01:05:38 +0000312</ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000313
John Criswelle4c57cc2005-05-12 16:52:32 +0000314<p>...and it also shows a convention that we follow in this document. When
Chris Lattnere5d947b2004-12-09 16:36:40 +0000315demonstrating instructions, we will follow an instruction with a comment that
316defines the type and name of value produced. Comments are shown in italic
317text.</p>
318
Misha Brukman9d0919f2003-11-08 01:05:38 +0000319</div>
Chris Lattnerfa730212004-12-09 16:11:40 +0000320
321<!-- *********************************************************************** -->
322<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
323<!-- *********************************************************************** -->
324
325<!-- ======================================================================= -->
326<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
327</div>
328
329<div class="doc_text">
330
331<p>LLVM programs are composed of "Module"s, each of which is a
332translation unit of the input programs. Each module consists of
333functions, global variables, and symbol table entries. Modules may be
334combined together with the LLVM linker, which merges function (and
335global variable) definitions, resolves forward declarations, and merges
336symbol table entries. Here is an example of the "hello world" module:</p>
337
338<pre><i>; Declare the string constant as a global constant...</i>
339<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
340 href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00" <i>; [13 x sbyte]*</i>
341
342<i>; External declaration of the puts function</i>
343<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
344
345<i>; Definition of main function</i>
346int %main() { <i>; int()* </i>
347 <i>; Convert [13x sbyte]* to sbyte *...</i>
348 %cast210 = <a
349 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
350
351 <i>; Call puts function to write out the string to stdout...</i>
352 <a
353 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
354 <a
355 href="#i_ret">ret</a> int 0<br>}<br></pre>
356
357<p>This example is made up of a <a href="#globalvars">global variable</a>
358named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
359function, and a <a href="#functionstructure">function definition</a>
360for "<tt>main</tt>".</p>
361
Chris Lattnere5d947b2004-12-09 16:36:40 +0000362<p>In general, a module is made up of a list of global values,
363where both functions and global variables are global values. Global values are
364represented by a pointer to a memory location (in this case, a pointer to an
365array of char, and a pointer to a function), and have one of the following <a
366href="#linkage">linkage types</a>.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000367
Chris Lattnere5d947b2004-12-09 16:36:40 +0000368</div>
369
370<!-- ======================================================================= -->
371<div class="doc_subsection">
372 <a name="linkage">Linkage Types</a>
373</div>
374
375<div class="doc_text">
376
377<p>
378All Global Variables and Functions have one of the following types of linkage:
379</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000380
381<dl>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000382
Chris Lattnerfa730212004-12-09 16:11:40 +0000383 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000384
385 <dd>Global values with internal linkage are only directly accessible by
386 objects in the current module. In particular, linking code into a module with
387 an internal global value may cause the internal to be renamed as necessary to
388 avoid collisions. Because the symbol is internal to the module, all
389 references can be updated. This corresponds to the notion of the
390 '<tt>static</tt>' keyword in C, or the idea of "anonymous namespaces" in C++.
Chris Lattnerfa730212004-12-09 16:11:40 +0000391 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000392
Chris Lattnerfa730212004-12-09 16:11:40 +0000393 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000394
395 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt> linkage, with
396 the twist that linking together two modules defining the same
397 <tt>linkonce</tt> globals will cause one of the globals to be discarded. This
398 is typically used to implement inline functions. Unreferenced
399 <tt>linkonce</tt> globals are allowed to be discarded.
Chris Lattnerfa730212004-12-09 16:11:40 +0000400 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000401
Chris Lattnerfa730212004-12-09 16:11:40 +0000402 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000403
404 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage,
405 except that unreferenced <tt>weak</tt> globals may not be discarded. This is
406 used to implement constructs in C such as "<tt>int X;</tt>" at global scope.
Chris Lattnerfa730212004-12-09 16:11:40 +0000407 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000408
Chris Lattnerfa730212004-12-09 16:11:40 +0000409 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000410
411 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
412 pointer to array type. When two global variables with appending linkage are
413 linked together, the two global arrays are appended together. This is the
414 LLVM, typesafe, equivalent of having the system linker append together
415 "sections" with identical names when .o files are linked.
Chris Lattnerfa730212004-12-09 16:11:40 +0000416 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000417
Chris Lattnerfa730212004-12-09 16:11:40 +0000418 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000419
420 <dd>If none of the above identifiers are used, the global is externally
421 visible, meaning that it participates in linkage and can be used to resolve
422 external symbol references.
Chris Lattnerfa730212004-12-09 16:11:40 +0000423 </dd>
424</dl>
425
Chris Lattnerfa730212004-12-09 16:11:40 +0000426<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
427variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
428variable and was linked with this one, one of the two would be renamed,
429preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
430external (i.e., lacking any linkage declarations), they are accessible
431outside of the current module. It is illegal for a function <i>declaration</i>
432to have any linkage type other than "externally visible".</a></p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000433
Chris Lattnerfa730212004-12-09 16:11:40 +0000434</div>
435
436<!-- ======================================================================= -->
437<div class="doc_subsection">
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000438 <a name="callingconv">Calling Conventions</a>
439</div>
440
441<div class="doc_text">
442
443<p>LLVM <a href="#functionstructure">functions</a>, <a href="#i_call">calls</a>
444and <a href="#i_invoke">invokes</a> can all have an optional calling convention
445specified for the call. The calling convention of any pair of dynamic
446caller/callee must match, or the behavior of the program is undefined. The
447following calling conventions are supported by LLVM, and more may be added in
448the future:</p>
449
450<dl>
451 <dt><b>"<tt>ccc</tt>" - The C calling convention</b>:</dt>
452
453 <dd>This calling convention (the default if no other calling convention is
454 specified) matches the target C calling conventions. This calling convention
John Criswelle4c57cc2005-05-12 16:52:32 +0000455 supports varargs function calls and tolerates some mismatch in the declared
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000456 prototype and implemented declaration of the function (as does normal C).
457 </dd>
458
459 <dt><b>"<tt>fastcc</tt>" - The fast calling convention</b>:</dt>
460
461 <dd>This calling convention attempts to make calls as fast as possible
462 (e.g. by passing things in registers). This calling convention allows the
463 target to use whatever tricks it wants to produce fast code for the target,
Chris Lattner8cdc5bc2005-05-06 23:08:23 +0000464 without having to conform to an externally specified ABI. Implementations of
465 this convention should allow arbitrary tail call optimization to be supported.
466 This calling convention does not support varargs and requires the prototype of
467 all callees to exactly match the prototype of the function definition.
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000468 </dd>
469
470 <dt><b>"<tt>coldcc</tt>" - The cold calling convention</b>:</dt>
471
472 <dd>This calling convention attempts to make code in the caller as efficient
473 as possible under the assumption that the call is not commonly executed. As
474 such, these calls often preserve all registers so that the call does not break
475 any live ranges in the caller side. This calling convention does not support
476 varargs and requires the prototype of all callees to exactly match the
477 prototype of the function definition.
478 </dd>
479
Chris Lattnercfe6b372005-05-07 01:46:40 +0000480 <dt><b>"<tt>cc &lt;<em>n</em>&gt;</tt>" - Numbered convention</b>:</dt>
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000481
482 <dd>Any calling convention may be specified by number, allowing
483 target-specific calling conventions to be used. Target specific calling
484 conventions start at 64.
485 </dd>
Chris Lattnercfe6b372005-05-07 01:46:40 +0000486</dl>
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000487
488<p>More calling conventions can be added/defined on an as-needed basis, to
489support pascal conventions or any other well-known target-independent
490convention.</p>
491
492</div>
493
494<!-- ======================================================================= -->
495<div class="doc_subsection">
Chris Lattnerfa730212004-12-09 16:11:40 +0000496 <a name="globalvars">Global Variables</a>
497</div>
498
499<div class="doc_text">
500
Chris Lattner3689a342005-02-12 19:30:21 +0000501<p>Global variables define regions of memory allocated at compilation time
Chris Lattner88f6c462005-11-12 00:45:07 +0000502instead of run-time. Global variables may optionally be initialized, may have
503an explicit section to be placed in, and may
Chris Lattner2cbdc452005-11-06 08:02:57 +0000504have an optional explicit alignment specified. A
John Criswell0ec250c2005-10-24 16:17:18 +0000505variable may be defined as a global "constant," which indicates that the
Chris Lattner3689a342005-02-12 19:30:21 +0000506contents of the variable will <b>never</b> be modified (enabling better
507optimization, allowing the global data to be placed in the read-only section of
508an executable, etc). Note that variables that need runtime initialization
John Criswell0ec250c2005-10-24 16:17:18 +0000509cannot be marked "constant" as there is a store to the variable.</p>
Chris Lattner3689a342005-02-12 19:30:21 +0000510
511<p>
512LLVM explicitly allows <em>declarations</em> of global variables to be marked
513constant, even if the final definition of the global is not. This capability
514can be used to enable slightly better optimization of the program, but requires
515the language definition to guarantee that optimizations based on the
516'constantness' are valid for the translation units that do not include the
517definition.
518</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000519
520<p>As SSA values, global variables define pointer values that are in
521scope (i.e. they dominate) all basic blocks in the program. Global
522variables always define a pointer to their "content" type because they
523describe a region of memory, and all memory objects in LLVM are
524accessed through pointers.</p>
525
Chris Lattner88f6c462005-11-12 00:45:07 +0000526<p>LLVM allows an explicit section to be specified for globals. If the target
527supports it, it will emit globals to the section specified.</p>
528
Chris Lattner2cbdc452005-11-06 08:02:57 +0000529<p>An explicit alignment may be specified for a global. If not present, or if
530the alignment is set to zero, the alignment of the global is set by the target
531to whatever it feels convenient. If an explicit alignment is specified, the
532global is forced to have at least that much alignment. All alignments must be
533a power of 2.</p>
534
Chris Lattnerfa730212004-12-09 16:11:40 +0000535</div>
536
537
538<!-- ======================================================================= -->
539<div class="doc_subsection">
540 <a name="functionstructure">Functions</a>
541</div>
542
543<div class="doc_text">
544
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000545<p>LLVM function definitions consist of an optional <a href="#linkage">linkage
546type</a>, an optional <a href="#callingconv">calling convention</a>, a return
Chris Lattner88f6c462005-11-12 00:45:07 +0000547type, a function name, a (possibly empty) argument list, an optional section,
548an optional alignment, an opening curly brace,
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000549a list of basic blocks, and a closing curly brace. LLVM function declarations
550are defined with the "<tt>declare</tt>" keyword, an optional <a
Chris Lattner2cbdc452005-11-06 08:02:57 +0000551href="#callingconv">calling convention</a>, a return type, a function name,
552a possibly empty list of arguments, and an optional alignment.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000553
554<p>A function definition contains a list of basic blocks, forming the CFG for
555the function. Each basic block may optionally start with a label (giving the
556basic block a symbol table entry), contains a list of instructions, and ends
557with a <a href="#terminators">terminator</a> instruction (such as a branch or
558function return).</p>
559
John Criswelle4c57cc2005-05-12 16:52:32 +0000560<p>The first basic block in a program is special in two ways: it is immediately
Chris Lattnerfa730212004-12-09 16:11:40 +0000561executed on entrance to the function, and it is not allowed to have predecessor
562basic blocks (i.e. there can not be any branches to the entry block of a
563function). Because the block can have no predecessors, it also cannot have any
564<a href="#i_phi">PHI nodes</a>.</p>
565
566<p>LLVM functions are identified by their name and type signature. Hence, two
567functions with the same name but different parameter lists or return values are
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000568considered different functions, and LLVM will resolve references to each
Chris Lattnerfa730212004-12-09 16:11:40 +0000569appropriately.</p>
570
Chris Lattner88f6c462005-11-12 00:45:07 +0000571<p>LLVM allows an explicit section to be specified for functions. If the target
572supports it, it will emit functions to the section specified.</p>
573
Chris Lattner2cbdc452005-11-06 08:02:57 +0000574<p>An explicit alignment may be specified for a function. If not present, or if
575the alignment is set to zero, the alignment of the function is set by the target
576to whatever it feels convenient. If an explicit alignment is specified, the
577function is forced to have at least that much alignment. All alignments must be
578a power of 2.</p>
579
Chris Lattnerfa730212004-12-09 16:11:40 +0000580</div>
581
582
583
Chris Lattner00950542001-06-06 20:29:01 +0000584<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000585<div class="doc_section"> <a name="typesystem">Type System</a> </div>
586<!-- *********************************************************************** -->
Chris Lattnerfa730212004-12-09 16:11:40 +0000587
Misha Brukman9d0919f2003-11-08 01:05:38 +0000588<div class="doc_text">
Chris Lattnerfa730212004-12-09 16:11:40 +0000589
Misha Brukman9d0919f2003-11-08 01:05:38 +0000590<p>The LLVM type system is one of the most important features of the
Chris Lattner261efe92003-11-25 01:02:51 +0000591intermediate representation. Being typed enables a number of
592optimizations to be performed on the IR directly, without having to do
593extra analyses on the side before the transformation. A strong type
594system makes it easier to read the generated code and enables novel
595analyses and transformations that are not feasible to perform on normal
596three address code representations.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000597
598</div>
599
Chris Lattner00950542001-06-06 20:29:01 +0000600<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000601<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000602<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +0000603<p>The primitive types are the fundamental building blocks of the LLVM
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000604system. The current set of primitive types is as follows:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000605
Reid Spencerd3f876c2004-11-01 08:19:36 +0000606<table class="layout">
607 <tr class="layout">
608 <td class="left">
609 <table>
Chris Lattner261efe92003-11-25 01:02:51 +0000610 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000611 <tr><th>Type</th><th>Description</th></tr>
612 <tr><td><tt>void</tt></td><td>No value</td></tr>
Misha Brukmancfa87bc2005-04-22 18:02:52 +0000613 <tr><td><tt>ubyte</tt></td><td>Unsigned 8-bit value</td></tr>
614 <tr><td><tt>ushort</tt></td><td>Unsigned 16-bit value</td></tr>
615 <tr><td><tt>uint</tt></td><td>Unsigned 32-bit value</td></tr>
616 <tr><td><tt>ulong</tt></td><td>Unsigned 64-bit value</td></tr>
617 <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000618 <tr><td><tt>label</tt></td><td>Branch destination</td></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000619 </tbody>
620 </table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000621 </td>
622 <td class="right">
623 <table>
Chris Lattner261efe92003-11-25 01:02:51 +0000624 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000625 <tr><th>Type</th><th>Description</th></tr>
626 <tr><td><tt>bool</tt></td><td>True or False value</td></tr>
Misha Brukmancfa87bc2005-04-22 18:02:52 +0000627 <tr><td><tt>sbyte</tt></td><td>Signed 8-bit value</td></tr>
628 <tr><td><tt>short</tt></td><td>Signed 16-bit value</td></tr>
629 <tr><td><tt>int</tt></td><td>Signed 32-bit value</td></tr>
630 <tr><td><tt>long</tt></td><td>Signed 64-bit value</td></tr>
631 <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000632 </tbody>
633 </table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000634 </td>
635 </tr>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000636</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000637</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000638
Chris Lattner00950542001-06-06 20:29:01 +0000639<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000640<div class="doc_subsubsection"> <a name="t_classifications">Type
641Classifications</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000642<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000643<p>These different primitive types fall into a few useful
644classifications:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000645
646<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +0000647 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000648 <tr><th>Classification</th><th>Types</th></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000649 <tr>
650 <td><a name="t_signed">signed</a></td>
651 <td><tt>sbyte, short, int, long, float, double</tt></td>
652 </tr>
653 <tr>
654 <td><a name="t_unsigned">unsigned</a></td>
655 <td><tt>ubyte, ushort, uint, ulong</tt></td>
656 </tr>
657 <tr>
658 <td><a name="t_integer">integer</a></td>
659 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
660 </tr>
661 <tr>
662 <td><a name="t_integral">integral</a></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000663 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt>
664 </td>
Chris Lattner261efe92003-11-25 01:02:51 +0000665 </tr>
666 <tr>
667 <td><a name="t_floating">floating point</a></td>
668 <td><tt>float, double</tt></td>
669 </tr>
670 <tr>
671 <td><a name="t_firstclass">first class</a></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000672 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long,<br>
673 float, double, <a href="#t_pointer">pointer</a>,
674 <a href="#t_packed">packed</a></tt></td>
Chris Lattner261efe92003-11-25 01:02:51 +0000675 </tr>
676 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000677</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000678
Chris Lattner261efe92003-11-25 01:02:51 +0000679<p>The <a href="#t_firstclass">first class</a> types are perhaps the
680most important. Values of these types are the only ones which can be
681produced by instructions, passed as arguments, or used as operands to
682instructions. This means that all structures and arrays must be
683manipulated either by pointer or by component.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000684</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000685
Chris Lattner00950542001-06-06 20:29:01 +0000686<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000687<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000688
Misha Brukman9d0919f2003-11-08 01:05:38 +0000689<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +0000690
Chris Lattner261efe92003-11-25 01:02:51 +0000691<p>The real power in LLVM comes from the derived types in the system.
692This is what allows a programmer to represent arrays, functions,
693pointers, and other useful types. Note that these derived types may be
694recursive: For example, it is possible to have a two dimensional array.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000695
Misha Brukman9d0919f2003-11-08 01:05:38 +0000696</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000697
Chris Lattner00950542001-06-06 20:29:01 +0000698<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000699<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000700
Misha Brukman9d0919f2003-11-08 01:05:38 +0000701<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +0000702
Chris Lattner00950542001-06-06 20:29:01 +0000703<h5>Overview:</h5>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000704
Misha Brukman9d0919f2003-11-08 01:05:38 +0000705<p>The array type is a very simple derived type that arranges elements
Chris Lattner261efe92003-11-25 01:02:51 +0000706sequentially in memory. The array type requires a size (number of
707elements) and an underlying data type.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000708
Chris Lattner7faa8832002-04-14 06:13:44 +0000709<h5>Syntax:</h5>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000710
711<pre>
712 [&lt;# elements&gt; x &lt;elementtype&gt;]
713</pre>
714
John Criswelle4c57cc2005-05-12 16:52:32 +0000715<p>The number of elements is a constant integer value; elementtype may
Chris Lattner261efe92003-11-25 01:02:51 +0000716be any type with a size.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000717
Chris Lattner7faa8832002-04-14 06:13:44 +0000718<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000719<table class="layout">
720 <tr class="layout">
721 <td class="left">
722 <tt>[40 x int ]</tt><br/>
723 <tt>[41 x int ]</tt><br/>
724 <tt>[40 x uint]</tt><br/>
725 </td>
726 <td class="left">
727 Array of 40 integer values.<br/>
728 Array of 41 integer values.<br/>
729 Array of 40 unsigned integer values.<br/>
730 </td>
731 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000732</table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000733<p>Here are some examples of multidimensional arrays:</p>
734<table class="layout">
735 <tr class="layout">
736 <td class="left">
737 <tt>[3 x [4 x int]]</tt><br/>
738 <tt>[12 x [10 x float]]</tt><br/>
739 <tt>[2 x [3 x [4 x uint]]]</tt><br/>
740 </td>
741 <td class="left">
John Criswellc1f786c2005-05-13 22:25:59 +0000742 3x4 array of integer values.<br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000743 12x10 array of single precision floating point values.<br/>
744 2x3x4 array of unsigned integer values.<br/>
745 </td>
746 </tr>
747</table>
Chris Lattnere67a9512005-06-24 17:22:57 +0000748
John Criswell0ec250c2005-10-24 16:17:18 +0000749<p>Note that 'variable sized arrays' can be implemented in LLVM with a zero
750length array. Normally, accesses past the end of an array are undefined in
Chris Lattnere67a9512005-06-24 17:22:57 +0000751LLVM (e.g. it is illegal to access the 5th element of a 3 element array).
752As a special case, however, zero length arrays are recognized to be variable
753length. This allows implementation of 'pascal style arrays' with the LLVM
754type "{ int, [0 x float]}", for example.</p>
755
Misha Brukman9d0919f2003-11-08 01:05:38 +0000756</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000757
Chris Lattner00950542001-06-06 20:29:01 +0000758<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000759<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000760<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000761<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000762<p>The function type can be thought of as a function signature. It
763consists of a return type and a list of formal parameter types.
John Criswell009900b2003-11-25 21:45:46 +0000764Function types are usually used to build virtual function tables
Chris Lattner261efe92003-11-25 01:02:51 +0000765(which are structures of pointers to functions), for indirect function
766calls, and when defining a function.</p>
John Criswell009900b2003-11-25 21:45:46 +0000767<p>
768The return type of a function type cannot be an aggregate type.
769</p>
Chris Lattner00950542001-06-06 20:29:01 +0000770<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000771<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
John Criswell0ec250c2005-10-24 16:17:18 +0000772<p>...where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
Misha Brukmanc24b7582004-08-12 20:16:08 +0000773specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner27f71f22003-09-03 00:41:47 +0000774which indicates that the function takes a variable number of arguments.
775Variable argument functions can access their arguments with the <a
Chris Lattner261efe92003-11-25 01:02:51 +0000776 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000777<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000778<table class="layout">
779 <tr class="layout">
780 <td class="left">
781 <tt>int (int)</tt> <br/>
782 <tt>float (int, int *) *</tt><br/>
783 <tt>int (sbyte *, ...)</tt><br/>
784 </td>
785 <td class="left">
786 function taking an <tt>int</tt>, returning an <tt>int</tt><br/>
787 <a href="#t_pointer">Pointer</a> to a function that takes an
Misha Brukmanc24b7582004-08-12 20:16:08 +0000788 <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
Reid Spencerd3f876c2004-11-01 08:19:36 +0000789 returning <tt>float</tt>.<br/>
790 A vararg function that takes at least one <a href="#t_pointer">pointer</a>
791 to <tt>sbyte</tt> (signed char in C), which returns an integer. This is
792 the signature for <tt>printf</tt> in LLVM.<br/>
793 </td>
794 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000795</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000796
Misha Brukman9d0919f2003-11-08 01:05:38 +0000797</div>
Chris Lattner00950542001-06-06 20:29:01 +0000798<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000799<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000800<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000801<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000802<p>The structure type is used to represent a collection of data members
803together in memory. The packing of the field types is defined to match
804the ABI of the underlying processor. The elements of a structure may
805be any type that has a size.</p>
806<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
807and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
808field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
809instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000810<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000811<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +0000812<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000813<table class="layout">
814 <tr class="layout">
815 <td class="left">
816 <tt>{ int, int, int }</tt><br/>
817 <tt>{ float, int (int) * }</tt><br/>
818 </td>
819 <td class="left">
820 a triple of three <tt>int</tt> values<br/>
821 A pair, where the first element is a <tt>float</tt> and the second element
822 is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a>
823 that takes an <tt>int</tt>, returning an <tt>int</tt>.<br/>
824 </td>
825 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000826</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000827</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000828
Chris Lattner00950542001-06-06 20:29:01 +0000829<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000830<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000831<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +0000832<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000833<p>As in many languages, the pointer type represents a pointer or
834reference to another object, which must live in memory.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000835<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000836<pre> &lt;type&gt; *<br></pre>
Chris Lattner7faa8832002-04-14 06:13:44 +0000837<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000838<table class="layout">
839 <tr class="layout">
840 <td class="left">
841 <tt>[4x int]*</tt><br/>
842 <tt>int (int *) *</tt><br/>
843 </td>
844 <td class="left">
845 A <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of
846 four <tt>int</tt> values<br/>
847 A <a href="#t_pointer">pointer</a> to a <a
Chris Lattnera977c482005-02-19 02:22:14 +0000848 href="#t_function">function</a> that takes an <tt>int*</tt>, returning an
Reid Spencerd3f876c2004-11-01 08:19:36 +0000849 <tt>int</tt>.<br/>
850 </td>
851 </tr>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000852</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000853</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000854
Chris Lattnera58561b2004-08-12 19:12:28 +0000855<!-- _______________________________________________________________________ -->
856<div class="doc_subsubsection"> <a name="t_packed">Packed Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000857<div class="doc_text">
Chris Lattner69c11bb2005-04-25 17:34:15 +0000858
Chris Lattnera58561b2004-08-12 19:12:28 +0000859<h5>Overview:</h5>
Chris Lattner69c11bb2005-04-25 17:34:15 +0000860
Chris Lattnera58561b2004-08-12 19:12:28 +0000861<p>A packed type is a simple derived type that represents a vector
862of elements. Packed types are used when multiple primitive data
863are operated in parallel using a single instruction (SIMD).
864A packed type requires a size (number of
Chris Lattnerb8d172f2005-11-10 01:44:22 +0000865elements) and an underlying primitive data type. Vectors must have a power
866of two length (1, 2, 4, 8, 16 ...). Packed types are
Chris Lattnera58561b2004-08-12 19:12:28 +0000867considered <a href="#t_firstclass">first class</a>.</p>
Chris Lattner69c11bb2005-04-25 17:34:15 +0000868
Chris Lattnera58561b2004-08-12 19:12:28 +0000869<h5>Syntax:</h5>
Chris Lattner69c11bb2005-04-25 17:34:15 +0000870
871<pre>
872 &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;
873</pre>
874
John Criswellc1f786c2005-05-13 22:25:59 +0000875<p>The number of elements is a constant integer value; elementtype may
Chris Lattnera58561b2004-08-12 19:12:28 +0000876be any integral or floating point type.</p>
Chris Lattner69c11bb2005-04-25 17:34:15 +0000877
Chris Lattnera58561b2004-08-12 19:12:28 +0000878<h5>Examples:</h5>
Chris Lattner69c11bb2005-04-25 17:34:15 +0000879
Reid Spencerd3f876c2004-11-01 08:19:36 +0000880<table class="layout">
881 <tr class="layout">
882 <td class="left">
883 <tt>&lt;4 x int&gt;</tt><br/>
884 <tt>&lt;8 x float&gt;</tt><br/>
885 <tt>&lt;2 x uint&gt;</tt><br/>
886 </td>
887 <td class="left">
888 Packed vector of 4 integer values.<br/>
889 Packed vector of 8 floating-point values.<br/>
890 Packed vector of 2 unsigned integer values.<br/>
891 </td>
892 </tr>
893</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000894</div>
895
Chris Lattner69c11bb2005-04-25 17:34:15 +0000896<!-- _______________________________________________________________________ -->
897<div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div>
898<div class="doc_text">
899
900<h5>Overview:</h5>
901
902<p>Opaque types are used to represent unknown types in the system. This
903corresponds (for example) to the C notion of a foward declared structure type.
904In LLVM, opaque types can eventually be resolved to any type (not just a
905structure type).</p>
906
907<h5>Syntax:</h5>
908
909<pre>
910 opaque
911</pre>
912
913<h5>Examples:</h5>
914
915<table class="layout">
916 <tr class="layout">
917 <td class="left">
918 <tt>opaque</tt>
919 </td>
920 <td class="left">
921 An opaque type.<br/>
922 </td>
923 </tr>
924</table>
925</div>
926
927
Chris Lattnerc3f59762004-12-09 17:30:23 +0000928<!-- *********************************************************************** -->
929<div class="doc_section"> <a name="constants">Constants</a> </div>
930<!-- *********************************************************************** -->
931
932<div class="doc_text">
933
934<p>LLVM has several different basic types of constants. This section describes
935them all and their syntax.</p>
936
937</div>
938
939<!-- ======================================================================= -->
Reid Spencercc16dc32004-12-09 18:02:53 +0000940<div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000941
942<div class="doc_text">
943
944<dl>
945 <dt><b>Boolean constants</b></dt>
946
947 <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
948 constants of the <tt><a href="#t_primitive">bool</a></tt> type.
949 </dd>
950
951 <dt><b>Integer constants</b></dt>
952
Reid Spencercc16dc32004-12-09 18:02:53 +0000953 <dd>Standard integers (such as '4') are constants of the <a
Chris Lattnerc3f59762004-12-09 17:30:23 +0000954 href="#t_integer">integer</a> type. Negative numbers may be used with signed
955 integer types.
956 </dd>
957
958 <dt><b>Floating point constants</b></dt>
959
960 <dd>Floating point constants use standard decimal notation (e.g. 123.421),
961 exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
Chris Lattnerc3f59762004-12-09 17:30:23 +0000962 notation (see below). Floating point constants must have a <a
963 href="#t_floating">floating point</a> type. </dd>
964
965 <dt><b>Null pointer constants</b></dt>
966
John Criswell9e2485c2004-12-10 15:51:16 +0000967 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
Chris Lattnerc3f59762004-12-09 17:30:23 +0000968 and must be of <a href="#t_pointer">pointer type</a>.</dd>
969
970</dl>
971
John Criswell9e2485c2004-12-10 15:51:16 +0000972<p>The one non-intuitive notation for constants is the optional hexadecimal form
Chris Lattnerc3f59762004-12-09 17:30:23 +0000973of floating point constants. For example, the form '<tt>double
9740x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
9754.5e+15</tt>'. The only time hexadecimal floating point constants are required
Reid Spencercc16dc32004-12-09 18:02:53 +0000976(and the only time that they are generated by the disassembler) is when a
977floating point constant must be emitted but it cannot be represented as a
978decimal floating point number. For example, NaN's, infinities, and other
979special values are represented in their IEEE hexadecimal format so that
980assembly and disassembly do not cause any bits to change in the constants.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000981
982</div>
983
984<!-- ======================================================================= -->
985<div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a>
986</div>
987
988<div class="doc_text">
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000989<p>Aggregate constants arise from aggregation of simple constants
990and smaller aggregate constants.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000991
992<dl>
993 <dt><b>Structure constants</b></dt>
994
995 <dd>Structure constants are represented with notation similar to structure
996 type definitions (a comma separated list of elements, surrounded by braces
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000997 (<tt>{}</tt>)). For example: "<tt>{ int 4, float 17.0, int* %G }</tt>",
998 where "<tt>%G</tt>" is declared as "<tt>%G = external global int</tt>". Structure constants
999 must have <a href="#t_struct">structure type</a>, and the number and
Chris Lattnerc3f59762004-12-09 17:30:23 +00001000 types of elements must match those specified by the type.
1001 </dd>
1002
1003 <dt><b>Array constants</b></dt>
1004
1005 <dd>Array constants are represented with notation similar to array type
1006 definitions (a comma separated list of elements, surrounded by square brackets
John Criswell9e2485c2004-12-10 15:51:16 +00001007 (<tt>[]</tt>)). For example: "<tt>[ int 42, int 11, int 74 ]</tt>". Array
Chris Lattnerc3f59762004-12-09 17:30:23 +00001008 constants must have <a href="#t_array">array type</a>, and the number and
1009 types of elements must match those specified by the type.
1010 </dd>
1011
1012 <dt><b>Packed constants</b></dt>
1013
1014 <dd>Packed constants are represented with notation similar to packed type
1015 definitions (a comma separated list of elements, surrounded by
John Criswell9e2485c2004-12-10 15:51:16 +00001016 less-than/greater-than's (<tt>&lt;&gt;</tt>)). For example: "<tt>&lt; int 42,
Chris Lattnerc3f59762004-12-09 17:30:23 +00001017 int 11, int 74, int 100 &gt;</tt>". Packed constants must have <a
1018 href="#t_packed">packed type</a>, and the number and types of elements must
1019 match those specified by the type.
1020 </dd>
1021
1022 <dt><b>Zero initialization</b></dt>
1023
1024 <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
1025 value to zero of <em>any</em> type, including scalar and aggregate types.
1026 This is often used to avoid having to print large zero initializers (e.g. for
John Criswell0ec250c2005-10-24 16:17:18 +00001027 large arrays) and is always exactly equivalent to using explicit zero
Chris Lattnerc3f59762004-12-09 17:30:23 +00001028 initializers.
1029 </dd>
1030</dl>
1031
1032</div>
1033
1034<!-- ======================================================================= -->
1035<div class="doc_subsection">
1036 <a name="globalconstants">Global Variable and Function Addresses</a>
1037</div>
1038
1039<div class="doc_text">
1040
1041<p>The addresses of <a href="#globalvars">global variables</a> and <a
1042href="#functionstructure">functions</a> are always implicitly valid (link-time)
John Criswell9e2485c2004-12-10 15:51:16 +00001043constants. These constants are explicitly referenced when the <a
1044href="#identifiers">identifier for the global</a> is used and always have <a
Chris Lattnerc3f59762004-12-09 17:30:23 +00001045href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
1046file:</p>
1047
1048<pre>
1049 %X = global int 17
1050 %Y = global int 42
1051 %Z = global [2 x int*] [ int* %X, int* %Y ]
1052</pre>
1053
1054</div>
1055
1056<!-- ======================================================================= -->
Reid Spencer2dc45b82004-12-09 18:13:12 +00001057<div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001058<div class="doc_text">
Reid Spencer2dc45b82004-12-09 18:13:12 +00001059 <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has
John Criswellc1f786c2005-05-13 22:25:59 +00001060 no specific value. Undefined values may be of any type and be used anywhere
Reid Spencer2dc45b82004-12-09 18:13:12 +00001061 a constant is permitted.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001062
Reid Spencer2dc45b82004-12-09 18:13:12 +00001063 <p>Undefined values indicate to the compiler that the program is well defined
1064 no matter what value is used, giving the compiler more freedom to optimize.
1065 </p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001066</div>
1067
1068<!-- ======================================================================= -->
1069<div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
1070</div>
1071
1072<div class="doc_text">
1073
1074<p>Constant expressions are used to allow expressions involving other constants
1075to be used as constants. Constant expressions may be of any <a
John Criswellc1f786c2005-05-13 22:25:59 +00001076href="#t_firstclass">first class</a> type and may involve any LLVM operation
Chris Lattnerc3f59762004-12-09 17:30:23 +00001077that does not have side effects (e.g. load and call are not supported). The
1078following is the syntax for constant expressions:</p>
1079
1080<dl>
1081 <dt><b><tt>cast ( CST to TYPE )</tt></b></dt>
1082
1083 <dd>Cast a constant to another type.</dd>
1084
1085 <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
1086
1087 <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
1088 constants. As with the <a href="#i_getelementptr">getelementptr</a>
1089 instruction, the index list may have zero or more indexes, which are required
1090 to make sense for the type of "CSTPTR".</dd>
1091
Robert Bocchino9fbe1452006-01-10 19:31:34 +00001092 <dt><b><tt>select ( COND, VAL1, VAL2 )</tt></b></dt>
1093
1094 <dd>Perform the <a href="#i_select">select operation</a> on
1095 constants.
1096
1097 <dt><b><tt>extractelement ( VAL, IDX )</tt></b></dt>
1098
1099 <dd>Perform the <a href="#i_extractelement">extractelement
1100 operation</a> on constants.
1101
Chris Lattnerc3f59762004-12-09 17:30:23 +00001102 <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
1103
Reid Spencer2dc45b82004-12-09 18:13:12 +00001104 <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
1105 be any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise
Chris Lattnerc3f59762004-12-09 17:30:23 +00001106 binary</a> operations. The constraints on operands are the same as those for
1107 the corresponding instruction (e.g. no bitwise operations on floating point
John Criswelle4c57cc2005-05-12 16:52:32 +00001108 values are allowed).</dd>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001109</dl>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001110</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +00001111
Chris Lattner00950542001-06-06 20:29:01 +00001112<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00001113<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
1114<!-- *********************************************************************** -->
Chris Lattnerc3f59762004-12-09 17:30:23 +00001115
Misha Brukman9d0919f2003-11-08 01:05:38 +00001116<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +00001117
Chris Lattner261efe92003-11-25 01:02:51 +00001118<p>The LLVM instruction set consists of several different
1119classifications of instructions: <a href="#terminators">terminator
John Criswellc1f786c2005-05-13 22:25:59 +00001120instructions</a>, <a href="#binaryops">binary instructions</a>,
1121<a href="#bitwiseops">bitwise binary instructions</a>, <a
Chris Lattner261efe92003-11-25 01:02:51 +00001122 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
1123instructions</a>.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001124
Misha Brukman9d0919f2003-11-08 01:05:38 +00001125</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001126
Chris Lattner00950542001-06-06 20:29:01 +00001127<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001128<div class="doc_subsection"> <a name="terminators">Terminator
1129Instructions</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001130
Misha Brukman9d0919f2003-11-08 01:05:38 +00001131<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +00001132
Chris Lattner261efe92003-11-25 01:02:51 +00001133<p>As mentioned <a href="#functionstructure">previously</a>, every
1134basic block in a program ends with a "Terminator" instruction, which
1135indicates which block should be executed after the current block is
1136finished. These terminator instructions typically yield a '<tt>void</tt>'
1137value: they produce control flow, not values (the one exception being
1138the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
John Criswell9e2485c2004-12-10 15:51:16 +00001139<p>There are six different terminator instructions: the '<a
Chris Lattner261efe92003-11-25 01:02:51 +00001140 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
1141instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
Chris Lattner35eca582004-10-16 18:04:13 +00001142the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
1143 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
1144 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001145
Misha Brukman9d0919f2003-11-08 01:05:38 +00001146</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001147
Chris Lattner00950542001-06-06 20:29:01 +00001148<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001149<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
1150Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001151<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001152<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001153<pre> ret &lt;type&gt; &lt;value&gt; <i>; Return a value from a non-void function</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001154 ret void <i>; Return from void function</i>
Chris Lattner00950542001-06-06 20:29:01 +00001155</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001156<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001157<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
John Criswellc1f786c2005-05-13 22:25:59 +00001158value) from a function back to the caller.</p>
John Criswell4457dc92004-04-09 16:48:45 +00001159<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner261efe92003-11-25 01:02:51 +00001160returns a value and then causes control flow, and one that just causes
1161control flow to occur.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001162<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001163<p>The '<tt>ret</tt>' instruction may return any '<a
1164 href="#t_firstclass">first class</a>' type. Notice that a function is
1165not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
1166instruction inside of the function that returns a value that does not
1167match the return type of the function.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001168<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001169<p>When the '<tt>ret</tt>' instruction is executed, control flow
1170returns back to the calling function's context. If the caller is a "<a
John Criswellfa081872004-06-25 15:16:57 +00001171 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner261efe92003-11-25 01:02:51 +00001172the instruction after the call. If the caller was an "<a
1173 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
John Criswelle4c57cc2005-05-12 16:52:32 +00001174at the beginning of the "normal" destination block. If the instruction
Chris Lattner261efe92003-11-25 01:02:51 +00001175returns a value, that value shall set the call or invoke instruction's
1176return value.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001177<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001178<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001179 ret void <i>; Return from a void function</i>
Chris Lattner00950542001-06-06 20:29:01 +00001180</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001181</div>
Chris Lattner00950542001-06-06 20:29:01 +00001182<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001183<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001184<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001185<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001186<pre> br bool &lt;cond&gt;, label &lt;iftrue&gt;, label &lt;iffalse&gt;<br> br label &lt;dest&gt; <i>; Unconditional branch</i>
Chris Lattner00950542001-06-06 20:29:01 +00001187</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001188<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001189<p>The '<tt>br</tt>' instruction is used to cause control flow to
1190transfer to a different basic block in the current function. There are
1191two forms of this instruction, corresponding to a conditional branch
1192and an unconditional branch.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001193<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001194<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
1195single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
1196unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
1197value as a target.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001198<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001199<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
1200argument is evaluated. If the value is <tt>true</tt>, control flows
1201to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
1202control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001203<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001204<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
1205 href="#i_ret">ret</a> int 1<br>IfUnequal:<br> <a href="#i_ret">ret</a> int 0<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001206</div>
Chris Lattner00950542001-06-06 20:29:01 +00001207<!-- _______________________________________________________________________ -->
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001208<div class="doc_subsubsection">
1209 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
1210</div>
1211
Misha Brukman9d0919f2003-11-08 01:05:38 +00001212<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001213<h5>Syntax:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001214
1215<pre>
1216 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
1217</pre>
1218
Chris Lattner00950542001-06-06 20:29:01 +00001219<h5>Overview:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001220
1221<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
1222several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +00001223instruction, allowing a branch to occur to one of many possible
1224destinations.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001225
1226
Chris Lattner00950542001-06-06 20:29:01 +00001227<h5>Arguments:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001228
1229<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
1230comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
1231an array of pairs of comparison value constants and '<tt>label</tt>'s. The
1232table is not allowed to contain duplicate constant entries.</p>
1233
Chris Lattner00950542001-06-06 20:29:01 +00001234<h5>Semantics:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001235
Chris Lattner261efe92003-11-25 01:02:51 +00001236<p>The <tt>switch</tt> instruction specifies a table of values and
1237destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswell84114752004-06-25 16:05:06 +00001238table is searched for the given value. If the value is found, control flow is
1239transfered to the corresponding destination; otherwise, control flow is
1240transfered to the default destination.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001241
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001242<h5>Implementation:</h5>
1243
1244<p>Depending on properties of the target machine and the particular
1245<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswell84114752004-06-25 16:05:06 +00001246ways. For example, it could be generated as a series of chained conditional
1247branches or with a lookup table.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001248
1249<h5>Example:</h5>
1250
1251<pre>
1252 <i>; Emulate a conditional br instruction</i>
1253 %Val = <a href="#i_cast">cast</a> bool %value to int
1254 switch int %Val, label %truedest [int 0, label %falsedest ]
1255
1256 <i>; Emulate an unconditional br instruction</i>
1257 switch uint 0, label %dest [ ]
1258
1259 <i>; Implement a jump table:</i>
1260 switch uint %val, label %otherwise [ uint 0, label %onzero
1261 uint 1, label %onone
1262 uint 2, label %ontwo ]
Chris Lattner00950542001-06-06 20:29:01 +00001263</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001264</div>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001265
Chris Lattner00950542001-06-06 20:29:01 +00001266<!-- _______________________________________________________________________ -->
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001267<div class="doc_subsubsection">
1268 <a name="i_invoke">'<tt>invoke</tt>' Instruction</a>
1269</div>
1270
Misha Brukman9d0919f2003-11-08 01:05:38 +00001271<div class="doc_text">
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001272
Chris Lattner00950542001-06-06 20:29:01 +00001273<h5>Syntax:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001274
1275<pre>
1276 &lt;result&gt; = invoke [<a href="#callingconv">cconv</a>] &lt;ptr to function ty&gt; %&lt;function ptr val&gt;(&lt;function args&gt;)
1277 to label &lt;normal label&gt; except label &lt;exception label&gt;
1278</pre>
1279
Chris Lattner6536cfe2002-05-06 22:08:29 +00001280<h5>Overview:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001281
1282<p>The '<tt>invoke</tt>' instruction causes control to transfer to a specified
1283function, with the possibility of control flow transfer to either the
John Criswelle4c57cc2005-05-12 16:52:32 +00001284'<tt>normal</tt>' label or the
1285'<tt>exception</tt>' label. If the callee function returns with the
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001286"<tt><a href="#i_ret">ret</a></tt>" instruction, control flow will return to the
1287"normal" label. If the callee (or any indirect callees) returns with the "<a
John Criswelle4c57cc2005-05-12 16:52:32 +00001288href="#i_unwind"><tt>unwind</tt></a>" instruction, control is interrupted and
1289continued at the dynamically nearest "exception" label.</p>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001290
Chris Lattner00950542001-06-06 20:29:01 +00001291<h5>Arguments:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001292
Misha Brukman9d0919f2003-11-08 01:05:38 +00001293<p>This instruction requires several arguments:</p>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001294
Chris Lattner00950542001-06-06 20:29:01 +00001295<ol>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001296 <li>
John Criswellc1f786c2005-05-13 22:25:59 +00001297 The optional "cconv" marker indicates which <a href="callingconv">calling
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001298 convention</a> the call should use. If none is specified, the call defaults
1299 to using C calling conventions.
1300 </li>
1301 <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to
1302 function value being invoked. In most cases, this is a direct function
1303 invocation, but indirect <tt>invoke</tt>s are just as possible, branching off
1304 an arbitrary pointer to function value.
1305 </li>
1306
1307 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a
1308 function to be invoked. </li>
1309
1310 <li>'<tt>function args</tt>': argument list whose types match the function
1311 signature argument types. If the function signature indicates the function
1312 accepts a variable number of arguments, the extra arguments can be
1313 specified. </li>
1314
1315 <li>'<tt>normal label</tt>': the label reached when the called function
1316 executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
1317
1318 <li>'<tt>exception label</tt>': the label reached when a callee returns with
1319 the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
1320
Chris Lattner00950542001-06-06 20:29:01 +00001321</ol>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001322
Chris Lattner00950542001-06-06 20:29:01 +00001323<h5>Semantics:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001324
Misha Brukman9d0919f2003-11-08 01:05:38 +00001325<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001326href="#i_call">call</a></tt>' instruction in most regards. The primary
1327difference is that it establishes an association with a label, which is used by
1328the runtime library to unwind the stack.</p>
1329
1330<p>This instruction is used in languages with destructors to ensure that proper
1331cleanup is performed in the case of either a <tt>longjmp</tt> or a thrown
1332exception. Additionally, this is important for implementation of
1333'<tt>catch</tt>' clauses in high-level languages that support them.</p>
1334
Chris Lattner00950542001-06-06 20:29:01 +00001335<h5>Example:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001336<pre>
1337 %retval = invoke int %Test(int 15) to label %Continue
1338 except label %TestCleanup <i>; {int}:retval set</i>
1339 %retval = invoke <a href="#callingconv">coldcc</a> int %Test(int 15) to label %Continue
1340 except label %TestCleanup <i>; {int}:retval set</i>
Chris Lattner00950542001-06-06 20:29:01 +00001341</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001342</div>
Chris Lattner35eca582004-10-16 18:04:13 +00001343
1344
Chris Lattner27f71f22003-09-03 00:41:47 +00001345<!-- _______________________________________________________________________ -->
Chris Lattner35eca582004-10-16 18:04:13 +00001346
Chris Lattner261efe92003-11-25 01:02:51 +00001347<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
1348Instruction</a> </div>
Chris Lattner35eca582004-10-16 18:04:13 +00001349
Misha Brukman9d0919f2003-11-08 01:05:38 +00001350<div class="doc_text">
Chris Lattner35eca582004-10-16 18:04:13 +00001351
Chris Lattner27f71f22003-09-03 00:41:47 +00001352<h5>Syntax:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001353<pre>
1354 unwind
1355</pre>
1356
Chris Lattner27f71f22003-09-03 00:41:47 +00001357<h5>Overview:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001358
1359<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
1360at the first callee in the dynamic call stack which used an <a
1361href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
1362primarily used to implement exception handling.</p>
1363
Chris Lattner27f71f22003-09-03 00:41:47 +00001364<h5>Semantics:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001365
1366<p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to
1367immediately halt. The dynamic call stack is then searched for the first <a
1368href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
1369execution continues at the "exceptional" destination block specified by the
1370<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
1371dynamic call chain, undefined behavior results.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001372</div>
Chris Lattner35eca582004-10-16 18:04:13 +00001373
1374<!-- _______________________________________________________________________ -->
1375
1376<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
1377Instruction</a> </div>
1378
1379<div class="doc_text">
1380
1381<h5>Syntax:</h5>
1382<pre>
1383 unreachable
1384</pre>
1385
1386<h5>Overview:</h5>
1387
1388<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
1389instruction is used to inform the optimizer that a particular portion of the
1390code is not reachable. This can be used to indicate that the code after a
1391no-return function cannot be reached, and other facts.</p>
1392
1393<h5>Semantics:</h5>
1394
1395<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
1396</div>
1397
1398
1399
Chris Lattner00950542001-06-06 20:29:01 +00001400<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001401<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001402<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001403<p>Binary operators are used to do most of the computation in a
1404program. They require two operands, execute an operation on them, and
John Criswell9e2485c2004-12-10 15:51:16 +00001405produce a single value. The operands might represent
Chris Lattnera58561b2004-08-12 19:12:28 +00001406multiple data, as is the case with the <a href="#t_packed">packed</a> data type.
1407The result value of a binary operator is not
Chris Lattner261efe92003-11-25 01:02:51 +00001408necessarily the same type as its operands.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001409<p>There are several different binary operators:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001410</div>
Chris Lattner00950542001-06-06 20:29:01 +00001411<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001412<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
1413Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001414<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001415<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001416<pre> &lt;result&gt; = add &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001417</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001418<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001419<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001420<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001421<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattnera58561b2004-08-12 19:12:28 +00001422 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
1423 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1424Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001425<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001426<p>The value produced is the integer or floating point sum of the two
1427operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001428<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001429<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001430</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001431</div>
Chris Lattner00950542001-06-06 20:29:01 +00001432<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001433<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
1434Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001435<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001436<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001437<pre> &lt;result&gt; = sub &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001438</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001439<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001440<p>The '<tt>sub</tt>' instruction returns the difference of its two
1441operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001442<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
1443instruction present in most other intermediate representations.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001444<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001445<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001446 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001447values.
1448This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1449Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001450<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001451<p>The value produced is the integer or floating point difference of
1452the two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001453<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001454<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001455 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
1456</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001457</div>
Chris Lattner00950542001-06-06 20:29:01 +00001458<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001459<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
1460Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001461<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001462<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001463<pre> &lt;result&gt; = mul &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001464</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001465<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001466<p>The '<tt>mul</tt>' instruction returns the product of its two
1467operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001468<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001469<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001470 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001471values.
1472This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1473Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001474<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001475<p>The value produced is the integer or floating point product of the
Misha Brukman9d0919f2003-11-08 01:05:38 +00001476two operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001477<p>There is no signed vs unsigned multiplication. The appropriate
1478action is taken based on the type of the operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001479<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001480<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001481</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001482</div>
Chris Lattner00950542001-06-06 20:29:01 +00001483<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001484<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
1485Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001486<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001487<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001488<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1489</pre>
1490<h5>Overview:</h5>
1491<p>The '<tt>div</tt>' instruction returns the quotient of its two
1492operands.</p>
1493<h5>Arguments:</h5>
1494<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
1495 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001496values.
1497This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1498Both arguments must have identical types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001499<h5>Semantics:</h5>
1500<p>The value produced is the integer or floating point quotient of the
1501two operands.</p>
1502<h5>Example:</h5>
1503<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
1504</pre>
1505</div>
1506<!-- _______________________________________________________________________ -->
1507<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
1508Instruction</a> </div>
1509<div class="doc_text">
1510<h5>Syntax:</h5>
1511<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1512</pre>
1513<h5>Overview:</h5>
1514<p>The '<tt>rem</tt>' instruction returns the remainder from the
1515division of its two operands.</p>
1516<h5>Arguments:</h5>
1517<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1518 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001519values.
1520This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1521Both arguments must have identical types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001522<h5>Semantics:</h5>
1523<p>This returns the <i>remainder</i> of a division (where the result
1524has the same sign as the divisor), not the <i>modulus</i> (where the
1525result has the same sign as the dividend) of a value. For more
John Criswell0ec250c2005-10-24 16:17:18 +00001526information about the difference, see <a
Chris Lattner261efe92003-11-25 01:02:51 +00001527 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1528Math Forum</a>.</p>
1529<h5>Example:</h5>
1530<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1531</pre>
1532</div>
1533<!-- _______________________________________________________________________ -->
1534<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1535Instructions</a> </div>
1536<div class="doc_text">
1537<h5>Syntax:</h5>
1538<pre> &lt;result&gt; = seteq &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001539 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1540 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1541 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1542 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1543 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1544</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001545<h5>Overview:</h5>
1546<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1547value based on a comparison of their two operands.</p>
1548<h5>Arguments:</h5>
1549<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1550be of <a href="#t_firstclass">first class</a> type (it is not possible
1551to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1552or '<tt>void</tt>' values, etc...). Both arguments must have identical
1553types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001554<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001555<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1556value if both operands are equal.<br>
1557The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1558value if both operands are unequal.<br>
1559The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1560value if the first operand is less than the second operand.<br>
1561The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1562value if the first operand is greater than the second operand.<br>
1563The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1564value if the first operand is less than or equal to the second operand.<br>
1565The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1566value if the first operand is greater than or equal to the second
1567operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001568<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001569<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner00950542001-06-06 20:29:01 +00001570 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
1571 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1572 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1573 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1574 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1575</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001576</div>
Chris Lattner00950542001-06-06 20:29:01 +00001577<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001578<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1579Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001580<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001581<p>Bitwise binary operators are used to do various forms of
1582bit-twiddling in a program. They are generally very efficient
John Criswell9e2485c2004-12-10 15:51:16 +00001583instructions and can commonly be strength reduced from other
Chris Lattner261efe92003-11-25 01:02:51 +00001584instructions. They require two operands, execute an operation on them,
1585and produce a single value. The resulting value of the bitwise binary
1586operators is always the same type as its first operand.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001587</div>
Chris Lattner00950542001-06-06 20:29:01 +00001588<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001589<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1590Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001591<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001592<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001593<pre> &lt;result&gt; = and &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001594</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001595<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001596<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1597its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001598<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001599<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001600 href="#t_integral">integral</a> values. Both arguments must have
1601identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001602<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001603<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001604<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001605<div style="align: center">
Misha Brukman9d0919f2003-11-08 01:05:38 +00001606<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +00001607 <tbody>
1608 <tr>
1609 <td>In0</td>
1610 <td>In1</td>
1611 <td>Out</td>
1612 </tr>
1613 <tr>
1614 <td>0</td>
1615 <td>0</td>
1616 <td>0</td>
1617 </tr>
1618 <tr>
1619 <td>0</td>
1620 <td>1</td>
1621 <td>0</td>
1622 </tr>
1623 <tr>
1624 <td>1</td>
1625 <td>0</td>
1626 <td>0</td>
1627 </tr>
1628 <tr>
1629 <td>1</td>
1630 <td>1</td>
1631 <td>1</td>
1632 </tr>
1633 </tbody>
1634</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001635</div>
Chris Lattner00950542001-06-06 20:29:01 +00001636<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001637<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001638 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1639 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1640</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001641</div>
Chris Lattner00950542001-06-06 20:29:01 +00001642<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001643<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001644<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001645<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001646<pre> &lt;result&gt; = or &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001647</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001648<h5>Overview:</h5>
1649<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1650or of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001651<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001652<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001653 href="#t_integral">integral</a> values. Both arguments must have
1654identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001655<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001656<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001657<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001658<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001659<table border="1" cellspacing="0" cellpadding="4">
1660 <tbody>
1661 <tr>
1662 <td>In0</td>
1663 <td>In1</td>
1664 <td>Out</td>
1665 </tr>
1666 <tr>
1667 <td>0</td>
1668 <td>0</td>
1669 <td>0</td>
1670 </tr>
1671 <tr>
1672 <td>0</td>
1673 <td>1</td>
1674 <td>1</td>
1675 </tr>
1676 <tr>
1677 <td>1</td>
1678 <td>0</td>
1679 <td>1</td>
1680 </tr>
1681 <tr>
1682 <td>1</td>
1683 <td>1</td>
1684 <td>1</td>
1685 </tr>
1686 </tbody>
1687</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001688</div>
Chris Lattner00950542001-06-06 20:29:01 +00001689<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001690<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001691 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1692 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1693</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001694</div>
Chris Lattner00950542001-06-06 20:29:01 +00001695<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001696<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1697Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001698<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001699<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001700<pre> &lt;result&gt; = xor &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001701</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001702<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001703<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1704or of its two operands. The <tt>xor</tt> is used to implement the
1705"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001706<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001707<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001708 href="#t_integral">integral</a> values. Both arguments must have
1709identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001710<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001711<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001712<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001713<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001714<table border="1" cellspacing="0" cellpadding="4">
1715 <tbody>
1716 <tr>
1717 <td>In0</td>
1718 <td>In1</td>
1719 <td>Out</td>
1720 </tr>
1721 <tr>
1722 <td>0</td>
1723 <td>0</td>
1724 <td>0</td>
1725 </tr>
1726 <tr>
1727 <td>0</td>
1728 <td>1</td>
1729 <td>1</td>
1730 </tr>
1731 <tr>
1732 <td>1</td>
1733 <td>0</td>
1734 <td>1</td>
1735 </tr>
1736 <tr>
1737 <td>1</td>
1738 <td>1</td>
1739 <td>0</td>
1740 </tr>
1741 </tbody>
1742</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001743</div>
Chris Lattner261efe92003-11-25 01:02:51 +00001744<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001745<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001746<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001747 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1748 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner27f71f22003-09-03 00:41:47 +00001749 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner00950542001-06-06 20:29:01 +00001750</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001751</div>
Chris Lattner00950542001-06-06 20:29:01 +00001752<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001753<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1754Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001755<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001756<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001757<pre> &lt;result&gt; = shl &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001758</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001759<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001760<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1761the left a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001762<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001763<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001764 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1765type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001766<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001767<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001768<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001769<pre> &lt;result&gt; = shl int 4, ubyte %var <i>; yields {int}:result = 4 &lt;&lt; %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001770 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1771 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1772</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001773</div>
Chris Lattner00950542001-06-06 20:29:01 +00001774<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001775<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1776Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001777<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001778<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001779<pre> &lt;result&gt; = shr &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001780</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001781<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001782<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1783the right a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001784<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001785<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001786 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1787type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001788<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001789<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1790most significant bit is duplicated in the newly free'd bit positions.
1791If the first argument is unsigned, zero bits shall fill the empty
1792positions.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001793<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001794<pre> &lt;result&gt; = shr int 4, ubyte %var <i>; yields {int}:result = 4 &gt;&gt; %var</i>
Chris Lattner8c6bb902003-06-18 21:30:51 +00001795 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001796 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner8c6bb902003-06-18 21:30:51 +00001797 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1798 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner00950542001-06-06 20:29:01 +00001799</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001800</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001801
Chris Lattner00950542001-06-06 20:29:01 +00001802<!-- ======================================================================= -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00001803<div class="doc_subsection">
1804 <a name="memoryops">Memory Access Operations</a>
1805</div>
1806
Misha Brukman9d0919f2003-11-08 01:05:38 +00001807<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00001808
Chris Lattner261efe92003-11-25 01:02:51 +00001809<p>A key design point of an SSA-based representation is how it
1810represents memory. In LLVM, no memory locations are in SSA form, which
1811makes things very simple. This section describes how to read, write,
John Criswell9e2485c2004-12-10 15:51:16 +00001812allocate, and free memory in LLVM.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001813
Misha Brukman9d0919f2003-11-08 01:05:38 +00001814</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001815
Chris Lattner00950542001-06-06 20:29:01 +00001816<!-- _______________________________________________________________________ -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00001817<div class="doc_subsubsection">
1818 <a name="i_malloc">'<tt>malloc</tt>' Instruction</a>
1819</div>
1820
Misha Brukman9d0919f2003-11-08 01:05:38 +00001821<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00001822
Chris Lattner00950542001-06-06 20:29:01 +00001823<h5>Syntax:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001824
1825<pre>
1826 &lt;result&gt; = malloc &lt;type&gt;[, uint &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001827</pre>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001828
Chris Lattner00950542001-06-06 20:29:01 +00001829<h5>Overview:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001830
Chris Lattner261efe92003-11-25 01:02:51 +00001831<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1832heap and returns a pointer to it.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001833
Chris Lattner00950542001-06-06 20:29:01 +00001834<h5>Arguments:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001835
1836<p>The '<tt>malloc</tt>' instruction allocates
1837<tt>sizeof(&lt;type&gt;)*NumElements</tt>
John Criswell6e4ca612004-02-24 16:13:56 +00001838bytes of memory from the operating system and returns a pointer of the
Chris Lattner2cbdc452005-11-06 08:02:57 +00001839appropriate type to the program. If "NumElements" is specified, it is the
1840number of elements allocated. If an alignment is specified, the value result
1841of the allocation is guaranteed to be aligned to at least that boundary. If
1842not specified, or if zero, the target can choose to align the allocation on any
1843convenient boundary.</p>
1844
Misha Brukman9d0919f2003-11-08 01:05:38 +00001845<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001846
Chris Lattner00950542001-06-06 20:29:01 +00001847<h5>Semantics:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001848
Chris Lattner261efe92003-11-25 01:02:51 +00001849<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1850a pointer is returned.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001851
Chris Lattner2cbdc452005-11-06 08:02:57 +00001852<h5>Example:</h5>
1853
1854<pre>
1855 %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
1856
1857 %size = <a href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001858 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1859 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001860 %array3 = malloc int, uint 4, align 1024 <i>; yields {int*}:array3</i>
1861 %array4 = malloc int, align 1024 <i>; yields {int*}:array4</i>
Chris Lattner00950542001-06-06 20:29:01 +00001862</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001863</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001864
Chris Lattner00950542001-06-06 20:29:01 +00001865<!-- _______________________________________________________________________ -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00001866<div class="doc_subsubsection">
1867 <a name="i_free">'<tt>free</tt>' Instruction</a>
1868</div>
1869
Misha Brukman9d0919f2003-11-08 01:05:38 +00001870<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00001871
Chris Lattner00950542001-06-06 20:29:01 +00001872<h5>Syntax:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001873
1874<pre>
1875 free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner00950542001-06-06 20:29:01 +00001876</pre>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001877
Chris Lattner00950542001-06-06 20:29:01 +00001878<h5>Overview:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001879
Chris Lattner261efe92003-11-25 01:02:51 +00001880<p>The '<tt>free</tt>' instruction returns memory back to the unused
John Criswellc1f786c2005-05-13 22:25:59 +00001881memory heap to be reallocated in the future.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001882
Chris Lattner00950542001-06-06 20:29:01 +00001883<h5>Arguments:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001884
Chris Lattner261efe92003-11-25 01:02:51 +00001885<p>'<tt>value</tt>' shall be a pointer value that points to a value
1886that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1887instruction.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001888
Chris Lattner00950542001-06-06 20:29:01 +00001889<h5>Semantics:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001890
John Criswell9e2485c2004-12-10 15:51:16 +00001891<p>Access to the memory pointed to by the pointer is no longer defined
Chris Lattner261efe92003-11-25 01:02:51 +00001892after this instruction executes.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001893
Chris Lattner00950542001-06-06 20:29:01 +00001894<h5>Example:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001895
1896<pre>
1897 %array = <a href="#i_malloc">malloc</a> [4 x ubyte] <i>; yields {[4 x ubyte]*}:array</i>
Chris Lattner00950542001-06-06 20:29:01 +00001898 free [4 x ubyte]* %array
1899</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001900</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001901
Chris Lattner00950542001-06-06 20:29:01 +00001902<!-- _______________________________________________________________________ -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00001903<div class="doc_subsubsection">
1904 <a name="i_alloca">'<tt>alloca</tt>' Instruction</a>
1905</div>
1906
Misha Brukman9d0919f2003-11-08 01:05:38 +00001907<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00001908
Chris Lattner00950542001-06-06 20:29:01 +00001909<h5>Syntax:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001910
1911<pre>
1912 &lt;result&gt; = alloca &lt;type&gt;[, uint &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001913</pre>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001914
Chris Lattner00950542001-06-06 20:29:01 +00001915<h5>Overview:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001916
Chris Lattner261efe92003-11-25 01:02:51 +00001917<p>The '<tt>alloca</tt>' instruction allocates memory on the current
1918stack frame of the procedure that is live until the current function
1919returns to its caller.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001920
Chris Lattner00950542001-06-06 20:29:01 +00001921<h5>Arguments:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001922
John Criswell9e2485c2004-12-10 15:51:16 +00001923<p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001924bytes of memory on the runtime stack, returning a pointer of the
Chris Lattner2cbdc452005-11-06 08:02:57 +00001925appropriate type to the program. If "NumElements" is specified, it is the
1926number of elements allocated. If an alignment is specified, the value result
1927of the allocation is guaranteed to be aligned to at least that boundary. If
1928not specified, or if zero, the target can choose to align the allocation on any
1929convenient boundary.</p>
1930
Misha Brukman9d0919f2003-11-08 01:05:38 +00001931<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001932
Chris Lattner00950542001-06-06 20:29:01 +00001933<h5>Semantics:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001934
John Criswellc1f786c2005-05-13 22:25:59 +00001935<p>Memory is allocated; a pointer is returned. '<tt>alloca</tt>'d
Chris Lattner261efe92003-11-25 01:02:51 +00001936memory is automatically released when the function returns. The '<tt>alloca</tt>'
1937instruction is commonly used to represent automatic variables that must
1938have an address available. When the function returns (either with the <tt><a
John Criswelldae2e932005-05-12 16:55:34 +00001939 href="#i_ret">ret</a></tt> or <tt><a href="#i_unwind">unwind</a></tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001940instructions), the memory is reclaimed.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001941
Chris Lattner00950542001-06-06 20:29:01 +00001942<h5>Example:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001943
1944<pre>
1945 %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001946 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001947 %ptr = alloca int, uint 4, align 1024 <i>; yields {int*}:ptr</i>
1948 %ptr = alloca int, align 1024 <i>; yields {int*}:ptr</i>
Chris Lattner00950542001-06-06 20:29:01 +00001949</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001950</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00001951
Chris Lattner00950542001-06-06 20:29:01 +00001952<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001953<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1954Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001955<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00001956<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001957<pre> &lt;result&gt; = load &lt;ty&gt;* &lt;pointer&gt;<br> &lt;result&gt; = volatile load &lt;ty&gt;* &lt;pointer&gt;<br></pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001958<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001959<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001960<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001961<p>The argument to the '<tt>load</tt>' instruction specifies the memory
John Criswell0ec250c2005-10-24 16:17:18 +00001962address from which to load. The pointer must point to a <a
Chris Lattnere53e5082004-06-03 22:57:15 +00001963 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
John Criswell0ec250c2005-10-24 16:17:18 +00001964marked as <tt>volatile</tt>, then the optimizer is not allowed to modify
Chris Lattner261efe92003-11-25 01:02:51 +00001965the number or order of execution of this <tt>load</tt> with other
1966volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1967instructions. </p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001968<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001969<p>The location of memory pointed to is loaded.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001970<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001971<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1972 <a
1973 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001974 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1975</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001976</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001977<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001978<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1979Instruction</a> </div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001980<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001981<pre> store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt; <i>; yields {void}</i>
Chris Lattnerf0651072003-09-08 18:27:49 +00001982 volatile store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt; <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001983</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001984<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001985<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001986<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001987<p>There are two arguments to the '<tt>store</tt>' instruction: a value
John Criswell0ec250c2005-10-24 16:17:18 +00001988to store and an address in which to store it. The type of the '<tt>&lt;pointer&gt;</tt>'
Chris Lattner261efe92003-11-25 01:02:51 +00001989operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
John Criswellc1f786c2005-05-13 22:25:59 +00001990operand. If the <tt>store</tt> is marked as <tt>volatile</tt>, then the
Chris Lattner261efe92003-11-25 01:02:51 +00001991optimizer is not allowed to modify the number or order of execution of
1992this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1993 href="#i_store">store</a></tt> instructions.</p>
1994<h5>Semantics:</h5>
1995<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
1996at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001997<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001998<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1999 <a
2000 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002001 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
2002</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002003<!-- _______________________________________________________________________ -->
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002004<div class="doc_subsubsection">
2005 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
2006</div>
2007
Misha Brukman9d0919f2003-11-08 01:05:38 +00002008<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00002009<h5>Syntax:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002010<pre>
2011 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
2012</pre>
2013
Chris Lattner7faa8832002-04-14 06:13:44 +00002014<h5>Overview:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002015
2016<p>
2017The '<tt>getelementptr</tt>' instruction is used to get the address of a
2018subelement of an aggregate data structure.</p>
2019
Chris Lattner7faa8832002-04-14 06:13:44 +00002020<h5>Arguments:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002021
2022<p>This instruction takes a list of integer constants that indicate what
2023elements of the aggregate object to index to. The actual types of the arguments
2024provided depend on the type of the first pointer argument. The
2025'<tt>getelementptr</tt>' instruction is used to index down through the type
John Criswellfc6b8952005-05-16 16:17:45 +00002026levels of a structure or to a specific index in an array. When indexing into a
2027structure, only <tt>uint</tt>
John Criswellc1f786c2005-05-13 22:25:59 +00002028integer constants are allowed. When indexing into an array or pointer,
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002029<tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
2030
Chris Lattner261efe92003-11-25 01:02:51 +00002031<p>For example, let's consider a C code fragment and how it gets
2032compiled to LLVM:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002033
2034<pre>
2035 struct RT {
2036 char A;
2037 int B[10][20];
2038 char C;
2039 };
2040 struct ST {
2041 int X;
2042 double Y;
2043 struct RT Z;
2044 };
2045
2046 int *foo(struct ST *s) {
2047 return &amp;s[1].Z.B[5][13];
2048 }
2049</pre>
2050
Misha Brukman9d0919f2003-11-08 01:05:38 +00002051<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002052
2053<pre>
2054 %RT = type { sbyte, [10 x [20 x int]], sbyte }
2055 %ST = type { int, double, %RT }
2056
Brian Gaeke7283e7c2004-07-02 21:08:14 +00002057 implementation
2058
2059 int* %foo(%ST* %s) {
2060 entry:
2061 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002062 ret int* %reg
2063 }
2064</pre>
2065
Chris Lattner7faa8832002-04-14 06:13:44 +00002066<h5>Semantics:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002067
2068<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
John Criswellc1f786c2005-05-13 22:25:59 +00002069on the pointer type that is being indexed into. <a href="#t_pointer">Pointer</a>
Chris Lattnere53e5082004-06-03 22:57:15 +00002070and <a href="#t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
2071<tt>ulong</tt>, or <tt>long</tt> values, and <a href="#t_struct">structure</a>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002072types require <tt>uint</tt> <b>constants</b>.</p>
2073
Misha Brukman9d0919f2003-11-08 01:05:38 +00002074<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002075type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
2076}</tt>' type, a structure. The second index indexes into the third element of
2077the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
2078sbyte }</tt>' type, another structure. The third index indexes into the second
2079element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
2080array. The two dimensions of the array are subscripted into, yielding an
John Criswellfc6b8952005-05-16 16:17:45 +00002081'<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction returns a pointer
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002082to this element, thus computing a value of '<tt>int*</tt>' type.</p>
2083
Chris Lattner261efe92003-11-25 01:02:51 +00002084<p>Note that it is perfectly legal to index partially through a
2085structure, returning a pointer to an inner element. Because of this,
2086the LLVM code for the given testcase is equivalent to:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002087
2088<pre>
Chris Lattnerd4f6b172005-03-07 22:13:59 +00002089 int* %foo(%ST* %s) {
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002090 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
2091 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
2092 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
2093 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
2094 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
2095 ret int* %t5
2096 }
Chris Lattner6536cfe2002-05-06 22:08:29 +00002097</pre>
Chris Lattnere67a9512005-06-24 17:22:57 +00002098
2099<p>Note that it is undefined to access an array out of bounds: array and
2100pointer indexes must always be within the defined bounds of the array type.
2101The one exception for this rules is zero length arrays. These arrays are
2102defined to be accessible as variable length arrays, which requires access
2103beyond the zero'th element.</p>
2104
Chris Lattner7faa8832002-04-14 06:13:44 +00002105<h5>Example:</h5>
Chris Lattnere67a9512005-06-24 17:22:57 +00002106
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002107<pre>
2108 <i>; yields [12 x ubyte]*:aptr</i>
2109 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
2110</pre>
2111
2112</div>
Chris Lattner00950542001-06-06 20:29:01 +00002113<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00002114<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002115<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +00002116<p>The instructions in this category are the "miscellaneous"
Chris Lattner261efe92003-11-25 01:02:51 +00002117instructions, which defy better classification.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002118</div>
Chris Lattner00950542001-06-06 20:29:01 +00002119<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00002120<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
2121Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002122<div class="doc_text">
Chris Lattner33ba0d92001-07-09 00:26:23 +00002123<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002124<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner33ba0d92001-07-09 00:26:23 +00002125<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002126<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
2127the SSA graph representing the function.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00002128<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002129<p>The type of the incoming values are specified with the first type
2130field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
2131as arguments, with one pair for each predecessor basic block of the
2132current block. Only values of <a href="#t_firstclass">first class</a>
2133type may be used as the value arguments to the PHI node. Only labels
2134may be used as the label arguments.</p>
2135<p>There must be no non-phi instructions between the start of a basic
2136block and the PHI instructions: i.e. PHI instructions must be first in
2137a basic block.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00002138<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002139<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
2140value specified by the parameter, depending on which basic block we
2141came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00002142<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002143<pre>Loop: ; Infinite loop that counts from 0 on up...<br> %indvar = phi uint [ 0, %LoopHeader ], [ %nextindvar, %Loop ]<br> %nextindvar = add uint %indvar, 1<br> br label %Loop<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002144</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002145
Chris Lattner6536cfe2002-05-06 22:08:29 +00002146<!-- _______________________________________________________________________ -->
Chris Lattnercc37aae2004-03-12 05:50:16 +00002147<div class="doc_subsubsection">
2148 <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
2149</div>
2150
Misha Brukman9d0919f2003-11-08 01:05:38 +00002151<div class="doc_text">
Chris Lattnercc37aae2004-03-12 05:50:16 +00002152
Chris Lattner6536cfe2002-05-06 22:08:29 +00002153<h5>Syntax:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002154
2155<pre>
2156 &lt;result&gt; = cast &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Chris Lattner6536cfe2002-05-06 22:08:29 +00002157</pre>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002158
Chris Lattner6536cfe2002-05-06 22:08:29 +00002159<h5>Overview:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002160
2161<p>
2162The '<tt>cast</tt>' instruction is used as the primitive means to convert
2163integers to floating point, change data type sizes, and break type safety (by
2164casting pointers).
2165</p>
2166
2167
Chris Lattner6536cfe2002-05-06 22:08:29 +00002168<h5>Arguments:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002169
2170<p>
2171The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
2172class value, and a type to cast it to, which must also be a <a
2173href="#t_firstclass">first class</a> type.
2174</p>
2175
Chris Lattner6536cfe2002-05-06 22:08:29 +00002176<h5>Semantics:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002177
2178<p>
2179This instruction follows the C rules for explicit casts when determining how the
2180data being cast must change to fit in its new container.
2181</p>
2182
2183<p>
2184When casting to bool, any value that would be considered true in the context of
2185a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
2186all else are '<tt>false</tt>'.
2187</p>
2188
2189<p>
2190When extending an integral value from a type of one signness to another (for
2191example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
2192<b>source</b> value is signed, and zero-extended if the source value is
2193unsigned. <tt>bool</tt> values are always zero extended into either zero or
2194one.
2195</p>
2196
Chris Lattner33ba0d92001-07-09 00:26:23 +00002197<h5>Example:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002198
2199<pre>
2200 %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattner7bae3952002-06-25 18:03:17 +00002201 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner33ba0d92001-07-09 00:26:23 +00002202</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002203</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002204
2205<!-- _______________________________________________________________________ -->
2206<div class="doc_subsubsection">
2207 <a name="i_select">'<tt>select</tt>' Instruction</a>
2208</div>
2209
2210<div class="doc_text">
2211
2212<h5>Syntax:</h5>
2213
2214<pre>
2215 &lt;result&gt; = select bool &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
2216</pre>
2217
2218<h5>Overview:</h5>
2219
2220<p>
2221The '<tt>select</tt>' instruction is used to choose one value based on a
2222condition, without branching.
2223</p>
2224
2225
2226<h5>Arguments:</h5>
2227
2228<p>
2229The '<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.
2230</p>
2231
2232<h5>Semantics:</h5>
2233
2234<p>
2235If the boolean condition evaluates to true, the instruction returns the first
John Criswellfc6b8952005-05-16 16:17:45 +00002236value argument; otherwise, it returns the second value argument.
Chris Lattnercc37aae2004-03-12 05:50:16 +00002237</p>
2238
2239<h5>Example:</h5>
2240
2241<pre>
2242 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
2243</pre>
2244</div>
2245
2246
Robert Bocchino3a558662006-01-05 17:37:02 +00002247<!-- _______________________________________________________________________ -->
2248<div class="doc_subsubsection">
2249 <a name="i_extractelement">'<tt>extractelement</tt>' Instruction</a>
2250</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002251
Robert Bocchino3a558662006-01-05 17:37:02 +00002252<div class="doc_text">
2253
2254<h5>Syntax:</h5>
2255
2256<pre>
2257 &lt;result&gt; = extractelement &lt;n x &lt;ty&gt;&gt; &lt;val&gt;, uint &lt;idx&gt; <i>; yields &lt;ty&gt;</i>
2258</pre>
2259
2260<h5>Overview:</h5>
2261
2262<p>
2263The '<tt>extractelement</tt>' instruction extracts a single scalar
2264element from a vector at a specified index.
2265</p>
2266
2267
2268<h5>Arguments:</h5>
2269
2270<p>
2271The first operand of an '<tt>extractelement</tt>' instruction is a
2272value of <a href="#t_packed">packed</a> type. The second operand is
2273an index indicating the position from which to extract the element.
2274The index may be a variable.</p>
2275
2276<h5>Semantics:</h5>
2277
2278<p>
2279The result is a scalar of the same type as the element type of
2280<tt>val</tt>. Its value is the value at position <tt>idx</tt> of
2281<tt>val</tt>. If <tt>idx</tt> exceeds the length of <tt>val</tt>, the
2282results are undefined.
2283</p>
2284
2285<h5>Example:</h5>
2286
2287<pre>
2288 %result = extractelement &lt;4 x int&gt; %vec, uint 0 <i>; yields int</i>
2289</pre>
2290</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002291
2292
Chris Lattner33ba0d92001-07-09 00:26:23 +00002293<!-- _______________________________________________________________________ -->
Chris Lattner2bff5242005-05-06 05:47:36 +00002294<div class="doc_subsubsection">
2295 <a name="i_call">'<tt>call</tt>' Instruction</a>
2296</div>
2297
Misha Brukman9d0919f2003-11-08 01:05:38 +00002298<div class="doc_text">
Chris Lattner2bff5242005-05-06 05:47:36 +00002299
Chris Lattner00950542001-06-06 20:29:01 +00002300<h5>Syntax:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00002301<pre>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00002302 &lt;result&gt; = [tail] call [<a href="#callingconv">cconv</a>] &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)
Chris Lattner2bff5242005-05-06 05:47:36 +00002303</pre>
2304
Chris Lattner00950542001-06-06 20:29:01 +00002305<h5>Overview:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00002306
Misha Brukman9d0919f2003-11-08 01:05:38 +00002307<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00002308
Chris Lattner00950542001-06-06 20:29:01 +00002309<h5>Arguments:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00002310
Misha Brukman9d0919f2003-11-08 01:05:38 +00002311<p>This instruction requires several arguments:</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00002312
Chris Lattner6536cfe2002-05-06 22:08:29 +00002313<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00002314 <li>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00002315 <p>The optional "tail" marker indicates whether the callee function accesses
2316 any allocas or varargs in the caller. If the "tail" marker is present, the
Chris Lattner2bff5242005-05-06 05:47:36 +00002317 function call is eligible for tail call optimization. Note that calls may
2318 be marked "tail" even if they do not occur before a <a
2319 href="#i_ret"><tt>ret</tt></a> instruction.
Chris Lattner261efe92003-11-25 01:02:51 +00002320 </li>
2321 <li>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00002322 <p>The optional "cconv" marker indicates which <a href="callingconv">calling
2323 convention</a> the call should use. If none is specified, the call defaults
2324 to using C calling conventions.
2325 </li>
2326 <li>
Chris Lattner2bff5242005-05-06 05:47:36 +00002327 <p>'<tt>ty</tt>': shall be the signature of the pointer to function value
2328 being invoked. The argument types must match the types implied by this
John Criswellfc6b8952005-05-16 16:17:45 +00002329 signature. This type can be omitted if the function is not varargs and
2330 if the function type does not return a pointer to a function.</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00002331 </li>
2332 <li>
2333 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to
2334 be invoked. In most cases, this is a direct function invocation, but
2335 indirect <tt>call</tt>s are just as possible, calling an arbitrary pointer
John Criswellfc6b8952005-05-16 16:17:45 +00002336 to function value.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002337 </li>
2338 <li>
2339 <p>'<tt>function args</tt>': argument list whose types match the
Reid Spencera7e302a2005-05-01 22:22:57 +00002340 function signature argument types. All arguments must be of
2341 <a href="#t_firstclass">first class</a> type. If the function signature
2342 indicates the function accepts a variable number of arguments, the extra
2343 arguments can be specified.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002344 </li>
Chris Lattner6536cfe2002-05-06 22:08:29 +00002345</ol>
Chris Lattner2bff5242005-05-06 05:47:36 +00002346
Chris Lattner00950542001-06-06 20:29:01 +00002347<h5>Semantics:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00002348
Chris Lattner261efe92003-11-25 01:02:51 +00002349<p>The '<tt>call</tt>' instruction is used to cause control flow to
2350transfer to a specified function, with its incoming arguments bound to
2351the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
2352instruction in the called function, control flow continues with the
2353instruction after the function call, and the return value of the
2354function is bound to the result argument. This is a simpler case of
2355the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00002356
Chris Lattner00950542001-06-06 20:29:01 +00002357<h5>Example:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00002358
2359<pre>
2360 %retval = call int %test(int %argc)
2361 call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42);
2362 %X = tail call int %foo()
Chris Lattnerbad10ee2005-05-06 22:57:40 +00002363 %Y = tail call <a href="#callingconv">fastcc</a> int %foo()
Chris Lattner2bff5242005-05-06 05:47:36 +00002364</pre>
2365
Misha Brukman9d0919f2003-11-08 01:05:38 +00002366</div>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002367
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002368<!-- _______________________________________________________________________ -->
Chris Lattnere19d7a72004-09-27 21:51:25 +00002369<div class="doc_subsubsection">
Chris Lattnerfb6977d2006-01-13 23:26:01 +00002370 <a name="i_va_arg">'<tt>va_arg</tt>' Instruction</a>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002371</div>
2372
Misha Brukman9d0919f2003-11-08 01:05:38 +00002373<div class="doc_text">
Chris Lattnere19d7a72004-09-27 21:51:25 +00002374
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002375<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002376
2377<pre>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002378 &lt;resultval&gt; = va_arg &lt;va_list*&gt; &lt;arglist&gt;, &lt;argty&gt;
Chris Lattnere19d7a72004-09-27 21:51:25 +00002379</pre>
2380
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002381<h5>Overview:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002382
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002383<p>The '<tt>va_arg</tt>' instruction is used to access arguments passed through
Chris Lattnere19d7a72004-09-27 21:51:25 +00002384the "variable argument" area of a function call. It is used to implement the
2385<tt>va_arg</tt> macro in C.</p>
2386
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002387<h5>Arguments:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002388
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002389<p>This instruction takes a <tt>va_list*</tt> value and the type of
2390the argument. It returns a value of the specified argument type and
Jeff Cohen25d4f7e2005-11-11 02:15:27 +00002391increments the <tt>va_list</tt> to point to the next argument. Again, the
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002392actual type of <tt>va_list</tt> is target specific.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002393
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002394<h5>Semantics:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002395
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002396<p>The '<tt>va_arg</tt>' instruction loads an argument of the specified
2397type from the specified <tt>va_list</tt> and causes the
2398<tt>va_list</tt> to point to the next argument. For more information,
2399see the variable argument handling <a href="#int_varargs">Intrinsic
2400Functions</a>.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002401
2402<p>It is legal for this instruction to be called in a function which does not
2403take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002404function.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002405
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002406<p><tt>va_arg</tt> is an LLVM instruction instead of an <a
John Criswellfc6b8952005-05-16 16:17:45 +00002407href="#intrinsics">intrinsic function</a> because it takes a type as an
Chris Lattnere19d7a72004-09-27 21:51:25 +00002408argument.</p>
2409
Chris Lattner8d1a81d2003-10-18 05:51:36 +00002410<h5>Example:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002411
2412<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
2413
Misha Brukman9d0919f2003-11-08 01:05:38 +00002414</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002415
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002416<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00002417<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
2418<!-- *********************************************************************** -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002419
Misha Brukman9d0919f2003-11-08 01:05:38 +00002420<div class="doc_text">
Chris Lattner33aec9e2004-02-12 17:01:32 +00002421
2422<p>LLVM supports the notion of an "intrinsic function". These functions have
John Criswellfc6b8952005-05-16 16:17:45 +00002423well known names and semantics and are required to follow certain
Chris Lattner33aec9e2004-02-12 17:01:32 +00002424restrictions. Overall, these instructions represent an extension mechanism for
2425the LLVM language that does not require changing all of the transformations in
2426LLVM to add to the language (or the bytecode reader/writer, the parser,
2427etc...).</p>
2428
John Criswellfc6b8952005-05-16 16:17:45 +00002429<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix. This
2430prefix is reserved in LLVM for intrinsic names; thus, functions may not be named
Chris Lattner33aec9e2004-02-12 17:01:32 +00002431this. Intrinsic functions must always be external functions: you cannot define
2432the body of intrinsic functions. Intrinsic functions may only be used in call
2433or invoke instructions: it is illegal to take the address of an intrinsic
2434function. Additionally, because intrinsic functions are part of the LLVM
2435language, it is required that they all be documented here if any are added.</p>
2436
2437
John Criswellfc6b8952005-05-16 16:17:45 +00002438<p>To learn how to add an intrinsic function, please see the <a
Chris Lattner590cff32005-05-11 03:35:57 +00002439href="ExtendingLLVM.html">Extending LLVM Guide</a>.
Chris Lattner33aec9e2004-02-12 17:01:32 +00002440</p>
2441
Misha Brukman9d0919f2003-11-08 01:05:38 +00002442</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002443
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002444<!-- ======================================================================= -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002445<div class="doc_subsection">
2446 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
2447</div>
2448
Misha Brukman9d0919f2003-11-08 01:05:38 +00002449<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00002450
Misha Brukman9d0919f2003-11-08 01:05:38 +00002451<p>Variable argument support is defined in LLVM with the <a
Chris Lattnerfb6977d2006-01-13 23:26:01 +00002452 href="#i_va_arg"><tt>va_arg</tt></a> instruction and these three
Chris Lattner261efe92003-11-25 01:02:51 +00002453intrinsic functions. These functions are related to the similarly
2454named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002455
Chris Lattner261efe92003-11-25 01:02:51 +00002456<p>All of these functions operate on arguments that use a
2457target-specific value type "<tt>va_list</tt>". The LLVM assembly
2458language reference manual does not define what this type is, so all
2459transformations should be prepared to handle intrinsics with any type
2460used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002461
Misha Brukman9d0919f2003-11-08 01:05:38 +00002462<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner261efe92003-11-25 01:02:51 +00002463instruction and the variable argument handling intrinsic functions are
2464used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002465
Chris Lattner33aec9e2004-02-12 17:01:32 +00002466<pre>
2467int %test(int %X, ...) {
2468 ; Initialize variable argument processing
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002469 %ap = alloca sbyte*
2470 call void %<a href="#i_va_start">llvm.va_start</a>(sbyte** %ap)
Chris Lattner33aec9e2004-02-12 17:01:32 +00002471
2472 ; Read a single integer argument
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002473 %tmp = va_arg sbyte** %ap, int
Chris Lattner33aec9e2004-02-12 17:01:32 +00002474
2475 ; Demonstrate usage of llvm.va_copy and llvm.va_end
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002476 %aq = alloca sbyte*
Andrew Lenharthd0a4c622005-06-22 20:38:11 +00002477 call void %<a href="#i_va_copy">llvm.va_copy</a>(sbyte** %aq, sbyte** %ap)
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002478 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte** %aq)
Chris Lattner33aec9e2004-02-12 17:01:32 +00002479
2480 ; Stop processing of arguments.
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002481 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte** %ap)
Chris Lattner33aec9e2004-02-12 17:01:32 +00002482 ret int %tmp
2483}
2484</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002485</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002486
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002487<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002488<div class="doc_subsubsection">
2489 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
2490</div>
2491
2492
Misha Brukman9d0919f2003-11-08 01:05:38 +00002493<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002494<h5>Syntax:</h5>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002495<pre> declare void %llvm.va_start(&lt;va_list&gt;* &lt;arglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002496<h5>Overview:</h5>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002497<P>The '<tt>llvm.va_start</tt>' intrinsic initializes
2498<tt>*&lt;arglist&gt;</tt> for subsequent use by <tt><a
2499href="#i_va_arg">va_arg</a></tt>.</p>
2500
2501<h5>Arguments:</h5>
2502
2503<P>The argument is a pointer to a <tt>va_list</tt> element to initialize.</p>
2504
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002505<h5>Semantics:</h5>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002506
2507<P>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
2508macro available in C. In a target-dependent way, it initializes the
2509<tt>va_list</tt> element the argument points to, so that the next call to
2510<tt>va_arg</tt> will produce the first variable argument passed to the function.
2511Unlike the C <tt>va_start</tt> macro, this intrinsic does not need to know the
2512last argument of the function, the compiler can figure that out.</p>
2513
Misha Brukman9d0919f2003-11-08 01:05:38 +00002514</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002515
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002516<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002517<div class="doc_subsubsection">
2518 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
2519</div>
2520
Misha Brukman9d0919f2003-11-08 01:05:38 +00002521<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002522<h5>Syntax:</h5>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002523<pre> declare void %llvm.va_end(&lt;va_list*&gt; &lt;arglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002524<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002525<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
2526which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
2527or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002528<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002529<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002530<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002531<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002532macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
2533Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
2534 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
2535with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002536</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002537
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002538<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002539<div class="doc_subsubsection">
2540 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
2541</div>
2542
Misha Brukman9d0919f2003-11-08 01:05:38 +00002543<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00002544
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002545<h5>Syntax:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002546
2547<pre>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002548 declare void %llvm.va_copy(&lt;va_list&gt;* &lt;destarglist&gt;,
Andrew Lenharthd0a4c622005-06-22 20:38:11 +00002549 &lt;va_list&gt;* &lt;srcarglist&gt;)
Chris Lattnerd7923912004-05-23 21:06:01 +00002550</pre>
2551
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002552<h5>Overview:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002553
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002554<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position from
2555the source argument list to the destination argument list.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002556
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002557<h5>Arguments:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002558
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002559<p>The first argument is a pointer to a <tt>va_list</tt> element to initialize.
Andrew Lenharthd0a4c622005-06-22 20:38:11 +00002560The second argument is a pointer to a <tt>va_list</tt> element to copy from.</p>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002561
Chris Lattnerd7923912004-05-23 21:06:01 +00002562
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002563<h5>Semantics:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002564
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00002565<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt> macro
2566available in C. In a target-dependent way, it copies the source
2567<tt>va_list</tt> element into the destination list. This intrinsic is necessary
2568because the <tt><a href="i_va_begin">llvm.va_begin</a></tt> intrinsic may be
Chris Lattnerd7923912004-05-23 21:06:01 +00002569arbitrarily complex and require memory allocation, for example.</p>
2570
Misha Brukman9d0919f2003-11-08 01:05:38 +00002571</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002572
Chris Lattner33aec9e2004-02-12 17:01:32 +00002573<!-- ======================================================================= -->
2574<div class="doc_subsection">
Chris Lattnerd7923912004-05-23 21:06:01 +00002575 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
2576</div>
2577
2578<div class="doc_text">
2579
2580<p>
2581LLVM support for <a href="GarbageCollection.html">Accurate Garbage
2582Collection</a> requires the implementation and generation of these intrinsics.
2583These intrinsics allow identification of <a href="#i_gcroot">GC roots on the
2584stack</a>, as well as garbage collector implementations that require <a
2585href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers.
2586Front-ends for type-safe garbage collected languages should generate these
2587intrinsics to make use of the LLVM garbage collectors. For more details, see <a
2588href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
2589</p>
2590</div>
2591
2592<!-- _______________________________________________________________________ -->
2593<div class="doc_subsubsection">
2594 <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
2595</div>
2596
2597<div class="doc_text">
2598
2599<h5>Syntax:</h5>
2600
2601<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00002602 declare void %llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
Chris Lattnerd7923912004-05-23 21:06:01 +00002603</pre>
2604
2605<h5>Overview:</h5>
2606
John Criswell9e2485c2004-12-10 15:51:16 +00002607<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
Chris Lattnerd7923912004-05-23 21:06:01 +00002608the code generator, and allows some metadata to be associated with it.</p>
2609
2610<h5>Arguments:</h5>
2611
2612<p>The first argument specifies the address of a stack object that contains the
2613root pointer. The second pointer (which must be either a constant or a global
2614value address) contains the meta-data to be associated with the root.</p>
2615
2616<h5>Semantics:</h5>
2617
2618<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
2619location. At compile-time, the code generator generates information to allow
2620the runtime to find the pointer at GC safe points.
2621</p>
2622
2623</div>
2624
2625
2626<!-- _______________________________________________________________________ -->
2627<div class="doc_subsubsection">
2628 <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
2629</div>
2630
2631<div class="doc_text">
2632
2633<h5>Syntax:</h5>
2634
2635<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00002636 declare sbyte* %llvm.gcread(sbyte** %Ptr)
Chris Lattnerd7923912004-05-23 21:06:01 +00002637</pre>
2638
2639<h5>Overview:</h5>
2640
2641<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
2642locations, allowing garbage collector implementations that require read
2643barriers.</p>
2644
2645<h5>Arguments:</h5>
2646
2647<p>The argument is the address to read from, which should be an address
2648allocated from the garbage collector.</p>
2649
2650<h5>Semantics:</h5>
2651
2652<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
2653instruction, but may be replaced with substantially more complex code by the
2654garbage collector runtime, as needed.</p>
2655
2656</div>
2657
2658
2659<!-- _______________________________________________________________________ -->
2660<div class="doc_subsubsection">
2661 <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
2662</div>
2663
2664<div class="doc_text">
2665
2666<h5>Syntax:</h5>
2667
2668<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00002669 declare void %llvm.gcwrite(sbyte* %P1, sbyte** %P2)
Chris Lattnerd7923912004-05-23 21:06:01 +00002670</pre>
2671
2672<h5>Overview:</h5>
2673
2674<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
2675locations, allowing garbage collector implementations that require write
2676barriers (such as generational or reference counting collectors).</p>
2677
2678<h5>Arguments:</h5>
2679
2680<p>The first argument is the reference to store, and the second is the heap
2681location to store to.</p>
2682
2683<h5>Semantics:</h5>
2684
2685<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
2686instruction, but may be replaced with substantially more complex code by the
2687garbage collector runtime, as needed.</p>
2688
2689</div>
2690
2691
2692
2693<!-- ======================================================================= -->
2694<div class="doc_subsection">
Chris Lattner10610642004-02-14 04:08:35 +00002695 <a name="int_codegen">Code Generator Intrinsics</a>
2696</div>
2697
2698<div class="doc_text">
2699<p>
2700These intrinsics are provided by LLVM to expose special features that may only
2701be implemented with code generator support.
2702</p>
2703
2704</div>
2705
2706<!-- _______________________________________________________________________ -->
2707<div class="doc_subsubsection">
2708 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
2709</div>
2710
2711<div class="doc_text">
2712
2713<h5>Syntax:</h5>
2714<pre>
Chris Lattnerfcf39d42006-01-13 01:20:27 +00002715 declare sbyte *%llvm.returnaddress(uint &lt;level&gt;)
Chris Lattner10610642004-02-14 04:08:35 +00002716</pre>
2717
2718<h5>Overview:</h5>
2719
2720<p>
2721The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
2722indicating the return address of the current function or one of its callers.
2723</p>
2724
2725<h5>Arguments:</h5>
2726
2727<p>
2728The argument to this intrinsic indicates which function to return the address
2729for. Zero indicates the calling function, one indicates its caller, etc. The
2730argument is <b>required</b> to be a constant integer value.
2731</p>
2732
2733<h5>Semantics:</h5>
2734
2735<p>
2736The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
2737the return address of the specified call frame, or zero if it cannot be
2738identified. The value returned by this intrinsic is likely to be incorrect or 0
2739for arguments other than zero, so it should only be used for debugging purposes.
2740</p>
2741
2742<p>
2743Note that calling this intrinsic does not prevent function inlining or other
Chris Lattnerb40bb382005-03-07 20:30:51 +00002744aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner10610642004-02-14 04:08:35 +00002745source-language caller.
2746</p>
2747</div>
2748
2749
2750<!-- _______________________________________________________________________ -->
2751<div class="doc_subsubsection">
2752 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
2753</div>
2754
2755<div class="doc_text">
2756
2757<h5>Syntax:</h5>
2758<pre>
Chris Lattnerfcf39d42006-01-13 01:20:27 +00002759 declare sbyte *%llvm.frameaddress(uint &lt;level&gt;)
Chris Lattner10610642004-02-14 04:08:35 +00002760</pre>
2761
2762<h5>Overview:</h5>
2763
2764<p>
2765The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
2766pointer value for the specified stack frame.
2767</p>
2768
2769<h5>Arguments:</h5>
2770
2771<p>
2772The argument to this intrinsic indicates which function to return the frame
2773pointer for. Zero indicates the calling function, one indicates its caller,
2774etc. The argument is <b>required</b> to be a constant integer value.
2775</p>
2776
2777<h5>Semantics:</h5>
2778
2779<p>
2780The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
2781the frame address of the specified call frame, or zero if it cannot be
2782identified. The value returned by this intrinsic is likely to be incorrect or 0
2783for arguments other than zero, so it should only be used for debugging purposes.
2784</p>
2785
2786<p>
2787Note that calling this intrinsic does not prevent function inlining or other
Chris Lattnerb40bb382005-03-07 20:30:51 +00002788aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner10610642004-02-14 04:08:35 +00002789source-language caller.
2790</p>
2791</div>
2792
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00002793<!-- _______________________________________________________________________ -->
2794<div class="doc_subsubsection">
Chris Lattner57e1f392006-01-13 02:03:13 +00002795 <a name="i_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a>
2796</div>
2797
2798<div class="doc_text">
2799
2800<h5>Syntax:</h5>
2801<pre>
2802 declare sbyte *%llvm.stacksave()
2803</pre>
2804
2805<h5>Overview:</h5>
2806
2807<p>
2808The '<tt>llvm.stacksave</tt>' intrinsic is used to remember the current state of
2809the function stack, for use with <a href="#i_stackrestore">
2810<tt>llvm.stackrestore</tt></a>. This is useful for implementing language
2811features like scoped automatic variable sized arrays in C99.
2812</p>
2813
2814<h5>Semantics:</h5>
2815
2816<p>
2817This intrinsic returns a opaque pointer value that can be passed to <a
2818href="#i_stackrestore"><tt>llvm.stackrestore</tt></a>. When an
2819<tt>llvm.stackrestore</tt> intrinsic is executed with a value saved from
2820<tt>llvm.stacksave</tt>, it effectively restores the state of the stack to the
2821state it was in when the <tt>llvm.stacksave</tt> intrinsic executed. In
2822practice, this pops any <a href="#i_alloca">alloca</a> blocks from the stack
2823that were allocated after the <tt>llvm.stacksave</tt> was executed.
2824</p>
2825
2826</div>
2827
2828<!-- _______________________________________________________________________ -->
2829<div class="doc_subsubsection">
2830 <a name="i_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a>
2831</div>
2832
2833<div class="doc_text">
2834
2835<h5>Syntax:</h5>
2836<pre>
2837 declare void %llvm.stackrestore(sbyte* %ptr)
2838</pre>
2839
2840<h5>Overview:</h5>
2841
2842<p>
2843The '<tt>llvm.stackrestore</tt>' intrinsic is used to restore the state of
2844the function stack to the state it was in when the corresponding <a
2845href="#llvm.stacksave"><tt>llvm.stacksave</tt></a> intrinsic executed. This is
2846useful for implementing language features like scoped automatic variable sized
2847arrays in C99.
2848</p>
2849
2850<h5>Semantics:</h5>
2851
2852<p>
2853See the description for <a href="#i_stacksave"><tt>llvm.stacksave</tt></a>.
2854</p>
2855
2856</div>
2857
2858
2859<!-- _______________________________________________________________________ -->
2860<div class="doc_subsubsection">
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00002861 <a name="i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a>
2862</div>
2863
2864<div class="doc_text">
2865
2866<h5>Syntax:</h5>
2867<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00002868 declare void %llvm.prefetch(sbyte * &lt;address&gt;,
2869 uint &lt;rw&gt;, uint &lt;locality&gt;)
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00002870</pre>
2871
2872<h5>Overview:</h5>
2873
2874
2875<p>
2876The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to insert
John Criswellfc6b8952005-05-16 16:17:45 +00002877a prefetch instruction if supported; otherwise, it is a noop. Prefetches have
2878no
2879effect on the behavior of the program but can change its performance
Chris Lattner2a615362005-02-28 19:47:14 +00002880characteristics.
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00002881</p>
2882
2883<h5>Arguments:</h5>
2884
2885<p>
2886<tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier
2887determining if the fetch should be for a read (0) or write (1), and
2888<tt>locality</tt> is a temporal locality specifier ranging from (0) - no
Chris Lattneraeffb4a2005-03-07 20:31:38 +00002889locality, to (3) - extremely local keep in cache. The <tt>rw</tt> and
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00002890<tt>locality</tt> arguments must be constant integers.
2891</p>
2892
2893<h5>Semantics:</h5>
2894
2895<p>
2896This intrinsic does not modify the behavior of the program. In particular,
2897prefetches cannot trap and do not produce a value. On targets that support this
2898intrinsic, the prefetch can provide hints to the processor cache for better
2899performance.
2900</p>
2901
2902</div>
2903
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00002904<!-- _______________________________________________________________________ -->
2905<div class="doc_subsubsection">
2906 <a name="i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a>
2907</div>
2908
2909<div class="doc_text">
2910
2911<h5>Syntax:</h5>
2912<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00002913 declare void %llvm.pcmarker( uint &lt;id&gt; )
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00002914</pre>
2915
2916<h5>Overview:</h5>
2917
2918
2919<p>
John Criswellfc6b8952005-05-16 16:17:45 +00002920The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a Program Counter
2921(PC) in a region of
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00002922code to simulators and other tools. The method is target specific, but it is
2923expected that the marker will use exported symbols to transmit the PC of the marker.
Jeff Cohen25d4f7e2005-11-11 02:15:27 +00002924The marker makes no guarantees that it will remain with any specific instruction
Chris Lattnerd07c3f42005-11-15 06:07:55 +00002925after optimizations. It is possible that the presence of a marker will inhibit
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00002926optimizations. The intended use is to be inserted after optmizations to allow
John Criswellfc6b8952005-05-16 16:17:45 +00002927correlations of simulation runs.
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00002928</p>
2929
2930<h5>Arguments:</h5>
2931
2932<p>
2933<tt>id</tt> is a numerical id identifying the marker.
2934</p>
2935
2936<h5>Semantics:</h5>
2937
2938<p>
2939This intrinsic does not modify the behavior of the program. Backends that do not
2940support this intrinisic may ignore it.
2941</p>
2942
2943</div>
2944
Andrew Lenharth51b8d542005-11-11 16:47:30 +00002945<!-- _______________________________________________________________________ -->
2946<div class="doc_subsubsection">
2947 <a name="i_readcyclecounter">'<tt>llvm.readcyclecounter</tt>' Intrinsic</a>
2948</div>
2949
2950<div class="doc_text">
2951
2952<h5>Syntax:</h5>
2953<pre>
2954 declare ulong %llvm.readcyclecounter( )
2955</pre>
2956
2957<h5>Overview:</h5>
2958
2959
2960<p>
2961The '<tt>llvm.readcyclecounter</tt>' intrinsic provides access to the cycle
2962counter register (or similar low latency, high accuracy clocks) on those targets
2963that support it. On X86, it should map to RDTSC. On Alpha, it should map to RPCC.
2964As the backing counters overflow quickly (on the order of 9 seconds on alpha), this
2965should only be used for small timings.
2966</p>
2967
2968<h5>Semantics:</h5>
2969
2970<p>
2971When directly supported, reading the cycle counter should not modify any memory.
2972Implementations are allowed to either return a application specific value or a
2973system wide value. On backends without support, this is lowered to a constant 0.
2974</p>
2975
2976</div>
2977
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00002978
John Criswell7123e272004-04-09 16:43:20 +00002979<!-- ======================================================================= -->
2980<div class="doc_subsection">
2981 <a name="int_os">Operating System Intrinsics</a>
2982</div>
2983
2984<div class="doc_text">
2985<p>
2986These intrinsics are provided by LLVM to support the implementation of
2987operating system level code.
2988</p>
2989
2990</div>
John Criswell183402a2004-04-12 15:02:16 +00002991
John Criswellcfd3bac2004-04-09 15:23:37 +00002992<!-- _______________________________________________________________________ -->
2993<div class="doc_subsubsection">
2994 <a name="i_readport">'<tt>llvm.readport</tt>' Intrinsic</a>
2995</div>
2996
2997<div class="doc_text">
2998
2999<h5>Syntax:</h5>
3000<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00003001 declare &lt;integer type&gt; %llvm.readport (&lt;integer type&gt; &lt;address&gt;)
John Criswellcfd3bac2004-04-09 15:23:37 +00003002</pre>
3003
3004<h5>Overview:</h5>
3005
3006<p>
John Criswell7123e272004-04-09 16:43:20 +00003007The '<tt>llvm.readport</tt>' intrinsic reads data from the specified hardware
3008I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00003009</p>
3010
3011<h5>Arguments:</h5>
3012
3013<p>
John Criswell7123e272004-04-09 16:43:20 +00003014The argument to this intrinsic indicates the hardware I/O address from which
3015to read the data. The address is in the hardware I/O address namespace (as
3016opposed to being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00003017</p>
3018
3019<h5>Semantics:</h5>
3020
3021<p>
John Criswell7123e272004-04-09 16:43:20 +00003022The '<tt>llvm.readport</tt>' intrinsic reads data from the hardware I/O port
3023specified by <i>address</i> and returns the value. The address and return
3024value must be integers, but the size is dependent upon the platform upon which
3025the program is code generated. For example, on x86, the address must be an
Misha Brukmancfa87bc2005-04-22 18:02:52 +00003026unsigned 16-bit value, and the return value must be 8, 16, or 32 bits.
John Criswellcfd3bac2004-04-09 15:23:37 +00003027</p>
3028
3029</div>
3030
3031<!-- _______________________________________________________________________ -->
3032<div class="doc_subsubsection">
3033 <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a>
3034</div>
3035
3036<div class="doc_text">
3037
3038<h5>Syntax:</h5>
3039<pre>
Chris Lattnerc3f59762004-12-09 17:30:23 +00003040 call void (&lt;integer type&gt;, &lt;integer type&gt;)*
3041 %llvm.writeport (&lt;integer type&gt; &lt;value&gt;,
3042 &lt;integer type&gt; &lt;address&gt;)
John Criswellcfd3bac2004-04-09 15:23:37 +00003043</pre>
3044
3045<h5>Overview:</h5>
3046
3047<p>
John Criswell7123e272004-04-09 16:43:20 +00003048The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified hardware
3049I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00003050</p>
3051
3052<h5>Arguments:</h5>
3053
3054<p>
John Criswell96db6fc2004-04-12 16:33:19 +00003055The first argument is the value to write to the I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00003056</p>
3057
3058<p>
John Criswell96db6fc2004-04-12 16:33:19 +00003059The second argument indicates the hardware I/O address to which data should be
3060written. The address is in the hardware I/O address namespace (as opposed to
3061being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00003062</p>
3063
3064<h5>Semantics:</h5>
3065
3066<p>
3067The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port
3068specified by <i>address</i>. The address and value must be integers, but the
3069size is dependent upon the platform upon which the program is code generated.
Misha Brukmancfa87bc2005-04-22 18:02:52 +00003070For example, on x86, the address must be an unsigned 16-bit value, and the
John Criswell7123e272004-04-09 16:43:20 +00003071value written must be 8, 16, or 32 bits in length.
John Criswellcfd3bac2004-04-09 15:23:37 +00003072</p>
3073
3074</div>
Chris Lattner10610642004-02-14 04:08:35 +00003075
John Criswell183402a2004-04-12 15:02:16 +00003076<!-- _______________________________________________________________________ -->
3077<div class="doc_subsubsection">
3078 <a name="i_readio">'<tt>llvm.readio</tt>' Intrinsic</a>
3079</div>
3080
3081<div class="doc_text">
3082
3083<h5>Syntax:</h5>
3084<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00003085 declare &lt;result&gt; %llvm.readio (&lt;ty&gt; * &lt;pointer&gt;)
John Criswell183402a2004-04-12 15:02:16 +00003086</pre>
3087
3088<h5>Overview:</h5>
3089
3090<p>
3091The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
3092address.
3093</p>
3094
3095<h5>Arguments:</h5>
3096
3097<p>
John Criswell96db6fc2004-04-12 16:33:19 +00003098The argument to this intrinsic is a pointer indicating the memory address from
3099which to read the data. The data must be a
3100<a href="#t_firstclass">first class</a> type.
John Criswell183402a2004-04-12 15:02:16 +00003101</p>
3102
3103<h5>Semantics:</h5>
3104
3105<p>
3106The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
John Criswell96db6fc2004-04-12 16:33:19 +00003107location specified by <i>pointer</i> and returns the value. The argument must
3108be a pointer, and the return value must be a
3109<a href="#t_firstclass">first class</a> type. However, certain architectures
Misha Brukmancfa87bc2005-04-22 18:02:52 +00003110may not support I/O on all first class types. For example, 32-bit processors
John Criswell96db6fc2004-04-12 16:33:19 +00003111may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00003112</p>
3113
3114<p>
John Criswell96db6fc2004-04-12 16:33:19 +00003115This intrinsic enforces an in-order memory model for llvm.readio and
3116llvm.writeio calls on machines that use dynamic scheduling. Dynamically
3117scheduled processors may execute loads and stores out of order, re-ordering at
3118run time accesses to memory mapped I/O registers. Using these intrinsics
3119ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00003120</p>
3121
3122</div>
3123
3124<!-- _______________________________________________________________________ -->
3125<div class="doc_subsubsection">
3126 <a name="i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a>
3127</div>
3128
3129<div class="doc_text">
3130
3131<h5>Syntax:</h5>
3132<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00003133 declare void %llvm.writeio (&lt;ty1&gt; &lt;value&gt;, &lt;ty2&gt; * &lt;pointer&gt;)
John Criswell183402a2004-04-12 15:02:16 +00003134</pre>
3135
3136<h5>Overview:</h5>
3137
3138<p>
3139The '<tt>llvm.writeio</tt>' intrinsic writes data to the specified memory
3140mapped I/O address.
3141</p>
3142
3143<h5>Arguments:</h5>
3144
3145<p>
John Criswell96db6fc2004-04-12 16:33:19 +00003146The first argument is the value to write to the memory mapped I/O location.
3147The second argument is a pointer indicating the memory address to which the
3148data should be written.
John Criswell183402a2004-04-12 15:02:16 +00003149</p>
3150
3151<h5>Semantics:</h5>
3152
3153<p>
3154The '<tt>llvm.writeio</tt>' intrinsic writes <i>value</i> to the memory mapped
John Criswell96db6fc2004-04-12 16:33:19 +00003155I/O address specified by <i>pointer</i>. The value must be a
3156<a href="#t_firstclass">first class</a> type. However, certain architectures
Misha Brukmancfa87bc2005-04-22 18:02:52 +00003157may not support I/O on all first class types. For example, 32-bit processors
John Criswell96db6fc2004-04-12 16:33:19 +00003158may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00003159</p>
3160
3161<p>
John Criswell96db6fc2004-04-12 16:33:19 +00003162This intrinsic enforces an in-order memory model for llvm.readio and
3163llvm.writeio calls on machines that use dynamic scheduling. Dynamically
3164scheduled processors may execute loads and stores out of order, re-ordering at
3165run time accesses to memory mapped I/O registers. Using these intrinsics
3166ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00003167</p>
3168
3169</div>
3170
Chris Lattner10610642004-02-14 04:08:35 +00003171<!-- ======================================================================= -->
3172<div class="doc_subsection">
Chris Lattner33aec9e2004-02-12 17:01:32 +00003173 <a name="int_libc">Standard C Library Intrinsics</a>
3174</div>
3175
3176<div class="doc_text">
3177<p>
Chris Lattner10610642004-02-14 04:08:35 +00003178LLVM provides intrinsics for a few important standard C library functions.
3179These intrinsics allow source-language front-ends to pass information about the
3180alignment of the pointer arguments to the code generator, providing opportunity
3181for more efficient code generation.
Chris Lattner33aec9e2004-02-12 17:01:32 +00003182</p>
3183
3184</div>
3185
3186<!-- _______________________________________________________________________ -->
3187<div class="doc_subsubsection">
3188 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
3189</div>
3190
3191<div class="doc_text">
3192
3193<h5>Syntax:</h5>
3194<pre>
Reid Spencerd4622352005-04-26 20:41:16 +00003195 declare void %llvm.memcpy(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
3196 uint &lt;len&gt;, uint &lt;align&gt;)
Chris Lattner33aec9e2004-02-12 17:01:32 +00003197</pre>
3198
3199<h5>Overview:</h5>
3200
3201<p>
3202The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
3203location to the destination location.
3204</p>
3205
3206<p>
3207Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
3208does not return a value, and takes an extra alignment argument.
3209</p>
3210
3211<h5>Arguments:</h5>
3212
3213<p>
3214The first argument is a pointer to the destination, the second is a pointer to
3215the source. The third argument is an (arbitrarily sized) integer argument
3216specifying the number of bytes to copy, and the fourth argument is the alignment
3217of the source and destination locations.
3218</p>
3219
Chris Lattner3301ced2004-02-12 21:18:15 +00003220<p>
3221If the call to this intrinisic has an alignment value that is not 0 or 1, then
3222the caller guarantees that the size of the copy is a multiple of the alignment
3223and that both the source and destination pointers are aligned to that boundary.
3224</p>
3225
Chris Lattner33aec9e2004-02-12 17:01:32 +00003226<h5>Semantics:</h5>
3227
3228<p>
3229The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
3230location to the destination location, which are not allowed to overlap. It
3231copies "len" bytes of memory over. If the argument is known to be aligned to
3232some boundary, this can be specified as the fourth argument, otherwise it should
3233be set to 0 or 1.
3234</p>
3235</div>
3236
3237
Chris Lattner0eb51b42004-02-12 18:10:10 +00003238<!-- _______________________________________________________________________ -->
3239<div class="doc_subsubsection">
3240 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
3241</div>
3242
3243<div class="doc_text">
3244
3245<h5>Syntax:</h5>
3246<pre>
Reid Spencerd4622352005-04-26 20:41:16 +00003247 declare void %llvm.memmove(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
3248 uint &lt;len&gt;, uint &lt;align&gt;)
Chris Lattner0eb51b42004-02-12 18:10:10 +00003249</pre>
3250
3251<h5>Overview:</h5>
3252
3253<p>
3254The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
3255location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>'
3256intrinsic but allows the two memory locations to overlap.
3257</p>
3258
3259<p>
3260Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
3261does not return a value, and takes an extra alignment argument.
3262</p>
3263
3264<h5>Arguments:</h5>
3265
3266<p>
3267The first argument is a pointer to the destination, the second is a pointer to
3268the source. The third argument is an (arbitrarily sized) integer argument
3269specifying the number of bytes to copy, and the fourth argument is the alignment
3270of the source and destination locations.
3271</p>
3272
Chris Lattner3301ced2004-02-12 21:18:15 +00003273<p>
3274If the call to this intrinisic has an alignment value that is not 0 or 1, then
3275the caller guarantees that the size of the copy is a multiple of the alignment
3276and that both the source and destination pointers are aligned to that boundary.
3277</p>
3278
Chris Lattner0eb51b42004-02-12 18:10:10 +00003279<h5>Semantics:</h5>
3280
3281<p>
3282The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
3283location to the destination location, which may overlap. It
3284copies "len" bytes of memory over. If the argument is known to be aligned to
3285some boundary, this can be specified as the fourth argument, otherwise it should
3286be set to 0 or 1.
3287</p>
3288</div>
3289
Chris Lattner8ff75902004-01-06 05:31:32 +00003290
Chris Lattner10610642004-02-14 04:08:35 +00003291<!-- _______________________________________________________________________ -->
3292<div class="doc_subsubsection">
3293 <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a>
3294</div>
3295
3296<div class="doc_text">
3297
3298<h5>Syntax:</h5>
3299<pre>
Reid Spencerd4622352005-04-26 20:41:16 +00003300 declare void %llvm.memset(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
3301 uint &lt;len&gt;, uint &lt;align&gt;)
Chris Lattner10610642004-02-14 04:08:35 +00003302</pre>
3303
3304<h5>Overview:</h5>
3305
3306<p>
3307The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular
3308byte value.
3309</p>
3310
3311<p>
3312Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
3313does not return a value, and takes an extra alignment argument.
3314</p>
3315
3316<h5>Arguments:</h5>
3317
3318<p>
3319The first argument is a pointer to the destination to fill, the second is the
3320byte value to fill it with, the third argument is an (arbitrarily sized) integer
3321argument specifying the number of bytes to fill, and the fourth argument is the
3322known alignment of destination location.
3323</p>
3324
3325<p>
3326If the call to this intrinisic has an alignment value that is not 0 or 1, then
3327the caller guarantees that the size of the copy is a multiple of the alignment
3328and that the destination pointer is aligned to that boundary.
3329</p>
3330
3331<h5>Semantics:</h5>
3332
3333<p>
3334The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the
3335destination location. If the argument is known to be aligned to some boundary,
3336this can be specified as the fourth argument, otherwise it should be set to 0 or
33371.
3338</p>
3339</div>
3340
3341
Chris Lattner32006282004-06-11 02:28:03 +00003342<!-- _______________________________________________________________________ -->
3343<div class="doc_subsubsection">
Alkis Evlogimenos26bbe932004-06-13 01:16:15 +00003344 <a name="i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a>
3345</div>
3346
3347<div class="doc_text">
3348
3349<h5>Syntax:</h5>
3350<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00003351 declare bool %llvm.isunordered(&lt;float or double&gt; Val1, &lt;float or double&gt; Val2)
Alkis Evlogimenos26bbe932004-06-13 01:16:15 +00003352</pre>
3353
3354<h5>Overview:</h5>
3355
3356<p>
3357The '<tt>llvm.isunordered</tt>' intrinsic returns true if either or both of the
3358specified floating point values is a NAN.
3359</p>
3360
3361<h5>Arguments:</h5>
3362
3363<p>
3364The arguments are floating point numbers of the same type.
3365</p>
3366
3367<h5>Semantics:</h5>
3368
3369<p>
3370If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise
3371false.
3372</p>
3373</div>
3374
3375
Chris Lattnera4d74142005-07-21 01:29:16 +00003376<!-- _______________________________________________________________________ -->
3377<div class="doc_subsubsection">
3378 <a name="i_sqrt">'<tt>llvm.sqrt</tt>' Intrinsic</a>
3379</div>
3380
3381<div class="doc_text">
3382
3383<h5>Syntax:</h5>
3384<pre>
3385 declare &lt;float or double&gt; %llvm.sqrt(&lt;float or double&gt; Val)
3386</pre>
3387
3388<h5>Overview:</h5>
3389
3390<p>
3391The '<tt>llvm.sqrt</tt>' intrinsic returns the sqrt of the specified operand,
3392returning the same value as the libm '<tt>sqrt</tt>' function would. Unlike
3393<tt>sqrt</tt> in libm, however, <tt>llvm.sqrt</tt> has undefined behavior for
3394negative numbers (which allows for better optimization).
3395</p>
3396
3397<h5>Arguments:</h5>
3398
3399<p>
3400The argument and return value are floating point numbers of the same type.
3401</p>
3402
3403<h5>Semantics:</h5>
3404
3405<p>
3406This function returns the sqrt of the specified operand if it is a positive
3407floating point number.
3408</p>
3409</div>
3410
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003411<!-- ======================================================================= -->
3412<div class="doc_subsection">
Nate Begeman7e36c472006-01-13 23:26:38 +00003413 <a name="int_manip">Bit Manipulation Intrinsics</a>
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003414</div>
3415
3416<div class="doc_text">
3417<p>
Nate Begeman7e36c472006-01-13 23:26:38 +00003418LLVM provides intrinsics for a few important bit manipulation operations.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003419These allow efficient code generation for some algorithms.
3420</p>
3421
3422</div>
3423
3424<!-- _______________________________________________________________________ -->
3425<div class="doc_subsubsection">
Nate Begeman7e36c472006-01-13 23:26:38 +00003426 <a name="i_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a>
3427</div>
3428
3429<div class="doc_text">
3430
3431<h5>Syntax:</h5>
3432<pre>
3433 declare ushort %llvm.bswap.i16( ushort &lt;id&gt; )
3434 declare uint %llvm.bswap.i32( uint &lt;id&gt; )
3435 declare ulong %llvm.bswap.i64( ulong &lt;id&gt; )
3436</pre>
3437
3438<h5>Overview:</h5>
3439
3440<p>
3441The '<tt>llvm.bwsap</tt>' family of intrinsics is used to byteswap a 16, 32 or
344264 bit quantity. These are useful for performing operations on data that is not
3443in the target's native byte order.
3444</p>
3445
3446<h5>Semantics:</h5>
3447
3448<p>
3449The llvm.bswap.16 intrinsic returns a ushort value that has the high and low
3450byte of the input ushort swapped. Similarly, the llvm.bswap.i32 intrinsic
3451returns a uint value that has the four bytes of the input uint swapped, so that
3452if the input bytes are numbered 0, 1, 2, 3 then the returned uint will have its
3453bytes in 3, 2, 1, 0 order. The llvm.bswap.i64 intrinsic extends this concept
3454to 64 bits.
3455</p>
3456
3457</div>
3458
3459<!-- _______________________________________________________________________ -->
3460<div class="doc_subsubsection">
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003461 <a name="int_ctpop">'<tt>llvm.ctpop</tt>' Intrinsic</a>
3462</div>
3463
3464<div class="doc_text">
3465
3466<h5>Syntax:</h5>
3467<pre>
3468 declare int %llvm.ctpop(int &lt;src&gt;)
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003469</pre>
3470
3471<h5>Overview:</h5>
3472
3473<p>
3474The '<tt>llvm.ctpop</tt>' intrinsic counts the number of ones in a variable.
3475</p>
3476
3477<h5>Arguments:</h5>
3478
3479<p>
Chris Lattnercfe6b372005-05-07 01:46:40 +00003480The only argument is the value to be counted. The argument may be of any
3481integer type. The return type must match the argument type.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003482</p>
3483
3484<h5>Semantics:</h5>
3485
3486<p>
3487The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable.
3488</p>
3489</div>
3490
3491<!-- _______________________________________________________________________ -->
3492<div class="doc_subsubsection">
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003493 <a name="int_ctlz">'<tt>llvm.ctlz</tt>' Intrinsic</a>
3494</div>
3495
3496<div class="doc_text">
3497
3498<h5>Syntax:</h5>
3499<pre>
3500 declare int %llvm.ctlz(int &lt;src&gt;)
3501
3502</pre>
3503
3504<h5>Overview:</h5>
3505
3506<p>
Chris Lattnercfe6b372005-05-07 01:46:40 +00003507The '<tt>llvm.ctlz</tt>' intrinsic counts the number of leading zeros in a
3508variable.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003509</p>
3510
3511<h5>Arguments:</h5>
3512
3513<p>
Chris Lattnercfe6b372005-05-07 01:46:40 +00003514The only argument is the value to be counted. The argument may be of any
3515integer type. The return type must match the argument type.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003516</p>
3517
3518<h5>Semantics:</h5>
3519
3520<p>
Chris Lattnereff29ab2005-05-15 19:39:26 +00003521The '<tt>llvm.ctlz</tt>' intrinsic counts the leading (most significant) zeros
3522in a variable. If the src == 0 then the result is the size in bits of the type
3523of src. For example, <tt>llvm.cttz(int 2) = 30</tt>.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00003524</p>
3525</div>
Chris Lattner32006282004-06-11 02:28:03 +00003526
3527
Chris Lattnereff29ab2005-05-15 19:39:26 +00003528
3529<!-- _______________________________________________________________________ -->
3530<div class="doc_subsubsection">
3531 <a name="int_cttz">'<tt>llvm.cttz</tt>' Intrinsic</a>
3532</div>
3533
3534<div class="doc_text">
3535
3536<h5>Syntax:</h5>
3537<pre>
3538 declare int %llvm.cttz(int &lt;src&gt;)
Chris Lattnereff29ab2005-05-15 19:39:26 +00003539</pre>
3540
3541<h5>Overview:</h5>
3542
3543<p>
3544The '<tt>llvm.cttz</tt>' intrinsic counts the number of trailing zeros.
3545</p>
3546
3547<h5>Arguments:</h5>
3548
3549<p>
3550The only argument is the value to be counted. The argument may be of any
3551integer type. The return type must match the argument type.
3552</p>
3553
3554<h5>Semantics:</h5>
3555
3556<p>
3557The '<tt>llvm.cttz</tt>' intrinsic counts the trailing (least significant) zeros
3558in a variable. If the src == 0 then the result is the size in bits of the type
3559of src. For example, <tt>llvm.cttz(2) = 1</tt>.
3560</p>
3561</div>
3562
Chris Lattner8ff75902004-01-06 05:31:32 +00003563<!-- ======================================================================= -->
3564<div class="doc_subsection">
3565 <a name="int_debugger">Debugger Intrinsics</a>
3566</div>
3567
3568<div class="doc_text">
3569<p>
3570The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
3571are described in the <a
3572href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
3573Debugging</a> document.
3574</p>
3575</div>
3576
3577
Chris Lattner00950542001-06-06 20:29:01 +00003578<!-- *********************************************************************** -->
Chris Lattner00950542001-06-06 20:29:01 +00003579<hr>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00003580<address>
3581 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
3582 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
3583 <a href="http://validator.w3.org/check/referer"><img
3584 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
3585
3586 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
3587 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
3588 Last modified: $Date$
3589</address>
Misha Brukman9d0919f2003-11-08 01:05:38 +00003590</body>
3591</html>