blob: 14c0eb520ee7c649f5fdf99c5422e5441df23698 [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>
6 <link rel="stylesheet" href="llvm.css" type="text/css">
7</head>
Chris Lattnerd7923912004-05-23 21:06:01 +00008
Misha Brukman9d0919f2003-11-08 01:05:38 +00009<body>
Chris Lattnerd7923912004-05-23 21:06:01 +000010
Chris Lattner261efe92003-11-25 01:02:51 +000011<div class="doc_title"> LLVM Language Reference Manual </div>
Chris Lattner00950542001-06-06 20:29:01 +000012<ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000013 <li><a href="#abstract">Abstract</a></li>
14 <li><a href="#introduction">Introduction</a></li>
15 <li><a href="#identifiers">Identifiers</a></li>
Chris Lattner00950542001-06-06 20:29:01 +000016 <li><a href="#typesystem">Type System</a>
17 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000018 <li><a href="#t_primitive">Primitive Types</a>
19 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000020 <li><a href="#t_classifications">Type Classifications</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000021 </ol>
22 </li>
Chris Lattner00950542001-06-06 20:29:01 +000023 <li><a href="#t_derived">Derived Types</a>
24 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000025 <li><a href="#t_array">Array Type</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000026 <li><a href="#t_function">Function Type</a></li>
27 <li><a href="#t_pointer">Pointer Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000028 <li><a href="#t_struct">Structure Type</a></li>
29<!-- <li><a href="#t_packed" >Packed Type</a> -->
30 </ol>
31 </li>
32 </ol>
33 </li>
Chris Lattner00950542001-06-06 20:29:01 +000034 <li><a href="#highlevel">High Level Structure</a>
35 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000036 <li><a href="#modulestructure">Module Structure</a></li>
37 <li><a href="#globalvars">Global Variables</a></li>
38 <li><a href="#functionstructure">Function Structure</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000039 </ol>
40 </li>
Chris Lattner00950542001-06-06 20:29:01 +000041 <li><a href="#instref">Instruction Reference</a>
42 <ol>
43 <li><a href="#terminators">Terminator Instructions</a>
44 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000045 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
46 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000047 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
48 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000049 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
50 </ol>
51 </li>
Chris Lattner00950542001-06-06 20:29:01 +000052 <li><a href="#binaryops">Binary Operations</a>
53 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000054 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
55 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
56 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
57 <li><a href="#i_div">'<tt>div</tt>' Instruction</a></li>
58 <li><a href="#i_rem">'<tt>rem</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000059 <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000060 </ol>
61 </li>
Chris Lattner00950542001-06-06 20:29:01 +000062 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
63 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000064 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000065 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000066 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
67 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
68 <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000069 </ol>
70 </li>
Chris Lattner00950542001-06-06 20:29:01 +000071 <li><a href="#memoryops">Memory Access Operations</a>
72 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000073 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
74 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
75 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
76 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
77 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
78 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
79 </ol>
80 </li>
Chris Lattner00950542001-06-06 20:29:01 +000081 <li><a href="#otherops">Other Operations</a>
82 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000083 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000084 <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li>
Chris Lattnercc37aae2004-03-12 05:50:16 +000085 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000086 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000087 <li><a href="#i_vanext">'<tt>vanext</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000088 <li><a href="#i_vaarg">'<tt>vaarg</tt>' Instruction</a></li>
Chris Lattner00950542001-06-06 20:29:01 +000089 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +000090 </li>
Chris Lattner00950542001-06-06 20:29:01 +000091 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +000092 </li>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +000093 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +000094 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000095 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
96 <ol>
97 <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
98 <li><a href="#i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
99 <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
100 </ol>
101 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000102 <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
103 <ol>
104 <li><a href="#i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li>
105 <li><a href="#i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li>
106 <li><a href="#i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li>
107 </ol>
108 </li>
Chris Lattner10610642004-02-14 04:08:35 +0000109 <li><a href="#int_codegen">Code Generator Intrinsics</a>
110 <ol>
111 <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
112 <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
John Criswell7123e272004-04-09 16:43:20 +0000113 </ol>
114 </li>
115 <li><a href="#int_os">Operating System Intrinsics</a>
116 <ol>
Chris Lattner32006282004-06-11 02:28:03 +0000117 <li><a href="#i_readport">'<tt>llvm.readport</tt>' Intrinsic</a></li>
118 <li><a href="#i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a></li>
John Criswell183402a2004-04-12 15:02:16 +0000119 <li><a href="#i_readio">'<tt>llvm.readio</tt>' Intrinsic</a></li>
120 <li><a href="#i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000121 </ol>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000122 <li><a href="#int_libc">Standard C Library Intrinsics</a>
123 <ol>
124 <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li>
Chris Lattner0eb51b42004-02-12 18:10:10 +0000125 <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000126 <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li>
Chris Lattner32006282004-06-11 02:28:03 +0000127 <li><a href="#i_isnan">'<tt>llvm.isnan</tt>' Intrinsic</a></li>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000128 </ol>
129 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000130 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000131 </ol>
132 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000133</ol>
Chris Lattnerd7923912004-05-23 21:06:01 +0000134
135<div class="doc_author">
136 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
137 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000138</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000139
Chris Lattner00950542001-06-06 20:29:01 +0000140<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000141<div class="doc_section"> <a name="abstract">Abstract </a></div>
142<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000143
Misha Brukman9d0919f2003-11-08 01:05:38 +0000144<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000145<p>This document is a reference manual for the LLVM assembly language.
146LLVM is an SSA based representation that provides type safety,
147low-level operations, flexibility, and the capability of representing
148'all' high-level languages cleanly. It is the common code
149representation used throughout all phases of the LLVM compilation
150strategy.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000151</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000152
Chris Lattner00950542001-06-06 20:29:01 +0000153<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000154<div class="doc_section"> <a name="introduction">Introduction</a> </div>
155<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000156
Misha Brukman9d0919f2003-11-08 01:05:38 +0000157<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000158
Chris Lattner261efe92003-11-25 01:02:51 +0000159<p>The LLVM code representation is designed to be used in three
160different forms: as an in-memory compiler IR, as an on-disk bytecode
161representation (suitable for fast loading by a Just-In-Time compiler),
162and as a human readable assembly language representation. This allows
163LLVM to provide a powerful intermediate representation for efficient
164compiler transformations and analysis, while providing a natural means
165to debug and visualize the transformations. The three different forms
166of LLVM are all equivalent. This document describes the human readable
167representation and notation.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000168
Chris Lattner261efe92003-11-25 01:02:51 +0000169<p>The LLVM representation aims to be a light-weight and low-level
170while being expressive, typed, and extensible at the same time. It
171aims to be a "universal IR" of sorts, by being at a low enough level
172that high-level ideas may be cleanly mapped to it (similar to how
173microprocessors are "universal IR's", allowing many source languages to
174be mapped to them). By providing type information, LLVM can be used as
175the target of optimizations: for example, through pointer analysis, it
176can be proven that a C automatic variable is never accessed outside of
177the current function... allowing it to be promoted to a simple SSA
178value instead of a memory location.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000179
Misha Brukman9d0919f2003-11-08 01:05:38 +0000180</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000181
Chris Lattner00950542001-06-06 20:29:01 +0000182<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000183<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000184
Misha Brukman9d0919f2003-11-08 01:05:38 +0000185<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000186
Chris Lattner261efe92003-11-25 01:02:51 +0000187<p>It is important to note that this document describes 'well formed'
188LLVM assembly language. There is a difference between what the parser
189accepts and what is considered 'well formed'. For example, the
190following instruction is syntactically okay, but not well formed:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000191
192<pre>
193 %x = <a href="#i_add">add</a> int 1, %x
194</pre>
195
Chris Lattner261efe92003-11-25 01:02:51 +0000196<p>...because the definition of <tt>%x</tt> does not dominate all of
197its uses. The LLVM infrastructure provides a verification pass that may
198be used to verify that an LLVM module is well formed. This pass is
199automatically run by the parser after parsing input assembly, and by
200the optimizer before it outputs bytecode. The violations pointed out
201by the verifier pass indicate bugs in transformation passes or input to
202the parser.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000203
Chris Lattner261efe92003-11-25 01:02:51 +0000204<!-- Describe the typesetting conventions here. --> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000205
Chris Lattner00950542001-06-06 20:29:01 +0000206<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000207<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000208<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000209
Misha Brukman9d0919f2003-11-08 01:05:38 +0000210<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000211
Chris Lattner261efe92003-11-25 01:02:51 +0000212<p>LLVM uses three different forms of identifiers, for different
213purposes:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000214
Chris Lattner00950542001-06-06 20:29:01 +0000215<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000216 <li>Numeric constants are represented as you would expect: 12, -3
John Criswell4457dc92004-04-09 16:48:45 +0000217123.421, etc. Floating point constants have an optional hexadecimal
Chris Lattner261efe92003-11-25 01:02:51 +0000218notation.</li>
219 <li>Named values are represented as a string of characters with a '%'
220prefix. For example, %foo, %DivisionByZero,
221%a.really.long.identifier. The actual regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
222Identifiers which require other characters in their names can be
223surrounded with quotes. In this way, anything except a <tt>"</tt>
224character can be used in a name.</li>
225 <li>Unnamed values are represented as an unsigned numeric value with
226a '%' prefix. For example, %12, %2, %44.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000227</ol>
John Criswell6794d922004-03-12 21:19:06 +0000228<p>LLVM requires that values start with a '%' sign for two reasons:
Chris Lattner261efe92003-11-25 01:02:51 +0000229Compilers don't need to worry about name clashes with reserved words,
230and the set of reserved words may be expanded in the future without
231penalty. Additionally, unnamed identifiers allow a compiler to quickly
232come up with a temporary variable without having to avoid symbol table
233conflicts.</p>
234<p>Reserved words in LLVM are very similar to reserved words in other
235languages. There are keywords for different opcodes ('<tt><a
236 href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
237 href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
238 href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>',
239etc...), and others. These reserved words cannot conflict with
240variable names, because none of them start with a '%' character.</p>
241<p>Here is an example of LLVM code to multiply the integer variable '<tt>%X</tt>'
242by 8:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000243<p>The easy way:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000244<pre> %result = <a href="#i_mul">mul</a> uint %X, 8<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000245<p>After strength reduction:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000246<pre> %result = <a href="#i_shl">shl</a> uint %X, ubyte 3<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000247<p>And the hard way:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000248<pre> <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
249 <a
250 href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
251 %result = <a
252 href="#i_add">add</a> uint %1, %1<br></pre>
253<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
254important lexical features of LLVM:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000255<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000256 <li>Comments are delimited with a '<tt>;</tt>' and go until the end
257of line.</li>
258 <li>Unnamed temporaries are created when the result of a computation
259is not assigned to a named value.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000260 <li>Unnamed temporaries are numbered sequentially</li>
261</ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000262<p>...and it also show a convention that we follow in this document.
263When demonstrating instructions, we will follow an instruction with a
264comment that defines the type and name of value produced. Comments are
265shown in italic text.</p>
266<p>The one non-intuitive notation for constants is the optional
267hexidecimal form of floating point constants. For example, the form '<tt>double
Chris Lattner2b7d3202002-05-06 03:03:22 +00002680x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
Chris Lattner261efe92003-11-25 01:02:51 +00002694.5e+15</tt>' which is also supported by the parser. The only time
270hexadecimal floating point constants are useful (and the only time that
271they are generated by the disassembler) is when an FP constant has to
272be emitted that is not representable as a decimal floating point number
273exactly. For example, NaN's, infinities, and other special cases are
274represented in their IEEE hexadecimal format so that assembly and
275disassembly do not cause any bits to change in the constants.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000276</div>
Chris Lattner00950542001-06-06 20:29:01 +0000277<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000278<div class="doc_section"> <a name="typesystem">Type System</a> </div>
279<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000280<div class="doc_text">
Misha Brukman9d0919f2003-11-08 01:05:38 +0000281<p>The LLVM type system is one of the most important features of the
Chris Lattner261efe92003-11-25 01:02:51 +0000282intermediate representation. Being typed enables a number of
283optimizations to be performed on the IR directly, without having to do
284extra analyses on the side before the transformation. A strong type
285system makes it easier to read the generated code and enables novel
286analyses and transformations that are not feasible to perform on normal
287three address code representations.</p>
Chris Lattner7bae3952002-06-25 18:03:17 +0000288<!-- The written form for the type system was heavily influenced by the
289syntactic problems with types in the C language<sup><a
Chris Lattner261efe92003-11-25 01:02:51 +0000290href="#rw_stroustrup">1</a></sup>.<p> --> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000291<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000292<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000293<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +0000294<p>The primitive types are the fundamental building blocks of the LLVM
Chris Lattner261efe92003-11-25 01:02:51 +0000295system. The current set of primitive types are as follows:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000296
297<table border="0" style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +0000298 <tbody>
299 <tr>
300 <td>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000301 <table border="1" cellspacing="0" cellpadding="4" style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +0000302 <tbody>
303 <tr>
304 <td><tt>void</tt></td>
305 <td>No value</td>
306 </tr>
307 <tr>
308 <td><tt>ubyte</tt></td>
309 <td>Unsigned 8 bit value</td>
310 </tr>
311 <tr>
312 <td><tt>ushort</tt></td>
313 <td>Unsigned 16 bit value</td>
314 </tr>
315 <tr>
316 <td><tt>uint</tt></td>
317 <td>Unsigned 32 bit value</td>
318 </tr>
319 <tr>
320 <td><tt>ulong</tt></td>
321 <td>Unsigned 64 bit value</td>
322 </tr>
323 <tr>
324 <td><tt>float</tt></td>
325 <td>32 bit floating point value</td>
326 </tr>
327 <tr>
328 <td><tt>label</tt></td>
329 <td>Branch destination</td>
330 </tr>
331 </tbody>
332 </table>
333 </td>
334 <td valign="top">
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000335 <table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +0000336 <tbody>
337 <tr>
338 <td><tt>bool</tt></td>
339 <td>True or False value</td>
340 </tr>
341 <tr>
342 <td><tt>sbyte</tt></td>
343 <td>Signed 8 bit value</td>
344 </tr>
345 <tr>
346 <td><tt>short</tt></td>
347 <td>Signed 16 bit value</td>
348 </tr>
349 <tr>
350 <td><tt>int</tt></td>
351 <td>Signed 32 bit value</td>
352 </tr>
353 <tr>
354 <td><tt>long</tt></td>
355 <td>Signed 64 bit value</td>
356 </tr>
357 <tr>
358 <td><tt>double</tt></td>
359 <td>64 bit floating point value</td>
360 </tr>
361 </tbody>
362 </table>
363 </td>
364 </tr>
365 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000366</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000367
Misha Brukman9d0919f2003-11-08 01:05:38 +0000368</div>
Chris Lattner00950542001-06-06 20:29:01 +0000369<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000370<div class="doc_subsubsection"> <a name="t_classifications">Type
371Classifications</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000372<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000373<p>These different primitive types fall into a few useful
374classifications:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000375
376<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +0000377 <tbody>
378 <tr>
379 <td><a name="t_signed">signed</a></td>
380 <td><tt>sbyte, short, int, long, float, double</tt></td>
381 </tr>
382 <tr>
383 <td><a name="t_unsigned">unsigned</a></td>
384 <td><tt>ubyte, ushort, uint, ulong</tt></td>
385 </tr>
386 <tr>
387 <td><a name="t_integer">integer</a></td>
388 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
389 </tr>
390 <tr>
391 <td><a name="t_integral">integral</a></td>
392 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
393 </tr>
394 <tr>
395 <td><a name="t_floating">floating point</a></td>
396 <td><tt>float, double</tt></td>
397 </tr>
398 <tr>
399 <td><a name="t_firstclass">first class</a></td>
400 <td><tt>bool, ubyte, sbyte, ushort, short,<br>
401uint, int, ulong, long, float, double, <a href="#t_pointer">pointer</a></tt></td>
402 </tr>
403 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000404</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000405
Chris Lattner261efe92003-11-25 01:02:51 +0000406<p>The <a href="#t_firstclass">first class</a> types are perhaps the
407most important. Values of these types are the only ones which can be
408produced by instructions, passed as arguments, or used as operands to
409instructions. This means that all structures and arrays must be
410manipulated either by pointer or by component.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000411</div>
Chris Lattner00950542001-06-06 20:29:01 +0000412<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000413<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000414<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000415<p>The real power in LLVM comes from the derived types in the system.
416This is what allows a programmer to represent arrays, functions,
417pointers, and other useful types. Note that these derived types may be
418recursive: For example, it is possible to have a two dimensional array.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000419</div>
Chris Lattner00950542001-06-06 20:29:01 +0000420<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000421<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000422<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000423<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000424<p>The array type is a very simple derived type that arranges elements
Chris Lattner261efe92003-11-25 01:02:51 +0000425sequentially in memory. The array type requires a size (number of
426elements) and an underlying data type.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000427<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000428<pre> [&lt;# elements&gt; x &lt;elementtype&gt;]<br></pre>
429<p>The number of elements is a constant integer value, elementtype may
430be any type with a size.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000431<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000432<p> <tt>[40 x int ]</tt>: Array of 40 integer values.<br>
433<tt>[41 x int ]</tt>: Array of 41 integer values.<br>
434<tt>[40 x uint]</tt>: Array of 40 unsigned integer values.</p>
435<p> </p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000436<p>Here are some examples of multidimensional arrays:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000437
Misha Brukman9d0919f2003-11-08 01:05:38 +0000438<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000439 <tbody>
440 <tr>
441 <td><tt>[3 x [4 x int]]</tt></td>
442 <td>: 3x4 array integer values.</td>
443 </tr>
444 <tr>
445 <td><tt>[12 x [10 x float]]</tt></td>
446 <td>: 12x10 array of single precision floating point values.</td>
447 </tr>
448 <tr>
449 <td><tt>[2 x [3 x [4 x uint]]]</tt></td>
450 <td>: 2x3x4 array of unsigned integer values.</td>
451 </tr>
452 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000453</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000454
Misha Brukman9d0919f2003-11-08 01:05:38 +0000455</div>
Chris Lattner00950542001-06-06 20:29:01 +0000456<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000457<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000458<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000459<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000460<p>The function type can be thought of as a function signature. It
461consists of a return type and a list of formal parameter types.
John Criswell009900b2003-11-25 21:45:46 +0000462Function types are usually used to build virtual function tables
Chris Lattner261efe92003-11-25 01:02:51 +0000463(which are structures of pointers to functions), for indirect function
464calls, and when defining a function.</p>
John Criswell009900b2003-11-25 21:45:46 +0000465<p>
466The return type of a function type cannot be an aggregate type.
467</p>
Chris Lattner00950542001-06-06 20:29:01 +0000468<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000469<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
470<p>Where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of
471type specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner27f71f22003-09-03 00:41:47 +0000472which indicates that the function takes a variable number of arguments.
473Variable argument functions can access their arguments with the <a
Chris Lattner261efe92003-11-25 01:02:51 +0000474 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000475<h5>Examples:</h5>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000476
Misha Brukman9d0919f2003-11-08 01:05:38 +0000477<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000478 <tbody>
479 <tr>
480 <td><tt>int (int)</tt></td>
481 <td>: function taking an <tt>int</tt>, returning an <tt>int</tt></td>
482 </tr>
483 <tr>
484 <td><tt>float (int, int *) *</tt></td>
485 <td>: <a href="#t_pointer">Pointer</a> to a function that takes
486an <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
487returning <tt>float</tt>.</td>
488 </tr>
489 <tr>
490 <td><tt>int (sbyte *, ...)</tt></td>
491 <td>: A vararg function that takes at least one <a
492 href="#t_pointer">pointer</a> to <tt>sbyte</tt> (signed char in C),
493which returns an integer. This is the signature for <tt>printf</tt>
494in LLVM.</td>
495 </tr>
496 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000497</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000498
Misha Brukman9d0919f2003-11-08 01:05:38 +0000499</div>
Chris Lattner00950542001-06-06 20:29:01 +0000500<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000501<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000502<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000503<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000504<p>The structure type is used to represent a collection of data members
505together in memory. The packing of the field types is defined to match
506the ABI of the underlying processor. The elements of a structure may
507be any type that has a size.</p>
508<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
509and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
510field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
511instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000512<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000513<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +0000514<h5>Examples:</h5>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000515
Misha Brukman9d0919f2003-11-08 01:05:38 +0000516<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000517 <tbody>
518 <tr>
519 <td><tt>{ int, int, int }</tt></td>
520 <td>: a triple of three <tt>int</tt> values</td>
521 </tr>
522 <tr>
523 <td><tt>{ float, int (int) * }</tt></td>
524 <td>: A pair, where the first element is a <tt>float</tt> and the
525second element is a <a href="#t_pointer">pointer</a> to a <a
Chris Lattnere53e5082004-06-03 22:57:15 +0000526 href="#t_function">function</a> that takes an <tt>int</tt>, returning
Chris Lattner261efe92003-11-25 01:02:51 +0000527an <tt>int</tt>.</td>
528 </tr>
529 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000530</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000531
Misha Brukman9d0919f2003-11-08 01:05:38 +0000532</div>
Chris Lattner00950542001-06-06 20:29:01 +0000533<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000534<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000535<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +0000536<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000537<p>As in many languages, the pointer type represents a pointer or
538reference to another object, which must live in memory.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000539<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000540<pre> &lt;type&gt; *<br></pre>
Chris Lattner7faa8832002-04-14 06:13:44 +0000541<h5>Examples:</h5>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000542
Misha Brukman9d0919f2003-11-08 01:05:38 +0000543<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000544 <tbody>
545 <tr>
546 <td><tt>[4x int]*</tt></td>
547 <td>: <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a>
548of four <tt>int</tt> values</td>
549 </tr>
550 <tr>
551 <td><tt>int (int *) *</tt></td>
552 <td>: A <a href="#t_pointer">pointer</a> to a <a
Chris Lattnere53e5082004-06-03 22:57:15 +0000553 href="#t_function">function</a> that takes an <tt>int</tt>, returning
Chris Lattner261efe92003-11-25 01:02:51 +0000554an <tt>int</tt>.</td>
555 </tr>
556 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000557</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000558
Misha Brukman9d0919f2003-11-08 01:05:38 +0000559</div>
Chris Lattner261efe92003-11-25 01:02:51 +0000560<!-- _______________________________________________________________________ --><!--
Misha Brukman9d0919f2003-11-08 01:05:38 +0000561<div class="doc_subsubsection">
562 <a name="t_packed">Packed Type</a>
563</div>
564
565<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000566
567Mention/decide that packed types work with saturation or not. Maybe have a packed+saturated type in addition to just a packed type.<p>
568
569Packed types should be 'nonsaturated' because standard data types are not saturated. Maybe have a saturated packed type?<p>
570
Misha Brukman9d0919f2003-11-08 01:05:38 +0000571</div>
572
Chris Lattner261efe92003-11-25 01:02:51 +0000573--><!-- *********************************************************************** -->
574<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
575<!-- *********************************************************************** --><!-- ======================================================================= -->
576<div class="doc_subsection"> <a name="modulestructure">Module Structure</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000577<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000578<p>LLVM programs are composed of "Module"s, each of which is a
579translation unit of the input programs. Each module consists of
580functions, global variables, and symbol table entries. Modules may be
581combined together with the LLVM linker, which merges function (and
582global variable) definitions, resolves forward declarations, and merges
583symbol table entries. Here is an example of the "hello world" module:</p>
584<pre><i>; Declare the string constant as a global constant...</i>
585<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
586 href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00" <i>; [13 x sbyte]*</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000587
Chris Lattner27f71f22003-09-03 00:41:47 +0000588<i>; External declaration of the puts function</i>
589<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000590
591<i>; Definition of main function</i>
Chris Lattner27f71f22003-09-03 00:41:47 +0000592int %main() { <i>; int()* </i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000593 <i>; Convert [13x sbyte]* to sbyte *...</i>
Chris Lattner261efe92003-11-25 01:02:51 +0000594 %cast210 = <a
595 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000596
597 <i>; Call puts function to write out the string to stdout...</i>
Chris Lattner261efe92003-11-25 01:02:51 +0000598 <a
599 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
600 <a
601 href="#i_ret">ret</a> int 0<br>}<br></pre>
602<p>This example is made up of a <a href="#globalvars">global variable</a>
603named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
604function, and a <a href="#functionstructure">function definition</a>
605for "<tt>main</tt>".</p>
606<a name="linkage"> In general, a module is made up of a list of global
607values, where both functions and global variables are global values.
608Global values are represented by a pointer to a memory location (in
609this case, a pointer to an array of char, and a pointer to a function),
610and have one of the following linkage types:</a>
611<p> </p>
Chris Lattner27f71f22003-09-03 00:41:47 +0000612<dl>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000613 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000614 <dd>Global values with internal linkage are only directly accessible
615by objects in the current module. In particular, linking code into a
616module with an internal global value may cause the internal to be
617renamed as necessary to avoid collisions. Because the symbol is
618internal to the module, all references can be updated. This
619corresponds to the notion of the '<tt>static</tt>' keyword in C, or the
620idea of "anonymous namespaces" in C++.
621 <p> </p>
622 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000623 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000624 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt>
625linkage, with the twist that linking together two modules defining the
626same <tt>linkonce</tt> globals will cause one of the globals to be
627discarded. This is typically used to implement inline functions.
628Unreferenced <tt>linkonce</tt> globals are allowed to be discarded.
629 <p> </p>
630 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000631 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000632 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt>
633linkage, except that unreferenced <tt>weak</tt> globals may not be
634discarded. This is used to implement constructs in C such as "<tt>int
635X;</tt>" at global scope.
636 <p> </p>
637 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000638 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000639 <dd>"<tt>appending</tt>" linkage may only be applied to global
640variables of pointer to array type. When two global variables with
641appending linkage are linked together, the two global arrays are
642appended together. This is the LLVM, typesafe, equivalent of having
643the system linker append together "sections" with identical names when
644.o files are linked.
645 <p> </p>
646 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000647 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000648 <dd>If none of the above identifiers are used, the global is
649externally visible, meaning that it participates in linkage and can be
650used to resolve external symbol references.
651 <p> </p>
652 </dd>
Chris Lattner261efe92003-11-25 01:02:51 +0000653</dl>
654<p> </p>
655<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
656variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
657variable and was linked with this one, one of the two would be renamed,
658preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
659external (i.e., lacking any linkage declarations), they are accessible
660outside of the current module. It is illegal for a function <i>declaration</i>
661to have any linkage type other than "externally visible".</a></p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000662</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000663
Chris Lattner00950542001-06-06 20:29:01 +0000664<!-- ======================================================================= -->
Chris Lattner9ee5d222004-03-08 16:49:10 +0000665<div class="doc_subsection">
666 <a name="globalvars">Global Variables</a>
667</div>
668
Misha Brukman9d0919f2003-11-08 01:05:38 +0000669<div class="doc_text">
Chris Lattner9ee5d222004-03-08 16:49:10 +0000670
Chris Lattner261efe92003-11-25 01:02:51 +0000671<p>Global variables define regions of memory allocated at compilation
672time instead of run-time. Global variables may optionally be
673initialized. A variable may be defined as a global "constant", which
674indicates that the contents of the variable will never be modified
Chris Lattner9ee5d222004-03-08 16:49:10 +0000675(opening options for optimization).</p>
676
Chris Lattner261efe92003-11-25 01:02:51 +0000677<p>As SSA values, global variables define pointer values that are in
678scope (i.e. they dominate) for all basic blocks in the program. Global
679variables always define a pointer to their "content" type because they
680describe a region of memory, and all memory objects in LLVM are
681accessed through pointers.</p>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000682
Misha Brukman9d0919f2003-11-08 01:05:38 +0000683</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000684
685
Chris Lattner2b7d3202002-05-06 03:03:22 +0000686<!-- ======================================================================= -->
Chris Lattner9ee5d222004-03-08 16:49:10 +0000687<div class="doc_subsection">
688 <a name="functionstructure">Functions</a>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000689</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000690
691<div class="doc_text">
692
693<p>LLVM function definitions are composed of a (possibly empty) argument list,
694an opening curly brace, a list of basic blocks, and a closing curly brace. LLVM
695function declarations are defined with the "<tt>declare</tt>" keyword, a
696function name, and a function signature.</p>
697
698<p>A function definition contains a list of basic blocks, forming the CFG for
699the function. Each basic block may optionally start with a label (giving the
700basic block a symbol table entry), contains a list of instructions, and ends
701with a <a href="#terminators">terminator</a> instruction (such as a branch or
702function return).</p>
703
704<p>The first basic block in program is special in two ways: it is immediately
705executed on entrance to the function, and it is not allowed to have predecessor
706basic blocks (i.e. there can not be any branches to the entry block of a
707function). Because the block can have no predecessors, it also cannot have any
708<a href="#i_phi">PHI nodes</a>.</p>
709
710<p>LLVM functions are identified by their name and type signature. Hence, two
711functions with the same name but different parameter lists or return values are
712considered different functions, and LLVM will resolves references to each
713appropriately.</p>
714
715</div>
716
717
Chris Lattner00950542001-06-06 20:29:01 +0000718<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000719<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
720<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000721<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000722<p>The LLVM instruction set consists of several different
723classifications of instructions: <a href="#terminators">terminator
724instructions</a>, <a href="#binaryops">binary instructions</a>, <a
725 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
726instructions</a>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000727</div>
Chris Lattner00950542001-06-06 20:29:01 +0000728<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000729<div class="doc_subsection"> <a name="terminators">Terminator
730Instructions</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000731<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000732<p>As mentioned <a href="#functionstructure">previously</a>, every
733basic block in a program ends with a "Terminator" instruction, which
734indicates which block should be executed after the current block is
735finished. These terminator instructions typically yield a '<tt>void</tt>'
736value: they produce control flow, not values (the one exception being
737the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000738<p>There are five different terminator instructions: the '<a
Chris Lattner261efe92003-11-25 01:02:51 +0000739 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
740instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
741the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, and the '<a
742 href="#i_unwind"><tt>unwind</tt></a>' instruction.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000743</div>
Chris Lattner00950542001-06-06 20:29:01 +0000744<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000745<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
746Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000747<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000748<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000749<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 +0000750 ret void <i>; Return from void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000751</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000752<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000753<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
754value) from a function, back to the caller.</p>
John Criswell4457dc92004-04-09 16:48:45 +0000755<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner261efe92003-11-25 01:02:51 +0000756returns a value and then causes control flow, and one that just causes
757control flow to occur.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000758<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000759<p>The '<tt>ret</tt>' instruction may return any '<a
760 href="#t_firstclass">first class</a>' type. Notice that a function is
761not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
762instruction inside of the function that returns a value that does not
763match the return type of the function.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000764<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000765<p>When the '<tt>ret</tt>' instruction is executed, control flow
766returns back to the calling function's context. If the caller is a "<a
767 href="#i_call"><tt>call</tt></a> instruction, execution continues at
768the instruction after the call. If the caller was an "<a
769 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
770at the beginning "normal" of the destination block. If the instruction
771returns a value, that value shall set the call or invoke instruction's
772return value.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000773<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000774<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner7faa8832002-04-14 06:13:44 +0000775 ret void <i>; Return from a void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000776</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000777</div>
Chris Lattner00950542001-06-06 20:29:01 +0000778<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000779<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000780<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000781<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000782<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 +0000783</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000784<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000785<p>The '<tt>br</tt>' instruction is used to cause control flow to
786transfer to a different basic block in the current function. There are
787two forms of this instruction, corresponding to a conditional branch
788and an unconditional branch.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000789<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000790<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
791single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
792unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
793value as a target.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000794<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000795<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
796argument is evaluated. If the value is <tt>true</tt>, control flows
797to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
798control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000799<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000800<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
801 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 +0000802</div>
Chris Lattner00950542001-06-06 20:29:01 +0000803<!-- _______________________________________________________________________ -->
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000804<div class="doc_subsubsection">
805 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
806</div>
807
Misha Brukman9d0919f2003-11-08 01:05:38 +0000808<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000809<h5>Syntax:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000810
811<pre>
812 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
813</pre>
814
Chris Lattner00950542001-06-06 20:29:01 +0000815<h5>Overview:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000816
817<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
818several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +0000819instruction, allowing a branch to occur to one of many possible
820destinations.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000821
822
Chris Lattner00950542001-06-06 20:29:01 +0000823<h5>Arguments:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000824
825<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
826comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
827an array of pairs of comparison value constants and '<tt>label</tt>'s. The
828table is not allowed to contain duplicate constant entries.</p>
829
Chris Lattner00950542001-06-06 20:29:01 +0000830<h5>Semantics:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000831
Chris Lattner261efe92003-11-25 01:02:51 +0000832<p>The <tt>switch</tt> instruction specifies a table of values and
833destinations. When the '<tt>switch</tt>' instruction is executed, this
834table is searched for the given value. If the value is found, the
835corresponding destination is branched to, otherwise the default value
836it transfered to.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000837
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000838<h5>Implementation:</h5>
839
840<p>Depending on properties of the target machine and the particular
841<tt>switch</tt> instruction, this instruction may be code generated in different
842ways, for example as a series of chained conditional branches, or with a lookup
843table.</p>
844
845<h5>Example:</h5>
846
847<pre>
848 <i>; Emulate a conditional br instruction</i>
849 %Val = <a href="#i_cast">cast</a> bool %value to int
850 switch int %Val, label %truedest [int 0, label %falsedest ]
851
852 <i>; Emulate an unconditional br instruction</i>
853 switch uint 0, label %dest [ ]
854
855 <i>; Implement a jump table:</i>
856 switch uint %val, label %otherwise [ uint 0, label %onzero
857 uint 1, label %onone
858 uint 2, label %ontwo ]
Chris Lattner00950542001-06-06 20:29:01 +0000859</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000860</div>
Chris Lattner00950542001-06-06 20:29:01 +0000861<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000862<div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>'
863Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000864<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000865<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000866<pre> &lt;result&gt; = invoke &lt;ptr to function ty&gt; %&lt;function ptr val&gt;(&lt;function args&gt;)<br> to label &lt;normal label&gt; except label &lt;exception label&gt;<br></pre>
Chris Lattner6536cfe2002-05-06 22:08:29 +0000867<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000868<p>The '<tt>invoke</tt>' instruction causes control to transfer to a
869specified function, with the possibility of control flow transfer to
870either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>.
871If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>"
872instruction, control flow will return to the "normal" label. If the
873callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
874instruction, control is interrupted, and continued at the dynamically
875nearest "except" label.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000876<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000877<p>This instruction requires several arguments:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000878<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000879 <li>'<tt>ptr to function ty</tt>': shall be the signature of the
880pointer to function value being invoked. In most cases, this is a
881direct function invocation, but indirect <tt>invoke</tt>s are just as
882possible, branching off an arbitrary pointer to function value. </li>
883 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer
884to a function to be invoked. </li>
885 <li>'<tt>function args</tt>': argument list whose types match the
886function signature argument types. If the function signature indicates
887the function accepts a variable number of arguments, the extra
888arguments can be specified. </li>
889 <li>'<tt>normal label</tt>': the label reached when the called
890function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
891 <li>'<tt>exception label</tt>': the label reached when a callee
892returns with the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
Chris Lattner00950542001-06-06 20:29:01 +0000893</ol>
Chris Lattner00950542001-06-06 20:29:01 +0000894<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000895<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner261efe92003-11-25 01:02:51 +0000896 href="#i_call">call</a></tt>' instruction in most regards. The
897primary difference is that it establishes an association with a label,
898which is used by the runtime library to unwind the stack.</p>
899<p>This instruction is used in languages with destructors to ensure
900that proper cleanup is performed in the case of either a <tt>longjmp</tt>
901or a thrown exception. Additionally, this is important for
902implementation of '<tt>catch</tt>' clauses in high-level languages that
903support them.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000904<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000905<pre> %retval = invoke int %Test(int 15)<br> to label %Continue<br> except label %TestCleanup <i>; {int}:retval set</i>
Chris Lattner00950542001-06-06 20:29:01 +0000906</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000907</div>
Chris Lattner27f71f22003-09-03 00:41:47 +0000908<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000909<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
910Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000911<div class="doc_text">
Chris Lattner27f71f22003-09-03 00:41:47 +0000912<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000913<pre> unwind<br></pre>
Chris Lattner27f71f22003-09-03 00:41:47 +0000914<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000915<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing
916control flow at the first callee in the dynamic call stack which used
917an <a href="#i_invoke"><tt>invoke</tt></a> instruction to perform the
918call. This is primarily used to implement exception handling.</p>
Chris Lattner27f71f22003-09-03 00:41:47 +0000919<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000920<p>The '<tt>unwind</tt>' intrinsic causes execution of the current
921function to immediately halt. The dynamic call stack is then searched
922for the first <a href="#i_invoke"><tt>invoke</tt></a> instruction on
923the call stack. Once found, execution continues at the "exceptional"
924destination block specified by the <tt>invoke</tt> instruction. If
925there is no <tt>invoke</tt> instruction in the dynamic call chain,
926undefined behavior results.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000927</div>
Chris Lattner00950542001-06-06 20:29:01 +0000928<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000929<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000930<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000931<p>Binary operators are used to do most of the computation in a
932program. They require two operands, execute an operation on them, and
933produce a single value. The result value of a binary operator is not
934necessarily the same type as its operands.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000935<p>There are several different binary operators:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000936</div>
Chris Lattner00950542001-06-06 20:29:01 +0000937<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000938<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
939Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000940<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000941<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000942<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 +0000943</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000944<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000945<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000946<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000947<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +0000948 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
949values. Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000950<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000951<p>The value produced is the integer or floating point sum of the two
952operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000953<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000954<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner00950542001-06-06 20:29:01 +0000955</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000956</div>
Chris Lattner00950542001-06-06 20:29:01 +0000957<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000958<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
959Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000960<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000961<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000962<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 +0000963</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000964<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000965<p>The '<tt>sub</tt>' instruction returns the difference of its two
966operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000967<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
968instruction present in most other intermediate representations.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000969<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000970<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +0000971 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
972values. Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000973<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000974<p>The value produced is the integer or floating point difference of
975the two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000976<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000977<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner00950542001-06-06 20:29:01 +0000978 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
979</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000980</div>
Chris Lattner00950542001-06-06 20:29:01 +0000981<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000982<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
983Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000984<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000985<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000986<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 +0000987</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000988<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000989<p>The '<tt>mul</tt>' instruction returns the product of its two
990operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000991<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000992<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +0000993 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
994values. Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000995<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000996<p>The value produced is the integer or floating point product of the
Misha Brukman9d0919f2003-11-08 01:05:38 +0000997two operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000998<p>There is no signed vs unsigned multiplication. The appropriate
999action is taken based on the type of the operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001000<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001001<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001002</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001003</div>
Chris Lattner00950542001-06-06 20:29:01 +00001004<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001005<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
1006Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001007<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001008<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001009<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1010</pre>
1011<h5>Overview:</h5>
1012<p>The '<tt>div</tt>' instruction returns the quotient of its two
1013operands.</p>
1014<h5>Arguments:</h5>
1015<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
1016 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
1017values. Both arguments must have identical types.</p>
1018<h5>Semantics:</h5>
1019<p>The value produced is the integer or floating point quotient of the
1020two operands.</p>
1021<h5>Example:</h5>
1022<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
1023</pre>
1024</div>
1025<!-- _______________________________________________________________________ -->
1026<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
1027Instruction</a> </div>
1028<div class="doc_text">
1029<h5>Syntax:</h5>
1030<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1031</pre>
1032<h5>Overview:</h5>
1033<p>The '<tt>rem</tt>' instruction returns the remainder from the
1034division of its two operands.</p>
1035<h5>Arguments:</h5>
1036<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1037 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
1038values. Both arguments must have identical types.</p>
1039<h5>Semantics:</h5>
1040<p>This returns the <i>remainder</i> of a division (where the result
1041has the same sign as the divisor), not the <i>modulus</i> (where the
1042result has the same sign as the dividend) of a value. For more
1043information about the difference, see: <a
1044 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1045Math Forum</a>.</p>
1046<h5>Example:</h5>
1047<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1048</pre>
1049</div>
1050<!-- _______________________________________________________________________ -->
1051<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1052Instructions</a> </div>
1053<div class="doc_text">
1054<h5>Syntax:</h5>
1055<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 +00001056 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1057 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1058 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1059 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1060 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1061</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001062<h5>Overview:</h5>
1063<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1064value based on a comparison of their two operands.</p>
1065<h5>Arguments:</h5>
1066<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1067be of <a href="#t_firstclass">first class</a> type (it is not possible
1068to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1069or '<tt>void</tt>' values, etc...). Both arguments must have identical
1070types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001071<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001072<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1073value if both operands are equal.<br>
1074The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1075value if both operands are unequal.<br>
1076The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1077value if the first operand is less than the second operand.<br>
1078The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1079value if the first operand is greater than the second operand.<br>
1080The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1081value if the first operand is less than or equal to the second operand.<br>
1082The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1083value if the first operand is greater than or equal to the second
1084operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001085<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001086<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner00950542001-06-06 20:29:01 +00001087 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
1088 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1089 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1090 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1091 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1092</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001093</div>
Chris Lattner00950542001-06-06 20:29:01 +00001094<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001095<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1096Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001097<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001098<p>Bitwise binary operators are used to do various forms of
1099bit-twiddling in a program. They are generally very efficient
1100instructions, and can commonly be strength reduced from other
1101instructions. They require two operands, execute an operation on them,
1102and produce a single value. The resulting value of the bitwise binary
1103operators is always the same type as its first operand.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001104</div>
Chris Lattner00950542001-06-06 20:29:01 +00001105<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001106<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1107Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001108<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001109<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001110<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 +00001111</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001112<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001113<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1114its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001115<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001116<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001117 href="#t_integral">integral</a> values. Both arguments must have
1118identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001119<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001120<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001121<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001122<div style="align: center">
Misha Brukman9d0919f2003-11-08 01:05:38 +00001123<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +00001124 <tbody>
1125 <tr>
1126 <td>In0</td>
1127 <td>In1</td>
1128 <td>Out</td>
1129 </tr>
1130 <tr>
1131 <td>0</td>
1132 <td>0</td>
1133 <td>0</td>
1134 </tr>
1135 <tr>
1136 <td>0</td>
1137 <td>1</td>
1138 <td>0</td>
1139 </tr>
1140 <tr>
1141 <td>1</td>
1142 <td>0</td>
1143 <td>0</td>
1144 </tr>
1145 <tr>
1146 <td>1</td>
1147 <td>1</td>
1148 <td>1</td>
1149 </tr>
1150 </tbody>
1151</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001152</div>
Chris Lattner00950542001-06-06 20:29:01 +00001153<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001154<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001155 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1156 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1157</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001158</div>
Chris Lattner00950542001-06-06 20:29:01 +00001159<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001160<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001161<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001162<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001163<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 +00001164</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001165<h5>Overview:</h5>
1166<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1167or of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001168<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001169<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001170 href="#t_integral">integral</a> values. Both arguments must have
1171identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001172<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001173<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001174<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001175<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001176<table border="1" cellspacing="0" cellpadding="4">
1177 <tbody>
1178 <tr>
1179 <td>In0</td>
1180 <td>In1</td>
1181 <td>Out</td>
1182 </tr>
1183 <tr>
1184 <td>0</td>
1185 <td>0</td>
1186 <td>0</td>
1187 </tr>
1188 <tr>
1189 <td>0</td>
1190 <td>1</td>
1191 <td>1</td>
1192 </tr>
1193 <tr>
1194 <td>1</td>
1195 <td>0</td>
1196 <td>1</td>
1197 </tr>
1198 <tr>
1199 <td>1</td>
1200 <td>1</td>
1201 <td>1</td>
1202 </tr>
1203 </tbody>
1204</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001205</div>
Chris Lattner00950542001-06-06 20:29:01 +00001206<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001207<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001208 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1209 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1210</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001211</div>
Chris Lattner00950542001-06-06 20:29:01 +00001212<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001213<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1214Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001215<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001216<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001217<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 +00001218</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001219<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001220<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1221or of its two operands. The <tt>xor</tt> is used to implement the
1222"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001223<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001224<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001225 href="#t_integral">integral</a> values. Both arguments must have
1226identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001227<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001228<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001229<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001230<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001231<table border="1" cellspacing="0" cellpadding="4">
1232 <tbody>
1233 <tr>
1234 <td>In0</td>
1235 <td>In1</td>
1236 <td>Out</td>
1237 </tr>
1238 <tr>
1239 <td>0</td>
1240 <td>0</td>
1241 <td>0</td>
1242 </tr>
1243 <tr>
1244 <td>0</td>
1245 <td>1</td>
1246 <td>1</td>
1247 </tr>
1248 <tr>
1249 <td>1</td>
1250 <td>0</td>
1251 <td>1</td>
1252 </tr>
1253 <tr>
1254 <td>1</td>
1255 <td>1</td>
1256 <td>0</td>
1257 </tr>
1258 </tbody>
1259</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001260</div>
Chris Lattner261efe92003-11-25 01:02:51 +00001261<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001262<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001263<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001264 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1265 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner27f71f22003-09-03 00:41:47 +00001266 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner00950542001-06-06 20:29:01 +00001267</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001268</div>
Chris Lattner00950542001-06-06 20:29:01 +00001269<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001270<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1271Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001272<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001273<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001274<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 +00001275</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001276<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001277<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1278the left a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001279<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001280<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001281 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1282type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001283<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001284<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001285<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001286<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 +00001287 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1288 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1289</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001290</div>
Chris Lattner00950542001-06-06 20:29:01 +00001291<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001292<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1293Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001294<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001295<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001296<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 +00001297</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001298<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001299<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1300the right a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001301<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001302<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001303 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1304type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001305<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001306<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1307most significant bit is duplicated in the newly free'd bit positions.
1308If the first argument is unsigned, zero bits shall fill the empty
1309positions.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001310<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001311<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 +00001312 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001313 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner8c6bb902003-06-18 21:30:51 +00001314 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1315 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner00950542001-06-06 20:29:01 +00001316</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001317</div>
Chris Lattner00950542001-06-06 20:29:01 +00001318<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001319<div class="doc_subsection"> <a name="memoryops">Memory Access
1320Operations</a></div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001321<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001322<p>A key design point of an SSA-based representation is how it
1323represents memory. In LLVM, no memory locations are in SSA form, which
1324makes things very simple. This section describes how to read, write,
1325allocate and free memory in LLVM.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001326</div>
Chris Lattner00950542001-06-06 20:29:01 +00001327<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001328<div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>'
1329Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001330<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001331<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001332<pre> &lt;result&gt; = malloc &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001333 &lt;result&gt; = malloc &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001334</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001335<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001336<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1337heap and returns a pointer to it.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001338<h5>Arguments:</h5>
John Criswell6e4ca612004-02-24 16:13:56 +00001339<p>The '<tt>malloc</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1340bytes of memory from the operating system and returns a pointer of the
Chris Lattner261efe92003-11-25 01:02:51 +00001341appropriate type to the program. The second form of the instruction is
1342a shorter version of the first instruction that defaults to allocating
1343one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001344<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001345<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001346<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1347a pointer is returned.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001348<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001349<pre> %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001350
Chris Lattner261efe92003-11-25 01:02:51 +00001351 %size = <a
1352 href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001353 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1354 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001355</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001356</div>
Chris Lattner00950542001-06-06 20:29:01 +00001357<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001358<div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>'
1359Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001360<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001361<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001362<pre> free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner00950542001-06-06 20:29:01 +00001363</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001364<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001365<p>The '<tt>free</tt>' instruction returns memory back to the unused
1366memory heap, to be reallocated in the future.</p>
1367<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001368<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001369<p>'<tt>value</tt>' shall be a pointer value that points to a value
1370that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1371instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001372<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001373<p>Access to the memory pointed to by the pointer is not longer defined
1374after this instruction executes.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001375<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001376<pre> %array = <a href="#i_malloc">malloc</a> [4 x ubyte] <i>; yields {[4 x ubyte]*}:array</i>
Chris Lattner00950542001-06-06 20:29:01 +00001377 free [4 x ubyte]* %array
1378</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001379</div>
Chris Lattner00950542001-06-06 20:29:01 +00001380<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001381<div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>'
1382Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001383<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001384<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001385<pre> &lt;result&gt; = alloca &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001386 &lt;result&gt; = alloca &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001387</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001388<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001389<p>The '<tt>alloca</tt>' instruction allocates memory on the current
1390stack frame of the procedure that is live until the current function
1391returns to its caller.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001392<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001393<p>The the '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1394bytes of memory on the runtime stack, returning a pointer of the
1395appropriate type to the program. The second form of the instruction is
1396a shorter version of the first that defaults to allocating one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001397<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001398<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001399<p>Memory is allocated, a pointer is returned. '<tt>alloca</tt>'d
1400memory is automatically released when the function returns. The '<tt>alloca</tt>'
1401instruction is commonly used to represent automatic variables that must
1402have an address available. When the function returns (either with the <tt><a
1403 href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001404instructions), the memory is reclaimed.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001405<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001406<pre> %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001407 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner00950542001-06-06 20:29:01 +00001408</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001409</div>
Chris Lattner00950542001-06-06 20:29:01 +00001410<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001411<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1412Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001413<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00001414<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001415<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 +00001416<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001417<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001418<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001419<p>The argument to the '<tt>load</tt>' instruction specifies the memory
1420address to load from. The pointer must point to a <a
Chris Lattnere53e5082004-06-03 22:57:15 +00001421 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
Chris Lattner261efe92003-11-25 01:02:51 +00001422marked as <tt>volatile</tt> then the optimizer is not allowed to modify
1423the number or order of execution of this <tt>load</tt> with other
1424volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1425instructions. </p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001426<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001427<p>The location of memory pointed to is loaded.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001428<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001429<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1430 <a
1431 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001432 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1433</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001434</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001435<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001436<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1437Instruction</a> </div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001438<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001439<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 +00001440 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 +00001441</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001442<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001443<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001444<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001445<p>There are two arguments to the '<tt>store</tt>' instruction: a value
1446to store and an address to store it into. The type of the '<tt>&lt;pointer&gt;</tt>'
1447operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
1448operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the
1449optimizer is not allowed to modify the number or order of execution of
1450this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1451 href="#i_store">store</a></tt> instructions.</p>
1452<h5>Semantics:</h5>
1453<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
1454at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001455<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001456<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1457 <a
1458 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001459 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1460</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001461<!-- _______________________________________________________________________ -->
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001462<div class="doc_subsubsection">
1463 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
1464</div>
1465
Misha Brukman9d0919f2003-11-08 01:05:38 +00001466<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00001467<h5>Syntax:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001468<pre>
1469 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
1470</pre>
1471
Chris Lattner7faa8832002-04-14 06:13:44 +00001472<h5>Overview:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001473
1474<p>
1475The '<tt>getelementptr</tt>' instruction is used to get the address of a
1476subelement of an aggregate data structure.</p>
1477
Chris Lattner7faa8832002-04-14 06:13:44 +00001478<h5>Arguments:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001479
1480<p>This instruction takes a list of integer constants that indicate what
1481elements of the aggregate object to index to. The actual types of the arguments
1482provided depend on the type of the first pointer argument. The
1483'<tt>getelementptr</tt>' instruction is used to index down through the type
1484levels of a structure. When indexing into a structure, only <tt>uint</tt>
1485integer constants are allowed. When indexing into an array or pointer
1486<tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
1487
Chris Lattner261efe92003-11-25 01:02:51 +00001488<p>For example, let's consider a C code fragment and how it gets
1489compiled to LLVM:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001490
1491<pre>
1492 struct RT {
1493 char A;
1494 int B[10][20];
1495 char C;
1496 };
1497 struct ST {
1498 int X;
1499 double Y;
1500 struct RT Z;
1501 };
1502
1503 int *foo(struct ST *s) {
1504 return &amp;s[1].Z.B[5][13];
1505 }
1506</pre>
1507
Misha Brukman9d0919f2003-11-08 01:05:38 +00001508<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001509
1510<pre>
1511 %RT = type { sbyte, [10 x [20 x int]], sbyte }
1512 %ST = type { int, double, %RT }
1513
1514 int* "foo"(%ST* %s) {
1515 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13<br>
1516 ret int* %reg
1517 }
1518</pre>
1519
Chris Lattner7faa8832002-04-14 06:13:44 +00001520<h5>Semantics:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001521
1522<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
Chris Lattnere53e5082004-06-03 22:57:15 +00001523on the pointer type that is being index into. <a href="#t_pointer">Pointer</a>
1524and <a href="#t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
1525<tt>ulong</tt>, or <tt>long</tt> values, and <a href="#t_struct">structure</a>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001526types require <tt>uint</tt> <b>constants</b>.</p>
1527
Misha Brukman9d0919f2003-11-08 01:05:38 +00001528<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001529type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
1530}</tt>' type, a structure. The second index indexes into the third element of
1531the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
1532sbyte }</tt>' type, another structure. The third index indexes into the second
1533element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
1534array. The two dimensions of the array are subscripted into, yielding an
1535'<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction return a pointer
1536to this element, thus computing a value of '<tt>int*</tt>' type.</p>
1537
Chris Lattner261efe92003-11-25 01:02:51 +00001538<p>Note that it is perfectly legal to index partially through a
1539structure, returning a pointer to an inner element. Because of this,
1540the LLVM code for the given testcase is equivalent to:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001541
1542<pre>
1543 int* "foo"(%ST* %s) {
1544 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
1545 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
1546 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
1547 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
1548 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
1549 ret int* %t5
1550 }
Chris Lattner6536cfe2002-05-06 22:08:29 +00001551</pre>
Chris Lattner7faa8832002-04-14 06:13:44 +00001552<h5>Example:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001553<pre>
1554 <i>; yields [12 x ubyte]*:aptr</i>
1555 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
1556</pre>
1557
1558</div>
Chris Lattner00950542001-06-06 20:29:01 +00001559<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001560<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001561<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +00001562<p>The instructions in this category are the "miscellaneous"
Chris Lattner261efe92003-11-25 01:02:51 +00001563instructions, which defy better classification.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001564</div>
Chris Lattner00950542001-06-06 20:29:01 +00001565<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001566<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
1567Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001568<div class="doc_text">
Chris Lattner33ba0d92001-07-09 00:26:23 +00001569<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001570<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001571<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001572<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
1573the SSA graph representing the function.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001574<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001575<p>The type of the incoming values are specified with the first type
1576field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
1577as arguments, with one pair for each predecessor basic block of the
1578current block. Only values of <a href="#t_firstclass">first class</a>
1579type may be used as the value arguments to the PHI node. Only labels
1580may be used as the label arguments.</p>
1581<p>There must be no non-phi instructions between the start of a basic
1582block and the PHI instructions: i.e. PHI instructions must be first in
1583a basic block.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001584<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001585<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
1586value specified by the parameter, depending on which basic block we
1587came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001588<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001589<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 +00001590</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001591
Chris Lattner6536cfe2002-05-06 22:08:29 +00001592<!-- _______________________________________________________________________ -->
Chris Lattnercc37aae2004-03-12 05:50:16 +00001593<div class="doc_subsubsection">
1594 <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
1595</div>
1596
Misha Brukman9d0919f2003-11-08 01:05:38 +00001597<div class="doc_text">
Chris Lattnercc37aae2004-03-12 05:50:16 +00001598
Chris Lattner6536cfe2002-05-06 22:08:29 +00001599<h5>Syntax:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001600
1601<pre>
1602 &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 +00001603</pre>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001604
Chris Lattner6536cfe2002-05-06 22:08:29 +00001605<h5>Overview:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001606
1607<p>
1608The '<tt>cast</tt>' instruction is used as the primitive means to convert
1609integers to floating point, change data type sizes, and break type safety (by
1610casting pointers).
1611</p>
1612
1613
Chris Lattner6536cfe2002-05-06 22:08:29 +00001614<h5>Arguments:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001615
1616<p>
1617The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
1618class value, and a type to cast it to, which must also be a <a
1619href="#t_firstclass">first class</a> type.
1620</p>
1621
Chris Lattner6536cfe2002-05-06 22:08:29 +00001622<h5>Semantics:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001623
1624<p>
1625This instruction follows the C rules for explicit casts when determining how the
1626data being cast must change to fit in its new container.
1627</p>
1628
1629<p>
1630When casting to bool, any value that would be considered true in the context of
1631a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
1632all else are '<tt>false</tt>'.
1633</p>
1634
1635<p>
1636When extending an integral value from a type of one signness to another (for
1637example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
1638<b>source</b> value is signed, and zero-extended if the source value is
1639unsigned. <tt>bool</tt> values are always zero extended into either zero or
1640one.
1641</p>
1642
Chris Lattner33ba0d92001-07-09 00:26:23 +00001643<h5>Example:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001644
1645<pre>
1646 %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattner7bae3952002-06-25 18:03:17 +00001647 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001648</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001649</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001650
1651<!-- _______________________________________________________________________ -->
1652<div class="doc_subsubsection">
1653 <a name="i_select">'<tt>select</tt>' Instruction</a>
1654</div>
1655
1656<div class="doc_text">
1657
1658<h5>Syntax:</h5>
1659
1660<pre>
1661 &lt;result&gt; = select bool &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
1662</pre>
1663
1664<h5>Overview:</h5>
1665
1666<p>
1667The '<tt>select</tt>' instruction is used to choose one value based on a
1668condition, without branching.
1669</p>
1670
1671
1672<h5>Arguments:</h5>
1673
1674<p>
1675The '<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.
1676</p>
1677
1678<h5>Semantics:</h5>
1679
1680<p>
1681If the boolean condition evaluates to true, the instruction returns the first
1682value argument, otherwise it returns the second value argument.
1683</p>
1684
1685<h5>Example:</h5>
1686
1687<pre>
1688 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
1689</pre>
1690</div>
1691
1692
1693
1694
1695
Chris Lattner33ba0d92001-07-09 00:26:23 +00001696<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001697<div class="doc_subsubsection"> <a name="i_call">'<tt>call</tt>'
1698Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001699<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001700<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001701<pre> &lt;result&gt; = call &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +00001702<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001703<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001704<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001705<p>This instruction requires several arguments:</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001706<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00001707 <li>
1708 <p>'<tt>ty</tt>': shall be the signature of the pointer to function
1709value being invoked. The argument types must match the types implied
1710by this signature.</p>
1711 </li>
1712 <li>
1713 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a
1714function to be invoked. In most cases, this is a direct function
1715invocation, but indirect <tt>call</tt>s are just as possible,
1716calling an arbitrary pointer to function values.</p>
1717 </li>
1718 <li>
1719 <p>'<tt>function args</tt>': argument list whose types match the
1720function signature argument types. If the function signature
1721indicates the function accepts a variable number of arguments, the
1722extra arguments can be specified.</p>
1723 </li>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001724</ol>
Chris Lattner00950542001-06-06 20:29:01 +00001725<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001726<p>The '<tt>call</tt>' instruction is used to cause control flow to
1727transfer to a specified function, with its incoming arguments bound to
1728the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
1729instruction in the called function, control flow continues with the
1730instruction after the function call, and the return value of the
1731function is bound to the result argument. This is a simpler case of
1732the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001733<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001734<pre> %retval = call int %test(int %argc)<br> call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42);<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001735</div>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001736<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001737<div class="doc_subsubsection"> <a name="i_vanext">'<tt>vanext</tt>'
1738Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001739<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001740<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001741<pre> &lt;resultarglist&gt; = vanext &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001742<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001743<p>The '<tt>vanext</tt>' instruction is used to access arguments passed
1744through the "variable argument" area of a function call. It is used to
1745implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001746<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001747<p>This instruction takes a <tt>valist</tt> value and the type of the
1748argument. It returns another <tt>valist</tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001749<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001750<p>The '<tt>vanext</tt>' instruction advances the specified <tt>valist</tt>
1751past an argument of the specified type. In conjunction with the <a
1752 href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement
1753the <tt>va_arg</tt> macro available in C. For more information, see
1754the variable argument handling <a href="#int_varargs">Intrinsic
1755Functions</a>.</p>
1756<p>It is legal for this instruction to be called in a function which
1757does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001758function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001759<p><tt>vanext</tt> is an LLVM instruction instead of an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001760 href="#intrinsics">intrinsic function</a> because it takes an type as
1761an argument.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001762<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001763<p>See the <a href="#int_varargs">variable argument processing</a>
1764section.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001765</div>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001766<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001767<div class="doc_subsubsection"> <a name="i_vaarg">'<tt>vaarg</tt>'
1768Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001769<div class="doc_text">
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001770<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001771<pre> &lt;resultval&gt; = vaarg &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;<br></pre>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001772<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001773<p>The '<tt>vaarg</tt>' instruction is used to access arguments passed
1774through the "variable argument" area of a function call. It is used to
1775implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001776<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001777<p>This instruction takes a <tt>valist</tt> value and the type of the
1778argument. It returns a value of the specified argument type.</p>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001779<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001780<p>The '<tt>vaarg</tt>' instruction loads an argument of the specified
1781type from the specified <tt>va_list</tt>. In conjunction with the <a
1782 href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to
1783implement the <tt>va_arg</tt> macro available in C. For more
1784information, see the variable argument handling <a href="#int_varargs">Intrinsic
1785Functions</a>.</p>
1786<p>It is legal for this instruction to be called in a function which
1787does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001788function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001789<p><tt>vaarg</tt> is an LLVM instruction instead of an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001790 href="#intrinsics">intrinsic function</a> because it takes an type as
1791an argument.</p>
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001792<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001793<p>See the <a href="#int_varargs">variable argument processing</a>
1794section.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001795</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001796
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001797<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00001798<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
1799<!-- *********************************************************************** -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001800
Misha Brukman9d0919f2003-11-08 01:05:38 +00001801<div class="doc_text">
Chris Lattner33aec9e2004-02-12 17:01:32 +00001802
1803<p>LLVM supports the notion of an "intrinsic function". These functions have
1804well known names and semantics, and are required to follow certain
1805restrictions. Overall, these instructions represent an extension mechanism for
1806the LLVM language that does not require changing all of the transformations in
1807LLVM to add to the language (or the bytecode reader/writer, the parser,
1808etc...).</p>
1809
1810<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix, this
1811prefix is reserved in LLVM for intrinsic names, thus functions may not be named
1812this. Intrinsic functions must always be external functions: you cannot define
1813the body of intrinsic functions. Intrinsic functions may only be used in call
1814or invoke instructions: it is illegal to take the address of an intrinsic
1815function. Additionally, because intrinsic functions are part of the LLVM
1816language, it is required that they all be documented here if any are added.</p>
1817
1818
1819<p>
1820Adding an intrinsic to LLVM is straight-forward if it is possible to express the
1821concept in LLVM directly (ie, code generator support is not _required_). To do
1822this, extend the default implementation of the IntrinsicLowering class to handle
1823the intrinsic. Code generators use this class to lower intrinsics they do not
1824understand to raw LLVM instructions that they do.
1825</p>
1826
Misha Brukman9d0919f2003-11-08 01:05:38 +00001827</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001828
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001829<!-- ======================================================================= -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001830<div class="doc_subsection">
1831 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
1832</div>
1833
Misha Brukman9d0919f2003-11-08 01:05:38 +00001834<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00001835
Misha Brukman9d0919f2003-11-08 01:05:38 +00001836<p>Variable argument support is defined in LLVM with the <a
Chris Lattner261efe92003-11-25 01:02:51 +00001837 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
1838intrinsic functions. These functions are related to the similarly
1839named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00001840
Chris Lattner261efe92003-11-25 01:02:51 +00001841<p>All of these functions operate on arguments that use a
1842target-specific value type "<tt>va_list</tt>". The LLVM assembly
1843language reference manual does not define what this type is, so all
1844transformations should be prepared to handle intrinsics with any type
1845used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00001846
Misha Brukman9d0919f2003-11-08 01:05:38 +00001847<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner261efe92003-11-25 01:02:51 +00001848instruction and the variable argument handling intrinsic functions are
1849used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00001850
Chris Lattner33aec9e2004-02-12 17:01:32 +00001851<pre>
1852int %test(int %X, ...) {
1853 ; Initialize variable argument processing
1854 %ap = call sbyte* %<a href="#i_va_start">llvm.va_start</a>()
1855
1856 ; Read a single integer argument
1857 %tmp = vaarg sbyte* %ap, int
1858
1859 ; Advance to the next argument
1860 %ap2 = vanext sbyte* %ap, int
1861
1862 ; Demonstrate usage of llvm.va_copy and llvm.va_end
1863 %aq = call sbyte* %<a href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2)
1864 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %aq)
1865
1866 ; Stop processing of arguments.
1867 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %ap2)
1868 ret int %tmp
1869}
1870</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001871</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001872
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001873<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001874<div class="doc_subsubsection">
1875 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
1876</div>
1877
1878
Misha Brukman9d0919f2003-11-08 01:05:38 +00001879<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001880<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001881<pre> call va_list ()* %llvm.va_start()<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001882<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001883<p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt>&lt;arglist&gt;</tt>
1884for subsequent use by the variable argument intrinsics.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001885<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001886<p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001887macro available in C. In a target-dependent way, it initializes and
1888returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt>
1889will produce the first variable argument passed to the function. Unlike
1890the C <tt>va_start</tt> macro, this intrinsic does not need to know the
1891last argument of the function, the compiler can figure that out.</p>
1892<p>Note that this intrinsic function is only legal to be called from
1893within the body of a variable argument function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001894</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001895
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001896<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001897<div class="doc_subsubsection">
1898 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
1899</div>
1900
Misha Brukman9d0919f2003-11-08 01:05:38 +00001901<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001902<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001903<pre> call void (va_list)* %llvm.va_end(va_list &lt;arglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001904<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001905<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
1906which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
1907or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001908<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001909<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001910<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001911<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001912macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
1913Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
1914 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
1915with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001916</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001917
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001918<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001919<div class="doc_subsubsection">
1920 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
1921</div>
1922
Misha Brukman9d0919f2003-11-08 01:05:38 +00001923<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00001924
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001925<h5>Syntax:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00001926
1927<pre>
1928 call va_list (va_list)* %llvm.va_copy(va_list &lt;destarglist&gt;)
1929</pre>
1930
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001931<h5>Overview:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00001932
1933<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position
1934from the source argument list to the destination argument list.</p>
1935
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001936<h5>Arguments:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00001937
Misha Brukman9d0919f2003-11-08 01:05:38 +00001938<p>The argument is the <tt>va_list</tt> to copy.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00001939
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001940<h5>Semantics:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00001941
Misha Brukman9d0919f2003-11-08 01:05:38 +00001942<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
Chris Lattnerd7923912004-05-23 21:06:01 +00001943macro available in C. In a target-dependent way, it copies the source
1944<tt>va_list</tt> element into the returned list. This intrinsic is necessary
1945because the <tt><a href="i_va_start">llvm.va_start</a></tt> intrinsic may be
1946arbitrarily complex and require memory allocation, for example.</p>
1947
Misha Brukman9d0919f2003-11-08 01:05:38 +00001948</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001949
Chris Lattner33aec9e2004-02-12 17:01:32 +00001950<!-- ======================================================================= -->
1951<div class="doc_subsection">
Chris Lattnerd7923912004-05-23 21:06:01 +00001952 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
1953</div>
1954
1955<div class="doc_text">
1956
1957<p>
1958LLVM support for <a href="GarbageCollection.html">Accurate Garbage
1959Collection</a> requires the implementation and generation of these intrinsics.
1960These intrinsics allow identification of <a href="#i_gcroot">GC roots on the
1961stack</a>, as well as garbage collector implementations that require <a
1962href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers.
1963Front-ends for type-safe garbage collected languages should generate these
1964intrinsics to make use of the LLVM garbage collectors. For more details, see <a
1965href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
1966</p>
1967</div>
1968
1969<!-- _______________________________________________________________________ -->
1970<div class="doc_subsubsection">
1971 <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
1972</div>
1973
1974<div class="doc_text">
1975
1976<h5>Syntax:</h5>
1977
1978<pre>
1979 call void (&lt;ty&gt;**, &lt;ty2&gt;*)* %llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
1980</pre>
1981
1982<h5>Overview:</h5>
1983
1984<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existance of a GC root to
1985the code generator, and allows some metadata to be associated with it.</p>
1986
1987<h5>Arguments:</h5>
1988
1989<p>The first argument specifies the address of a stack object that contains the
1990root pointer. The second pointer (which must be either a constant or a global
1991value address) contains the meta-data to be associated with the root.</p>
1992
1993<h5>Semantics:</h5>
1994
1995<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
1996location. At compile-time, the code generator generates information to allow
1997the runtime to find the pointer at GC safe points.
1998</p>
1999
2000</div>
2001
2002
2003<!-- _______________________________________________________________________ -->
2004<div class="doc_subsubsection">
2005 <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
2006</div>
2007
2008<div class="doc_text">
2009
2010<h5>Syntax:</h5>
2011
2012<pre>
2013 call sbyte* (sbyte**)* %llvm.gcread(sbyte** %Ptr)
2014</pre>
2015
2016<h5>Overview:</h5>
2017
2018<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
2019locations, allowing garbage collector implementations that require read
2020barriers.</p>
2021
2022<h5>Arguments:</h5>
2023
2024<p>The argument is the address to read from, which should be an address
2025allocated from the garbage collector.</p>
2026
2027<h5>Semantics:</h5>
2028
2029<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
2030instruction, but may be replaced with substantially more complex code by the
2031garbage collector runtime, as needed.</p>
2032
2033</div>
2034
2035
2036<!-- _______________________________________________________________________ -->
2037<div class="doc_subsubsection">
2038 <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
2039</div>
2040
2041<div class="doc_text">
2042
2043<h5>Syntax:</h5>
2044
2045<pre>
2046 call void (sbyte*, sbyte**)* %llvm.gcwrite(sbyte* %P1, sbyte** %P2)
2047</pre>
2048
2049<h5>Overview:</h5>
2050
2051<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
2052locations, allowing garbage collector implementations that require write
2053barriers (such as generational or reference counting collectors).</p>
2054
2055<h5>Arguments:</h5>
2056
2057<p>The first argument is the reference to store, and the second is the heap
2058location to store to.</p>
2059
2060<h5>Semantics:</h5>
2061
2062<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
2063instruction, but may be replaced with substantially more complex code by the
2064garbage collector runtime, as needed.</p>
2065
2066</div>
2067
2068
2069
2070<!-- ======================================================================= -->
2071<div class="doc_subsection">
Chris Lattner10610642004-02-14 04:08:35 +00002072 <a name="int_codegen">Code Generator Intrinsics</a>
2073</div>
2074
2075<div class="doc_text">
2076<p>
2077These intrinsics are provided by LLVM to expose special features that may only
2078be implemented with code generator support.
2079</p>
2080
2081</div>
2082
2083<!-- _______________________________________________________________________ -->
2084<div class="doc_subsubsection">
2085 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
2086</div>
2087
2088<div class="doc_text">
2089
2090<h5>Syntax:</h5>
2091<pre>
2092 call void* ()* %llvm.returnaddress(uint &lt;level&gt;)
2093</pre>
2094
2095<h5>Overview:</h5>
2096
2097<p>
2098The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
2099indicating the return address of the current function or one of its callers.
2100</p>
2101
2102<h5>Arguments:</h5>
2103
2104<p>
2105The argument to this intrinsic indicates which function to return the address
2106for. Zero indicates the calling function, one indicates its caller, etc. The
2107argument is <b>required</b> to be a constant integer value.
2108</p>
2109
2110<h5>Semantics:</h5>
2111
2112<p>
2113The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
2114the return address of the specified call frame, or zero if it cannot be
2115identified. The value returned by this intrinsic is likely to be incorrect or 0
2116for arguments other than zero, so it should only be used for debugging purposes.
2117</p>
2118
2119<p>
2120Note that calling this intrinsic does not prevent function inlining or other
2121aggressive transformations, so the value returned may not that of the obvious
2122source-language caller.
2123</p>
2124</div>
2125
2126
2127<!-- _______________________________________________________________________ -->
2128<div class="doc_subsubsection">
2129 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
2130</div>
2131
2132<div class="doc_text">
2133
2134<h5>Syntax:</h5>
2135<pre>
2136 call void* ()* %llvm.frameaddress(uint &lt;level&gt;)
2137</pre>
2138
2139<h5>Overview:</h5>
2140
2141<p>
2142The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
2143pointer value for the specified stack frame.
2144</p>
2145
2146<h5>Arguments:</h5>
2147
2148<p>
2149The argument to this intrinsic indicates which function to return the frame
2150pointer for. Zero indicates the calling function, one indicates its caller,
2151etc. The argument is <b>required</b> to be a constant integer value.
2152</p>
2153
2154<h5>Semantics:</h5>
2155
2156<p>
2157The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
2158the frame address of the specified call frame, or zero if it cannot be
2159identified. The value returned by this intrinsic is likely to be incorrect or 0
2160for arguments other than zero, so it should only be used for debugging purposes.
2161</p>
2162
2163<p>
2164Note that calling this intrinsic does not prevent function inlining or other
2165aggressive transformations, so the value returned may not that of the obvious
2166source-language caller.
2167</p>
2168</div>
2169
John Criswell7123e272004-04-09 16:43:20 +00002170<!-- ======================================================================= -->
2171<div class="doc_subsection">
2172 <a name="int_os">Operating System Intrinsics</a>
2173</div>
2174
2175<div class="doc_text">
2176<p>
2177These intrinsics are provided by LLVM to support the implementation of
2178operating system level code.
2179</p>
2180
2181</div>
John Criswell183402a2004-04-12 15:02:16 +00002182
John Criswellcfd3bac2004-04-09 15:23:37 +00002183<!-- _______________________________________________________________________ -->
2184<div class="doc_subsubsection">
2185 <a name="i_readport">'<tt>llvm.readport</tt>' Intrinsic</a>
2186</div>
2187
2188<div class="doc_text">
2189
2190<h5>Syntax:</h5>
2191<pre>
John Criswell7123e272004-04-09 16:43:20 +00002192 call &lt;integer type&gt; (&lt;integer type&gt;)* %llvm.readport (&lt;integer type&gt; &lt;address&gt;)
John Criswellcfd3bac2004-04-09 15:23:37 +00002193</pre>
2194
2195<h5>Overview:</h5>
2196
2197<p>
John Criswell7123e272004-04-09 16:43:20 +00002198The '<tt>llvm.readport</tt>' intrinsic reads data from the specified hardware
2199I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002200</p>
2201
2202<h5>Arguments:</h5>
2203
2204<p>
John Criswell7123e272004-04-09 16:43:20 +00002205The argument to this intrinsic indicates the hardware I/O address from which
2206to read the data. The address is in the hardware I/O address namespace (as
2207opposed to being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002208</p>
2209
2210<h5>Semantics:</h5>
2211
2212<p>
John Criswell7123e272004-04-09 16:43:20 +00002213The '<tt>llvm.readport</tt>' intrinsic reads data from the hardware I/O port
2214specified by <i>address</i> and returns the value. The address and return
2215value must be integers, but the size is dependent upon the platform upon which
2216the program is code generated. For example, on x86, the address must be an
2217unsigned 16 bit value, and the return value must be 8, 16, or 32 bits.
John Criswellcfd3bac2004-04-09 15:23:37 +00002218</p>
2219
2220</div>
2221
2222<!-- _______________________________________________________________________ -->
2223<div class="doc_subsubsection">
2224 <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a>
2225</div>
2226
2227<div class="doc_text">
2228
2229<h5>Syntax:</h5>
2230<pre>
John Criswell7123e272004-04-09 16:43:20 +00002231 call void (&lt;integer type&gt;, &lt;integer type&gt;)* %llvm.writeport (&lt;integer type&gt; &lt;value&gt;, &lt;integer type&gt; &lt;address&gt;)
John Criswellcfd3bac2004-04-09 15:23:37 +00002232</pre>
2233
2234<h5>Overview:</h5>
2235
2236<p>
John Criswell7123e272004-04-09 16:43:20 +00002237The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified hardware
2238I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002239</p>
2240
2241<h5>Arguments:</h5>
2242
2243<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002244The first argument is the value to write to the I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002245</p>
2246
2247<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002248The second argument indicates the hardware I/O address to which data should be
2249written. The address is in the hardware I/O address namespace (as opposed to
2250being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002251</p>
2252
2253<h5>Semantics:</h5>
2254
2255<p>
2256The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port
2257specified by <i>address</i>. The address and value must be integers, but the
2258size is dependent upon the platform upon which the program is code generated.
John Criswell7123e272004-04-09 16:43:20 +00002259For example, on x86, the address must be an unsigned 16 bit value, and the
2260value written must be 8, 16, or 32 bits in length.
John Criswellcfd3bac2004-04-09 15:23:37 +00002261</p>
2262
2263</div>
Chris Lattner10610642004-02-14 04:08:35 +00002264
John Criswell183402a2004-04-12 15:02:16 +00002265<!-- _______________________________________________________________________ -->
2266<div class="doc_subsubsection">
2267 <a name="i_readio">'<tt>llvm.readio</tt>' Intrinsic</a>
2268</div>
2269
2270<div class="doc_text">
2271
2272<h5>Syntax:</h5>
2273<pre>
John Criswell96db6fc2004-04-12 16:33:19 +00002274 call &lt;result&gt; (&lt;ty&gt;*)* %llvm.readio (&lt;ty&gt; * &lt;pointer&gt;)
John Criswell183402a2004-04-12 15:02:16 +00002275</pre>
2276
2277<h5>Overview:</h5>
2278
2279<p>
2280The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
2281address.
2282</p>
2283
2284<h5>Arguments:</h5>
2285
2286<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002287The argument to this intrinsic is a pointer indicating the memory address from
2288which to read the data. The data must be a
2289<a href="#t_firstclass">first class</a> type.
John Criswell183402a2004-04-12 15:02:16 +00002290</p>
2291
2292<h5>Semantics:</h5>
2293
2294<p>
2295The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
John Criswell96db6fc2004-04-12 16:33:19 +00002296location specified by <i>pointer</i> and returns the value. The argument must
2297be a pointer, and the return value must be a
2298<a href="#t_firstclass">first class</a> type. However, certain architectures
2299may not support I/O on all first class types. For example, 32 bit processors
2300may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00002301</p>
2302
2303<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002304This intrinsic enforces an in-order memory model for llvm.readio and
2305llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2306scheduled processors may execute loads and stores out of order, re-ordering at
2307run time accesses to memory mapped I/O registers. Using these intrinsics
2308ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00002309</p>
2310
2311</div>
2312
2313<!-- _______________________________________________________________________ -->
2314<div class="doc_subsubsection">
2315 <a name="i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a>
2316</div>
2317
2318<div class="doc_text">
2319
2320<h5>Syntax:</h5>
2321<pre>
John Criswell96db6fc2004-04-12 16:33:19 +00002322 call void (&lt;ty1&gt;, &lt;ty2&gt;*)* %llvm.writeio (&lt;ty1&gt; &lt;value&gt;, &lt;ty2&gt; * &lt;pointer&gt;)
John Criswell183402a2004-04-12 15:02:16 +00002323</pre>
2324
2325<h5>Overview:</h5>
2326
2327<p>
2328The '<tt>llvm.writeio</tt>' intrinsic writes data to the specified memory
2329mapped I/O address.
2330</p>
2331
2332<h5>Arguments:</h5>
2333
2334<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002335The first argument is the value to write to the memory mapped I/O location.
2336The second argument is a pointer indicating the memory address to which the
2337data should be written.
John Criswell183402a2004-04-12 15:02:16 +00002338</p>
2339
2340<h5>Semantics:</h5>
2341
2342<p>
2343The '<tt>llvm.writeio</tt>' intrinsic writes <i>value</i> to the memory mapped
John Criswell96db6fc2004-04-12 16:33:19 +00002344I/O address specified by <i>pointer</i>. The value must be a
2345<a href="#t_firstclass">first class</a> type. However, certain architectures
2346may not support I/O on all first class types. For example, 32 bit processors
2347may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00002348</p>
2349
2350<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002351This intrinsic enforces an in-order memory model for llvm.readio and
2352llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2353scheduled processors may execute loads and stores out of order, re-ordering at
2354run time accesses to memory mapped I/O registers. Using these intrinsics
2355ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00002356</p>
2357
2358</div>
2359
2360
Chris Lattner10610642004-02-14 04:08:35 +00002361<!-- ======================================================================= -->
2362<div class="doc_subsection">
Chris Lattner33aec9e2004-02-12 17:01:32 +00002363 <a name="int_libc">Standard C Library Intrinsics</a>
2364</div>
2365
2366<div class="doc_text">
2367<p>
Chris Lattner10610642004-02-14 04:08:35 +00002368LLVM provides intrinsics for a few important standard C library functions.
2369These intrinsics allow source-language front-ends to pass information about the
2370alignment of the pointer arguments to the code generator, providing opportunity
2371for more efficient code generation.
Chris Lattner33aec9e2004-02-12 17:01:32 +00002372</p>
2373
2374</div>
2375
2376<!-- _______________________________________________________________________ -->
2377<div class="doc_subsubsection">
2378 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
2379</div>
2380
2381<div class="doc_text">
2382
2383<h5>Syntax:</h5>
2384<pre>
2385 call void (sbyte*, sbyte*, uint, uint)* %llvm.memcpy(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2386 uint &lt;len&gt;, uint &lt;align&gt;)
2387</pre>
2388
2389<h5>Overview:</h5>
2390
2391<p>
2392The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2393location to the destination location.
2394</p>
2395
2396<p>
2397Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
2398does not return a value, and takes an extra alignment argument.
2399</p>
2400
2401<h5>Arguments:</h5>
2402
2403<p>
2404The first argument is a pointer to the destination, the second is a pointer to
2405the source. The third argument is an (arbitrarily sized) integer argument
2406specifying the number of bytes to copy, and the fourth argument is the alignment
2407of the source and destination locations.
2408</p>
2409
Chris Lattner3301ced2004-02-12 21:18:15 +00002410<p>
2411If the call to this intrinisic has an alignment value that is not 0 or 1, then
2412the caller guarantees that the size of the copy is a multiple of the alignment
2413and that both the source and destination pointers are aligned to that boundary.
2414</p>
2415
Chris Lattner33aec9e2004-02-12 17:01:32 +00002416<h5>Semantics:</h5>
2417
2418<p>
2419The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2420location to the destination location, which are not allowed to overlap. It
2421copies "len" bytes of memory over. If the argument is known to be aligned to
2422some boundary, this can be specified as the fourth argument, otherwise it should
2423be set to 0 or 1.
2424</p>
2425</div>
2426
2427
Chris Lattner0eb51b42004-02-12 18:10:10 +00002428<!-- _______________________________________________________________________ -->
2429<div class="doc_subsubsection">
2430 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
2431</div>
2432
2433<div class="doc_text">
2434
2435<h5>Syntax:</h5>
2436<pre>
2437 call void (sbyte*, sbyte*, uint, uint)* %llvm.memmove(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2438 uint &lt;len&gt;, uint &lt;align&gt;)
2439</pre>
2440
2441<h5>Overview:</h5>
2442
2443<p>
2444The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
2445location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>'
2446intrinsic but allows the two memory locations to overlap.
2447</p>
2448
2449<p>
2450Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
2451does not return a value, and takes an extra alignment argument.
2452</p>
2453
2454<h5>Arguments:</h5>
2455
2456<p>
2457The first argument is a pointer to the destination, the second is a pointer to
2458the source. The third argument is an (arbitrarily sized) integer argument
2459specifying the number of bytes to copy, and the fourth argument is the alignment
2460of the source and destination locations.
2461</p>
2462
Chris Lattner3301ced2004-02-12 21:18:15 +00002463<p>
2464If the call to this intrinisic has an alignment value that is not 0 or 1, then
2465the caller guarantees that the size of the copy is a multiple of the alignment
2466and that both the source and destination pointers are aligned to that boundary.
2467</p>
2468
Chris Lattner0eb51b42004-02-12 18:10:10 +00002469<h5>Semantics:</h5>
2470
2471<p>
2472The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
2473location to the destination location, which may overlap. It
2474copies "len" bytes of memory over. If the argument is known to be aligned to
2475some boundary, this can be specified as the fourth argument, otherwise it should
2476be set to 0 or 1.
2477</p>
2478</div>
2479
Chris Lattner8ff75902004-01-06 05:31:32 +00002480
Chris Lattner10610642004-02-14 04:08:35 +00002481<!-- _______________________________________________________________________ -->
2482<div class="doc_subsubsection">
2483 <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a>
2484</div>
2485
2486<div class="doc_text">
2487
2488<h5>Syntax:</h5>
2489<pre>
2490 call void (sbyte*, ubyte, uint, uint)* %llvm.memset(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
2491 uint &lt;len&gt;, uint &lt;align&gt;)
2492</pre>
2493
2494<h5>Overview:</h5>
2495
2496<p>
2497The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular
2498byte value.
2499</p>
2500
2501<p>
2502Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
2503does not return a value, and takes an extra alignment argument.
2504</p>
2505
2506<h5>Arguments:</h5>
2507
2508<p>
2509The first argument is a pointer to the destination to fill, the second is the
2510byte value to fill it with, the third argument is an (arbitrarily sized) integer
2511argument specifying the number of bytes to fill, and the fourth argument is the
2512known alignment of destination location.
2513</p>
2514
2515<p>
2516If the call to this intrinisic has an alignment value that is not 0 or 1, then
2517the caller guarantees that the size of the copy is a multiple of the alignment
2518and that the destination pointer is aligned to that boundary.
2519</p>
2520
2521<h5>Semantics:</h5>
2522
2523<p>
2524The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the
2525destination location. If the argument is known to be aligned to some boundary,
2526this can be specified as the fourth argument, otherwise it should be set to 0 or
25271.
2528</p>
2529</div>
2530
2531
Chris Lattner32006282004-06-11 02:28:03 +00002532<!-- _______________________________________________________________________ -->
2533<div class="doc_subsubsection">
2534 <a name="i_isnan">'<tt>llvm.isnan</tt>' Intrinsic</a>
2535</div>
2536
2537<div class="doc_text">
2538
2539<h5>Syntax:</h5>
2540<pre>
2541 call bool (&lt;float or double&gt;)* %llvm.isnan(&lt;float or double&gt; Val)
2542</pre>
2543
2544<h5>Overview:</h5>
2545
2546<p>
2547The '<tt>llvm.isnan</tt>' intrinsic returns true if the specific floating point
2548value is a NAN.
2549</p>
2550
2551<h5>Arguments:</h5>
2552
2553<p>
2554The argument is a floating point number.
2555</p>
2556
2557<h5>Semantics:</h5>
2558
2559<p>
2560If the argument is a SNAN or QNAN, it returns true, otherwise false.
2561</p>
2562</div>
2563
2564
2565
2566
Chris Lattner8ff75902004-01-06 05:31:32 +00002567<!-- ======================================================================= -->
2568<div class="doc_subsection">
2569 <a name="int_debugger">Debugger Intrinsics</a>
2570</div>
2571
2572<div class="doc_text">
2573<p>
2574The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
2575are described in the <a
2576href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
2577Debugging</a> document.
2578</p>
2579</div>
2580
2581
Chris Lattner00950542001-06-06 20:29:01 +00002582<!-- *********************************************************************** -->
Chris Lattner00950542001-06-06 20:29:01 +00002583<hr>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002584<address>
2585 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
2586 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
2587 <a href="http://validator.w3.org/check/referer"><img
2588 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
2589
2590 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
2591 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
2592 Last modified: $Date$
2593</address>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002594</body>
2595</html>