blob: 18912ac07e772022b5e050433fd0f9364acc0c03 [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>
Chris Lattner35eca582004-10-16 18:04:13 +000054 <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000055 </ol>
56 </li>
Chris Lattner00950542001-06-06 20:29:01 +000057 <li><a href="#binaryops">Binary Operations</a>
58 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000059 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
60 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
61 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
62 <li><a href="#i_div">'<tt>div</tt>' Instruction</a></li>
63 <li><a href="#i_rem">'<tt>rem</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000064 <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000065 </ol>
66 </li>
Chris Lattner00950542001-06-06 20:29:01 +000067 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
68 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000069 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000070 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000071 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
72 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
73 <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000074 </ol>
75 </li>
Chris Lattner00950542001-06-06 20:29:01 +000076 <li><a href="#memoryops">Memory Access Operations</a>
77 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000078 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
79 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
80 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
81 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
82 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
83 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
84 </ol>
85 </li>
Chris Lattner00950542001-06-06 20:29:01 +000086 <li><a href="#otherops">Other Operations</a>
87 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000088 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000089 <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li>
Chris Lattnercc37aae2004-03-12 05:50:16 +000090 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000091 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000092 <li><a href="#i_vanext">'<tt>vanext</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000093 <li><a href="#i_vaarg">'<tt>vaarg</tt>' Instruction</a></li>
Chris Lattner00950542001-06-06 20:29:01 +000094 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +000095 </li>
Chris Lattner00950542001-06-06 20:29:01 +000096 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +000097 </li>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +000098 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +000099 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000100 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
101 <ol>
102 <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
103 <li><a href="#i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
104 <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
105 </ol>
106 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000107 <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
108 <ol>
109 <li><a href="#i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li>
110 <li><a href="#i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li>
111 <li><a href="#i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li>
112 </ol>
113 </li>
Chris Lattner10610642004-02-14 04:08:35 +0000114 <li><a href="#int_codegen">Code Generator Intrinsics</a>
115 <ol>
116 <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
117 <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
John Criswell7123e272004-04-09 16:43:20 +0000118 </ol>
119 </li>
120 <li><a href="#int_os">Operating System Intrinsics</a>
121 <ol>
Chris Lattner32006282004-06-11 02:28:03 +0000122 <li><a href="#i_readport">'<tt>llvm.readport</tt>' Intrinsic</a></li>
123 <li><a href="#i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a></li>
John Criswell183402a2004-04-12 15:02:16 +0000124 <li><a href="#i_readio">'<tt>llvm.readio</tt>' Intrinsic</a></li>
125 <li><a href="#i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000126 </ol>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000127 <li><a href="#int_libc">Standard C Library Intrinsics</a>
128 <ol>
129 <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li>
Chris Lattner0eb51b42004-02-12 18:10:10 +0000130 <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li>
Chris Lattner10610642004-02-14 04:08:35 +0000131 <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li>
Alkis Evlogimenos96853722004-06-12 19:19:14 +0000132 <li><a href="#i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a></li>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000133 </ol>
134 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000135 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000136 </ol>
137 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000138</ol>
Chris Lattnerd7923912004-05-23 21:06:01 +0000139
140<div class="doc_author">
141 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
142 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000143</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000144
Chris Lattner00950542001-06-06 20:29:01 +0000145<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000146<div class="doc_section"> <a name="abstract">Abstract </a></div>
147<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000148
Misha Brukman9d0919f2003-11-08 01:05:38 +0000149<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000150<p>This document is a reference manual for the LLVM assembly language.
151LLVM is an SSA based representation that provides type safety,
152low-level operations, flexibility, and the capability of representing
153'all' high-level languages cleanly. It is the common code
154representation used throughout all phases of the LLVM compilation
155strategy.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000156</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000157
Chris Lattner00950542001-06-06 20:29:01 +0000158<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000159<div class="doc_section"> <a name="introduction">Introduction</a> </div>
160<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000161
Misha Brukman9d0919f2003-11-08 01:05:38 +0000162<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000163
Chris Lattner261efe92003-11-25 01:02:51 +0000164<p>The LLVM code representation is designed to be used in three
165different forms: as an in-memory compiler IR, as an on-disk bytecode
166representation (suitable for fast loading by a Just-In-Time compiler),
167and as a human readable assembly language representation. This allows
168LLVM to provide a powerful intermediate representation for efficient
169compiler transformations and analysis, while providing a natural means
170to debug and visualize the transformations. The three different forms
171of LLVM are all equivalent. This document describes the human readable
172representation and notation.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000173
Chris Lattner261efe92003-11-25 01:02:51 +0000174<p>The LLVM representation aims to be a light-weight and low-level
175while being expressive, typed, and extensible at the same time. It
176aims to be a "universal IR" of sorts, by being at a low enough level
177that high-level ideas may be cleanly mapped to it (similar to how
178microprocessors are "universal IR's", allowing many source languages to
179be mapped to them). By providing type information, LLVM can be used as
180the target of optimizations: for example, through pointer analysis, it
181can be proven that a C automatic variable is never accessed outside of
182the current function... allowing it to be promoted to a simple SSA
183value instead of a memory location.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000184
Misha Brukman9d0919f2003-11-08 01:05:38 +0000185</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000186
Chris Lattner00950542001-06-06 20:29:01 +0000187<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000188<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000189
Misha Brukman9d0919f2003-11-08 01:05:38 +0000190<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000191
Chris Lattner261efe92003-11-25 01:02:51 +0000192<p>It is important to note that this document describes 'well formed'
193LLVM assembly language. There is a difference between what the parser
194accepts and what is considered 'well formed'. For example, the
195following instruction is syntactically okay, but not well formed:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000196
197<pre>
198 %x = <a href="#i_add">add</a> int 1, %x
199</pre>
200
Chris Lattner261efe92003-11-25 01:02:51 +0000201<p>...because the definition of <tt>%x</tt> does not dominate all of
202its uses. The LLVM infrastructure provides a verification pass that may
203be used to verify that an LLVM module is well formed. This pass is
204automatically run by the parser after parsing input assembly, and by
205the optimizer before it outputs bytecode. The violations pointed out
206by the verifier pass indicate bugs in transformation passes or input to
207the parser.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000208
Chris Lattner261efe92003-11-25 01:02:51 +0000209<!-- Describe the typesetting conventions here. --> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000210
Chris Lattner00950542001-06-06 20:29:01 +0000211<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000212<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000213<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000214
Misha Brukman9d0919f2003-11-08 01:05:38 +0000215<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000216
Chris Lattner261efe92003-11-25 01:02:51 +0000217<p>LLVM uses three different forms of identifiers, for different
218purposes:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000219
Chris Lattner00950542001-06-06 20:29:01 +0000220<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000221 <li>Numeric constants are represented as you would expect: 12, -3
John Criswell4457dc92004-04-09 16:48:45 +0000222123.421, etc. Floating point constants have an optional hexadecimal
Chris Lattner261efe92003-11-25 01:02:51 +0000223notation.</li>
224 <li>Named values are represented as a string of characters with a '%'
225prefix. For example, %foo, %DivisionByZero,
226%a.really.long.identifier. The actual regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
227Identifiers which require other characters in their names can be
228surrounded with quotes. In this way, anything except a <tt>"</tt>
229character can be used in a name.</li>
230 <li>Unnamed values are represented as an unsigned numeric value with
231a '%' prefix. For example, %12, %2, %44.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000232</ol>
John Criswell6794d922004-03-12 21:19:06 +0000233<p>LLVM requires that values start with a '%' sign for two reasons:
Chris Lattner261efe92003-11-25 01:02:51 +0000234Compilers don't need to worry about name clashes with reserved words,
235and the set of reserved words may be expanded in the future without
236penalty. Additionally, unnamed identifiers allow a compiler to quickly
237come up with a temporary variable without having to avoid symbol table
238conflicts.</p>
239<p>Reserved words in LLVM are very similar to reserved words in other
240languages. There are keywords for different opcodes ('<tt><a
241 href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
242 href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
243 href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>',
244etc...), and others. These reserved words cannot conflict with
245variable names, because none of them start with a '%' character.</p>
246<p>Here is an example of LLVM code to multiply the integer variable '<tt>%X</tt>'
247by 8:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000248<p>The easy way:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000249<pre> %result = <a href="#i_mul">mul</a> uint %X, 8<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000250<p>After strength reduction:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000251<pre> %result = <a href="#i_shl">shl</a> uint %X, ubyte 3<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000252<p>And the hard way:</p>
Chris Lattner261efe92003-11-25 01:02:51 +0000253<pre> <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
254 <a
255 href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
256 %result = <a
257 href="#i_add">add</a> uint %1, %1<br></pre>
258<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
259important lexical features of LLVM:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000260<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000261 <li>Comments are delimited with a '<tt>;</tt>' and go until the end
262of line.</li>
263 <li>Unnamed temporaries are created when the result of a computation
264is not assigned to a named value.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000265 <li>Unnamed temporaries are numbered sequentially</li>
266</ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000267<p>...and it also show a convention that we follow in this document.
268When demonstrating instructions, we will follow an instruction with a
269comment that defines the type and name of value produced. Comments are
270shown in italic text.</p>
271<p>The one non-intuitive notation for constants is the optional
272hexidecimal form of floating point constants. For example, the form '<tt>double
Chris Lattner2b7d3202002-05-06 03:03:22 +00002730x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
Chris Lattner261efe92003-11-25 01:02:51 +00002744.5e+15</tt>' which is also supported by the parser. The only time
275hexadecimal floating point constants are useful (and the only time that
276they are generated by the disassembler) is when an FP constant has to
277be emitted that is not representable as a decimal floating point number
278exactly. For example, NaN's, infinities, and other special cases are
279represented in their IEEE hexadecimal format so that assembly and
280disassembly do not cause any bits to change in the constants.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000281</div>
Chris Lattner00950542001-06-06 20:29:01 +0000282<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000283<div class="doc_section"> <a name="typesystem">Type System</a> </div>
284<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000285<div class="doc_text">
Misha Brukman9d0919f2003-11-08 01:05:38 +0000286<p>The LLVM type system is one of the most important features of the
Chris Lattner261efe92003-11-25 01:02:51 +0000287intermediate representation. Being typed enables a number of
288optimizations to be performed on the IR directly, without having to do
289extra analyses on the side before the transformation. A strong type
290system makes it easier to read the generated code and enables novel
291analyses and transformations that are not feasible to perform on normal
292three address code representations.</p>
Chris Lattner7bae3952002-06-25 18:03:17 +0000293<!-- The written form for the type system was heavily influenced by the
294syntactic problems with types in the C language<sup><a
Chris Lattner261efe92003-11-25 01:02:51 +0000295href="#rw_stroustrup">1</a></sup>.<p> --> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000296<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000297<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000298<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +0000299<p>The primitive types are the fundamental building blocks of the LLVM
Chris Lattner261efe92003-11-25 01:02:51 +0000300system. The current set of primitive types are as follows:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000301
302<table border="0" style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +0000303 <tbody>
304 <tr>
305 <td>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000306 <table border="1" cellspacing="0" cellpadding="4" style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +0000307 <tbody>
308 <tr>
309 <td><tt>void</tt></td>
310 <td>No value</td>
311 </tr>
312 <tr>
313 <td><tt>ubyte</tt></td>
314 <td>Unsigned 8 bit value</td>
315 </tr>
316 <tr>
317 <td><tt>ushort</tt></td>
318 <td>Unsigned 16 bit value</td>
319 </tr>
320 <tr>
321 <td><tt>uint</tt></td>
322 <td>Unsigned 32 bit value</td>
323 </tr>
324 <tr>
325 <td><tt>ulong</tt></td>
326 <td>Unsigned 64 bit value</td>
327 </tr>
328 <tr>
329 <td><tt>float</tt></td>
330 <td>32 bit floating point value</td>
331 </tr>
332 <tr>
333 <td><tt>label</tt></td>
334 <td>Branch destination</td>
335 </tr>
336 </tbody>
337 </table>
338 </td>
339 <td valign="top">
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000340 <table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +0000341 <tbody>
342 <tr>
343 <td><tt>bool</tt></td>
344 <td>True or False value</td>
345 </tr>
346 <tr>
347 <td><tt>sbyte</tt></td>
348 <td>Signed 8 bit value</td>
349 </tr>
350 <tr>
351 <td><tt>short</tt></td>
352 <td>Signed 16 bit value</td>
353 </tr>
354 <tr>
355 <td><tt>int</tt></td>
356 <td>Signed 32 bit value</td>
357 </tr>
358 <tr>
359 <td><tt>long</tt></td>
360 <td>Signed 64 bit value</td>
361 </tr>
362 <tr>
363 <td><tt>double</tt></td>
364 <td>64 bit floating point value</td>
365 </tr>
366 </tbody>
367 </table>
368 </td>
369 </tr>
370 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000371</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000372
Misha Brukman9d0919f2003-11-08 01:05:38 +0000373</div>
Chris Lattner00950542001-06-06 20:29:01 +0000374<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000375<div class="doc_subsubsection"> <a name="t_classifications">Type
376Classifications</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000377<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000378<p>These different primitive types fall into a few useful
379classifications:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000380
381<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +0000382 <tbody>
383 <tr>
384 <td><a name="t_signed">signed</a></td>
385 <td><tt>sbyte, short, int, long, float, double</tt></td>
386 </tr>
387 <tr>
388 <td><a name="t_unsigned">unsigned</a></td>
389 <td><tt>ubyte, ushort, uint, ulong</tt></td>
390 </tr>
391 <tr>
392 <td><a name="t_integer">integer</a></td>
393 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
394 </tr>
395 <tr>
396 <td><a name="t_integral">integral</a></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000397 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt>
398 </td>
Chris Lattner261efe92003-11-25 01:02:51 +0000399 </tr>
400 <tr>
401 <td><a name="t_floating">floating point</a></td>
402 <td><tt>float, double</tt></td>
403 </tr>
404 <tr>
405 <td><a name="t_firstclass">first class</a></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000406 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long,<br>
407 float, double, <a href="#t_pointer">pointer</a>,
408 <a href="#t_packed">packed</a></tt></td>
Chris Lattner261efe92003-11-25 01:02:51 +0000409 </tr>
410 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000411</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000412
Chris Lattner261efe92003-11-25 01:02:51 +0000413<p>The <a href="#t_firstclass">first class</a> types are perhaps the
414most important. Values of these types are the only ones which can be
415produced by instructions, passed as arguments, or used as operands to
416instructions. This means that all structures and arrays must be
417manipulated either by pointer or by component.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000418</div>
Chris Lattner00950542001-06-06 20:29:01 +0000419<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000420<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000421<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000422<p>The real power in LLVM comes from the derived types in the system.
423This is what allows a programmer to represent arrays, functions,
424pointers, and other useful types. Note that these derived types may be
425recursive: For example, it is possible to have a two dimensional array.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000426</div>
Chris Lattner00950542001-06-06 20:29:01 +0000427<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000428<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000429<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000430<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000431<p>The array type is a very simple derived type that arranges elements
Chris Lattner261efe92003-11-25 01:02:51 +0000432sequentially in memory. The array type requires a size (number of
433elements) and an underlying data type.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000434<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000435<pre> [&lt;# elements&gt; x &lt;elementtype&gt;]<br></pre>
436<p>The number of elements is a constant integer value, elementtype may
437be any type with a size.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000438<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000439<p> <tt>[40 x int ]</tt>: Array of 40 integer values.<br>
440<tt>[41 x int ]</tt>: Array of 41 integer values.<br>
441<tt>[40 x uint]</tt>: Array of 40 unsigned integer values.</p>
442<p> </p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000443<p>Here are some examples of multidimensional arrays:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000444
Misha Brukman9d0919f2003-11-08 01:05:38 +0000445<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000446 <tbody>
447 <tr>
448 <td><tt>[3 x [4 x int]]</tt></td>
449 <td>: 3x4 array integer values.</td>
450 </tr>
451 <tr>
452 <td><tt>[12 x [10 x float]]</tt></td>
453 <td>: 12x10 array of single precision floating point values.</td>
454 </tr>
455 <tr>
456 <td><tt>[2 x [3 x [4 x uint]]]</tt></td>
457 <td>: 2x3x4 array of unsigned integer values.</td>
458 </tr>
459 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000460</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000461
Misha Brukman9d0919f2003-11-08 01:05:38 +0000462</div>
Chris Lattner00950542001-06-06 20:29:01 +0000463<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000464<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000465<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000466<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000467<p>The function type can be thought of as a function signature. It
468consists of a return type and a list of formal parameter types.
John Criswell009900b2003-11-25 21:45:46 +0000469Function types are usually used to build virtual function tables
Chris Lattner261efe92003-11-25 01:02:51 +0000470(which are structures of pointers to functions), for indirect function
471calls, and when defining a function.</p>
John Criswell009900b2003-11-25 21:45:46 +0000472<p>
473The return type of a function type cannot be an aggregate type.
474</p>
Chris Lattner00950542001-06-06 20:29:01 +0000475<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000476<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000477<p>Where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
478specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner27f71f22003-09-03 00:41:47 +0000479which indicates that the function takes a variable number of arguments.
480Variable argument functions can access their arguments with the <a
Chris Lattner261efe92003-11-25 01:02:51 +0000481 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000482<h5>Examples:</h5>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000483
Misha Brukman9d0919f2003-11-08 01:05:38 +0000484<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000485 <tbody>
486 <tr>
487 <td><tt>int (int)</tt></td>
488 <td>: function taking an <tt>int</tt>, returning an <tt>int</tt></td>
489 </tr>
490 <tr>
491 <td><tt>float (int, int *) *</tt></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000492 <td>: <a href="#t_pointer">Pointer</a> to a function that takes an
493 <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
494 returning <tt>float</tt>.</td>
Chris Lattner261efe92003-11-25 01:02:51 +0000495 </tr>
496 <tr>
497 <td><tt>int (sbyte *, ...)</tt></td>
498 <td>: A vararg function that takes at least one <a
Misha Brukmanc24b7582004-08-12 20:16:08 +0000499 href="#t_pointer">pointer</a> to <tt>sbyte</tt> (signed char in C), which
500 returns an integer. This is the signature for <tt>printf</tt> in
501 LLVM.</td>
Chris Lattner261efe92003-11-25 01:02:51 +0000502 </tr>
503 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000504</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000505
Misha Brukman9d0919f2003-11-08 01:05:38 +0000506</div>
Chris Lattner00950542001-06-06 20:29:01 +0000507<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000508<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000509<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000510<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000511<p>The structure type is used to represent a collection of data members
512together in memory. The packing of the field types is defined to match
513the ABI of the underlying processor. The elements of a structure may
514be any type that has a size.</p>
515<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
516and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
517field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
518instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000519<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000520<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +0000521<h5>Examples:</h5>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000522
Misha Brukman9d0919f2003-11-08 01:05:38 +0000523<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000524 <tbody>
525 <tr>
526 <td><tt>{ int, int, int }</tt></td>
527 <td>: a triple of three <tt>int</tt> values</td>
528 </tr>
529 <tr>
530 <td><tt>{ float, int (int) * }</tt></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000531 <td>: A pair, where the first element is a <tt>float</tt> and the second
532 element is a <a href="#t_pointer">pointer</a> to a <a
533 href="#t_function">function</a> that takes an <tt>int</tt>, returning an
534 <tt>int</tt>.</td>
Chris Lattner261efe92003-11-25 01:02:51 +0000535 </tr>
536 </tbody>
Chris Lattner00950542001-06-06 20:29:01 +0000537</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000538
Misha Brukman9d0919f2003-11-08 01:05:38 +0000539</div>
Chris Lattner00950542001-06-06 20:29:01 +0000540<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000541<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000542<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +0000543<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000544<p>As in many languages, the pointer type represents a pointer or
545reference to another object, which must live in memory.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +0000546<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000547<pre> &lt;type&gt; *<br></pre>
Chris Lattner7faa8832002-04-14 06:13:44 +0000548<h5>Examples:</h5>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000549
Misha Brukman9d0919f2003-11-08 01:05:38 +0000550<table border="0" cellpadding="0" cellspacing="0">
Chris Lattner261efe92003-11-25 01:02:51 +0000551 <tbody>
552 <tr>
553 <td><tt>[4x int]*</tt></td>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000554 <td>: <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of
555 four <tt>int</tt> values</td>
Chris Lattner261efe92003-11-25 01:02:51 +0000556 </tr>
557 <tr>
558 <td><tt>int (int *) *</tt></td>
559 <td>: A <a href="#t_pointer">pointer</a> to a <a
Misha Brukmanc24b7582004-08-12 20:16:08 +0000560 href="#t_function">function</a> that takes an <tt>int</tt>, returning an
561 <tt>int</tt>.</td>
Chris Lattner261efe92003-11-25 01:02:51 +0000562 </tr>
563 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000564</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000565</div>
Chris Lattnera58561b2004-08-12 19:12:28 +0000566<!-- _______________________________________________________________________ -->
567<div class="doc_subsubsection"> <a name="t_packed">Packed Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000568<div class="doc_text">
Chris Lattnera58561b2004-08-12 19:12:28 +0000569<h5>Overview:</h5>
570<p>A packed type is a simple derived type that represents a vector
571of elements. Packed types are used when multiple primitive data
572are operated in parallel using a single instruction (SIMD).
573A packed type requires a size (number of
574elements) and an underlying primitive data type. Packed types are
575considered <a href="#t_firstclass">first class</a>.</p>
576<h5>Syntax:</h5>
577<pre> &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;<br></pre>
578<p>The number of elements is a constant integer value, elementtype may
579be any integral or floating point type.</p>
580<h5>Examples:</h5>
581<p> <tt>&lt;4 x int&gt;</tt>: Packed vector of 4 integer values.<br>
582<tt>&lt;8 x float&gt;</tt>: Packed vector of 8 floating-point values.<br>
583<tt>&lt;2 x uint&gt;</tt>: Packed vector of 2 unsigned integer values.</p>
584<p> </p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000585</div>
586
Chris Lattnera58561b2004-08-12 19:12:28 +0000587<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000588<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000589<!-- *********************************************************************** -->
590<!-- ======================================================================= -->
591<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
592</div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000593<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000594<p>LLVM programs are composed of "Module"s, each of which is a
595translation unit of the input programs. Each module consists of
596functions, global variables, and symbol table entries. Modules may be
597combined together with the LLVM linker, which merges function (and
598global variable) definitions, resolves forward declarations, and merges
599symbol table entries. Here is an example of the "hello world" module:</p>
600<pre><i>; Declare the string constant as a global constant...</i>
601<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
602 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 +0000603
Chris Lattner27f71f22003-09-03 00:41:47 +0000604<i>; External declaration of the puts function</i>
605<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000606
607<i>; Definition of main function</i>
Chris Lattner27f71f22003-09-03 00:41:47 +0000608int %main() { <i>; int()* </i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000609 <i>; Convert [13x sbyte]* to sbyte *...</i>
Chris Lattner261efe92003-11-25 01:02:51 +0000610 %cast210 = <a
611 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +0000612
613 <i>; Call puts function to write out the string to stdout...</i>
Chris Lattner261efe92003-11-25 01:02:51 +0000614 <a
615 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
616 <a
617 href="#i_ret">ret</a> int 0<br>}<br></pre>
618<p>This example is made up of a <a href="#globalvars">global variable</a>
619named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
620function, and a <a href="#functionstructure">function definition</a>
621for "<tt>main</tt>".</p>
622<a name="linkage"> In general, a module is made up of a list of global
623values, where both functions and global variables are global values.
624Global values are represented by a pointer to a memory location (in
625this case, a pointer to an array of char, and a pointer to a function),
626and have one of the following linkage types:</a>
627<p> </p>
Chris Lattner27f71f22003-09-03 00:41:47 +0000628<dl>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000629 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000630 <dd>Global values with internal linkage are only directly accessible
631by objects in the current module. In particular, linking code into a
632module with an internal global value may cause the internal to be
633renamed as necessary to avoid collisions. Because the symbol is
634internal to the module, all references can be updated. This
635corresponds to the notion of the '<tt>static</tt>' keyword in C, or the
636idea of "anonymous namespaces" in C++.
637 <p> </p>
638 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000639 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000640 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt>
641linkage, with the twist that linking together two modules defining the
642same <tt>linkonce</tt> globals will cause one of the globals to be
643discarded. This is typically used to implement inline functions.
644Unreferenced <tt>linkonce</tt> globals are allowed to be discarded.
645 <p> </p>
646 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000647 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000648 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt>
649linkage, except that unreferenced <tt>weak</tt> globals may not be
650discarded. This is used to implement constructs in C such as "<tt>int
651X;</tt>" at global scope.
652 <p> </p>
653 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000654 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000655 <dd>"<tt>appending</tt>" linkage may only be applied to global
656variables of pointer to array type. When two global variables with
657appending linkage are linked together, the two global arrays are
658appended together. This is the LLVM, typesafe, equivalent of having
659the system linker append together "sections" with identical names when
660.o files are linked.
661 <p> </p>
662 </dd>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000663 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattner261efe92003-11-25 01:02:51 +0000664 <dd>If none of the above identifiers are used, the global is
665externally visible, meaning that it participates in linkage and can be
666used to resolve external symbol references.
667 <p> </p>
668 </dd>
Chris Lattner261efe92003-11-25 01:02:51 +0000669</dl>
670<p> </p>
671<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
672variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
673variable and was linked with this one, one of the two would be renamed,
674preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
675external (i.e., lacking any linkage declarations), they are accessible
676outside of the current module. It is illegal for a function <i>declaration</i>
677to have any linkage type other than "externally visible".</a></p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000678</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000679
Chris Lattner00950542001-06-06 20:29:01 +0000680<!-- ======================================================================= -->
Chris Lattner9ee5d222004-03-08 16:49:10 +0000681<div class="doc_subsection">
682 <a name="globalvars">Global Variables</a>
683</div>
684
Misha Brukman9d0919f2003-11-08 01:05:38 +0000685<div class="doc_text">
Chris Lattner9ee5d222004-03-08 16:49:10 +0000686
Chris Lattner261efe92003-11-25 01:02:51 +0000687<p>Global variables define regions of memory allocated at compilation
688time instead of run-time. Global variables may optionally be
689initialized. A variable may be defined as a global "constant", which
690indicates that the contents of the variable will never be modified
Chris Lattner9ee5d222004-03-08 16:49:10 +0000691(opening options for optimization).</p>
692
Chris Lattner261efe92003-11-25 01:02:51 +0000693<p>As SSA values, global variables define pointer values that are in
694scope (i.e. they dominate) for all basic blocks in the program. Global
695variables always define a pointer to their "content" type because they
696describe a region of memory, and all memory objects in LLVM are
697accessed through pointers.</p>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000698
Misha Brukman9d0919f2003-11-08 01:05:38 +0000699</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000700
701
Chris Lattner2b7d3202002-05-06 03:03:22 +0000702<!-- ======================================================================= -->
Chris Lattner9ee5d222004-03-08 16:49:10 +0000703<div class="doc_subsection">
704 <a name="functionstructure">Functions</a>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000705</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +0000706
707<div class="doc_text">
708
709<p>LLVM function definitions are composed of a (possibly empty) argument list,
710an opening curly brace, a list of basic blocks, and a closing curly brace. LLVM
711function declarations are defined with the "<tt>declare</tt>" keyword, a
712function name, and a function signature.</p>
713
714<p>A function definition contains a list of basic blocks, forming the CFG for
715the function. Each basic block may optionally start with a label (giving the
716basic block a symbol table entry), contains a list of instructions, and ends
717with a <a href="#terminators">terminator</a> instruction (such as a branch or
718function return).</p>
719
720<p>The first basic block in program is special in two ways: it is immediately
721executed on entrance to the function, and it is not allowed to have predecessor
722basic blocks (i.e. there can not be any branches to the entry block of a
723function). Because the block can have no predecessors, it also cannot have any
724<a href="#i_phi">PHI nodes</a>.</p>
725
726<p>LLVM functions are identified by their name and type signature. Hence, two
727functions with the same name but different parameter lists or return values are
728considered different functions, and LLVM will resolves references to each
729appropriately.</p>
730
731</div>
732
733
Chris Lattner00950542001-06-06 20:29:01 +0000734<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000735<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
736<!-- *********************************************************************** -->
Misha Brukman9d0919f2003-11-08 01:05:38 +0000737<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000738<p>The LLVM instruction set consists of several different
739classifications of instructions: <a href="#terminators">terminator
740instructions</a>, <a href="#binaryops">binary instructions</a>, <a
741 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
742instructions</a>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000743</div>
Chris Lattner00950542001-06-06 20:29:01 +0000744<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000745<div class="doc_subsection"> <a name="terminators">Terminator
746Instructions</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000747<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000748<p>As mentioned <a href="#functionstructure">previously</a>, every
749basic block in a program ends with a "Terminator" instruction, which
750indicates which block should be executed after the current block is
751finished. These terminator instructions typically yield a '<tt>void</tt>'
752value: they produce control flow, not values (the one exception being
753the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000754<p>There are five different terminator instructions: the '<a
Chris Lattner261efe92003-11-25 01:02:51 +0000755 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
756instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
Chris Lattner35eca582004-10-16 18:04:13 +0000757the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
758 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
759 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000760</div>
Chris Lattner00950542001-06-06 20:29:01 +0000761<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000762<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
763Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000764<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000765<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000766<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 +0000767 ret void <i>; Return from void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000768</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000769<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000770<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
771value) from a function, back to the caller.</p>
John Criswell4457dc92004-04-09 16:48:45 +0000772<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner261efe92003-11-25 01:02:51 +0000773returns a value and then causes control flow, and one that just causes
774control flow to occur.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000775<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000776<p>The '<tt>ret</tt>' instruction may return any '<a
777 href="#t_firstclass">first class</a>' type. Notice that a function is
778not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
779instruction inside of the function that returns a value that does not
780match the return type of the function.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000781<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000782<p>When the '<tt>ret</tt>' instruction is executed, control flow
783returns back to the calling function's context. If the caller is a "<a
John Criswellfa081872004-06-25 15:16:57 +0000784 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner261efe92003-11-25 01:02:51 +0000785the instruction after the call. If the caller was an "<a
786 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
787at the beginning "normal" of the destination block. If the instruction
788returns a value, that value shall set the call or invoke instruction's
789return value.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000790<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000791<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner7faa8832002-04-14 06:13:44 +0000792 ret void <i>; Return from a void function</i>
Chris Lattner00950542001-06-06 20:29:01 +0000793</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000794</div>
Chris Lattner00950542001-06-06 20:29:01 +0000795<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000796<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000797<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000798<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000799<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 +0000800</pre>
Chris Lattner00950542001-06-06 20:29:01 +0000801<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000802<p>The '<tt>br</tt>' instruction is used to cause control flow to
803transfer to a different basic block in the current function. There are
804two forms of this instruction, corresponding to a conditional branch
805and an unconditional branch.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000806<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000807<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
808single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
809unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
810value as a target.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000811<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000812<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
813argument is evaluated. If the value is <tt>true</tt>, control flows
814to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
815control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000816<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000817<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
818 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 +0000819</div>
Chris Lattner00950542001-06-06 20:29:01 +0000820<!-- _______________________________________________________________________ -->
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000821<div class="doc_subsubsection">
822 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
823</div>
824
Misha Brukman9d0919f2003-11-08 01:05:38 +0000825<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000826<h5>Syntax:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000827
828<pre>
829 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
830</pre>
831
Chris Lattner00950542001-06-06 20:29:01 +0000832<h5>Overview:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000833
834<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
835several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +0000836instruction, allowing a branch to occur to one of many possible
837destinations.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000838
839
Chris Lattner00950542001-06-06 20:29:01 +0000840<h5>Arguments:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000841
842<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
843comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
844an array of pairs of comparison value constants and '<tt>label</tt>'s. The
845table is not allowed to contain duplicate constant entries.</p>
846
Chris Lattner00950542001-06-06 20:29:01 +0000847<h5>Semantics:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000848
Chris Lattner261efe92003-11-25 01:02:51 +0000849<p>The <tt>switch</tt> instruction specifies a table of values and
850destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswell84114752004-06-25 16:05:06 +0000851table is searched for the given value. If the value is found, control flow is
852transfered to the corresponding destination; otherwise, control flow is
853transfered to the default destination.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000854
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000855<h5>Implementation:</h5>
856
857<p>Depending on properties of the target machine and the particular
858<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswell84114752004-06-25 16:05:06 +0000859ways. For example, it could be generated as a series of chained conditional
860branches or with a lookup table.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +0000861
862<h5>Example:</h5>
863
864<pre>
865 <i>; Emulate a conditional br instruction</i>
866 %Val = <a href="#i_cast">cast</a> bool %value to int
867 switch int %Val, label %truedest [int 0, label %falsedest ]
868
869 <i>; Emulate an unconditional br instruction</i>
870 switch uint 0, label %dest [ ]
871
872 <i>; Implement a jump table:</i>
873 switch uint %val, label %otherwise [ uint 0, label %onzero
874 uint 1, label %onone
875 uint 2, label %ontwo ]
Chris Lattner00950542001-06-06 20:29:01 +0000876</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000877</div>
Chris Lattner00950542001-06-06 20:29:01 +0000878<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000879<div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>'
880Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000881<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000882<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000883<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 +0000884<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000885<p>The '<tt>invoke</tt>' instruction causes control to transfer to a
886specified function, with the possibility of control flow transfer to
887either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>.
888If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>"
889instruction, control flow will return to the "normal" label. If the
890callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
891instruction, control is interrupted, and continued at the dynamically
892nearest "except" label.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000893<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000894<p>This instruction requires several arguments:</p>
Chris Lattner00950542001-06-06 20:29:01 +0000895<ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000896 <li>'<tt>ptr to function ty</tt>': shall be the signature of the
897pointer to function value being invoked. In most cases, this is a
898direct function invocation, but indirect <tt>invoke</tt>s are just as
899possible, branching off an arbitrary pointer to function value. </li>
900 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer
901to a function to be invoked. </li>
902 <li>'<tt>function args</tt>': argument list whose types match the
903function signature argument types. If the function signature indicates
904the function accepts a variable number of arguments, the extra
905arguments can be specified. </li>
906 <li>'<tt>normal label</tt>': the label reached when the called
907function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
908 <li>'<tt>exception label</tt>': the label reached when a callee
909returns with the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
Chris Lattner00950542001-06-06 20:29:01 +0000910</ol>
Chris Lattner00950542001-06-06 20:29:01 +0000911<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000912<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner261efe92003-11-25 01:02:51 +0000913 href="#i_call">call</a></tt>' instruction in most regards. The
914primary difference is that it establishes an association with a label,
915which is used by the runtime library to unwind the stack.</p>
916<p>This instruction is used in languages with destructors to ensure
917that proper cleanup is performed in the case of either a <tt>longjmp</tt>
918or a thrown exception. Additionally, this is important for
919implementation of '<tt>catch</tt>' clauses in high-level languages that
920support them.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000921<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000922<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 +0000923</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000924</div>
Chris Lattner35eca582004-10-16 18:04:13 +0000925
926
Chris Lattner27f71f22003-09-03 00:41:47 +0000927<!-- _______________________________________________________________________ -->
Chris Lattner35eca582004-10-16 18:04:13 +0000928
Chris Lattner261efe92003-11-25 01:02:51 +0000929<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
930Instruction</a> </div>
Chris Lattner35eca582004-10-16 18:04:13 +0000931
Misha Brukman9d0919f2003-11-08 01:05:38 +0000932<div class="doc_text">
Chris Lattner35eca582004-10-16 18:04:13 +0000933
Chris Lattner27f71f22003-09-03 00:41:47 +0000934<h5>Syntax:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +0000935<pre>
936 unwind
937</pre>
938
Chris Lattner27f71f22003-09-03 00:41:47 +0000939<h5>Overview:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +0000940
941<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
942at the first callee in the dynamic call stack which used an <a
943href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
944primarily used to implement exception handling.</p>
945
Chris Lattner27f71f22003-09-03 00:41:47 +0000946<h5>Semantics:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +0000947
948<p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to
949immediately halt. The dynamic call stack is then searched for the first <a
950href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
951execution continues at the "exceptional" destination block specified by the
952<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
953dynamic call chain, undefined behavior results.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000954</div>
Chris Lattner35eca582004-10-16 18:04:13 +0000955
956<!-- _______________________________________________________________________ -->
957
958<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
959Instruction</a> </div>
960
961<div class="doc_text">
962
963<h5>Syntax:</h5>
964<pre>
965 unreachable
966</pre>
967
968<h5>Overview:</h5>
969
970<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
971instruction is used to inform the optimizer that a particular portion of the
972code is not reachable. This can be used to indicate that the code after a
973no-return function cannot be reached, and other facts.</p>
974
975<h5>Semantics:</h5>
976
977<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
978</div>
979
980
981
Chris Lattner00950542001-06-06 20:29:01 +0000982<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000983<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000984<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000985<p>Binary operators are used to do most of the computation in a
986program. They require two operands, execute an operation on them, and
Chris Lattnera58561b2004-08-12 19:12:28 +0000987produce a single value. Although, that single value might represent
988multiple data, as is the case with the <a href="#t_packed">packed</a> data type.
989The result value of a binary operator is not
Chris Lattner261efe92003-11-25 01:02:51 +0000990necessarily the same type as its operands.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000991<p>There are several different binary operators:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000992</div>
Chris Lattner00950542001-06-06 20:29:01 +0000993<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000994<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
995Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000996<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000997<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000998<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 +0000999</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001000<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001001<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001002<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001003<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattnera58561b2004-08-12 19:12:28 +00001004 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
1005 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1006Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001007<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001008<p>The value produced is the integer or floating point sum of the two
1009operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001010<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001011<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001012</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001013</div>
Chris Lattner00950542001-06-06 20:29:01 +00001014<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001015<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
1016Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001017<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001018<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001019<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 +00001020</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001021<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001022<p>The '<tt>sub</tt>' instruction returns the difference of its two
1023operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001024<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
1025instruction present in most other intermediate representations.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001026<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001027<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001028 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001029values.
1030This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1031Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001032<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001033<p>The value produced is the integer or floating point difference of
1034the two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001035<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001036<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001037 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
1038</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001039</div>
Chris Lattner00950542001-06-06 20:29:01 +00001040<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001041<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
1042Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001043<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001044<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001045<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 +00001046</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001047<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001048<p>The '<tt>mul</tt>' instruction returns the product of its two
1049operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001050<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001051<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001052 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001053values.
1054This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1055Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001056<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001057<p>The value produced is the integer or floating point product of the
Misha Brukman9d0919f2003-11-08 01:05:38 +00001058two operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001059<p>There is no signed vs unsigned multiplication. The appropriate
1060action is taken based on the type of the operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001061<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001062<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001063</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001064</div>
Chris Lattner00950542001-06-06 20:29:01 +00001065<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001066<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
1067Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001068<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001069<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001070<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1071</pre>
1072<h5>Overview:</h5>
1073<p>The '<tt>div</tt>' instruction returns the quotient of its two
1074operands.</p>
1075<h5>Arguments:</h5>
1076<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
1077 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001078values.
1079This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1080Both arguments must have identical types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001081<h5>Semantics:</h5>
1082<p>The value produced is the integer or floating point quotient of the
1083two operands.</p>
1084<h5>Example:</h5>
1085<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
1086</pre>
1087</div>
1088<!-- _______________________________________________________________________ -->
1089<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
1090Instruction</a> </div>
1091<div class="doc_text">
1092<h5>Syntax:</h5>
1093<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1094</pre>
1095<h5>Overview:</h5>
1096<p>The '<tt>rem</tt>' instruction returns the remainder from the
1097division of its two operands.</p>
1098<h5>Arguments:</h5>
1099<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1100 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001101values.
1102This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1103Both arguments must have identical types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001104<h5>Semantics:</h5>
1105<p>This returns the <i>remainder</i> of a division (where the result
1106has the same sign as the divisor), not the <i>modulus</i> (where the
1107result has the same sign as the dividend) of a value. For more
1108information about the difference, see: <a
1109 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1110Math Forum</a>.</p>
1111<h5>Example:</h5>
1112<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1113</pre>
1114</div>
1115<!-- _______________________________________________________________________ -->
1116<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1117Instructions</a> </div>
1118<div class="doc_text">
1119<h5>Syntax:</h5>
1120<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 +00001121 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1122 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1123 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1124 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1125 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1126</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001127<h5>Overview:</h5>
1128<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1129value based on a comparison of their two operands.</p>
1130<h5>Arguments:</h5>
1131<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1132be of <a href="#t_firstclass">first class</a> type (it is not possible
1133to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1134or '<tt>void</tt>' values, etc...). Both arguments must have identical
1135types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001136<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001137<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1138value if both operands are equal.<br>
1139The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1140value if both operands are unequal.<br>
1141The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1142value if the first operand is less than the second operand.<br>
1143The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1144value if the first operand is greater than the second operand.<br>
1145The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1146value if the first operand is less than or equal to the second operand.<br>
1147The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1148value if the first operand is greater than or equal to the second
1149operand.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001150<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001151<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner00950542001-06-06 20:29:01 +00001152 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
1153 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1154 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1155 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1156 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1157</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001158</div>
Chris Lattner00950542001-06-06 20:29:01 +00001159<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001160<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1161Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001162<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001163<p>Bitwise binary operators are used to do various forms of
1164bit-twiddling in a program. They are generally very efficient
1165instructions, and can commonly be strength reduced from other
1166instructions. They require two operands, execute an operation on them,
1167and produce a single value. The resulting value of the bitwise binary
1168operators is always the same type as its first operand.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001169</div>
Chris Lattner00950542001-06-06 20:29:01 +00001170<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001171<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1172Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001173<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001174<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001175<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 +00001176</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001177<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001178<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1179its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001180<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001181<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001182 href="#t_integral">integral</a> values. Both arguments must have
1183identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001184<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001185<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001186<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001187<div style="align: center">
Misha Brukman9d0919f2003-11-08 01:05:38 +00001188<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +00001189 <tbody>
1190 <tr>
1191 <td>In0</td>
1192 <td>In1</td>
1193 <td>Out</td>
1194 </tr>
1195 <tr>
1196 <td>0</td>
1197 <td>0</td>
1198 <td>0</td>
1199 </tr>
1200 <tr>
1201 <td>0</td>
1202 <td>1</td>
1203 <td>0</td>
1204 </tr>
1205 <tr>
1206 <td>1</td>
1207 <td>0</td>
1208 <td>0</td>
1209 </tr>
1210 <tr>
1211 <td>1</td>
1212 <td>1</td>
1213 <td>1</td>
1214 </tr>
1215 </tbody>
1216</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001217</div>
Chris Lattner00950542001-06-06 20:29:01 +00001218<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001219<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001220 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1221 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1222</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001223</div>
Chris Lattner00950542001-06-06 20:29:01 +00001224<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001225<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001226<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001227<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001228<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 +00001229</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00001230<h5>Overview:</h5>
1231<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1232or of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001233<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001234<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001235 href="#t_integral">integral</a> values. Both arguments must have
1236identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001237<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001238<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001239<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001240<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001241<table border="1" cellspacing="0" cellpadding="4">
1242 <tbody>
1243 <tr>
1244 <td>In0</td>
1245 <td>In1</td>
1246 <td>Out</td>
1247 </tr>
1248 <tr>
1249 <td>0</td>
1250 <td>0</td>
1251 <td>0</td>
1252 </tr>
1253 <tr>
1254 <td>0</td>
1255 <td>1</td>
1256 <td>1</td>
1257 </tr>
1258 <tr>
1259 <td>1</td>
1260 <td>0</td>
1261 <td>1</td>
1262 </tr>
1263 <tr>
1264 <td>1</td>
1265 <td>1</td>
1266 <td>1</td>
1267 </tr>
1268 </tbody>
1269</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001270</div>
Chris Lattner00950542001-06-06 20:29:01 +00001271<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001272<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001273 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1274 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1275</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001276</div>
Chris Lattner00950542001-06-06 20:29:01 +00001277<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001278<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1279Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001280<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001281<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001282<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 +00001283</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001284<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001285<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1286or of its two operands. The <tt>xor</tt> is used to implement the
1287"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001288<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001289<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001290 href="#t_integral">integral</a> values. Both arguments must have
1291identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001292<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001293<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001294<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001295<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00001296<table border="1" cellspacing="0" cellpadding="4">
1297 <tbody>
1298 <tr>
1299 <td>In0</td>
1300 <td>In1</td>
1301 <td>Out</td>
1302 </tr>
1303 <tr>
1304 <td>0</td>
1305 <td>0</td>
1306 <td>0</td>
1307 </tr>
1308 <tr>
1309 <td>0</td>
1310 <td>1</td>
1311 <td>1</td>
1312 </tr>
1313 <tr>
1314 <td>1</td>
1315 <td>0</td>
1316 <td>1</td>
1317 </tr>
1318 <tr>
1319 <td>1</td>
1320 <td>1</td>
1321 <td>0</td>
1322 </tr>
1323 </tbody>
1324</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001325</div>
Chris Lattner261efe92003-11-25 01:02:51 +00001326<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001327<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001328<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001329 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1330 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner27f71f22003-09-03 00:41:47 +00001331 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner00950542001-06-06 20:29:01 +00001332</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001333</div>
Chris Lattner00950542001-06-06 20:29:01 +00001334<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001335<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1336Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001337<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001338<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001339<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 +00001340</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001341<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001342<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1343the left a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001344<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001345<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001346 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1347type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001348<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001349<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001350<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001351<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 +00001352 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1353 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1354</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001355</div>
Chris Lattner00950542001-06-06 20:29:01 +00001356<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001357<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1358Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001359<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001360<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001361<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 +00001362</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001363<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001364<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1365the right a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001366<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001367<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner261efe92003-11-25 01:02:51 +00001368 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1369type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001370<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001371<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1372most significant bit is duplicated in the newly free'd bit positions.
1373If the first argument is unsigned, zero bits shall fill the empty
1374positions.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001375<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001376<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 +00001377 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001378 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner8c6bb902003-06-18 21:30:51 +00001379 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1380 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</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_subsection"> <a name="memoryops">Memory Access
1385Operations</a></div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001386<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001387<p>A key design point of an SSA-based representation is how it
1388represents memory. In LLVM, no memory locations are in SSA form, which
1389makes things very simple. This section describes how to read, write,
1390allocate and free memory in LLVM.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001391</div>
Chris Lattner00950542001-06-06 20:29:01 +00001392<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001393<div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>'
1394Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001395<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001396<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001397<pre> &lt;result&gt; = malloc &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001398 &lt;result&gt; = malloc &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001399</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001400<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001401<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1402heap and returns a pointer to it.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001403<h5>Arguments:</h5>
John Criswell6e4ca612004-02-24 16:13:56 +00001404<p>The '<tt>malloc</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1405bytes of memory from the operating system and returns a pointer of the
Chris Lattner261efe92003-11-25 01:02:51 +00001406appropriate type to the program. The second form of the instruction is
1407a shorter version of the first instruction that defaults to allocating
1408one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001409<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001410<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001411<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1412a pointer is returned.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001413<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001414<pre> %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001415
Chris Lattner261efe92003-11-25 01:02:51 +00001416 %size = <a
1417 href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001418 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1419 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner00950542001-06-06 20:29:01 +00001420</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001421</div>
Chris Lattner00950542001-06-06 20:29:01 +00001422<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001423<div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>'
1424Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001425<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001426<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001427<pre> free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner00950542001-06-06 20:29:01 +00001428</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001429<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001430<p>The '<tt>free</tt>' instruction returns memory back to the unused
1431memory heap, to be reallocated in the future.</p>
1432<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00001433<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001434<p>'<tt>value</tt>' shall be a pointer value that points to a value
1435that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1436instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001437<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001438<p>Access to the memory pointed to by the pointer is not longer defined
1439after this instruction executes.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001440<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001441<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 +00001442 free [4 x ubyte]* %array
1443</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001444</div>
Chris Lattner00950542001-06-06 20:29:01 +00001445<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001446<div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>'
1447Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001448<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001449<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001450<pre> &lt;result&gt; = alloca &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001451 &lt;result&gt; = alloca &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001452</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001453<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001454<p>The '<tt>alloca</tt>' instruction allocates memory on the current
1455stack frame of the procedure that is live until the current function
1456returns to its caller.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001457<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001458<p>The the '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1459bytes of memory on the runtime stack, returning a pointer of the
1460appropriate type to the program. The second form of the instruction is
1461a shorter version of the first that defaults to allocating one element.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001462<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001463<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001464<p>Memory is allocated, a pointer is returned. '<tt>alloca</tt>'d
1465memory is automatically released when the function returns. The '<tt>alloca</tt>'
1466instruction is commonly used to represent automatic variables that must
1467have an address available. When the function returns (either with the <tt><a
1468 href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001469instructions), the memory is reclaimed.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001470<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001471<pre> %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001472 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner00950542001-06-06 20:29:01 +00001473</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001474</div>
Chris Lattner00950542001-06-06 20:29:01 +00001475<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001476<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1477Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001478<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00001479<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001480<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 +00001481<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001482<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001483<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001484<p>The argument to the '<tt>load</tt>' instruction specifies the memory
1485address to load from. The pointer must point to a <a
Chris Lattnere53e5082004-06-03 22:57:15 +00001486 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
Chris Lattner261efe92003-11-25 01:02:51 +00001487marked as <tt>volatile</tt> then the optimizer is not allowed to modify
1488the number or order of execution of this <tt>load</tt> with other
1489volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1490instructions. </p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001491<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001492<p>The location of memory pointed to is loaded.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001493<h5>Examples:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001494<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1495 <a
1496 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001497 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1498</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001499</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001500<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001501<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1502Instruction</a> </div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001503<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001504<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 +00001505 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 +00001506</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001507<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001508<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001509<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001510<p>There are two arguments to the '<tt>store</tt>' instruction: a value
1511to store and an address to store it into. The type of the '<tt>&lt;pointer&gt;</tt>'
1512operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
1513operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the
1514optimizer is not allowed to modify the number or order of execution of
1515this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1516 href="#i_store">store</a></tt> instructions.</p>
1517<h5>Semantics:</h5>
1518<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
1519at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001520<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001521<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1522 <a
1523 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001524 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1525</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00001526<!-- _______________________________________________________________________ -->
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001527<div class="doc_subsubsection">
1528 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
1529</div>
1530
Misha Brukman9d0919f2003-11-08 01:05:38 +00001531<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00001532<h5>Syntax:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001533<pre>
1534 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
1535</pre>
1536
Chris Lattner7faa8832002-04-14 06:13:44 +00001537<h5>Overview:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001538
1539<p>
1540The '<tt>getelementptr</tt>' instruction is used to get the address of a
1541subelement of an aggregate data structure.</p>
1542
Chris Lattner7faa8832002-04-14 06:13:44 +00001543<h5>Arguments:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001544
1545<p>This instruction takes a list of integer constants that indicate what
1546elements of the aggregate object to index to. The actual types of the arguments
1547provided depend on the type of the first pointer argument. The
1548'<tt>getelementptr</tt>' instruction is used to index down through the type
1549levels of a structure. When indexing into a structure, only <tt>uint</tt>
1550integer constants are allowed. When indexing into an array or pointer
1551<tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
1552
Chris Lattner261efe92003-11-25 01:02:51 +00001553<p>For example, let's consider a C code fragment and how it gets
1554compiled to LLVM:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001555
1556<pre>
1557 struct RT {
1558 char A;
1559 int B[10][20];
1560 char C;
1561 };
1562 struct ST {
1563 int X;
1564 double Y;
1565 struct RT Z;
1566 };
1567
1568 int *foo(struct ST *s) {
1569 return &amp;s[1].Z.B[5][13];
1570 }
1571</pre>
1572
Misha Brukman9d0919f2003-11-08 01:05:38 +00001573<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001574
1575<pre>
1576 %RT = type { sbyte, [10 x [20 x int]], sbyte }
1577 %ST = type { int, double, %RT }
1578
Brian Gaeke7283e7c2004-07-02 21:08:14 +00001579 implementation
1580
1581 int* %foo(%ST* %s) {
1582 entry:
1583 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001584 ret int* %reg
1585 }
1586</pre>
1587
Chris Lattner7faa8832002-04-14 06:13:44 +00001588<h5>Semantics:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001589
1590<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
Chris Lattnere53e5082004-06-03 22:57:15 +00001591on the pointer type that is being index into. <a href="#t_pointer">Pointer</a>
1592and <a href="#t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
1593<tt>ulong</tt>, or <tt>long</tt> values, and <a href="#t_struct">structure</a>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001594types require <tt>uint</tt> <b>constants</b>.</p>
1595
Misha Brukman9d0919f2003-11-08 01:05:38 +00001596<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001597type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
1598}</tt>' type, a structure. The second index indexes into the third element of
1599the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
1600sbyte }</tt>' type, another structure. The third index indexes into the second
1601element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
1602array. The two dimensions of the array are subscripted into, yielding an
1603'<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction return a pointer
1604to this element, thus computing a value of '<tt>int*</tt>' type.</p>
1605
Chris Lattner261efe92003-11-25 01:02:51 +00001606<p>Note that it is perfectly legal to index partially through a
1607structure, returning a pointer to an inner element. Because of this,
1608the LLVM code for the given testcase is equivalent to:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001609
1610<pre>
1611 int* "foo"(%ST* %s) {
1612 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
1613 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
1614 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
1615 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
1616 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
1617 ret int* %t5
1618 }
Chris Lattner6536cfe2002-05-06 22:08:29 +00001619</pre>
Chris Lattner7faa8832002-04-14 06:13:44 +00001620<h5>Example:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00001621<pre>
1622 <i>; yields [12 x ubyte]*:aptr</i>
1623 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
1624</pre>
1625
1626</div>
Chris Lattner00950542001-06-06 20:29:01 +00001627<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001628<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001629<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +00001630<p>The instructions in this category are the "miscellaneous"
Chris Lattner261efe92003-11-25 01:02:51 +00001631instructions, which defy better classification.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001632</div>
Chris Lattner00950542001-06-06 20:29:01 +00001633<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001634<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
1635Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001636<div class="doc_text">
Chris Lattner33ba0d92001-07-09 00:26:23 +00001637<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001638<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001639<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001640<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
1641the SSA graph representing the function.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001642<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001643<p>The type of the incoming values are specified with the first type
1644field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
1645as arguments, with one pair for each predecessor basic block of the
1646current block. Only values of <a href="#t_firstclass">first class</a>
1647type may be used as the value arguments to the PHI node. Only labels
1648may be used as the label arguments.</p>
1649<p>There must be no non-phi instructions between the start of a basic
1650block and the PHI instructions: i.e. PHI instructions must be first in
1651a basic block.</p>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001652<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001653<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
1654value specified by the parameter, depending on which basic block we
1655came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001656<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001657<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 +00001658</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001659
Chris Lattner6536cfe2002-05-06 22:08:29 +00001660<!-- _______________________________________________________________________ -->
Chris Lattnercc37aae2004-03-12 05:50:16 +00001661<div class="doc_subsubsection">
1662 <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
1663</div>
1664
Misha Brukman9d0919f2003-11-08 01:05:38 +00001665<div class="doc_text">
Chris Lattnercc37aae2004-03-12 05:50:16 +00001666
Chris Lattner6536cfe2002-05-06 22:08:29 +00001667<h5>Syntax:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001668
1669<pre>
1670 &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 +00001671</pre>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001672
Chris Lattner6536cfe2002-05-06 22:08:29 +00001673<h5>Overview:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001674
1675<p>
1676The '<tt>cast</tt>' instruction is used as the primitive means to convert
1677integers to floating point, change data type sizes, and break type safety (by
1678casting pointers).
1679</p>
1680
1681
Chris Lattner6536cfe2002-05-06 22:08:29 +00001682<h5>Arguments:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001683
1684<p>
1685The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
1686class value, and a type to cast it to, which must also be a <a
1687href="#t_firstclass">first class</a> type.
1688</p>
1689
Chris Lattner6536cfe2002-05-06 22:08:29 +00001690<h5>Semantics:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001691
1692<p>
1693This instruction follows the C rules for explicit casts when determining how the
1694data being cast must change to fit in its new container.
1695</p>
1696
1697<p>
1698When casting to bool, any value that would be considered true in the context of
1699a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
1700all else are '<tt>false</tt>'.
1701</p>
1702
1703<p>
1704When extending an integral value from a type of one signness to another (for
1705example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
1706<b>source</b> value is signed, and zero-extended if the source value is
1707unsigned. <tt>bool</tt> values are always zero extended into either zero or
1708one.
1709</p>
1710
Chris Lattner33ba0d92001-07-09 00:26:23 +00001711<h5>Example:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001712
1713<pre>
1714 %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattner7bae3952002-06-25 18:03:17 +00001715 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner33ba0d92001-07-09 00:26:23 +00001716</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001717</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00001718
1719<!-- _______________________________________________________________________ -->
1720<div class="doc_subsubsection">
1721 <a name="i_select">'<tt>select</tt>' Instruction</a>
1722</div>
1723
1724<div class="doc_text">
1725
1726<h5>Syntax:</h5>
1727
1728<pre>
1729 &lt;result&gt; = select bool &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
1730</pre>
1731
1732<h5>Overview:</h5>
1733
1734<p>
1735The '<tt>select</tt>' instruction is used to choose one value based on a
1736condition, without branching.
1737</p>
1738
1739
1740<h5>Arguments:</h5>
1741
1742<p>
1743The '<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.
1744</p>
1745
1746<h5>Semantics:</h5>
1747
1748<p>
1749If the boolean condition evaluates to true, the instruction returns the first
1750value argument, otherwise it returns the second value argument.
1751</p>
1752
1753<h5>Example:</h5>
1754
1755<pre>
1756 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
1757</pre>
1758</div>
1759
1760
1761
1762
1763
Chris Lattner33ba0d92001-07-09 00:26:23 +00001764<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001765<div class="doc_subsubsection"> <a name="i_call">'<tt>call</tt>'
1766Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001767<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001768<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001769<pre> &lt;result&gt; = call &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +00001770<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001771<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001772<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001773<p>This instruction requires several arguments:</p>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001774<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00001775 <li>
1776 <p>'<tt>ty</tt>': shall be the signature of the pointer to function
1777value being invoked. The argument types must match the types implied
1778by this signature.</p>
1779 </li>
1780 <li>
1781 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a
1782function to be invoked. In most cases, this is a direct function
1783invocation, but indirect <tt>call</tt>s are just as possible,
1784calling an arbitrary pointer to function values.</p>
1785 </li>
1786 <li>
1787 <p>'<tt>function args</tt>': argument list whose types match the
1788function signature argument types. If the function signature
1789indicates the function accepts a variable number of arguments, the
1790extra arguments can be specified.</p>
1791 </li>
Chris Lattner6536cfe2002-05-06 22:08:29 +00001792</ol>
Chris Lattner00950542001-06-06 20:29:01 +00001793<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001794<p>The '<tt>call</tt>' instruction is used to cause control flow to
1795transfer to a specified function, with its incoming arguments bound to
1796the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
1797instruction in the called function, control flow continues with the
1798instruction after the function call, and the return value of the
1799function is bound to the result argument. This is a simpler case of
1800the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001801<h5>Example:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001802<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 +00001803</div>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001804
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001805<!-- _______________________________________________________________________ -->
Chris Lattnere19d7a72004-09-27 21:51:25 +00001806<div class="doc_subsubsection">
1807 <a name="i_vanext">'<tt>vanext</tt>' Instruction</a>
1808</div>
1809
Misha Brukman9d0919f2003-11-08 01:05:38 +00001810<div class="doc_text">
Chris Lattnere19d7a72004-09-27 21:51:25 +00001811
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001812<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001813
1814<pre>
1815 &lt;resultarglist&gt; = vanext &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;
1816</pre>
1817
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001818<h5>Overview:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001819
Chris Lattner261efe92003-11-25 01:02:51 +00001820<p>The '<tt>vanext</tt>' instruction is used to access arguments passed
1821through the "variable argument" area of a function call. It is used to
1822implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001823
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001824<h5>Arguments:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001825
1826<p>This instruction takes a <tt>va_list</tt> value and the type of the
1827argument. It returns another <tt>va_list</tt>. The actual type of
1828<tt>va_list</tt> may be defined differently for different targets. Most targets
1829use a <tt>va_list</tt> type of <tt>sbyte*</tt> or some other pointer type.</p>
1830
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001831<h5>Semantics:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001832
1833<p>The '<tt>vanext</tt>' instruction advances the specified <tt>va_list</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001834past an argument of the specified type. In conjunction with the <a
1835 href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement
1836the <tt>va_arg</tt> macro available in C. For more information, see
1837the variable argument handling <a href="#int_varargs">Intrinsic
1838Functions</a>.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001839
Chris Lattner261efe92003-11-25 01:02:51 +00001840<p>It is legal for this instruction to be called in a function which
1841does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001842function.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001843
Misha Brukman9d0919f2003-11-08 01:05:38 +00001844<p><tt>vanext</tt> is an LLVM instruction instead of an <a
Chris Lattnere19d7a72004-09-27 21:51:25 +00001845href="#intrinsics">intrinsic function</a> because it takes a type as an
1846argument. The type refers to the current argument in the <tt>va_list</tt>, it
1847tells the compiler how far on the stack it needs to advance to find the next
1848argument</p>
1849
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001850<h5>Example:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001851
Chris Lattner261efe92003-11-25 01:02:51 +00001852<p>See the <a href="#int_varargs">variable argument processing</a>
1853section.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001854
Misha Brukman9d0919f2003-11-08 01:05:38 +00001855</div>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001856
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001857<!-- _______________________________________________________________________ -->
Chris Lattnere19d7a72004-09-27 21:51:25 +00001858<div class="doc_subsubsection">
1859 <a name="i_vaarg">'<tt>vaarg</tt>' Instruction</a>
1860</div>
1861
Misha Brukman9d0919f2003-11-08 01:05:38 +00001862<div class="doc_text">
Chris Lattnere19d7a72004-09-27 21:51:25 +00001863
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001864<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001865
1866<pre>
1867 &lt;resultval&gt; = vaarg &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;
1868</pre>
1869
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001870<h5>Overview:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001871
1872<p>The '<tt>vaarg</tt>' instruction is used to access arguments passed through
1873the "variable argument" area of a function call. It is used to implement the
1874<tt>va_arg</tt> macro in C.</p>
1875
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001876<h5>Arguments:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001877
1878<p>This instruction takes a <tt>va_list</tt> value and the type of the
1879argument. It returns a value of the specified argument type. Again, the actual
1880type of <tt>va_list</tt> is target specific.</p>
1881
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001882<h5>Semantics:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001883
1884<p>The '<tt>vaarg</tt>' instruction loads an argument of the specified type from
1885the specified <tt>va_list</tt>. In conjunction with the <a
1886href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to implement the
1887<tt>va_arg</tt> macro available in C. For more information, see the variable
1888argument handling <a href="#int_varargs">Intrinsic Functions</a>.</p>
1889
1890<p>It is legal for this instruction to be called in a function which does not
1891take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001892function.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001893
Misha Brukman9d0919f2003-11-08 01:05:38 +00001894<p><tt>vaarg</tt> is an LLVM instruction instead of an <a
Chris Lattnere19d7a72004-09-27 21:51:25 +00001895href="#intrinsics">intrinsic function</a> because it takes an type as an
1896argument.</p>
1897
Chris Lattner8d1a81d2003-10-18 05:51:36 +00001898<h5>Example:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001899
1900<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
1901
Misha Brukman9d0919f2003-11-08 01:05:38 +00001902</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001903
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001904<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00001905<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
1906<!-- *********************************************************************** -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001907
Misha Brukman9d0919f2003-11-08 01:05:38 +00001908<div class="doc_text">
Chris Lattner33aec9e2004-02-12 17:01:32 +00001909
1910<p>LLVM supports the notion of an "intrinsic function". These functions have
1911well known names and semantics, and are required to follow certain
1912restrictions. Overall, these instructions represent an extension mechanism for
1913the LLVM language that does not require changing all of the transformations in
1914LLVM to add to the language (or the bytecode reader/writer, the parser,
1915etc...).</p>
1916
1917<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix, this
1918prefix is reserved in LLVM for intrinsic names, thus functions may not be named
1919this. Intrinsic functions must always be external functions: you cannot define
1920the body of intrinsic functions. Intrinsic functions may only be used in call
1921or invoke instructions: it is illegal to take the address of an intrinsic
1922function. Additionally, because intrinsic functions are part of the LLVM
1923language, it is required that they all be documented here if any are added.</p>
1924
1925
1926<p>
1927Adding an intrinsic to LLVM is straight-forward if it is possible to express the
1928concept in LLVM directly (ie, code generator support is not _required_). To do
1929this, extend the default implementation of the IntrinsicLowering class to handle
1930the intrinsic. Code generators use this class to lower intrinsics they do not
1931understand to raw LLVM instructions that they do.
1932</p>
1933
Misha Brukman9d0919f2003-11-08 01:05:38 +00001934</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001935
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001936<!-- ======================================================================= -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001937<div class="doc_subsection">
1938 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
1939</div>
1940
Misha Brukman9d0919f2003-11-08 01:05:38 +00001941<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00001942
Misha Brukman9d0919f2003-11-08 01:05:38 +00001943<p>Variable argument support is defined in LLVM with the <a
Chris Lattner261efe92003-11-25 01:02:51 +00001944 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
1945intrinsic functions. These functions are related to the similarly
1946named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00001947
Chris Lattner261efe92003-11-25 01:02:51 +00001948<p>All of these functions operate on arguments that use a
1949target-specific value type "<tt>va_list</tt>". The LLVM assembly
1950language reference manual does not define what this type is, so all
1951transformations should be prepared to handle intrinsics with any type
1952used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00001953
Misha Brukman9d0919f2003-11-08 01:05:38 +00001954<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner261efe92003-11-25 01:02:51 +00001955instruction and the variable argument handling intrinsic functions are
1956used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00001957
Chris Lattner33aec9e2004-02-12 17:01:32 +00001958<pre>
1959int %test(int %X, ...) {
1960 ; Initialize variable argument processing
1961 %ap = call sbyte* %<a href="#i_va_start">llvm.va_start</a>()
1962
1963 ; Read a single integer argument
1964 %tmp = vaarg sbyte* %ap, int
1965
1966 ; Advance to the next argument
1967 %ap2 = vanext sbyte* %ap, int
1968
1969 ; Demonstrate usage of llvm.va_copy and llvm.va_end
1970 %aq = call sbyte* %<a href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2)
1971 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %aq)
1972
1973 ; Stop processing of arguments.
1974 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %ap2)
1975 ret int %tmp
1976}
1977</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001978</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001979
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001980<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00001981<div class="doc_subsubsection">
1982 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
1983</div>
1984
1985
Misha Brukman9d0919f2003-11-08 01:05:38 +00001986<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001987<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00001988<pre> call &lt;va_list&gt; ()* %llvm.va_start()<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001989<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001990<p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt>&lt;arglist&gt;</tt>
1991for subsequent use by the variable argument intrinsics.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00001992<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001993<p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00001994macro available in C. In a target-dependent way, it initializes and
1995returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt>
1996will produce the first variable argument passed to the function. Unlike
1997the C <tt>va_start</tt> macro, this intrinsic does not need to know the
1998last argument of the function, the compiler can figure that out.</p>
1999<p>Note that this intrinsic function is only legal to be called from
2000within the body of a variable argument function.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002001</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002002
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002003<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002004<div class="doc_subsubsection">
2005 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
2006</div>
2007
Misha Brukman9d0919f2003-11-08 01:05:38 +00002008<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002009<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002010<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 +00002011<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002012<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
2013which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
2014or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002015<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002016<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002017<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002018<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002019macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
2020Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
2021 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
2022with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002023</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002024
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002025<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00002026<div class="doc_subsubsection">
2027 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
2028</div>
2029
Misha Brukman9d0919f2003-11-08 01:05:38 +00002030<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00002031
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002032<h5>Syntax:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002033
2034<pre>
Chris Lattnere19d7a72004-09-27 21:51:25 +00002035 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 +00002036</pre>
2037
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002038<h5>Overview:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002039
2040<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position
2041from the source argument list to the destination argument list.</p>
2042
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002043<h5>Arguments:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002044
Misha Brukman9d0919f2003-11-08 01:05:38 +00002045<p>The argument is the <tt>va_list</tt> to copy.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00002046
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00002047<h5>Semantics:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00002048
Misha Brukman9d0919f2003-11-08 01:05:38 +00002049<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
Chris Lattnerd7923912004-05-23 21:06:01 +00002050macro available in C. In a target-dependent way, it copies the source
2051<tt>va_list</tt> element into the returned list. This intrinsic is necessary
Chris Lattnerfcd37252004-06-21 22:52:48 +00002052because the <tt><a href="#i_va_start">llvm.va_start</a></tt> intrinsic may be
Chris Lattnerd7923912004-05-23 21:06:01 +00002053arbitrarily complex and require memory allocation, for example.</p>
2054
Misha Brukman9d0919f2003-11-08 01:05:38 +00002055</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00002056
Chris Lattner33aec9e2004-02-12 17:01:32 +00002057<!-- ======================================================================= -->
2058<div class="doc_subsection">
Chris Lattnerd7923912004-05-23 21:06:01 +00002059 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
2060</div>
2061
2062<div class="doc_text">
2063
2064<p>
2065LLVM support for <a href="GarbageCollection.html">Accurate Garbage
2066Collection</a> requires the implementation and generation of these intrinsics.
2067These intrinsics allow identification of <a href="#i_gcroot">GC roots on the
2068stack</a>, as well as garbage collector implementations that require <a
2069href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers.
2070Front-ends for type-safe garbage collected languages should generate these
2071intrinsics to make use of the LLVM garbage collectors. For more details, see <a
2072href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
2073</p>
2074</div>
2075
2076<!-- _______________________________________________________________________ -->
2077<div class="doc_subsubsection">
2078 <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
2079</div>
2080
2081<div class="doc_text">
2082
2083<h5>Syntax:</h5>
2084
2085<pre>
2086 call void (&lt;ty&gt;**, &lt;ty2&gt;*)* %llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
2087</pre>
2088
2089<h5>Overview:</h5>
2090
2091<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existance of a GC root to
2092the code generator, and allows some metadata to be associated with it.</p>
2093
2094<h5>Arguments:</h5>
2095
2096<p>The first argument specifies the address of a stack object that contains the
2097root pointer. The second pointer (which must be either a constant or a global
2098value address) contains the meta-data to be associated with the root.</p>
2099
2100<h5>Semantics:</h5>
2101
2102<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
2103location. At compile-time, the code generator generates information to allow
2104the runtime to find the pointer at GC safe points.
2105</p>
2106
2107</div>
2108
2109
2110<!-- _______________________________________________________________________ -->
2111<div class="doc_subsubsection">
2112 <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
2113</div>
2114
2115<div class="doc_text">
2116
2117<h5>Syntax:</h5>
2118
2119<pre>
2120 call sbyte* (sbyte**)* %llvm.gcread(sbyte** %Ptr)
2121</pre>
2122
2123<h5>Overview:</h5>
2124
2125<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
2126locations, allowing garbage collector implementations that require read
2127barriers.</p>
2128
2129<h5>Arguments:</h5>
2130
2131<p>The argument is the address to read from, which should be an address
2132allocated from the garbage collector.</p>
2133
2134<h5>Semantics:</h5>
2135
2136<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
2137instruction, but may be replaced with substantially more complex code by the
2138garbage collector runtime, as needed.</p>
2139
2140</div>
2141
2142
2143<!-- _______________________________________________________________________ -->
2144<div class="doc_subsubsection">
2145 <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
2146</div>
2147
2148<div class="doc_text">
2149
2150<h5>Syntax:</h5>
2151
2152<pre>
2153 call void (sbyte*, sbyte**)* %llvm.gcwrite(sbyte* %P1, sbyte** %P2)
2154</pre>
2155
2156<h5>Overview:</h5>
2157
2158<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
2159locations, allowing garbage collector implementations that require write
2160barriers (such as generational or reference counting collectors).</p>
2161
2162<h5>Arguments:</h5>
2163
2164<p>The first argument is the reference to store, and the second is the heap
2165location to store to.</p>
2166
2167<h5>Semantics:</h5>
2168
2169<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
2170instruction, but may be replaced with substantially more complex code by the
2171garbage collector runtime, as needed.</p>
2172
2173</div>
2174
2175
2176
2177<!-- ======================================================================= -->
2178<div class="doc_subsection">
Chris Lattner10610642004-02-14 04:08:35 +00002179 <a name="int_codegen">Code Generator Intrinsics</a>
2180</div>
2181
2182<div class="doc_text">
2183<p>
2184These intrinsics are provided by LLVM to expose special features that may only
2185be implemented with code generator support.
2186</p>
2187
2188</div>
2189
2190<!-- _______________________________________________________________________ -->
2191<div class="doc_subsubsection">
2192 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
2193</div>
2194
2195<div class="doc_text">
2196
2197<h5>Syntax:</h5>
2198<pre>
2199 call void* ()* %llvm.returnaddress(uint &lt;level&gt;)
2200</pre>
2201
2202<h5>Overview:</h5>
2203
2204<p>
2205The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
2206indicating the return address of the current function or one of its callers.
2207</p>
2208
2209<h5>Arguments:</h5>
2210
2211<p>
2212The argument to this intrinsic indicates which function to return the address
2213for. Zero indicates the calling function, one indicates its caller, etc. The
2214argument is <b>required</b> to be a constant integer value.
2215</p>
2216
2217<h5>Semantics:</h5>
2218
2219<p>
2220The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
2221the return address of the specified call frame, or zero if it cannot be
2222identified. The value returned by this intrinsic is likely to be incorrect or 0
2223for arguments other than zero, so it should only be used for debugging purposes.
2224</p>
2225
2226<p>
2227Note that calling this intrinsic does not prevent function inlining or other
2228aggressive transformations, so the value returned may not that of the obvious
2229source-language caller.
2230</p>
2231</div>
2232
2233
2234<!-- _______________________________________________________________________ -->
2235<div class="doc_subsubsection">
2236 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
2237</div>
2238
2239<div class="doc_text">
2240
2241<h5>Syntax:</h5>
2242<pre>
2243 call void* ()* %llvm.frameaddress(uint &lt;level&gt;)
2244</pre>
2245
2246<h5>Overview:</h5>
2247
2248<p>
2249The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
2250pointer value for the specified stack frame.
2251</p>
2252
2253<h5>Arguments:</h5>
2254
2255<p>
2256The argument to this intrinsic indicates which function to return the frame
2257pointer for. Zero indicates the calling function, one indicates its caller,
2258etc. The argument is <b>required</b> to be a constant integer value.
2259</p>
2260
2261<h5>Semantics:</h5>
2262
2263<p>
2264The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
2265the frame address of the specified call frame, or zero if it cannot be
2266identified. The value returned by this intrinsic is likely to be incorrect or 0
2267for arguments other than zero, so it should only be used for debugging purposes.
2268</p>
2269
2270<p>
2271Note that calling this intrinsic does not prevent function inlining or other
2272aggressive transformations, so the value returned may not that of the obvious
2273source-language caller.
2274</p>
2275</div>
2276
John Criswell7123e272004-04-09 16:43:20 +00002277<!-- ======================================================================= -->
2278<div class="doc_subsection">
2279 <a name="int_os">Operating System Intrinsics</a>
2280</div>
2281
2282<div class="doc_text">
2283<p>
2284These intrinsics are provided by LLVM to support the implementation of
2285operating system level code.
2286</p>
2287
2288</div>
John Criswell183402a2004-04-12 15:02:16 +00002289
John Criswellcfd3bac2004-04-09 15:23:37 +00002290<!-- _______________________________________________________________________ -->
2291<div class="doc_subsubsection">
2292 <a name="i_readport">'<tt>llvm.readport</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 &lt;integer type&gt; (&lt;integer type&gt;)* %llvm.readport (&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.readport</tt>' intrinsic reads data from the specified hardware
2306I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002307</p>
2308
2309<h5>Arguments:</h5>
2310
2311<p>
John Criswell7123e272004-04-09 16:43:20 +00002312The argument to this intrinsic indicates the hardware I/O address from which
2313to read the data. The address is in the hardware I/O address namespace (as
2314opposed to being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002315</p>
2316
2317<h5>Semantics:</h5>
2318
2319<p>
John Criswell7123e272004-04-09 16:43:20 +00002320The '<tt>llvm.readport</tt>' intrinsic reads data from the hardware I/O port
2321specified by <i>address</i> and returns the value. The address and return
2322value must be integers, but the size is dependent upon the platform upon which
2323the program is code generated. For example, on x86, the address must be an
2324unsigned 16 bit value, and the return value must be 8, 16, or 32 bits.
John Criswellcfd3bac2004-04-09 15:23:37 +00002325</p>
2326
2327</div>
2328
2329<!-- _______________________________________________________________________ -->
2330<div class="doc_subsubsection">
2331 <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a>
2332</div>
2333
2334<div class="doc_text">
2335
2336<h5>Syntax:</h5>
2337<pre>
John Criswell7123e272004-04-09 16:43:20 +00002338 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 +00002339</pre>
2340
2341<h5>Overview:</h5>
2342
2343<p>
John Criswell7123e272004-04-09 16:43:20 +00002344The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified hardware
2345I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002346</p>
2347
2348<h5>Arguments:</h5>
2349
2350<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002351The first argument is the value to write to the I/O port.
John Criswellcfd3bac2004-04-09 15:23:37 +00002352</p>
2353
2354<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002355The second argument indicates the hardware I/O address to which data should be
2356written. The address is in the hardware I/O address namespace (as opposed to
2357being a memory location for memory mapped I/O).
John Criswellcfd3bac2004-04-09 15:23:37 +00002358</p>
2359
2360<h5>Semantics:</h5>
2361
2362<p>
2363The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port
2364specified by <i>address</i>. The address and value must be integers, but the
2365size is dependent upon the platform upon which the program is code generated.
John Criswell7123e272004-04-09 16:43:20 +00002366For example, on x86, the address must be an unsigned 16 bit value, and the
2367value written must be 8, 16, or 32 bits in length.
John Criswellcfd3bac2004-04-09 15:23:37 +00002368</p>
2369
2370</div>
Chris Lattner10610642004-02-14 04:08:35 +00002371
John Criswell183402a2004-04-12 15:02:16 +00002372<!-- _______________________________________________________________________ -->
2373<div class="doc_subsubsection">
2374 <a name="i_readio">'<tt>llvm.readio</tt>' Intrinsic</a>
2375</div>
2376
2377<div class="doc_text">
2378
2379<h5>Syntax:</h5>
2380<pre>
John Criswell96db6fc2004-04-12 16:33:19 +00002381 call &lt;result&gt; (&lt;ty&gt;*)* %llvm.readio (&lt;ty&gt; * &lt;pointer&gt;)
John Criswell183402a2004-04-12 15:02:16 +00002382</pre>
2383
2384<h5>Overview:</h5>
2385
2386<p>
2387The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
2388address.
2389</p>
2390
2391<h5>Arguments:</h5>
2392
2393<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002394The argument to this intrinsic is a pointer indicating the memory address from
2395which to read the data. The data must be a
2396<a href="#t_firstclass">first class</a> type.
John Criswell183402a2004-04-12 15:02:16 +00002397</p>
2398
2399<h5>Semantics:</h5>
2400
2401<p>
2402The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
John Criswell96db6fc2004-04-12 16:33:19 +00002403location specified by <i>pointer</i> and returns the value. The argument must
2404be a pointer, and the return value must be a
2405<a href="#t_firstclass">first class</a> type. However, certain architectures
2406may not support I/O on all first class types. For example, 32 bit processors
2407may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00002408</p>
2409
2410<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002411This intrinsic enforces an in-order memory model for llvm.readio and
2412llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2413scheduled processors may execute loads and stores out of order, re-ordering at
2414run time accesses to memory mapped I/O registers. Using these intrinsics
2415ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00002416</p>
2417
2418</div>
2419
2420<!-- _______________________________________________________________________ -->
2421<div class="doc_subsubsection">
2422 <a name="i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a>
2423</div>
2424
2425<div class="doc_text">
2426
2427<h5>Syntax:</h5>
2428<pre>
John Criswell96db6fc2004-04-12 16:33:19 +00002429 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 +00002430</pre>
2431
2432<h5>Overview:</h5>
2433
2434<p>
2435The '<tt>llvm.writeio</tt>' intrinsic writes data to the specified memory
2436mapped I/O address.
2437</p>
2438
2439<h5>Arguments:</h5>
2440
2441<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002442The first argument is the value to write to the memory mapped I/O location.
2443The second argument is a pointer indicating the memory address to which the
2444data should be written.
John Criswell183402a2004-04-12 15:02:16 +00002445</p>
2446
2447<h5>Semantics:</h5>
2448
2449<p>
2450The '<tt>llvm.writeio</tt>' intrinsic writes <i>value</i> to the memory mapped
John Criswell96db6fc2004-04-12 16:33:19 +00002451I/O address specified by <i>pointer</i>. The value must be a
2452<a href="#t_firstclass">first class</a> type. However, certain architectures
2453may not support I/O on all first class types. For example, 32 bit processors
2454may only support I/O on data types that are 32 bits or less.
John Criswell183402a2004-04-12 15:02:16 +00002455</p>
2456
2457<p>
John Criswell96db6fc2004-04-12 16:33:19 +00002458This intrinsic enforces an in-order memory model for llvm.readio and
2459llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2460scheduled processors may execute loads and stores out of order, re-ordering at
2461run time accesses to memory mapped I/O registers. Using these intrinsics
2462ensures that accesses to memory mapped I/O registers occur in program order.
John Criswell183402a2004-04-12 15:02:16 +00002463</p>
2464
2465</div>
2466
Chris Lattner10610642004-02-14 04:08:35 +00002467<!-- ======================================================================= -->
2468<div class="doc_subsection">
Chris Lattner33aec9e2004-02-12 17:01:32 +00002469 <a name="int_libc">Standard C Library Intrinsics</a>
2470</div>
2471
2472<div class="doc_text">
2473<p>
Chris Lattner10610642004-02-14 04:08:35 +00002474LLVM provides intrinsics for a few important standard C library functions.
2475These intrinsics allow source-language front-ends to pass information about the
2476alignment of the pointer arguments to the code generator, providing opportunity
2477for more efficient code generation.
Chris Lattner33aec9e2004-02-12 17:01:32 +00002478</p>
2479
2480</div>
2481
2482<!-- _______________________________________________________________________ -->
2483<div class="doc_subsubsection">
2484 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
2485</div>
2486
2487<div class="doc_text">
2488
2489<h5>Syntax:</h5>
2490<pre>
2491 call void (sbyte*, sbyte*, uint, uint)* %llvm.memcpy(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2492 uint &lt;len&gt;, uint &lt;align&gt;)
2493</pre>
2494
2495<h5>Overview:</h5>
2496
2497<p>
2498The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2499location to the destination location.
2500</p>
2501
2502<p>
2503Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
2504does not return a value, and takes an extra alignment argument.
2505</p>
2506
2507<h5>Arguments:</h5>
2508
2509<p>
2510The first argument is a pointer to the destination, the second is a pointer to
2511the source. The third argument is an (arbitrarily sized) integer argument
2512specifying the number of bytes to copy, and the fourth argument is the alignment
2513of the source and destination locations.
2514</p>
2515
Chris Lattner3301ced2004-02-12 21:18:15 +00002516<p>
2517If the call to this intrinisic has an alignment value that is not 0 or 1, then
2518the caller guarantees that the size of the copy is a multiple of the alignment
2519and that both the source and destination pointers are aligned to that boundary.
2520</p>
2521
Chris Lattner33aec9e2004-02-12 17:01:32 +00002522<h5>Semantics:</h5>
2523
2524<p>
2525The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2526location to the destination location, which are not allowed to overlap. It
2527copies "len" bytes of memory over. If the argument is known to be aligned to
2528some boundary, this can be specified as the fourth argument, otherwise it should
2529be set to 0 or 1.
2530</p>
2531</div>
2532
2533
Chris Lattner0eb51b42004-02-12 18:10:10 +00002534<!-- _______________________________________________________________________ -->
2535<div class="doc_subsubsection">
2536 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
2537</div>
2538
2539<div class="doc_text">
2540
2541<h5>Syntax:</h5>
2542<pre>
2543 call void (sbyte*, sbyte*, uint, uint)* %llvm.memmove(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2544 uint &lt;len&gt;, uint &lt;align&gt;)
2545</pre>
2546
2547<h5>Overview:</h5>
2548
2549<p>
2550The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
2551location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>'
2552intrinsic but allows the two memory locations to overlap.
2553</p>
2554
2555<p>
2556Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
2557does not return a value, and takes an extra alignment argument.
2558</p>
2559
2560<h5>Arguments:</h5>
2561
2562<p>
2563The first argument is a pointer to the destination, the second is a pointer to
2564the source. The third argument is an (arbitrarily sized) integer argument
2565specifying the number of bytes to copy, and the fourth argument is the alignment
2566of the source and destination locations.
2567</p>
2568
Chris Lattner3301ced2004-02-12 21:18:15 +00002569<p>
2570If the call to this intrinisic has an alignment value that is not 0 or 1, then
2571the caller guarantees that the size of the copy is a multiple of the alignment
2572and that both the source and destination pointers are aligned to that boundary.
2573</p>
2574
Chris Lattner0eb51b42004-02-12 18:10:10 +00002575<h5>Semantics:</h5>
2576
2577<p>
2578The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
2579location to the destination location, which may overlap. It
2580copies "len" bytes of memory over. If the argument is known to be aligned to
2581some boundary, this can be specified as the fourth argument, otherwise it should
2582be set to 0 or 1.
2583</p>
2584</div>
2585
Chris Lattner8ff75902004-01-06 05:31:32 +00002586
Chris Lattner10610642004-02-14 04:08:35 +00002587<!-- _______________________________________________________________________ -->
2588<div class="doc_subsubsection">
2589 <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a>
2590</div>
2591
2592<div class="doc_text">
2593
2594<h5>Syntax:</h5>
2595<pre>
2596 call void (sbyte*, ubyte, uint, uint)* %llvm.memset(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
2597 uint &lt;len&gt;, uint &lt;align&gt;)
2598</pre>
2599
2600<h5>Overview:</h5>
2601
2602<p>
2603The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular
2604byte value.
2605</p>
2606
2607<p>
2608Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
2609does not return a value, and takes an extra alignment argument.
2610</p>
2611
2612<h5>Arguments:</h5>
2613
2614<p>
2615The first argument is a pointer to the destination to fill, the second is the
2616byte value to fill it with, the third argument is an (arbitrarily sized) integer
2617argument specifying the number of bytes to fill, and the fourth argument is the
2618known alignment of destination location.
2619</p>
2620
2621<p>
2622If the call to this intrinisic has an alignment value that is not 0 or 1, then
2623the caller guarantees that the size of the copy is a multiple of the alignment
2624and that the destination pointer is aligned to that boundary.
2625</p>
2626
2627<h5>Semantics:</h5>
2628
2629<p>
2630The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the
2631destination location. If the argument is known to be aligned to some boundary,
2632this can be specified as the fourth argument, otherwise it should be set to 0 or
26331.
2634</p>
2635</div>
2636
2637
Chris Lattner32006282004-06-11 02:28:03 +00002638<!-- _______________________________________________________________________ -->
2639<div class="doc_subsubsection">
Alkis Evlogimenos26bbe932004-06-13 01:16:15 +00002640 <a name="i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a>
2641</div>
2642
2643<div class="doc_text">
2644
2645<h5>Syntax:</h5>
2646<pre>
2647 call bool (&lt;float or double&gt;, &lt;float or double&gt;)* %llvm.isunordered(&lt;float or double&gt; Val1,
2648 &lt;float or double&gt; Val2)
2649</pre>
2650
2651<h5>Overview:</h5>
2652
2653<p>
2654The '<tt>llvm.isunordered</tt>' intrinsic returns true if either or both of the
2655specified floating point values is a NAN.
2656</p>
2657
2658<h5>Arguments:</h5>
2659
2660<p>
2661The arguments are floating point numbers of the same type.
2662</p>
2663
2664<h5>Semantics:</h5>
2665
2666<p>
2667If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise
2668false.
2669</p>
2670</div>
2671
2672
Chris Lattner32006282004-06-11 02:28:03 +00002673
2674
Chris Lattner8ff75902004-01-06 05:31:32 +00002675<!-- ======================================================================= -->
2676<div class="doc_subsection">
2677 <a name="int_debugger">Debugger Intrinsics</a>
2678</div>
2679
2680<div class="doc_text">
2681<p>
2682The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
2683are described in the <a
2684href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
2685Debugging</a> document.
2686</p>
2687</div>
2688
2689
Chris Lattner00950542001-06-06 20:29:01 +00002690<!-- *********************************************************************** -->
Chris Lattner00950542001-06-06 20:29:01 +00002691<hr>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002692<address>
2693 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
2694 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
2695 <a href="http://validator.w3.org/check/referer"><img
2696 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
2697
2698 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
2699 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
2700 Last modified: $Date$
2701</address>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002702</body>
2703</html>