blob: 1a2093634f85cddab2f69b900ea10f0ec2d6f4f7 [file] [log] [blame]
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
Misha Brukman9d0919f2003-11-08 01:05:38 +00003<html>
4<head>
5 <title>LLVM Assembly Language Reference Manual</title>
Reid Spencer3921c742004-08-26 20:44:00 +00006 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7 <meta name="author" content="Chris Lattner">
8 <meta name="description"
9 content="LLVM Assembly Language Reference Manual.">
Misha Brukman9d0919f2003-11-08 01:05:38 +000010 <link rel="stylesheet" href="llvm.css" type="text/css">
11</head>
Chris Lattnerd7923912004-05-23 21:06:01 +000012
Misha Brukman9d0919f2003-11-08 01:05:38 +000013<body>
Chris Lattnerd7923912004-05-23 21:06:01 +000014
Chris Lattner261efe92003-11-25 01:02:51 +000015<div class="doc_title"> LLVM Language Reference Manual </div>
Chris Lattner00950542001-06-06 20:29:01 +000016<ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000017 <li><a href="#abstract">Abstract</a></li>
18 <li><a href="#introduction">Introduction</a></li>
19 <li><a href="#identifiers">Identifiers</a></li>
Chris Lattner00950542001-06-06 20:29:01 +000020 <li><a href="#typesystem">Type System</a>
21 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000022 <li><a href="#t_primitive">Primitive Types</a>
23 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000024 <li><a href="#t_classifications">Type Classifications</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000025 </ol>
26 </li>
Chris Lattner00950542001-06-06 20:29:01 +000027 <li><a href="#t_derived">Derived Types</a>
28 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000029 <li><a href="#t_array">Array Type</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000030 <li><a href="#t_function">Function Type</a></li>
31 <li><a href="#t_pointer">Pointer Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000032 <li><a href="#t_struct">Structure Type</a></li>
Chris Lattnera58561b2004-08-12 19:12:28 +000033 <li><a href="#t_packed">Packed Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000034 </ol>
35 </li>
36 </ol>
37 </li>
Chris Lattner00950542001-06-06 20:29:01 +000038 <li><a href="#highlevel">High Level Structure</a>
39 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000040 <li><a href="#modulestructure">Module Structure</a></li>
41 <li><a href="#globalvars">Global Variables</a></li>
42 <li><a href="#functionstructure">Function Structure</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000043 </ol>
44 </li>
Chris Lattner00950542001-06-06 20:29:01 +000045 <li><a href="#instref">Instruction Reference</a>
46 <ol>
47 <li><a href="#terminators">Terminator Instructions</a>
48 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000049 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
50 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000051 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
52 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000053 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
54 </ol>
55 </li>
Chris Lattner00950542001-06-06 20:29:01 +000056 <li><a href="#binaryops">Binary Operations</a>
57 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000058 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
59 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
60 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
61 <li><a href="#i_div">'<tt>div</tt>' Instruction</a></li>
62 <li><a href="#i_rem">'<tt>rem</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000063 <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000064 </ol>
65 </li>
Chris Lattner00950542001-06-06 20:29:01 +000066 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
67 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000068 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000069 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000070 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
71 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
72 <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000073 </ol>
74 </li>
Chris Lattner00950542001-06-06 20:29:01 +000075 <li><a href="#memoryops">Memory Access Operations</a>
76 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000077 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
78 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
79 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
80 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
81 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
82 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
83 </ol>
84 </li>
Chris Lattner00950542001-06-06 20:29:01 +000085 <li><a href="#otherops">Other Operations</a>
86 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000087 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000088 <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li>
Chris Lattnercc37aae2004-03-12 05:50:16 +000089 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000090 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000091 <li><a href="#i_vanext">'<tt>vanext</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000092 <li><a href="#i_vaarg">'<tt>vaarg</tt>' Instruction</a></li>
Chris Lattner00950542001-06-06 20:29:01 +000093 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +000094 </li>
Chris Lattner00950542001-06-06 20:29:01 +000095 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +000096 </li>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +000097 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +000098 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000099 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
100 <ol>
101 <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
102 <li><a href="#i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
103 <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
104 </ol>
105 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000106 <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
107 <ol>
108 <li><a href="#i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li>
109 <li><a href="#i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li>
110 <li><a href="#i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li>
111 </ol>
112 </li>
Chris Lattner10610642004-02-14 04:08:35 +0000113 <li><a href="#int_codegen">Code Generator Intrinsics</a>
114 <ol>
115 <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
116 <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
John Criswell7123e272004-04-09 16:43:20 +0000117 </ol>
118 </li>
119 <li><a href="#int_os">Operating System Intrinsics</a>
120 <ol>
Chris Lattner32006282004-06-11 02:28:03 +0000121 <li><a href="#i_readport">'<tt>llvm.readport</tt>' Intrinsic</a></li>
122 <li><a href="#i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a></li>
John Criswell183402a2004-04-12 15:02:16 +0000123 <li><a href="#i_readio">'<tt>llvm.readio</tt>' Intrinsic</a></li>
124 <li><a href="#i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000125 </ol>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000126 <li><a href="#int_libc">Standard C Library Intrinsics</a>
127 <ol>
128 <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li>
Chris Lattner0eb51b42004-02-12 18:10:10 +0000129 <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000130 <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li>
Alkis Evlogimenos96853722004-06-12 19:19:14 +0000131 <li><a href="#i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a></li>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000132 </ol>
133 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000134 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000135 </ol>
136 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000137</ol>
Chris Lattnerd7923912004-05-23 21:06:01 +0000138
139<div class="doc_author">
140 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
141 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000142</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000143
Chris Lattner00950542001-06-06 20:29:01 +0000144<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000145<div class="doc_section"> <a name="abstract">Abstract </a></div>
146<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000147
Misha Brukman9d0919f2003-11-08 01:05:38 +0000148<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000149<p>This document is a reference manual for the LLVM assembly language.
150LLVM is an SSA based representation that provides type safety,
151low-level operations, flexibility, and the capability of representing
152'all' high-level languages cleanly. It is the common code
153representation used throughout all phases of the LLVM compilation
154strategy.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000155</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000156
Chris Lattner00950542001-06-06 20:29:01 +0000157<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000158<div class="doc_section"> <a name="introduction">Introduction</a> </div>
159<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000160
Misha Brukman9d0919f2003-11-08 01:05:38 +0000161<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000162
Chris Lattner261efe92003-11-25 01:02:51 +0000163<p>The LLVM code representation is designed to be used in three
164different forms: as an in-memory compiler IR, as an on-disk bytecode
165representation (suitable for fast loading by a Just-In-Time compiler),
166and as a human readable assembly language representation. This allows
167LLVM to provide a powerful intermediate representation for efficient
168compiler transformations and analysis, while providing a natural means
169to debug and visualize the transformations. The three different forms
170of LLVM are all equivalent. This document describes the human readable
171representation and notation.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000172
Chris Lattner261efe92003-11-25 01:02:51 +0000173<p>The LLVM representation aims to be a light-weight and low-level
174while being expressive, typed, and extensible at the same time. It
175aims to be a "universal IR" of sorts, by being at a low enough level
176that high-level ideas may be cleanly mapped to it (similar to how
177microprocessors are "universal IR's", allowing many source languages to
178be mapped to them). By providing type information, LLVM can be used as
179the target of optimizations: for example, through pointer analysis, it
180can be proven that a C automatic variable is never accessed outside of
181the current function... allowing it to be promoted to a simple SSA
182value instead of a memory location.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000183
Misha Brukman9d0919f2003-11-08 01:05:38 +0000184</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000185
Chris Lattner00950542001-06-06 20:29:01 +0000186<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000187<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000188
Misha Brukman9d0919f2003-11-08 01:05:38 +0000189<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000190
Chris Lattner261efe92003-11-25 01:02:51 +0000191<p>It is important to note that this document describes 'well formed'
192LLVM assembly language. There is a difference between what the parser
193accepts and what is considered 'well formed'. For example, the
194following instruction is syntactically okay, but not well formed:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000195
196<pre>
197 %x = <a href="#i_add">add</a> int 1, %x
198</pre>
199
Chris Lattner261efe92003-11-25 01:02:51 +0000200<p>...because the definition of <tt>%x</tt> does not dominate all of
201its uses. The LLVM infrastructure provides a verification pass that may
202be used to verify that an LLVM module is well formed. This pass is
203automatically run by the parser after parsing input assembly, and by
204the optimizer before it outputs bytecode. The violations pointed out
205by the verifier pass indicate bugs in transformation passes or input to
206the parser.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000207
Chris Lattner261efe92003-11-25 01:02:51 +0000208<!-- Describe the typesetting conventions here. --> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000209
Chris Lattner00950542001-06-06 20:29:01 +0000210<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000211<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000212<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000213
Misha Brukman9d0919f2003-11-08 01:05:38 +0000214<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000215
Chris Lattner261efe92003-11-25 01:02:51 +0000216<p>LLVM uses three different forms of identifiers, for different
217purposes:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000218
Chris Lattner00950542001-06-06 20:29:01 +0000219<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000220 <li>Numeric constants are represented as you would expect: 12, -3
John Criswell4457dc92004-04-09 16:48:45 +0000221123.421, etc. Floating point constants have an optional hexadecimal
Chris Lattner261efe92003-11-25 01:02:51 +0000222notation.</li>
223 <li>Named values are represented as a string of characters with a '%'
224prefix. For example, %foo, %DivisionByZero,
225%a.really.long.identifier. The actual regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
226Identifiers which require other characters in their names can be
227surrounded with quotes. In this way, anything except a <tt>"</tt>
228character can be used in a name.</li>
229 <li>Unnamed values are represented as an unsigned numeric value with
230a '%' prefix. For example, %12, %2, %44.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000231</ol>
John Criswell6794d922004-03-12 21:19:06 +0000232<p>LLVM requires that values start with a '%' sign for two reasons:
Chris Lattner261efe92003-11-25 01:02:51 +0000233Compilers don't need to worry about name clashes with reserved words,
234and the set of reserved words may be expanded in the future without
235penalty. Additionally, unnamed identifiers allow a compiler to quickly
236come up with a temporary variable without having to avoid symbol table
237conflicts.</p>
238<p>Reserved words in LLVM are very similar to reserved words in other
239languages. There are keywords for different opcodes ('<tt><a
240 href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
241 href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
242 href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>',
243etc...), and others. These reserved words cannot conflict with
244variable names, because none of them start with a '%' character.</p>
245<p>Here is an example of LLVM code to multiply the integer variable '<tt>%X</tt>'
246by 8:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000247<p>The easy way:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000248<pre> %result = <a href="#i_mul">mul</a> uint %X, 8<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000249<p>After strength reduction:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000250<pre> %result = <a href="#i_shl">shl</a> uint %X, ubyte 3<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000251<p>And the hard way:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000252<pre> <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
253 <a
254 href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
255 %result = <a
256 href="#i_add">add</a> uint %1, %1<br></pre>
257<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
258important lexical features of LLVM:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000259<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000260 <li>Comments are delimited with a '<tt>;</tt>' and go until the end
261of line.</li>
262 <li>Unnamed temporaries are created when the result of a computation
263is not assigned to a named value.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000264 <li>Unnamed temporaries are numbered sequentially</li>
265</ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000266<p>...and it also show a convention that we follow in this document.
267When demonstrating instructions, we will follow an instruction with a
268comment that defines the type and name of value produced. Comments are
269shown in italic text.</p>
270<p>The one non-intuitive notation for constants is the optional
271hexidecimal form of floating point constants. For example, the form '<tt>double
Chris Lattner2b7d3202002-05-06 03:03:22 +00002720x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
Chris Lattner261efe92003-11-25 01:02:51 +00002734.5e+15</tt>' which is also supported by the parser. The only time
274hexadecimal floating point constants are useful (and the only time that
275they are generated by the disassembler) is when an FP constant has to
276be emitted that is not representable as a decimal floating point number
277exactly. For example, NaN's, infinities, and other special cases are
278represented in their IEEE hexadecimal format so that assembly and
279disassembly do not cause any bits to change in the constants.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000280</div>
Chris Lattner00950542001-06-06 20:29:01 +0000281<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000282<div class="doc_section"> <a name="typesystem">Type System</a> </div>
283<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000284<div class="doc_text">
Misha Brukman9d0919f2003-11-08 01:05:38 +0000285<p>The LLVM type system is one of the most important features of the
Chris Lattner261efe92003-11-25 01:02:51 +0000286intermediate representation. Being typed enables a number of
287optimizations to be performed on the IR directly, without having to do
288extra analyses on the side before the transformation. A strong type
289system makes it easier to read the generated code and enables novel
290analyses and transformations that are not feasible to perform on normal
291three address code representations.</p>
Chris Lattner7bae3952002-06-25 18:03:17 +0000292<!-- The written form for the type system was heavily influenced by the
293syntactic problems with types in the C language<sup><a
Chris Lattner261efe92003-11-25 01:02:51 +0000294href="#rw_stroustrup">1</a></sup>.<p> --> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000295<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000296<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000297<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +0000298<p>The primitive types are the fundamental building blocks of the LLVM
Chris Lattner261efe92003-11-25 01:02:51 +0000299system. The current set of primitive types are as follows:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000300
301<table border="0" style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +0000302 <tbody>
303 <tr>
304 <td>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000305 <table border="1" cellspacing="0" cellpadding="4" style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +0000306 <tbody>
307 <tr>
308 <td><tt>void</tt></td>
309 <td>No value</td>
310 </tr>
311 <tr>
312 <td><tt>ubyte</tt></td>
313 <td>Unsigned 8 bit value</td>
314 </tr>
315 <tr>
316 <td><tt>ushort</tt></td>
317 <td>Unsigned 16 bit value</td>
318 </tr>
319 <tr>
320 <td><tt>uint</tt></td>
321 <td>Unsigned 32 bit value</td>
322 </tr>
323 <tr>
324 <td><tt>ulong</tt></td>
325 <td>Unsigned 64 bit value</td>
326 </tr>
327 <tr>
328 <td><tt>float</tt></td>
329 <td>32 bit floating point value</td>
330 </tr>
331 <tr>
332 <td><tt>label</tt></td>
333 <td>Branch destination</td>
334 </tr>
335 </tbody>
336 </table>
337 </td>
338 <td valign="top">
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000339 <table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +0000340 <tbody>
341 <tr>
342 <td><tt>bool</tt></td>
343 <td>True or False value</td>
344 </tr>
345 <tr>
346 <td><tt>sbyte</tt></td>
347 <td>Signed 8 bit value</td>
348 </tr>
349 <tr>
350 <td><tt>short</tt></td>
351 <td>Signed 16 bit value</td>
352 </tr>
353 <tr>
354 <td><tt>int</tt></td>
355 <td>Signed 32 bit value</td>
356 </tr>
357 <tr>
358 <td><tt>long</tt></td>
359 <td>Signed 64 bit value</td>
360 </tr>
361 <tr>
362 <td><tt>double</tt></td>
363 <td>64 bit floating point value</td>
364 </tr>
365 </tbody>
366 </table>
367 </td>
368 </tr>
369 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000370</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000371
Misha Brukman9d0919f2003-11-08 01:05:38 +0000372</div>
Chris Lattner00950542001-06-06 20:29:01 +0000373<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000374<div class="doc_subsubsection"> <a name="t_classifications">Type
375Classifications</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000376<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000377<p>These different primitive types fall into a few useful
378classifications:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000379
380<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +0000381 <tbody>
382 <tr>
383 <td><a name="t_signed">signed</a></td>
384 <td><tt>sbyte, short, int, long, float, double</tt></td>
385 </tr>
386 <tr>
387 <td><a name="t_unsigned">unsigned</a></td>
388 <td><tt>ubyte, ushort, uint, ulong</tt></td>
389 </tr>
390 <tr>
391 <td><a name="t_integer">integer</a></td>
392 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
393 </tr>
394 <tr>
395 <td><a name="t_integral">integral</a></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000396 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt>
397 </td>
Chris Lattner261efe92003-11-25 01:02:51 +0000398 </tr>
399 <tr>
400 <td><a name="t_floating">floating point</a></td>
401 <td><tt>float, double</tt></td>
402 </tr>
403 <tr>
404 <td><a name="t_firstclass">first class</a></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000405 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long,<br>
406 float, double, <a href="#t_pointer">pointer</a>,
407 <a href="#t_packed">packed</a></tt></td>
Chris Lattner261efe92003-11-25 01:02:51 +0000408 </tr>
409 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000410</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000411
Chris Lattner261efe92003-11-25 01:02:51 +0000412<p>The <a href="#t_firstclass">first class</a> types are perhaps the
413most important. Values of these types are the only ones which can be
414produced by instructions, passed as arguments, or used as operands to
415instructions. This means that all structures and arrays must be
416manipulated either by pointer or by component.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000417</div>
Chris Lattner00950542001-06-06 20:29:01 +0000418<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000419<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000420<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000421<p>The real power in LLVM comes from the derived types in the system.
422This is what allows a programmer to represent arrays, functions,
423pointers, and other useful types. Note that these derived types may be
424recursive: For example, it is possible to have a two dimensional array.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000425</div>
Chris Lattner00950542001-06-06 20:29:01 +0000426<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000427<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000428<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000429<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000430<p>The array type is a very simple derived type that arranges elements
Chris Lattner261efe92003-11-25 01:02:51 +0000431sequentially in memory. The array type requires a size (number of
432elements) and an underlying data type.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000433<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000434<pre> [&lt;# elements&gt; x &lt;elementtype&gt;]<br></pre>
435<p>The number of elements is a constant integer value, elementtype may
436be any type with a size.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000437<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000438<p> <tt>[40 x int ]</tt>: Array of 40 integer values.<br>
439<tt>[41 x int ]</tt>: Array of 41 integer values.<br>
440<tt>[40 x uint]</tt>: Array of 40 unsigned integer values.</p>
441<p> </p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000442<p>Here are some examples of multidimensional arrays:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000443
Misha Brukman9d0919f2003-11-08 01:05:38 +0000444<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000445 <tbody>
446 <tr>
447 <td><tt>[3 x [4 x int]]</tt></td>
448 <td>: 3x4 array integer values.</td>
449 </tr>
450 <tr>
451 <td><tt>[12 x [10 x float]]</tt></td>
452 <td>: 12x10 array of single precision floating point values.</td>
453 </tr>
454 <tr>
455 <td><tt>[2 x [3 x [4 x uint]]]</tt></td>
456 <td>: 2x3x4 array of unsigned integer values.</td>
457 </tr>
458 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000459</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000460
Misha Brukman9d0919f2003-11-08 01:05:38 +0000461</div>
Chris Lattner00950542001-06-06 20:29:01 +0000462<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000463<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000464<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000465<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000466<p>The function type can be thought of as a function signature. It
467consists of a return type and a list of formal parameter types.
John Criswell009900b2003-11-25 21:45:46 +0000468Function types are usually used to build virtual function tables
Chris Lattner261efe92003-11-25 01:02:51 +0000469(which are structures of pointers to functions), for indirect function
470calls, and when defining a function.</p>
John Criswell009900b2003-11-25 21:45:46 +0000471<p>
472The return type of a function type cannot be an aggregate type.
473</p>
Chris Lattner00950542001-06-06 20:29:01 +0000474<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000475<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000476<p>Where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
477specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner27f71f22003-09-03 00:41:47 +0000478which indicates that the function takes a variable number of arguments.
479Variable argument functions can access their arguments with the <a
Chris Lattner261efe92003-11-25 01:02:51 +0000480 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000481<h5>Examples:</h5>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000482
Misha Brukman9d0919f2003-11-08 01:05:38 +0000483<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000484 <tbody>
485 <tr>
486 <td><tt>int (int)</tt></td>
487 <td>: function taking an <tt>int</tt>, returning an <tt>int</tt></td>
488 </tr>
489 <tr>
490 <td><tt>float (int, int *) *</tt></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000491 <td>: <a href="#t_pointer">Pointer</a> to a function that takes an
492 <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
493 returning <tt>float</tt>.</td>
Chris Lattner261efe92003-11-25 01:02:51 +0000494 </tr>
495 <tr>
496 <td><tt>int (sbyte *, ...)</tt></td>
497 <td>: A vararg function that takes at least one <a
Misha Brukmanc24b7582004-08-12 20:16:08 +0000498 href="#t_pointer">pointer</a> to <tt>sbyte</tt> (signed char in C), which
499 returns an integer. This is the signature for <tt>printf</tt> in
500 LLVM.</td>
Chris Lattner261efe92003-11-25 01:02:51 +0000501 </tr>
502 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000503</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000504
Misha Brukman9d0919f2003-11-08 01:05:38 +0000505</div>
Chris Lattner00950542001-06-06 20:29:01 +0000506<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000507<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000508<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000509<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000510<p>The structure type is used to represent a collection of data members
511together in memory. The packing of the field types is defined to match
512the ABI of the underlying processor. The elements of a structure may
513be any type that has a size.</p>
514<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
515and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
516field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
517instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000518<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000519<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +0000520<h5>Examples:</h5>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000521
Misha Brukman9d0919f2003-11-08 01:05:38 +0000522<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000523 <tbody>
524 <tr>
525 <td><tt>{ int, int, int }</tt></td>
526 <td>: a triple of three <tt>int</tt> values</td>
527 </tr>
528 <tr>
529 <td><tt>{ float, int (int) * }</tt></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000530 <td>: A pair, where the first element is a <tt>float</tt> and the second
531 element is a <a href="#t_pointer">pointer</a> to a <a
532 href="#t_function">function</a> that takes an <tt>int</tt>, returning an
533 <tt>int</tt>.</td>
Chris Lattner261efe92003-11-25 01:02:51 +0000534 </tr>
535 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000536</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000537
Misha Brukman9d0919f2003-11-08 01:05:38 +0000538</div>
Chris Lattner00950542001-06-06 20:29:01 +0000539<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000540<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000541<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +0000542<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000543<p>As in many languages, the pointer type represents a pointer or
544reference to another object, which must live in memory.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000545<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000546<pre> &lt;type&gt; *<br></pre>
Chris Lattner7faa8832002-04-14 06:13:44 +0000547<h5>Examples:</h5>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000548
Misha Brukman9d0919f2003-11-08 01:05:38 +0000549<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000550 <tbody>
551 <tr>
552 <td><tt>[4x int]*</tt></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000553 <td>: <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of
554 four <tt>int</tt> values</td>
Chris Lattner261efe92003-11-25 01:02:51 +0000555 </tr>
556 <tr>
557 <td><tt>int (int *) *</tt></td>
558 <td>: A <a href="#t_pointer">pointer</a> to a <a
Misha Brukmanc24b7582004-08-12 20:16:08 +0000559 href="#t_function">function</a> that takes an <tt>int</tt>, returning an
560 <tt>int</tt>.</td>
Chris Lattner261efe92003-11-25 01:02:51 +0000561 </tr>
562 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000563</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000564</div>
Chris Lattnera58561b2004-08-12 19:12:28 +0000565<!-- _______________________________________________________________________ -->
566<div class="doc_subsubsection"> <a name="t_packed">Packed Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000567<div class="doc_text">
Chris Lattnera58561b2004-08-12 19:12:28 +0000568<h5>Overview:</h5>
569<p>A packed type is a simple derived type that represents a vector
570of elements. Packed types are used when multiple primitive data
571are operated in parallel using a single instruction (SIMD).
572A packed type requires a size (number of
573elements) and an underlying primitive data type. Packed types are
574considered <a href="#t_firstclass">first class</a>.</p>
575<h5>Syntax:</h5>
576<pre> &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;<br></pre>
577<p>The number of elements is a constant integer value, elementtype may
578be any integral or floating point type.</p>
579<h5>Examples:</h5>
580<p> <tt>&lt;4 x int&gt;</tt>: Packed vector of 4 integer values.<br>
581<tt>&lt;8 x float&gt;</tt>: Packed vector of 8 floating-point values.<br>
582<tt>&lt;2 x uint&gt;</tt>: Packed vector of 2 unsigned integer values.</p>
583<p> </p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000584</div>
585
Chris Lattnera58561b2004-08-12 19:12:28 +0000586<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000587<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000588<!-- *********************************************************************** -->
589<!-- ======================================================================= -->
590<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
591</div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000592<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000593<p>LLVM programs are composed of "Module"s, each of which is a
594translation unit of the input programs. Each module consists of
595functions, global variables, and symbol table entries. Modules may be
596combined together with the LLVM linker, which merges function (and
597global variable) definitions, resolves forward declarations, and merges
598symbol table entries. Here is an example of the "hello world" module:</p>
599<pre><i>; Declare the string constant as a global constant...</i>
600<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
601 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 +0000602
Chris Lattner27f71f22003-09-03 00:41:47 +0000603<i>; External declaration of the puts function</i>
604<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000605
606<i>; Definition of main function</i>
Chris Lattner27f71f22003-09-03 00:41:47 +0000607int %main() { <i>; int()* </i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000608 <i>; Convert [13x sbyte]* to sbyte *...</i>
Chris Lattner261efe92003-11-25 01:02:51 +0000609 %cast210 = <a
610 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000611
612 <i>; Call puts function to write out the string to stdout...</i>
Chris Lattner261efe92003-11-25 01:02:51 +0000613 <a
614 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
615 <a
616 href="#i_ret">ret</a> int 0<br>}<br></pre>
617<p>This example is made up of a <a href="#globalvars">global variable</a>
618named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
619function, and a <a href="#functionstructure">function definition</a>
620for "<tt>main</tt>".</p>
621<a name="linkage"> In general, a module is made up of a list of global
622values, where both functions and global variables are global values.
623Global values are represented by a pointer to a memory location (in
624this case, a pointer to an array of char, and a pointer to a function),
625and have one of the following linkage types:</a>
626<p> </p>
Chris Lattner27f71f22003-09-03 00:41:47 +0000627<dl>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000628 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000629 <dd>Global values with internal linkage are only directly accessible
630by objects in the current module. In particular, linking code into a
631module with an internal global value may cause the internal to be
632renamed as necessary to avoid collisions. Because the symbol is
633internal to the module, all references can be updated. This
634corresponds to the notion of the '<tt>static</tt>' keyword in C, or the
635idea of "anonymous namespaces" in C++.
636 <p> </p>
637 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000638 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000639 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt>
640linkage, with the twist that linking together two modules defining the
641same <tt>linkonce</tt> globals will cause one of the globals to be
642discarded. This is typically used to implement inline functions.
643Unreferenced <tt>linkonce</tt> globals are allowed to be discarded.
644 <p> </p>
645 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000646 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000647 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt>
648linkage, except that unreferenced <tt>weak</tt> globals may not be
649discarded. This is used to implement constructs in C such as "<tt>int
650X;</tt>" at global scope.
651 <p> </p>
652 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000653 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000654 <dd>"<tt>appending</tt>" linkage may only be applied to global
655variables of pointer to array type. When two global variables with
656appending linkage are linked together, the two global arrays are
657appended together. This is the LLVM, typesafe, equivalent of having
658the system linker append together "sections" with identical names when
659.o files are linked.
660 <p> </p>
661 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000662 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000663 <dd>If none of the above identifiers are used, the global is
664externally visible, meaning that it participates in linkage and can be
665used to resolve external symbol references.
666 <p> </p>
667 </dd>
Chris Lattner261efe92003-11-25 01:02:51 +0000668</dl>
669<p> </p>
670<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
671variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
672variable and was linked with this one, one of the two would be renamed,
673preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
674external (i.e., lacking any linkage declarations), they are accessible
675outside of the current module. It is illegal for a function <i>declaration</i>
676to have any linkage type other than "externally visible".</a></p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000677</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000678
Chris Lattner00950542001-06-06 20:29:01 +0000679<!-- ======================================================================= -->
Chris Lattner9ee5d222004-03-08 16:49:10 +0000680<div class="doc_subsection">
681 <a name="globalvars">Global Variables</a>
682</div>
683
Misha Brukman9d0919f2003-11-08 01:05:38 +0000684<div class="doc_text">
Chris Lattner9ee5d222004-03-08 16:49:10 +0000685
Chris Lattner261efe92003-11-25 01:02:51 +0000686<p>Global variables define regions of memory allocated at compilation
687time instead of run-time. Global variables may optionally be
688initialized. A variable may be defined as a global "constant", which
689indicates that the contents of the variable will never be modified
Chris Lattner9ee5d222004-03-08 16:49:10 +0000690(opening options for optimization).</p>
691
Chris Lattner261efe92003-11-25 01:02:51 +0000692<p>As SSA values, global variables define pointer values that are in
693scope (i.e. they dominate) for all basic blocks in the program. Global
694variables always define a pointer to their "content" type because they
695describe a region of memory, and all memory objects in LLVM are
696accessed through pointers.</p>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000697
Misha Brukman9d0919f2003-11-08 01:05:38 +0000698</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000699
700
Chris Lattner2b7d3202002-05-06 03:03:22 +0000701<!-- ======================================================================= -->
Chris Lattner9ee5d222004-03-08 16:49:10 +0000702<div class="doc_subsection">
703 <a name="functionstructure">Functions</a>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000704</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000705
706<div class="doc_text">
707
708<p>LLVM function definitions are composed of a (possibly empty) argument list,
709an opening curly brace, a list of basic blocks, and a closing curly brace. LLVM
710function declarations are defined with the "<tt>declare</tt>" keyword, a
711function name, and a function signature.</p>
712
713<p>A function definition contains a list of basic blocks, forming the CFG for
714the function. Each basic block may optionally start with a label (giving the
715basic block a symbol table entry), contains a list of instructions, and ends
716with a <a href="#terminators">terminator</a> instruction (such as a branch or
717function return).</p>
718
719<p>The first basic block in program is special in two ways: it is immediately
720executed on entrance to the function, and it is not allowed to have predecessor
721basic blocks (i.e. there can not be any branches to the entry block of a
722function). Because the block can have no predecessors, it also cannot have any
723<a href="#i_phi">PHI nodes</a>.</p>
724
725<p>LLVM functions are identified by their name and type signature. Hence, two
726functions with the same name but different parameter lists or return values are
727considered different functions, and LLVM will resolves references to each
728appropriately.</p>
729
730</div>
731
732
Chris Lattner00950542001-06-06 20:29:01 +0000733<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000734<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
735<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000736<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000737<p>The LLVM instruction set consists of several different
738classifications of instructions: <a href="#terminators">terminator
739instructions</a>, <a href="#binaryops">binary instructions</a>, <a
740 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
741instructions</a>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000742</div>
Chris Lattner00950542001-06-06 20:29:01 +0000743<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000744<div class="doc_subsection"> <a name="terminators">Terminator
745Instructions</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000746<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000747<p>As mentioned <a href="#functionstructure">previously</a>, every
748basic block in a program ends with a "Terminator" instruction, which
749indicates which block should be executed after the current block is
750finished. These terminator instructions typically yield a '<tt>void</tt>'
751value: they produce control flow, not values (the one exception being
752the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000753<p>There are five different terminator instructions: the '<a
Chris Lattner261efe92003-11-25 01:02:51 +0000754 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
755instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
756the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, and the '<a
757 href="#i_unwind"><tt>unwind</tt></a>' instruction.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000758</div>
Chris Lattner00950542001-06-06 20:29:01 +0000759<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000760<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
761Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000762<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000763<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000764<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 +0000765 ret void <i>; Return from void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000766</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000767<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000768<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
769value) from a function, back to the caller.</p>
John Criswell4457dc92004-04-09 16:48:45 +0000770<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner261efe92003-11-25 01:02:51 +0000771returns a value and then causes control flow, and one that just causes
772control flow to occur.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000773<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000774<p>The '<tt>ret</tt>' instruction may return any '<a
775 href="#t_firstclass">first class</a>' type. Notice that a function is
776not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
777instruction inside of the function that returns a value that does not
778match the return type of the function.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000779<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000780<p>When the '<tt>ret</tt>' instruction is executed, control flow
781returns back to the calling function's context. If the caller is a "<a
John Criswellfa081872004-06-25 15:16:57 +0000782 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner261efe92003-11-25 01:02:51 +0000783the instruction after the call. If the caller was an "<a
784 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
785at the beginning "normal" of the destination block. If the instruction
786returns a value, that value shall set the call or invoke instruction's
787return value.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000788<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000789<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner7faa8832002-04-14 06:13:44 +0000790 ret void <i>; Return from a void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000791</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000792</div>
Chris Lattner00950542001-06-06 20:29:01 +0000793<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000794<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000795<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000796<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000797<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 +0000798</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000799<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000800<p>The '<tt>br</tt>' instruction is used to cause control flow to
801transfer to a different basic block in the current function. There are
802two forms of this instruction, corresponding to a conditional branch
803and an unconditional branch.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000804<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000805<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
806single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
807unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
808value as a target.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000809<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000810<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
811argument is evaluated. If the value is <tt>true</tt>, control flows
812to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
813control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000814<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000815<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
816 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 +0000817</div>
Chris Lattner00950542001-06-06 20:29:01 +0000818<!-- _______________________________________________________________________ -->
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000819<div class="doc_subsubsection">
820 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
821</div>
822
Misha Brukman9d0919f2003-11-08 01:05:38 +0000823<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000824<h5>Syntax:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000825
826<pre>
827 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
828</pre>
829
Chris Lattner00950542001-06-06 20:29:01 +0000830<h5>Overview:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000831
832<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
833several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +0000834instruction, allowing a branch to occur to one of many possible
835destinations.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000836
837
Chris Lattner00950542001-06-06 20:29:01 +0000838<h5>Arguments:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000839
840<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
841comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
842an array of pairs of comparison value constants and '<tt>label</tt>'s. The
843table is not allowed to contain duplicate constant entries.</p>
844
Chris Lattner00950542001-06-06 20:29:01 +0000845<h5>Semantics:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000846
Chris Lattner261efe92003-11-25 01:02:51 +0000847<p>The <tt>switch</tt> instruction specifies a table of values and
848destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswell84114752004-06-25 16:05:06 +0000849table is searched for the given value. If the value is found, control flow is
850transfered to the corresponding destination; otherwise, control flow is
851transfered to the default destination.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000852
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000853<h5>Implementation:</h5>
854
855<p>Depending on properties of the target machine and the particular
856<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswell84114752004-06-25 16:05:06 +0000857ways. For example, it could be generated as a series of chained conditional
858branches or with a lookup table.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000859
860<h5>Example:</h5>
861
862<pre>
863 <i>; Emulate a conditional br instruction</i>
864 %Val = <a href="#i_cast">cast</a> bool %value to int
865 switch int %Val, label %truedest [int 0, label %falsedest ]
866
867 <i>; Emulate an unconditional br instruction</i>
868 switch uint 0, label %dest [ ]
869
870 <i>; Implement a jump table:</i>
871 switch uint %val, label %otherwise [ uint 0, label %onzero
872 uint 1, label %onone
873 uint 2, label %ontwo ]
Chris Lattner00950542001-06-06 20:29:01 +0000874</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000875</div>
Chris Lattner00950542001-06-06 20:29:01 +0000876<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000877<div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>'
878Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000879<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000880<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000881<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 +0000882<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000883<p>The '<tt>invoke</tt>' instruction causes control to transfer to a
884specified function, with the possibility of control flow transfer to
885either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>.
886If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>"
887instruction, control flow will return to the "normal" label. If the
888callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
889instruction, control is interrupted, and continued at the dynamically
890nearest "except" label.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000891<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000892<p>This instruction requires several arguments:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000893<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000894 <li>'<tt>ptr to function ty</tt>': shall be the signature of the
895pointer to function value being invoked. In most cases, this is a
896direct function invocation, but indirect <tt>invoke</tt>s are just as
897possible, branching off an arbitrary pointer to function value. </li>
898 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer
899to a function to be invoked. </li>
900 <li>'<tt>function args</tt>': argument list whose types match the
901function signature argument types. If the function signature indicates
902the function accepts a variable number of arguments, the extra
903arguments can be specified. </li>
904 <li>'<tt>normal label</tt>': the label reached when the called
905function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
906 <li>'<tt>exception label</tt>': the label reached when a callee
907returns with the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
Chris Lattner00950542001-06-06 20:29:01 +0000908</ol>
Chris Lattner00950542001-06-06 20:29:01 +0000909<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000910<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner261efe92003-11-25 01:02:51 +0000911 href="#i_call">call</a></tt>' instruction in most regards. The
912primary difference is that it establishes an association with a label,
913which is used by the runtime library to unwind the stack.</p>
914<p>This instruction is used in languages with destructors to ensure
915that proper cleanup is performed in the case of either a <tt>longjmp</tt>
916or a thrown exception. Additionally, this is important for
917implementation of '<tt>catch</tt>' clauses in high-level languages that
918support them.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000919<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000920<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 +0000921</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000922</div>
Chris Lattner27f71f22003-09-03 00:41:47 +0000923<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000924<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
925Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000926<div class="doc_text">
Chris Lattner27f71f22003-09-03 00:41:47 +0000927<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000928<pre> unwind<br></pre>
Chris Lattner27f71f22003-09-03 00:41:47 +0000929<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000930<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing
931control flow at the first callee in the dynamic call stack which used
932an <a href="#i_invoke"><tt>invoke</tt></a> instruction to perform the
933call. This is primarily used to implement exception handling.</p>
Chris Lattner27f71f22003-09-03 00:41:47 +0000934<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000935<p>The '<tt>unwind</tt>' intrinsic causes execution of the current
936function to immediately halt. The dynamic call stack is then searched
937for the first <a href="#i_invoke"><tt>invoke</tt></a> instruction on
938the call stack. Once found, execution continues at the "exceptional"
939destination block specified by the <tt>invoke</tt> instruction. If
940there is no <tt>invoke</tt> instruction in the dynamic call chain,
941undefined behavior results.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000942</div>
Chris Lattner00950542001-06-06 20:29:01 +0000943<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000944<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000945<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000946<p>Binary operators are used to do most of the computation in a
947program. They require two operands, execute an operation on them, and
Chris Lattnera58561b2004-08-12 19:12:28 +0000948produce a single value. Although, that single value might represent
949multiple data, as is the case with the <a href="#t_packed">packed</a> data type.
950The result value of a binary operator is not
Chris Lattner261efe92003-11-25 01:02:51 +0000951necessarily the same type as its operands.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000952<p>There are several different binary operators:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000953</div>
Chris Lattner00950542001-06-06 20:29:01 +0000954<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000955<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
956Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000957<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000958<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000959<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 +0000960</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000961<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000962<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000963<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000964<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattnera58561b2004-08-12 19:12:28 +0000965 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
966 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
967Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000968<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000969<p>The value produced is the integer or floating point sum of the two
970operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000971<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000972<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner00950542001-06-06 20:29:01 +0000973</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000974</div>
Chris Lattner00950542001-06-06 20:29:01 +0000975<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000976<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
977Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000978<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000979<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000980<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 +0000981</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000982<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000983<p>The '<tt>sub</tt>' instruction returns the difference of its two
984operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000985<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
986instruction present in most other intermediate representations.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000987<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000988<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +0000989 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +0000990values.
991This instruction can also take <a href="#t_packed">packed</a> versions of the values.
992Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000993<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000994<p>The value produced is the integer or floating point difference of
995the two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000996<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000997<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner00950542001-06-06 20:29:01 +0000998 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
999</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001000</div>
Chris Lattner00950542001-06-06 20:29:01 +00001001<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001002<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
1003Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001004<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001005<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001006<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 +00001007</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001008<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001009<p>The '<tt>mul</tt>' instruction returns the product of its two
1010operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001011<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001012<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001013 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001014values.
1015This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1016Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001017<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001018<p>The value produced is the integer or floating point product of the
Misha Brukman9d0919f2003-11-08 01:05:38 +00001019two operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001020<p>There is no signed vs unsigned multiplication. The appropriate
1021action is taken based on the type of the operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001022<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001023<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001024</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001025</div>
Chris Lattner00950542001-06-06 20:29:01 +00001026<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001027<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
1028Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001029<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001030<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001031<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1032</pre>
1033<h5>Overview:</h5>
1034<p>The '<tt>div</tt>' instruction returns the quotient of its two
1035operands.</p>
1036<h5>Arguments:</h5>
1037<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
1038 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001039values.
1040This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1041Both arguments must have identical types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001042<h5>Semantics:</h5>
1043<p>The value produced is the integer or floating point quotient of the
1044two operands.</p>
1045<h5>Example:</h5>
1046<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
1047</pre>
1048</div>
1049<!-- _______________________________________________________________________ -->
1050<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
1051Instruction</a> </div>
1052<div class="doc_text">
1053<h5>Syntax:</h5>
1054<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1055</pre>
1056<h5>Overview:</h5>
1057<p>The '<tt>rem</tt>' instruction returns the remainder from the
1058division of its two operands.</p>
1059<h5>Arguments:</h5>
1060<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1061 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001062values.
1063This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1064Both arguments must have identical types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001065<h5>Semantics:</h5>
1066<p>This returns the <i>remainder</i> of a division (where the result
1067has the same sign as the divisor), not the <i>modulus</i> (where the
1068result has the same sign as the dividend) of a value. For more
1069information about the difference, see: <a
1070 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1071Math Forum</a>.</p>
1072<h5>Example:</h5>
1073<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1074</pre>
1075</div>
1076<!-- _______________________________________________________________________ -->
1077<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1078Instructions</a> </div>
1079<div class="doc_text">
1080<h5>Syntax:</h5>
1081<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 +00001082 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1083 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1084 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1085 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1086 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1087</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001088<h5>Overview:</h5>
1089<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1090value based on a comparison of their two operands.</p>
1091<h5>Arguments:</h5>
1092<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1093be of <a href="#t_firstclass">first class</a> type (it is not possible
1094to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1095or '<tt>void</tt>' values, etc...). Both arguments must have identical
1096types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001097<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001098<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1099value if both operands are equal.<br>
1100The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1101value if both operands are unequal.<br>
1102The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1103value if the first operand is less than the second operand.<br>
1104The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1105value if the first operand is greater than the second operand.<br>
1106The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1107value if the first operand is less than or equal to the second operand.<br>
1108The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1109value if the first operand is greater than or equal to the second
1110operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001111<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001112<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner00950542001-06-06 20:29:01 +00001113 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
1114 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1115 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1116 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1117 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1118</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001119</div>
Chris Lattner00950542001-06-06 20:29:01 +00001120<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001121<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1122Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001123<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001124<p>Bitwise binary operators are used to do various forms of
1125bit-twiddling in a program. They are generally very efficient
1126instructions, and can commonly be strength reduced from other
1127instructions. They require two operands, execute an operation on them,
1128and produce a single value. The resulting value of the bitwise binary
1129operators is always the same type as its first operand.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001130</div>
Chris Lattner00950542001-06-06 20:29:01 +00001131<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001132<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1133Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001134<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001135<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001136<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 +00001137</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001138<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001139<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1140its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001141<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001142<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001143 href="#t_integral">integral</a> values. Both arguments must have
1144identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001145<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001146<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001147<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001148<div style="align: center">
Misha Brukman9d0919f2003-11-08 01:05:38 +00001149<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +00001150 <tbody>
1151 <tr>
1152 <td>In0</td>
1153 <td>In1</td>
1154 <td>Out</td>
1155 </tr>
1156 <tr>
1157 <td>0</td>
1158 <td>0</td>
1159 <td>0</td>
1160 </tr>
1161 <tr>
1162 <td>0</td>
1163 <td>1</td>
1164 <td>0</td>
1165 </tr>
1166 <tr>
1167 <td>1</td>
1168 <td>0</td>
1169 <td>0</td>
1170 </tr>
1171 <tr>
1172 <td>1</td>
1173 <td>1</td>
1174 <td>1</td>
1175 </tr>
1176 </tbody>
1177</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001178</div>
Chris Lattner00950542001-06-06 20:29:01 +00001179<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001180<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001181 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1182 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1183</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001184</div>
Chris Lattner00950542001-06-06 20:29:01 +00001185<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001186<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001187<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001188<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001189<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 +00001190</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001191<h5>Overview:</h5>
1192<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1193or of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001194<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001195<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001196 href="#t_integral">integral</a> values. Both arguments must have
1197identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001198<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001199<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001200<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001201<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001202<table border="1" cellspacing="0" cellpadding="4">
1203 <tbody>
1204 <tr>
1205 <td>In0</td>
1206 <td>In1</td>
1207 <td>Out</td>
1208 </tr>
1209 <tr>
1210 <td>0</td>
1211 <td>0</td>
1212 <td>0</td>
1213 </tr>
1214 <tr>
1215 <td>0</td>
1216 <td>1</td>
1217 <td>1</td>
1218 </tr>
1219 <tr>
1220 <td>1</td>
1221 <td>0</td>
1222 <td>1</td>
1223 </tr>
1224 <tr>
1225 <td>1</td>
1226 <td>1</td>
1227 <td>1</td>
1228 </tr>
1229 </tbody>
1230</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001231</div>
Chris Lattner00950542001-06-06 20:29:01 +00001232<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001233<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001234 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1235 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1236</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001237</div>
Chris Lattner00950542001-06-06 20:29:01 +00001238<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001239<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1240Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001241<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001242<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001243<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 +00001244</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001245<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001246<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1247or of its two operands. The <tt>xor</tt> is used to implement the
1248"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001249<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001250<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001251 href="#t_integral">integral</a> values. Both arguments must have
1252identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001253<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001254<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001255<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001256<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001257<table border="1" cellspacing="0" cellpadding="4">
1258 <tbody>
1259 <tr>
1260 <td>In0</td>
1261 <td>In1</td>
1262 <td>Out</td>
1263 </tr>
1264 <tr>
1265 <td>0</td>
1266 <td>0</td>
1267 <td>0</td>
1268 </tr>
1269 <tr>
1270 <td>0</td>
1271 <td>1</td>
1272 <td>1</td>
1273 </tr>
1274 <tr>
1275 <td>1</td>
1276 <td>0</td>
1277 <td>1</td>
1278 </tr>
1279 <tr>
1280 <td>1</td>
1281 <td>1</td>
1282 <td>0</td>
1283 </tr>
1284 </tbody>
1285</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001286</div>
Chris Lattner261efe92003-11-25 01:02:51 +00001287<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001288<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001289<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001290 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1291 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner27f71f22003-09-03 00:41:47 +00001292 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner00950542001-06-06 20:29:01 +00001293</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001294</div>
Chris Lattner00950542001-06-06 20:29:01 +00001295<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001296<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1297Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001298<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001299<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001300<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 +00001301</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001302<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001303<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1304the left a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001305<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001306<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001307 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1308type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001309<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001310<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001311<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001312<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 +00001313 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1314 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1315</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001316</div>
Chris Lattner00950542001-06-06 20:29:01 +00001317<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001318<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1319Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001320<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001321<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001322<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 +00001323</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001324<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001325<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1326the right a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001327<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001328<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001329 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1330type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001331<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001332<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1333most significant bit is duplicated in the newly free'd bit positions.
1334If the first argument is unsigned, zero bits shall fill the empty
1335positions.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001336<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001337<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 +00001338 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001339 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner8c6bb902003-06-18 21:30:51 +00001340 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1341 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner00950542001-06-06 20:29:01 +00001342</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001343</div>
Chris Lattner00950542001-06-06 20:29:01 +00001344<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001345<div class="doc_subsection"> <a name="memoryops">Memory Access
1346Operations</a></div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001347<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001348<p>A key design point of an SSA-based representation is how it
1349represents memory. In LLVM, no memory locations are in SSA form, which
1350makes things very simple. This section describes how to read, write,
1351allocate and free memory in LLVM.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001352</div>
Chris Lattner00950542001-06-06 20:29:01 +00001353<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001354<div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>'
1355Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001356<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001357<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001358<pre> &lt;result&gt; = malloc &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001359 &lt;result&gt; = malloc &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001360</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001361<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001362<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1363heap and returns a pointer to it.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001364<h5>Arguments:</h5>
John Criswell6e4ca612004-02-24 16:13:56 +00001365<p>The '<tt>malloc</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1366bytes of memory from the operating system and returns a pointer of the
Chris Lattner261efe92003-11-25 01:02:51 +00001367appropriate type to the program. The second form of the instruction is
1368a shorter version of the first instruction that defaults to allocating
1369one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001370<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001371<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001372<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1373a pointer is returned.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001374<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001375<pre> %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001376
Chris Lattner261efe92003-11-25 01:02:51 +00001377 %size = <a
1378 href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001379 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1380 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001381</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001382</div>
Chris Lattner00950542001-06-06 20:29:01 +00001383<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001384<div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>'
1385Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001386<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001387<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001388<pre> free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner00950542001-06-06 20:29:01 +00001389</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001390<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001391<p>The '<tt>free</tt>' instruction returns memory back to the unused
1392memory heap, to be reallocated in the future.</p>
1393<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001394<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001395<p>'<tt>value</tt>' shall be a pointer value that points to a value
1396that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1397instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001398<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001399<p>Access to the memory pointed to by the pointer is not longer defined
1400after this instruction executes.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001401<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001402<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 +00001403 free [4 x ubyte]* %array
1404</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001405</div>
Chris Lattner00950542001-06-06 20:29:01 +00001406<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001407<div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>'
1408Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001409<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001410<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001411<pre> &lt;result&gt; = alloca &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001412 &lt;result&gt; = alloca &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001413</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001414<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001415<p>The '<tt>alloca</tt>' instruction allocates memory on the current
1416stack frame of the procedure that is live until the current function
1417returns to its caller.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001418<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001419<p>The the '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1420bytes of memory on the runtime stack, returning a pointer of the
1421appropriate type to the program. The second form of the instruction is
1422a shorter version of the first that defaults to allocating one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001423<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001424<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001425<p>Memory is allocated, a pointer is returned. '<tt>alloca</tt>'d
1426memory is automatically released when the function returns. The '<tt>alloca</tt>'
1427instruction is commonly used to represent automatic variables that must
1428have an address available. When the function returns (either with the <tt><a
1429 href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001430instructions), the memory is reclaimed.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001431<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001432<pre> %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001433 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner00950542001-06-06 20:29:01 +00001434</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001435</div>
Chris Lattner00950542001-06-06 20:29:01 +00001436<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001437<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1438Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001439<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00001440<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001441<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 +00001442<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001443<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001444<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001445<p>The argument to the '<tt>load</tt>' instruction specifies the memory
1446address to load from. The pointer must point to a <a
Chris Lattnere53e5082004-06-03 22:57:15 +00001447 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
Chris Lattner261efe92003-11-25 01:02:51 +00001448marked as <tt>volatile</tt> then the optimizer is not allowed to modify
1449the number or order of execution of this <tt>load</tt> with other
1450volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1451instructions. </p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001452<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001453<p>The location of memory pointed to is loaded.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001454<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001455<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1456 <a
1457 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001458 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1459</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001460</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001461<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001462<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1463Instruction</a> </div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001464<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001465<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 +00001466 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 +00001467</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001468<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001469<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001470<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001471<p>There are two arguments to the '<tt>store</tt>' instruction: a value
1472to store and an address to store it into. The type of the '<tt>&lt;pointer&gt;</tt>'
1473operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
1474operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the
1475optimizer is not allowed to modify the number or order of execution of
1476this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1477 href="#i_store">store</a></tt> instructions.</p>
1478<h5>Semantics:</h5>
1479<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
1480at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001481<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001482<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1483 <a
1484 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001485 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1486</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001487<!-- _______________________________________________________________________ -->
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001488<div class="doc_subsubsection">
1489 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
1490</div>
1491
Misha Brukman9d0919f2003-11-08 01:05:38 +00001492<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00001493<h5>Syntax:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001494<pre>
1495 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
1496</pre>
1497
Chris Lattner7faa8832002-04-14 06:13:44 +00001498<h5>Overview:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001499
1500<p>
1501The '<tt>getelementptr</tt>' instruction is used to get the address of a
1502subelement of an aggregate data structure.</p>
1503
Chris Lattner7faa8832002-04-14 06:13:44 +00001504<h5>Arguments:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001505
1506<p>This instruction takes a list of integer constants that indicate what
1507elements of the aggregate object to index to. The actual types of the arguments
1508provided depend on the type of the first pointer argument. The
1509'<tt>getelementptr</tt>' instruction is used to index down through the type
1510levels of a structure. When indexing into a structure, only <tt>uint</tt>
1511integer constants are allowed. When indexing into an array or pointer
1512<tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
1513
Chris Lattner261efe92003-11-25 01:02:51 +00001514<p>For example, let's consider a C code fragment and how it gets
1515compiled to LLVM:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001516
1517<pre>
1518 struct RT {
1519 char A;
1520 int B[10][20];
1521 char C;
1522 };
1523 struct ST {
1524 int X;
1525 double Y;
1526 struct RT Z;
1527 };
1528
1529 int *foo(struct ST *s) {
1530 return &amp;s[1].Z.B[5][13];
1531 }
1532</pre>
1533
Misha Brukman9d0919f2003-11-08 01:05:38 +00001534<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001535
1536<pre>
1537 %RT = type { sbyte, [10 x [20 x int]], sbyte }
1538 %ST = type { int, double, %RT }
1539
Brian Gaeke7283e7c2004-07-02 21:08:14 +00001540 implementation
1541
1542 int* %foo(%ST* %s) {
1543 entry:
1544 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001545 ret int* %reg
1546 }
1547</pre>
1548
Chris Lattner7faa8832002-04-14 06:13:44 +00001549<h5>Semantics:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001550
1551<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
Chris Lattnere53e5082004-06-03 22:57:15 +00001552on the pointer type that is being index into. <a href="#t_pointer">Pointer</a>
1553and <a href="#t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
1554<tt>ulong</tt>, or <tt>long</tt> values, and <a href="#t_struct">structure</a>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001555types require <tt>uint</tt> <b>constants</b>.</p>
1556
Misha Brukman9d0919f2003-11-08 01:05:38 +00001557<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001558type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
1559}</tt>' type, a structure. The second index indexes into the third element of
1560the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
1561sbyte }</tt>' type, another structure. The third index indexes into the second
1562element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
1563array. The two dimensions of the array are subscripted into, yielding an
1564'<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction return a pointer
1565to this element, thus computing a value of '<tt>int*</tt>' type.</p>
1566
Chris Lattner261efe92003-11-25 01:02:51 +00001567<p>Note that it is perfectly legal to index partially through a
1568structure, returning a pointer to an inner element. Because of this,
1569the LLVM code for the given testcase is equivalent to:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001570
1571<pre>
1572 int* "foo"(%ST* %s) {
1573 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
1574 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
1575 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
1576 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
1577 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
1578 ret int* %t5
1579 }
Chris Lattner6536cfe2002-05-06 22:08:29 +00001580</pre>
Chris Lattner7faa8832002-04-14 06:13:44 +00001581<h5>Example:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001582<pre>
1583 <i>; yields [12 x ubyte]*:aptr</i>
1584 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
1585</pre>
1586
1587</div>
Chris Lattner00950542001-06-06 20:29:01 +00001588<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001589<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001590<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +00001591<p>The instructions in this category are the "miscellaneous"
Chris Lattner261efe92003-11-25 01:02:51 +00001592instructions, which defy better classification.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001593</div>
Chris Lattner00950542001-06-06 20:29:01 +00001594<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001595<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
1596Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001597<div class="doc_text">
Chris Lattner33ba0d92001-07-09 00:26:23 +00001598<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001599<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001600<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001601<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
1602the SSA graph representing the function.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001603<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001604<p>The type of the incoming values are specified with the first type
1605field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
1606as arguments, with one pair for each predecessor basic block of the
1607current block. Only values of <a href="#t_firstclass">first class</a>
1608type may be used as the value arguments to the PHI node. Only labels
1609may be used as the label arguments.</p>
1610<p>There must be no non-phi instructions between the start of a basic
1611block and the PHI instructions: i.e. PHI instructions must be first in
1612a basic block.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001613<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001614<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
1615value specified by the parameter, depending on which basic block we
1616came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001617<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001618<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 +00001619</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001620
Chris Lattner6536cfe2002-05-06 22:08:29 +00001621<!-- _______________________________________________________________________ -->
Chris Lattnercc37aae2004-03-12 05:50:16 +00001622<div class="doc_subsubsection">
1623 <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
1624</div>
1625
Misha Brukman9d0919f2003-11-08 01:05:38 +00001626<div class="doc_text">
Chris Lattnercc37aae2004-03-12 05:50:16 +00001627
Chris Lattner6536cfe2002-05-06 22:08:29 +00001628<h5>Syntax:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001629
1630<pre>
1631 &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 +00001632</pre>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001633
Chris Lattner6536cfe2002-05-06 22:08:29 +00001634<h5>Overview:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001635
1636<p>
1637The '<tt>cast</tt>' instruction is used as the primitive means to convert
1638integers to floating point, change data type sizes, and break type safety (by
1639casting pointers).
1640</p>
1641
1642
Chris Lattner6536cfe2002-05-06 22:08:29 +00001643<h5>Arguments:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001644
1645<p>
1646The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
1647class value, and a type to cast it to, which must also be a <a
1648href="#t_firstclass">first class</a> type.
1649</p>
1650
Chris Lattner6536cfe2002-05-06 22:08:29 +00001651<h5>Semantics:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001652
1653<p>
1654This instruction follows the C rules for explicit casts when determining how the
1655data being cast must change to fit in its new container.
1656</p>
1657
1658<p>
1659When casting to bool, any value that would be considered true in the context of
1660a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
1661all else are '<tt>false</tt>'.
1662</p>
1663
1664<p>
1665When extending an integral value from a type of one signness to another (for
1666example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
1667<b>source</b> value is signed, and zero-extended if the source value is
1668unsigned. <tt>bool</tt> values are always zero extended into either zero or
1669one.
1670</p>
1671
Chris Lattner33ba0d92001-07-09 00:26:23 +00001672<h5>Example:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001673
1674<pre>
1675 %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattner7bae3952002-06-25 18:03:17 +00001676 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001677</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001678</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001679
1680<!-- _______________________________________________________________________ -->
1681<div class="doc_subsubsection">
1682 <a name="i_select">'<tt>select</tt>' Instruction</a>
1683</div>
1684
1685<div class="doc_text">
1686
1687<h5>Syntax:</h5>
1688
1689<pre>
1690 &lt;result&gt; = select bool &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
1691</pre>
1692
1693<h5>Overview:</h5>
1694
1695<p>
1696The '<tt>select</tt>' instruction is used to choose one value based on a
1697condition, without branching.
1698</p>
1699
1700
1701<h5>Arguments:</h5>
1702
1703<p>
1704The '<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.
1705</p>
1706
1707<h5>Semantics:</h5>
1708
1709<p>
1710If the boolean condition evaluates to true, the instruction returns the first
1711value argument, otherwise it returns the second value argument.
1712</p>
1713
1714<h5>Example:</h5>
1715
1716<pre>
1717 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
1718</pre>
1719</div>
1720
1721
1722
1723
1724
Chris Lattner33ba0d92001-07-09 00:26:23 +00001725<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001726<div class="doc_subsubsection"> <a name="i_call">'<tt>call</tt>'
1727Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001728<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001729<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001730<pre> &lt;result&gt; = call &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +00001731<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001732<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001733<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001734<p>This instruction requires several arguments:</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001735<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00001736 <li>
1737 <p>'<tt>ty</tt>': shall be the signature of the pointer to function
1738value being invoked. The argument types must match the types implied
1739by this signature.</p>
1740 </li>
1741 <li>
1742 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a
1743function to be invoked. In most cases, this is a direct function
1744invocation, but indirect <tt>call</tt>s are just as possible,
1745calling an arbitrary pointer to function values.</p>
1746 </li>
1747 <li>
1748 <p>'<tt>function args</tt>': argument list whose types match the
1749function signature argument types. If the function signature
1750indicates the function accepts a variable number of arguments, the
1751extra arguments can be specified.</p>
1752 </li>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001753</ol>
Chris Lattner00950542001-06-06 20:29:01 +00001754<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001755<p>The '<tt>call</tt>' instruction is used to cause control flow to
1756transfer to a specified function, with its incoming arguments bound to
1757the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
1758instruction in the called function, control flow continues with the
1759instruction after the function call, and the return value of the
1760function is bound to the result argument. This is a simpler case of
1761the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001762<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001763<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 +00001764</div>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001765
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001766<!-- _______________________________________________________________________ -->
Chris Lattnere19d7a72004-09-27 21:51:25 +00001767<div class="doc_subsubsection">
1768 <a name="i_vanext">'<tt>vanext</tt>' Instruction</a>
1769</div>
1770
Misha Brukman9d0919f2003-11-08 01:05:38 +00001771<div class="doc_text">
Chris Lattnere19d7a72004-09-27 21:51:25 +00001772
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001773<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001774
1775<pre>
1776 &lt;resultarglist&gt; = vanext &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;
1777</pre>
1778
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001779<h5>Overview:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001780
Chris Lattner261efe92003-11-25 01:02:51 +00001781<p>The '<tt>vanext</tt>' instruction is used to access arguments passed
1782through the "variable argument" area of a function call. It is used to
1783implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001784
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001785<h5>Arguments:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001786
1787<p>This instruction takes a <tt>va_list</tt> value and the type of the
1788argument. It returns another <tt>va_list</tt>. The actual type of
1789<tt>va_list</tt> may be defined differently for different targets. Most targets
1790use a <tt>va_list</tt> type of <tt>sbyte*</tt> or some other pointer type.</p>
1791
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001792<h5>Semantics:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001793
1794<p>The '<tt>vanext</tt>' instruction advances the specified <tt>va_list</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001795past an argument of the specified type. In conjunction with the <a
1796 href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement
1797the <tt>va_arg</tt> macro available in C. For more information, see
1798the variable argument handling <a href="#int_varargs">Intrinsic
1799Functions</a>.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001800
Chris Lattner261efe92003-11-25 01:02:51 +00001801<p>It is legal for this instruction to be called in a function which
1802does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001803function.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001804
Misha Brukman9d0919f2003-11-08 01:05:38 +00001805<p><tt>vanext</tt> is an LLVM instruction instead of an <a
Chris Lattnere19d7a72004-09-27 21:51:25 +00001806href="#intrinsics">intrinsic function</a> because it takes a type as an
1807argument. The type refers to the current argument in the <tt>va_list</tt>, it
1808tells the compiler how far on the stack it needs to advance to find the next
1809argument</p>
1810
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001811<h5>Example:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001812
Chris Lattner261efe92003-11-25 01:02:51 +00001813<p>See the <a href="#int_varargs">variable argument processing</a>
1814section.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001815
Misha Brukman9d0919f2003-11-08 01:05:38 +00001816</div>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001817
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001818<!-- _______________________________________________________________________ -->
Chris Lattnere19d7a72004-09-27 21:51:25 +00001819<div class="doc_subsubsection">
1820 <a name="i_vaarg">'<tt>vaarg</tt>' Instruction</a>
1821</div>
1822
Misha Brukman9d0919f2003-11-08 01:05:38 +00001823<div class="doc_text">
Chris Lattnere19d7a72004-09-27 21:51:25 +00001824
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001825<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001826
1827<pre>
1828 &lt;resultval&gt; = vaarg &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;
1829</pre>
1830
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001831<h5>Overview:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001832
1833<p>The '<tt>vaarg</tt>' instruction is used to access arguments passed through
1834the "variable argument" area of a function call. It is used to implement the
1835<tt>va_arg</tt> macro in C.</p>
1836
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001837<h5>Arguments:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001838
1839<p>This instruction takes a <tt>va_list</tt> value and the type of the
1840argument. It returns a value of the specified argument type. Again, the actual
1841type of <tt>va_list</tt> is target specific.</p>
1842
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001843<h5>Semantics:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001844
1845<p>The '<tt>vaarg</tt>' instruction loads an argument of the specified type from
1846the specified <tt>va_list</tt>. In conjunction with the <a
1847href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to implement the
1848<tt>va_arg</tt> macro available in C. For more information, see the variable
1849argument handling <a href="#int_varargs">Intrinsic Functions</a>.</p>
1850
1851<p>It is legal for this instruction to be called in a function which does not
1852take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001853function.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001854
Misha Brukman9d0919f2003-11-08 01:05:38 +00001855<p><tt>vaarg</tt> is an LLVM instruction instead of an <a
Chris Lattnere19d7a72004-09-27 21:51:25 +00001856href="#intrinsics">intrinsic function</a> because it takes an type as an
1857argument.</p>
1858
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001859<h5>Example:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001860
1861<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
1862
Misha Brukman9d0919f2003-11-08 01:05:38 +00001863</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001864
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001865<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00001866<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
1867<!-- *********************************************************************** -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001868
Misha Brukman9d0919f2003-11-08 01:05:38 +00001869<div class="doc_text">
Chris Lattner33aec9e2004-02-12 17:01:32 +00001870
1871<p>LLVM supports the notion of an "intrinsic function". These functions have
1872well known names and semantics, and are required to follow certain
1873restrictions. Overall, these instructions represent an extension mechanism for
1874the LLVM language that does not require changing all of the transformations in
1875LLVM to add to the language (or the bytecode reader/writer, the parser,
1876etc...).</p>
1877
1878<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix, this
1879prefix is reserved in LLVM for intrinsic names, thus functions may not be named
1880this. Intrinsic functions must always be external functions: you cannot define
1881the body of intrinsic functions. Intrinsic functions may only be used in call
1882or invoke instructions: it is illegal to take the address of an intrinsic
1883function. Additionally, because intrinsic functions are part of the LLVM
1884language, it is required that they all be documented here if any are added.</p>
1885
1886
1887<p>
1888Adding an intrinsic to LLVM is straight-forward if it is possible to express the
1889concept in LLVM directly (ie, code generator support is not _required_). To do
1890this, extend the default implementation of the IntrinsicLowering class to handle
1891the intrinsic. Code generators use this class to lower intrinsics they do not
1892understand to raw LLVM instructions that they do.
1893</p>
1894
Misha Brukman9d0919f2003-11-08 01:05:38 +00001895</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001896
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001897<!-- ======================================================================= -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001898<div class="doc_subsection">
1899 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
1900</div>
1901
Misha Brukman9d0919f2003-11-08 01:05:38 +00001902<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00001903
Misha Brukman9d0919f2003-11-08 01:05:38 +00001904<p>Variable argument support is defined in LLVM with the <a
Chris Lattner261efe92003-11-25 01:02:51 +00001905 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
1906intrinsic functions. These functions are related to the similarly
1907named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00001908
Chris Lattner261efe92003-11-25 01:02:51 +00001909<p>All of these functions operate on arguments that use a
1910target-specific value type "<tt>va_list</tt>". The LLVM assembly
1911language reference manual does not define what this type is, so all
1912transformations should be prepared to handle intrinsics with any type
1913used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00001914
Misha Brukman9d0919f2003-11-08 01:05:38 +00001915<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner261efe92003-11-25 01:02:51 +00001916instruction and the variable argument handling intrinsic functions are
1917used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00001918
Chris Lattner33aec9e2004-02-12 17:01:32 +00001919<pre>
1920int %test(int %X, ...) {
1921 ; Initialize variable argument processing
1922 %ap = call sbyte* %<a href="#i_va_start">llvm.va_start</a>()
1923
1924 ; Read a single integer argument
1925 %tmp = vaarg sbyte* %ap, int
1926
1927 ; Advance to the next argument
1928 %ap2 = vanext sbyte* %ap, int
1929
1930 ; Demonstrate usage of llvm.va_copy and llvm.va_end
1931 %aq = call sbyte* %<a href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2)
1932 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %aq)
1933
1934 ; Stop processing of arguments.
1935 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %ap2)
1936 ret int %tmp
1937}
1938</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001939</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001940
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001941<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001942<div class="doc_subsubsection">
1943 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
1944</div>
1945
1946
Misha Brukman9d0919f2003-11-08 01:05:38 +00001947<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001948<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001949<pre> call &lt;va_list&gt; ()* %llvm.va_start()<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001950<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001951<p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt>&lt;arglist&gt;</tt>
1952for subsequent use by the variable argument intrinsics.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001953<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001954<p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001955macro available in C. In a target-dependent way, it initializes and
1956returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt>
1957will produce the first variable argument passed to the function. Unlike
1958the C <tt>va_start</tt> macro, this intrinsic does not need to know the
1959last argument of the function, the compiler can figure that out.</p>
1960<p>Note that this intrinsic function is only legal to be called from
1961within the body of a variable argument function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001962</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001963
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001964<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001965<div class="doc_subsubsection">
1966 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
1967</div>
1968
Misha Brukman9d0919f2003-11-08 01:05:38 +00001969<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001970<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001971<pre> call void (&lt;va_list&gt;)* %llvm.va_end(&lt;va_list&gt; &lt;arglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001972<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001973<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
1974which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
1975or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001976<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001977<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001978<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001979<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001980macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
1981Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
1982 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
1983with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001984</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001985
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001986<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001987<div class="doc_subsubsection">
1988 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
1989</div>
1990
Misha Brukman9d0919f2003-11-08 01:05:38 +00001991<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00001992
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001993<h5>Syntax:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00001994
1995<pre>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001996 call &lt;va_list&gt; (&lt;va_list&gt;)* %llvm.va_copy(&lt;va_list&gt; &lt;destarglist&gt;)
Chris Lattnerd7923912004-05-23 21:06:01 +00001997</pre>
1998
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001999<h5>Overview:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002000
2001<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position
2002from the source argument list to the destination argument list.</p>
2003
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002004<h5>Arguments:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002005
Misha Brukman9d0919f2003-11-08 01:05:38 +00002006<p>The argument is the <tt>va_list</tt> to copy.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002007
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002008<h5>Semantics:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002009
Misha Brukman9d0919f2003-11-08 01:05:38 +00002010<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
Chris Lattnerd7923912004-05-23 21:06:01 +00002011macro available in C. In a target-dependent way, it copies the source
2012<tt>va_list</tt> element into the returned list. This intrinsic is necessary
Chris Lattnerfcd37252004-06-21 22:52:48 +00002013because the <tt><a href="#i_va_start">llvm.va_start</a></tt> intrinsic may be
Chris Lattnerd7923912004-05-23 21:06:01 +00002014arbitrarily complex and require memory allocation, for example.</p>
2015
Misha Brukman9d0919f2003-11-08 01:05:38 +00002016</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002017
Chris Lattner33aec9e2004-02-12 17:01:32 +00002018<!-- ======================================================================= -->
2019<div class="doc_subsection">
Chris Lattnerd7923912004-05-23 21:06:01 +00002020 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
2021</div>
2022
2023<div class="doc_text">
2024
2025<p>
2026LLVM support for <a href="GarbageCollection.html">Accurate Garbage
2027Collection</a> requires the implementation and generation of these intrinsics.
2028These intrinsics allow identification of <a href="#i_gcroot">GC roots on the
2029stack</a>, as well as garbage collector implementations that require <a
2030href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers.
2031Front-ends for type-safe garbage collected languages should generate these
2032intrinsics to make use of the LLVM garbage collectors. For more details, see <a
2033href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
2034</p>
2035</div>
2036
2037<!-- _______________________________________________________________________ -->
2038<div class="doc_subsubsection">
2039 <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
2040</div>
2041
2042<div class="doc_text">
2043
2044<h5>Syntax:</h5>
2045
2046<pre>
2047 call void (&lt;ty&gt;**, &lt;ty2&gt;*)* %llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
2048</pre>
2049
2050<h5>Overview:</h5>
2051
2052<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existance of a GC root to
2053the code generator, and allows some metadata to be associated with it.</p>
2054
2055<h5>Arguments:</h5>
2056
2057<p>The first argument specifies the address of a stack object that contains the
2058root pointer. The second pointer (which must be either a constant or a global
2059value address) contains the meta-data to be associated with the root.</p>
2060
2061<h5>Semantics:</h5>
2062
2063<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
2064location. At compile-time, the code generator generates information to allow
2065the runtime to find the pointer at GC safe points.
2066</p>
2067
2068</div>
2069
2070
2071<!-- _______________________________________________________________________ -->
2072<div class="doc_subsubsection">
2073 <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
2074</div>
2075
2076<div class="doc_text">
2077
2078<h5>Syntax:</h5>
2079
2080<pre>
2081 call sbyte* (sbyte**)* %llvm.gcread(sbyte** %Ptr)
2082</pre>
2083
2084<h5>Overview:</h5>
2085
2086<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
2087locations, allowing garbage collector implementations that require read
2088barriers.</p>
2089
2090<h5>Arguments:</h5>
2091
2092<p>The argument is the address to read from, which should be an address
2093allocated from the garbage collector.</p>
2094
2095<h5>Semantics:</h5>
2096
2097<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
2098instruction, but may be replaced with substantially more complex code by the
2099garbage collector runtime, as needed.</p>
2100
2101</div>
2102
2103
2104<!-- _______________________________________________________________________ -->
2105<div class="doc_subsubsection">
2106 <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
2107</div>
2108
2109<div class="doc_text">
2110
2111<h5>Syntax:</h5>
2112
2113<pre>
2114 call void (sbyte*, sbyte**)* %llvm.gcwrite(sbyte* %P1, sbyte** %P2)
2115</pre>
2116
2117<h5>Overview:</h5>
2118
2119<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
2120locations, allowing garbage collector implementations that require write
2121barriers (such as generational or reference counting collectors).</p>
2122
2123<h5>Arguments:</h5>
2124
2125<p>The first argument is the reference to store, and the second is the heap
2126location to store to.</p>
2127
2128<h5>Semantics:</h5>
2129
2130<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
2131instruction, but may be replaced with substantially more complex code by the
2132garbage collector runtime, as needed.</p>
2133
2134</div>
2135
2136
2137
2138<!-- ======================================================================= -->
2139<div class="doc_subsection">
Chris Lattner10610642004-02-14 04:08:35 +00002140 <a name="int_codegen">Code Generator Intrinsics</a>
2141</div>
2142
2143<div class="doc_text">
2144<p>
2145These intrinsics are provided by LLVM to expose special features that may only
2146be implemented with code generator support.
2147</p>
2148
2149</div>
2150
2151<!-- _______________________________________________________________________ -->
2152<div class="doc_subsubsection">
2153 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
2154</div>
2155
2156<div class="doc_text">
2157
2158<h5>Syntax:</h5>
2159<pre>
2160 call void* ()* %llvm.returnaddress(uint &lt;level&gt;)
2161</pre>
2162
2163<h5>Overview:</h5>
2164
2165<p>
2166The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
2167indicating the return address of the current function or one of its callers.
2168</p>
2169
2170<h5>Arguments:</h5>
2171
2172<p>
2173The argument to this intrinsic indicates which function to return the address
2174for. Zero indicates the calling function, one indicates its caller, etc. The
2175argument is <b>required</b> to be a constant integer value.
2176</p>
2177
2178<h5>Semantics:</h5>
2179
2180<p>
2181The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
2182the return address of the specified call frame, or zero if it cannot be
2183identified. The value returned by this intrinsic is likely to be incorrect or 0
2184for arguments other than zero, so it should only be used for debugging purposes.
2185</p>
2186
2187<p>
2188Note that calling this intrinsic does not prevent function inlining or other
2189aggressive transformations, so the value returned may not that of the obvious
2190source-language caller.
2191</p>
2192</div>
2193
2194
2195<!-- _______________________________________________________________________ -->
2196<div class="doc_subsubsection">
2197 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
2198</div>
2199
2200<div class="doc_text">
2201
2202<h5>Syntax:</h5>
2203<pre>
2204 call void* ()* %llvm.frameaddress(uint &lt;level&gt;)
2205</pre>
2206
2207<h5>Overview:</h5>
2208
2209<p>
2210The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
2211pointer value for the specified stack frame.
2212</p>
2213
2214<h5>Arguments:</h5>
2215
2216<p>
2217The argument to this intrinsic indicates which function to return the frame
2218pointer for. Zero indicates the calling function, one indicates its caller,
2219etc. The argument is <b>required</b> to be a constant integer value.
2220</p>
2221
2222<h5>Semantics:</h5>
2223
2224<p>
2225The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
2226the frame address of the specified call frame, or zero if it cannot be
2227identified. The value returned by this intrinsic is likely to be incorrect or 0
2228for arguments other than zero, so it should only be used for debugging purposes.
2229</p>
2230
2231<p>
2232Note that calling this intrinsic does not prevent function inlining or other
2233aggressive transformations, so the value returned may not that of the obvious
2234source-language caller.
2235</p>
2236</div>
2237
John Criswell7123e272004-04-09 16:43:20 +00002238<!-- ======================================================================= -->
2239<div class="doc_subsection">
2240 <a name="int_os">Operating System Intrinsics</a>
2241</div>
2242
2243<div class="doc_text">
2244<p>
2245These intrinsics are provided by LLVM to support the implementation of
2246operating system level code.
2247</p>
2248
2249</div>
John Criswell183402a2004-04-12 15:02:16 +00002250
John Criswellcfd3bac2004-04-09 15:23:37 +00002251<!-- _______________________________________________________________________ -->
2252<div class="doc_subsubsection">
2253 <a name="i_readport">'<tt>llvm.readport</tt>' Intrinsic</a>
2254</div>
2255
2256<div class="doc_text">
2257
2258<h5>Syntax:</h5>
2259<pre>
John Criswell7123e272004-04-09 16:43:20 +00002260 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 +00002261</pre>
2262
2263<h5>Overview:</h5>
2264
2265<p>
John Criswell7123e272004-04-09 16:43:20 +00002266The '<tt>llvm.readport</tt>' intrinsic reads data from the specified hardware
2267I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002268</p>
2269
2270<h5>Arguments:</h5>
2271
2272<p>
John Criswell7123e272004-04-09 16:43:20 +00002273The argument to this intrinsic indicates the hardware I/O address from which
2274to read the data. The address is in the hardware I/O address namespace (as
2275opposed to being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002276</p>
2277
2278<h5>Semantics:</h5>
2279
2280<p>
John Criswell7123e272004-04-09 16:43:20 +00002281The '<tt>llvm.readport</tt>' intrinsic reads data from the hardware I/O port
2282specified by <i>address</i> and returns the value. The address and return
2283value must be integers, but the size is dependent upon the platform upon which
2284the program is code generated. For example, on x86, the address must be an
2285unsigned 16 bit value, and the return value must be 8, 16, or 32 bits.
John Criswellcfd3bac2004-04-09 15:23:37 +00002286</p>
2287
2288</div>
2289
2290<!-- _______________________________________________________________________ -->
2291<div class="doc_subsubsection">
2292 <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a>
2293</div>
2294
2295<div class="doc_text">
2296
2297<h5>Syntax:</h5>
2298<pre>
John Criswell7123e272004-04-09 16:43:20 +00002299 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 +00002300</pre>
2301
2302<h5>Overview:</h5>
2303
2304<p>
John Criswell7123e272004-04-09 16:43:20 +00002305The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified hardware
2306I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002307</p>
2308
2309<h5>Arguments:</h5>
2310
2311<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002312The first argument is the value to write to the I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002313</p>
2314
2315<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002316The second argument indicates the hardware I/O address to which data should be
2317written. The address is in the hardware I/O address namespace (as opposed to
2318being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002319</p>
2320
2321<h5>Semantics:</h5>
2322
2323<p>
2324The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port
2325specified by <i>address</i>. The address and value must be integers, but the
2326size is dependent upon the platform upon which the program is code generated.
John Criswell7123e272004-04-09 16:43:20 +00002327For example, on x86, the address must be an unsigned 16 bit value, and the
2328value written must be 8, 16, or 32 bits in length.
John Criswellcfd3bac2004-04-09 15:23:37 +00002329</p>
2330
2331</div>
Chris Lattner10610642004-02-14 04:08:35 +00002332
John Criswell183402a2004-04-12 15:02:16 +00002333<!-- _______________________________________________________________________ -->
2334<div class="doc_subsubsection">
2335 <a name="i_readio">'<tt>llvm.readio</tt>' Intrinsic</a>
2336</div>
2337
2338<div class="doc_text">
2339
2340<h5>Syntax:</h5>
2341<pre>
John Criswell96db6fc2004-04-12 16:33:19 +00002342 call &lt;result&gt; (&lt;ty&gt;*)* %llvm.readio (&lt;ty&gt; * &lt;pointer&gt;)
John Criswell183402a2004-04-12 15:02:16 +00002343</pre>
2344
2345<h5>Overview:</h5>
2346
2347<p>
2348The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
2349address.
2350</p>
2351
2352<h5>Arguments:</h5>
2353
2354<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002355The argument to this intrinsic is a pointer indicating the memory address from
2356which to read the data. The data must be a
2357<a href="#t_firstclass">first class</a> type.
John Criswell183402a2004-04-12 15:02:16 +00002358</p>
2359
2360<h5>Semantics:</h5>
2361
2362<p>
2363The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
John Criswell96db6fc2004-04-12 16:33:19 +00002364location specified by <i>pointer</i> and returns the value. The argument must
2365be a pointer, and the return value must be a
2366<a href="#t_firstclass">first class</a> type. However, certain architectures
2367may not support I/O on all first class types. For example, 32 bit processors
2368may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00002369</p>
2370
2371<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002372This intrinsic enforces an in-order memory model for llvm.readio and
2373llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2374scheduled processors may execute loads and stores out of order, re-ordering at
2375run time accesses to memory mapped I/O registers. Using these intrinsics
2376ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00002377</p>
2378
2379</div>
2380
2381<!-- _______________________________________________________________________ -->
2382<div class="doc_subsubsection">
2383 <a name="i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a>
2384</div>
2385
2386<div class="doc_text">
2387
2388<h5>Syntax:</h5>
2389<pre>
John Criswell96db6fc2004-04-12 16:33:19 +00002390 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 +00002391</pre>
2392
2393<h5>Overview:</h5>
2394
2395<p>
2396The '<tt>llvm.writeio</tt>' intrinsic writes data to the specified memory
2397mapped I/O address.
2398</p>
2399
2400<h5>Arguments:</h5>
2401
2402<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002403The first argument is the value to write to the memory mapped I/O location.
2404The second argument is a pointer indicating the memory address to which the
2405data should be written.
John Criswell183402a2004-04-12 15:02:16 +00002406</p>
2407
2408<h5>Semantics:</h5>
2409
2410<p>
2411The '<tt>llvm.writeio</tt>' intrinsic writes <i>value</i> to the memory mapped
John Criswell96db6fc2004-04-12 16:33:19 +00002412I/O address specified by <i>pointer</i>. The value must be a
2413<a href="#t_firstclass">first class</a> type. However, certain architectures
2414may not support I/O on all first class types. For example, 32 bit processors
2415may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00002416</p>
2417
2418<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002419This intrinsic enforces an in-order memory model for llvm.readio and
2420llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2421scheduled processors may execute loads and stores out of order, re-ordering at
2422run time accesses to memory mapped I/O registers. Using these intrinsics
2423ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00002424</p>
2425
2426</div>
2427
Chris Lattner10610642004-02-14 04:08:35 +00002428<!-- ======================================================================= -->
2429<div class="doc_subsection">
Chris Lattner33aec9e2004-02-12 17:01:32 +00002430 <a name="int_libc">Standard C Library Intrinsics</a>
2431</div>
2432
2433<div class="doc_text">
2434<p>
Chris Lattner10610642004-02-14 04:08:35 +00002435LLVM provides intrinsics for a few important standard C library functions.
2436These intrinsics allow source-language front-ends to pass information about the
2437alignment of the pointer arguments to the code generator, providing opportunity
2438for more efficient code generation.
Chris Lattner33aec9e2004-02-12 17:01:32 +00002439</p>
2440
2441</div>
2442
2443<!-- _______________________________________________________________________ -->
2444<div class="doc_subsubsection">
2445 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
2446</div>
2447
2448<div class="doc_text">
2449
2450<h5>Syntax:</h5>
2451<pre>
2452 call void (sbyte*, sbyte*, uint, uint)* %llvm.memcpy(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2453 uint &lt;len&gt;, uint &lt;align&gt;)
2454</pre>
2455
2456<h5>Overview:</h5>
2457
2458<p>
2459The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2460location to the destination location.
2461</p>
2462
2463<p>
2464Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
2465does not return a value, and takes an extra alignment argument.
2466</p>
2467
2468<h5>Arguments:</h5>
2469
2470<p>
2471The first argument is a pointer to the destination, the second is a pointer to
2472the source. The third argument is an (arbitrarily sized) integer argument
2473specifying the number of bytes to copy, and the fourth argument is the alignment
2474of the source and destination locations.
2475</p>
2476
Chris Lattner3301ced2004-02-12 21:18:15 +00002477<p>
2478If the call to this intrinisic has an alignment value that is not 0 or 1, then
2479the caller guarantees that the size of the copy is a multiple of the alignment
2480and that both the source and destination pointers are aligned to that boundary.
2481</p>
2482
Chris Lattner33aec9e2004-02-12 17:01:32 +00002483<h5>Semantics:</h5>
2484
2485<p>
2486The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2487location to the destination location, which are not allowed to overlap. It
2488copies "len" bytes of memory over. If the argument is known to be aligned to
2489some boundary, this can be specified as the fourth argument, otherwise it should
2490be set to 0 or 1.
2491</p>
2492</div>
2493
2494
Chris Lattner0eb51b42004-02-12 18:10:10 +00002495<!-- _______________________________________________________________________ -->
2496<div class="doc_subsubsection">
2497 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
2498</div>
2499
2500<div class="doc_text">
2501
2502<h5>Syntax:</h5>
2503<pre>
2504 call void (sbyte*, sbyte*, uint, uint)* %llvm.memmove(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2505 uint &lt;len&gt;, uint &lt;align&gt;)
2506</pre>
2507
2508<h5>Overview:</h5>
2509
2510<p>
2511The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
2512location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>'
2513intrinsic but allows the two memory locations to overlap.
2514</p>
2515
2516<p>
2517Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
2518does not return a value, and takes an extra alignment argument.
2519</p>
2520
2521<h5>Arguments:</h5>
2522
2523<p>
2524The first argument is a pointer to the destination, the second is a pointer to
2525the source. The third argument is an (arbitrarily sized) integer argument
2526specifying the number of bytes to copy, and the fourth argument is the alignment
2527of the source and destination locations.
2528</p>
2529
Chris Lattner3301ced2004-02-12 21:18:15 +00002530<p>
2531If the call to this intrinisic has an alignment value that is not 0 or 1, then
2532the caller guarantees that the size of the copy is a multiple of the alignment
2533and that both the source and destination pointers are aligned to that boundary.
2534</p>
2535
Chris Lattner0eb51b42004-02-12 18:10:10 +00002536<h5>Semantics:</h5>
2537
2538<p>
2539The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
2540location to the destination location, which may overlap. It
2541copies "len" bytes of memory over. If the argument is known to be aligned to
2542some boundary, this can be specified as the fourth argument, otherwise it should
2543be set to 0 or 1.
2544</p>
2545</div>
2546
Chris Lattner8ff75902004-01-06 05:31:32 +00002547
Chris Lattner10610642004-02-14 04:08:35 +00002548<!-- _______________________________________________________________________ -->
2549<div class="doc_subsubsection">
2550 <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a>
2551</div>
2552
2553<div class="doc_text">
2554
2555<h5>Syntax:</h5>
2556<pre>
2557 call void (sbyte*, ubyte, uint, uint)* %llvm.memset(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
2558 uint &lt;len&gt;, uint &lt;align&gt;)
2559</pre>
2560
2561<h5>Overview:</h5>
2562
2563<p>
2564The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular
2565byte value.
2566</p>
2567
2568<p>
2569Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
2570does not return a value, and takes an extra alignment argument.
2571</p>
2572
2573<h5>Arguments:</h5>
2574
2575<p>
2576The first argument is a pointer to the destination to fill, the second is the
2577byte value to fill it with, the third argument is an (arbitrarily sized) integer
2578argument specifying the number of bytes to fill, and the fourth argument is the
2579known alignment of destination location.
2580</p>
2581
2582<p>
2583If the call to this intrinisic has an alignment value that is not 0 or 1, then
2584the caller guarantees that the size of the copy is a multiple of the alignment
2585and that the destination pointer is aligned to that boundary.
2586</p>
2587
2588<h5>Semantics:</h5>
2589
2590<p>
2591The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the
2592destination location. If the argument is known to be aligned to some boundary,
2593this can be specified as the fourth argument, otherwise it should be set to 0 or
25941.
2595</p>
2596</div>
2597
2598
Chris Lattner32006282004-06-11 02:28:03 +00002599<!-- _______________________________________________________________________ -->
2600<div class="doc_subsubsection">
Alkis Evlogimenos26bbe932004-06-13 01:16:15 +00002601 <a name="i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a>
2602</div>
2603
2604<div class="doc_text">
2605
2606<h5>Syntax:</h5>
2607<pre>
2608 call bool (&lt;float or double&gt;, &lt;float or double&gt;)* %llvm.isunordered(&lt;float or double&gt; Val1,
2609 &lt;float or double&gt; Val2)
2610</pre>
2611
2612<h5>Overview:</h5>
2613
2614<p>
2615The '<tt>llvm.isunordered</tt>' intrinsic returns true if either or both of the
2616specified floating point values is a NAN.
2617</p>
2618
2619<h5>Arguments:</h5>
2620
2621<p>
2622The arguments are floating point numbers of the same type.
2623</p>
2624
2625<h5>Semantics:</h5>
2626
2627<p>
2628If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise
2629false.
2630</p>
2631</div>
2632
2633
Chris Lattner32006282004-06-11 02:28:03 +00002634
2635
Chris Lattner8ff75902004-01-06 05:31:32 +00002636<!-- ======================================================================= -->
2637<div class="doc_subsection">
2638 <a name="int_debugger">Debugger Intrinsics</a>
2639</div>
2640
2641<div class="doc_text">
2642<p>
2643The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
2644are described in the <a
2645href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
2646Debugging</a> document.
2647</p>
2648</div>
2649
2650
Chris Lattner00950542001-06-06 20:29:01 +00002651<!-- *********************************************************************** -->
Chris Lattner00950542001-06-06 20:29:01 +00002652<hr>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002653<address>
2654 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
2655 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
2656 <a href="http://validator.w3.org/check/referer"><img
2657 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
2658
2659 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
2660 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
2661 Last modified: $Date$
2662</address>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002663</body>
2664</html>