blob: 41379db37f7cc0268740362cafba331b58fd2e29 [file] [log] [blame]
Misha Brukmanc501f552004-03-01 17:47:27 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
Misha Brukman76307852003-11-08 01:05:38 +00003<html>
4<head>
5 <title>LLVM Assembly Language Reference Manual</title>
Reid Spencercb84e432004-08-26 20:44:00 +00006 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7 <meta name="author" content="Chris Lattner">
8 <meta name="description"
9 content="LLVM Assembly Language Reference Manual.">
Misha Brukman76307852003-11-08 01:05:38 +000010 <link rel="stylesheet" href="llvm.css" type="text/css">
11</head>
Chris Lattner757528b0b2004-05-23 21:06:01 +000012
Misha Brukman76307852003-11-08 01:05:38 +000013<body>
Chris Lattner757528b0b2004-05-23 21:06:01 +000014
Chris Lattner48b383b02003-11-25 01:02:51 +000015<div class="doc_title"> LLVM Language Reference Manual </div>
Chris Lattner2f7c9632001-06-06 20:29:01 +000016<ol>
Misha Brukman76307852003-11-08 01:05:38 +000017 <li><a href="#abstract">Abstract</a></li>
18 <li><a href="#introduction">Introduction</a></li>
19 <li><a href="#identifiers">Identifiers</a></li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000020 <li><a href="#typesystem">Type System</a>
21 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000022 <li><a href="#t_primitive">Primitive Types</a>
23 <ol>
Misha Brukman76307852003-11-08 01:05:38 +000024 <li><a href="#t_classifications">Type Classifications</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000025 </ol>
26 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000027 <li><a href="#t_derived">Derived Types</a>
28 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000029 <li><a href="#t_array">Array Type</a></li>
Misha Brukman76307852003-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 Lattner48b383b02003-11-25 01:02:51 +000032 <li><a href="#t_struct">Structure Type</a></li>
Chris Lattnerc8cb6952004-08-12 19:12:28 +000033 <li><a href="#t_packed">Packed Type</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000034 </ol>
35 </li>
36 </ol>
37 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000038 <li><a href="#highlevel">High Level Structure</a>
39 <ol>
Misha Brukman76307852003-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 Lattner48b383b02003-11-25 01:02:51 +000043 </ol>
44 </li>
Chris Lattner2f7c9632001-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 Lattner48b383b02003-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 Brukman76307852003-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 Lattner48b383b02003-11-25 01:02:51 +000053 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
Chris Lattner08b7d5b2004-10-16 18:04:13 +000054 <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000055 </ol>
56 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000057 <li><a href="#binaryops">Binary Operations</a>
58 <ol>
Chris Lattner48b383b02003-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 Brukman76307852003-11-08 01:05:38 +000064 <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000065 </ol>
66 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000067 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
68 <ol>
Misha Brukman76307852003-11-08 01:05:38 +000069 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000070 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman76307852003-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 Lattner48b383b02003-11-25 01:02:51 +000074 </ol>
75 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000076 <li><a href="#memoryops">Memory Access Operations</a>
77 <ol>
Chris Lattner48b383b02003-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 Lattner2f7c9632001-06-06 20:29:01 +000086 <li><a href="#otherops">Other Operations</a>
87 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000088 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000089 <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li>
Chris Lattnerb53c28d2004-03-12 05:50:16 +000090 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000091 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000092 <li><a href="#i_vanext">'<tt>vanext</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000093 <li><a href="#i_vaarg">'<tt>vaarg</tt>' Instruction</a></li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000094 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000095 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000096 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000097 </li>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +000098 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +000099 <ol>
Chris Lattner48b383b02003-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 Lattner757528b0b2004-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 Lattner3649c3a2004-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 Criswellaa1c3c12004-04-09 16:43:20 +0000118 </ol>
119 </li>
120 <li><a href="#int_os">Operating System Intrinsics</a>
121 <ol>
Chris Lattner3b4f4372004-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 Criswella4501222004-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 Lattner3649c3a2004-02-14 04:08:35 +0000126 </ol>
Chris Lattnerfee11462004-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 Lattnerf30152e2004-02-12 18:10:10 +0000130 <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li>
Chris Lattner3649c3a2004-02-14 04:08:35 +0000131 <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li>
Alkis Evlogimenos9d740622004-06-12 19:19:14 +0000132 <li><a href="#i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a></li>
Chris Lattnerfee11462004-02-12 17:01:32 +0000133 </ol>
134 </li>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000135 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000136 </ol>
137 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000138</ol>
Chris Lattner757528b0b2004-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 Brukman76307852003-11-08 01:05:38 +0000143</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000144
Chris Lattner2f7c9632001-06-06 20:29:01 +0000145<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000146<div class="doc_section"> <a name="abstract">Abstract </a></div>
147<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000148
Misha Brukman76307852003-11-08 01:05:38 +0000149<div class="doc_text">
Chris Lattner48b383b02003-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 Brukman76307852003-11-08 01:05:38 +0000156</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000157
Chris Lattner2f7c9632001-06-06 20:29:01 +0000158<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000159<div class="doc_section"> <a name="introduction">Introduction</a> </div>
160<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000161
Misha Brukman76307852003-11-08 01:05:38 +0000162<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000163
Chris Lattner48b383b02003-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 Lattner757528b0b2004-05-23 21:06:01 +0000173
Chris Lattner48b383b02003-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 Lattner757528b0b2004-05-23 21:06:01 +0000184
Misha Brukman76307852003-11-08 01:05:38 +0000185</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000186
Chris Lattner2f7c9632001-06-06 20:29:01 +0000187<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000188<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000189
Misha Brukman76307852003-11-08 01:05:38 +0000190<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000191
Chris Lattner48b383b02003-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 Lattner757528b0b2004-05-23 21:06:01 +0000196
197<pre>
198 %x = <a href="#i_add">add</a> int 1, %x
199</pre>
200
Chris Lattner48b383b02003-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 Lattner757528b0b2004-05-23 21:06:01 +0000208
Chris Lattner48b383b02003-11-25 01:02:51 +0000209<!-- Describe the typesetting conventions here. --> </div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000210
Chris Lattner2f7c9632001-06-06 20:29:01 +0000211<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000212<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000213<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000214
Misha Brukman76307852003-11-08 01:05:38 +0000215<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000216
Chris Lattner48b383b02003-11-25 01:02:51 +0000217<p>LLVM uses three different forms of identifiers, for different
218purposes:</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000219
Chris Lattner2f7c9632001-06-06 20:29:01 +0000220<ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000221 <li>Numeric constants are represented as you would expect: 12, -3
John Criswell417228d2004-04-09 16:48:45 +0000222123.421, etc. Floating point constants have an optional hexadecimal
Chris Lattner48b383b02003-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 Brukman76307852003-11-08 01:05:38 +0000232</ol>
John Criswelleb55b522004-03-12 21:19:06 +0000233<p>LLVM requires that values start with a '%' sign for two reasons:
Chris Lattner48b383b02003-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 Brukman76307852003-11-08 01:05:38 +0000248<p>The easy way:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +0000249<pre> %result = <a href="#i_mul">mul</a> uint %X, 8<br></pre>
Misha Brukman76307852003-11-08 01:05:38 +0000250<p>After strength reduction:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +0000251<pre> %result = <a href="#i_shl">shl</a> uint %X, ubyte 3<br></pre>
Misha Brukman76307852003-11-08 01:05:38 +0000252<p>And the hard way:</p>
Chris Lattner48b383b02003-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 Lattner2f7c9632001-06-06 20:29:01 +0000260<ol>
Chris Lattner48b383b02003-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 Brukman76307852003-11-08 01:05:38 +0000265 <li>Unnamed temporaries are numbered sequentially</li>
266</ol>
Chris Lattner48b383b02003-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 Lattner095735d2002-05-06 03:03:22 +00002730x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
Chris Lattner48b383b02003-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 Brukman76307852003-11-08 01:05:38 +0000281</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000282<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000283<div class="doc_section"> <a name="typesystem">Type System</a> </div>
284<!-- *********************************************************************** -->
Misha Brukman76307852003-11-08 01:05:38 +0000285<div class="doc_text">
Misha Brukman76307852003-11-08 01:05:38 +0000286<p>The LLVM type system is one of the most important features of the
Chris Lattner48b383b02003-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 Lattnerd8f8ede2002-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 Lattner48b383b02003-11-25 01:02:51 +0000295href="#rw_stroustrup">1</a></sup>.<p> --> </div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000296<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000297<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000298<div class="doc_text">
John Criswell417228d2004-04-09 16:48:45 +0000299<p>The primitive types are the fundamental building blocks of the LLVM
Chris Lattner48b383b02003-11-25 01:02:51 +0000300system. The current set of primitive types are as follows:</p>
Misha Brukmanc501f552004-03-01 17:47:27 +0000301
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000302<table class="layout">
303 <tr class="layout">
304 <td class="left">
305 <table>
Chris Lattner48b383b02003-11-25 01:02:51 +0000306 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000307 <tr><th>Type</th><th>Description</th></tr>
308 <tr><td><tt>void</tt></td><td>No value</td></tr>
309 <tr><td><tt>ubyte</tt></td><td>Unsigned 8 bit value</td></tr>
310 <tr><td><tt>ushort</tt></td><td>Unsigned 16 bit value</td></tr>
311 <tr><td><tt>uint</tt></td><td>Unsigned 32 bit value</td></tr>
312 <tr><td><tt>ulong</tt></td><td>Unsigned 64 bit value</td></tr>
313 <tr><td><tt>float</tt></td><td>32 bit floating point value</td></tr>
314 <tr><td><tt>label</tt></td><td>Branch destination</td></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000315 </tbody>
316 </table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000317 </td>
318 <td class="right">
319 <table>
Chris Lattner48b383b02003-11-25 01:02:51 +0000320 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000321 <tr><th>Type</th><th>Description</th></tr>
322 <tr><td><tt>bool</tt></td><td>True or False value</td></tr>
323 <tr><td><tt>sbyte</tt></td><td>Signed 8 bit value</td></tr>
324 <tr><td><tt>short</tt></td><td>Signed 16 bit value</td></tr>
325 <tr><td><tt>int</tt></td><td>Signed 32 bit value</td></tr>
326 <tr><td><tt>long</tt></td><td>Signed 64 bit value</td></tr>
327 <tr><td><tt>double</tt></td><td>64 bit floating point value</td></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000328 </tbody>
329 </table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000330 </td>
331 </tr>
Misha Brukman76307852003-11-08 01:05:38 +0000332</table>
Misha Brukman76307852003-11-08 01:05:38 +0000333</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000334
Chris Lattner2f7c9632001-06-06 20:29:01 +0000335<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000336<div class="doc_subsubsection"> <a name="t_classifications">Type
337Classifications</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000338<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000339<p>These different primitive types fall into a few useful
340classifications:</p>
Misha Brukmanc501f552004-03-01 17:47:27 +0000341
342<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +0000343 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000344 <tr><th>Classification</th><th>Types</th></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000345 <tr>
346 <td><a name="t_signed">signed</a></td>
347 <td><tt>sbyte, short, int, long, float, double</tt></td>
348 </tr>
349 <tr>
350 <td><a name="t_unsigned">unsigned</a></td>
351 <td><tt>ubyte, ushort, uint, ulong</tt></td>
352 </tr>
353 <tr>
354 <td><a name="t_integer">integer</a></td>
355 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
356 </tr>
357 <tr>
358 <td><a name="t_integral">integral</a></td>
Misha Brukman20f9a622004-08-12 20:16:08 +0000359 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt>
360 </td>
Chris Lattner48b383b02003-11-25 01:02:51 +0000361 </tr>
362 <tr>
363 <td><a name="t_floating">floating point</a></td>
364 <td><tt>float, double</tt></td>
365 </tr>
366 <tr>
367 <td><a name="t_firstclass">first class</a></td>
Misha Brukman20f9a622004-08-12 20:16:08 +0000368 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long,<br>
369 float, double, <a href="#t_pointer">pointer</a>,
370 <a href="#t_packed">packed</a></tt></td>
Chris Lattner48b383b02003-11-25 01:02:51 +0000371 </tr>
372 </tbody>
Misha Brukman76307852003-11-08 01:05:38 +0000373</table>
Misha Brukmanc501f552004-03-01 17:47:27 +0000374
Chris Lattner48b383b02003-11-25 01:02:51 +0000375<p>The <a href="#t_firstclass">first class</a> types are perhaps the
376most important. Values of these types are the only ones which can be
377produced by instructions, passed as arguments, or used as operands to
378instructions. This means that all structures and arrays must be
379manipulated either by pointer or by component.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000380</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000381<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000382<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000383<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000384<p>The real power in LLVM comes from the derived types in the system.
385This is what allows a programmer to represent arrays, functions,
386pointers, and other useful types. Note that these derived types may be
387recursive: For example, it is possible to have a two dimensional array.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000388</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000389<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000390<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000391<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000392<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +0000393<p>The array type is a very simple derived type that arranges elements
Chris Lattner48b383b02003-11-25 01:02:51 +0000394sequentially in memory. The array type requires a size (number of
395elements) and an underlying data type.</p>
Chris Lattner590645f2002-04-14 06:13:44 +0000396<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000397<pre> [&lt;# elements&gt; x &lt;elementtype&gt;]<br></pre>
398<p>The number of elements is a constant integer value, elementtype may
399be any type with a size.</p>
Chris Lattner590645f2002-04-14 06:13:44 +0000400<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000401<table class="layout">
402 <tr class="layout">
403 <td class="left">
404 <tt>[40 x int ]</tt><br/>
405 <tt>[41 x int ]</tt><br/>
406 <tt>[40 x uint]</tt><br/>
407 </td>
408 <td class="left">
409 Array of 40 integer values.<br/>
410 Array of 41 integer values.<br/>
411 Array of 40 unsigned integer values.<br/>
412 </td>
413 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000414</table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000415<p>Here are some examples of multidimensional arrays:</p>
416<table class="layout">
417 <tr class="layout">
418 <td class="left">
419 <tt>[3 x [4 x int]]</tt><br/>
420 <tt>[12 x [10 x float]]</tt><br/>
421 <tt>[2 x [3 x [4 x uint]]]</tt><br/>
422 </td>
423 <td class="left">
424 3x4 array integer values.<br/>
425 12x10 array of single precision floating point values.<br/>
426 2x3x4 array of unsigned integer values.<br/>
427 </td>
428 </tr>
429</table>
Misha Brukman76307852003-11-08 01:05:38 +0000430</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000431
Chris Lattner2f7c9632001-06-06 20:29:01 +0000432<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000433<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000434<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000435<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000436<p>The function type can be thought of as a function signature. It
437consists of a return type and a list of formal parameter types.
John Criswella0d50d22003-11-25 21:45:46 +0000438Function types are usually used to build virtual function tables
Chris Lattner48b383b02003-11-25 01:02:51 +0000439(which are structures of pointers to functions), for indirect function
440calls, and when defining a function.</p>
John Criswella0d50d22003-11-25 21:45:46 +0000441<p>
442The return type of a function type cannot be an aggregate type.
443</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000444<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000445<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
Misha Brukman20f9a622004-08-12 20:16:08 +0000446<p>Where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
447specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner5ed60612003-09-03 00:41:47 +0000448which indicates that the function takes a variable number of arguments.
449Variable argument functions can access their arguments with the <a
Chris Lattner48b383b02003-11-25 01:02:51 +0000450 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000451<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000452<table class="layout">
453 <tr class="layout">
454 <td class="left">
455 <tt>int (int)</tt> <br/>
456 <tt>float (int, int *) *</tt><br/>
457 <tt>int (sbyte *, ...)</tt><br/>
458 </td>
459 <td class="left">
460 function taking an <tt>int</tt>, returning an <tt>int</tt><br/>
461 <a href="#t_pointer">Pointer</a> to a function that takes an
Misha Brukman20f9a622004-08-12 20:16:08 +0000462 <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000463 returning <tt>float</tt>.<br/>
464 A vararg function that takes at least one <a href="#t_pointer">pointer</a>
465 to <tt>sbyte</tt> (signed char in C), which returns an integer. This is
466 the signature for <tt>printf</tt> in LLVM.<br/>
467 </td>
468 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000469</table>
Misha Brukmanc501f552004-03-01 17:47:27 +0000470
Misha Brukman76307852003-11-08 01:05:38 +0000471</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000472<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000473<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000474<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000475<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000476<p>The structure type is used to represent a collection of data members
477together in memory. The packing of the field types is defined to match
478the ABI of the underlying processor. The elements of a structure may
479be any type that has a size.</p>
480<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
481and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
482field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
483instruction.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000484<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000485<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000486<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000487<table class="layout">
488 <tr class="layout">
489 <td class="left">
490 <tt>{ int, int, int }</tt><br/>
491 <tt>{ float, int (int) * }</tt><br/>
492 </td>
493 <td class="left">
494 a triple of three <tt>int</tt> values<br/>
495 A pair, where the first element is a <tt>float</tt> and the second element
496 is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a>
497 that takes an <tt>int</tt>, returning an <tt>int</tt>.<br/>
498 </td>
499 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000500</table>
Misha Brukman76307852003-11-08 01:05:38 +0000501</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000502
Chris Lattner2f7c9632001-06-06 20:29:01 +0000503<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000504<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000505<div class="doc_text">
Chris Lattner590645f2002-04-14 06:13:44 +0000506<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000507<p>As in many languages, the pointer type represents a pointer or
508reference to another object, which must live in memory.</p>
Chris Lattner590645f2002-04-14 06:13:44 +0000509<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000510<pre> &lt;type&gt; *<br></pre>
Chris Lattner590645f2002-04-14 06:13:44 +0000511<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000512<table class="layout">
513 <tr class="layout">
514 <td class="left">
515 <tt>[4x int]*</tt><br/>
516 <tt>int (int *) *</tt><br/>
517 </td>
518 <td class="left">
519 A <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of
520 four <tt>int</tt> values<br/>
521 A <a href="#t_pointer">pointer</a> to a <a
Misha Brukman20f9a622004-08-12 20:16:08 +0000522 href="#t_function">function</a> that takes an <tt>int</tt>, returning an
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000523 <tt>int</tt>.<br/>
524 </td>
525 </tr>
Misha Brukman76307852003-11-08 01:05:38 +0000526</table>
Misha Brukman76307852003-11-08 01:05:38 +0000527</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000528
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000529<!-- _______________________________________________________________________ -->
530<div class="doc_subsubsection"> <a name="t_packed">Packed Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000531<div class="doc_text">
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000532<h5>Overview:</h5>
533<p>A packed type is a simple derived type that represents a vector
534of elements. Packed types are used when multiple primitive data
535are operated in parallel using a single instruction (SIMD).
536A packed type requires a size (number of
537elements) and an underlying primitive data type. Packed types are
538considered <a href="#t_firstclass">first class</a>.</p>
539<h5>Syntax:</h5>
540<pre> &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;<br></pre>
541<p>The number of elements is a constant integer value, elementtype may
542be any integral or floating point type.</p>
543<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000544<table class="layout">
545 <tr class="layout">
546 <td class="left">
547 <tt>&lt;4 x int&gt;</tt><br/>
548 <tt>&lt;8 x float&gt;</tt><br/>
549 <tt>&lt;2 x uint&gt;</tt><br/>
550 </td>
551 <td class="left">
552 Packed vector of 4 integer values.<br/>
553 Packed vector of 8 floating-point values.<br/>
554 Packed vector of 2 unsigned integer values.<br/>
555 </td>
556 </tr>
557</table>
Misha Brukman76307852003-11-08 01:05:38 +0000558</div>
559
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000560<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000561<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
Misha Brukman20f9a622004-08-12 20:16:08 +0000562<!-- *********************************************************************** -->
563<!-- ======================================================================= -->
564<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
565</div>
Misha Brukman76307852003-11-08 01:05:38 +0000566<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000567<p>LLVM programs are composed of "Module"s, each of which is a
568translation unit of the input programs. Each module consists of
569functions, global variables, and symbol table entries. Modules may be
570combined together with the LLVM linker, which merges function (and
571global variable) definitions, resolves forward declarations, and merges
572symbol table entries. Here is an example of the "hello world" module:</p>
573<pre><i>; Declare the string constant as a global constant...</i>
574<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
575 href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00" <i>; [13 x sbyte]*</i>
Chris Lattner095735d2002-05-06 03:03:22 +0000576
Chris Lattner5ed60612003-09-03 00:41:47 +0000577<i>; External declaration of the puts function</i>
578<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
Chris Lattner095735d2002-05-06 03:03:22 +0000579
580<i>; Definition of main function</i>
Chris Lattner5ed60612003-09-03 00:41:47 +0000581int %main() { <i>; int()* </i>
Chris Lattner095735d2002-05-06 03:03:22 +0000582 <i>; Convert [13x sbyte]* to sbyte *...</i>
Chris Lattner48b383b02003-11-25 01:02:51 +0000583 %cast210 = <a
584 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
Chris Lattner095735d2002-05-06 03:03:22 +0000585
586 <i>; Call puts function to write out the string to stdout...</i>
Chris Lattner48b383b02003-11-25 01:02:51 +0000587 <a
588 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
589 <a
590 href="#i_ret">ret</a> int 0<br>}<br></pre>
591<p>This example is made up of a <a href="#globalvars">global variable</a>
592named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
593function, and a <a href="#functionstructure">function definition</a>
594for "<tt>main</tt>".</p>
595<a name="linkage"> In general, a module is made up of a list of global
596values, where both functions and global variables are global values.
597Global values are represented by a pointer to a memory location (in
598this case, a pointer to an array of char, and a pointer to a function),
599and have one of the following linkage types:</a>
600<p> </p>
Chris Lattner5ed60612003-09-03 00:41:47 +0000601<dl>
Misha Brukmanc501f552004-03-01 17:47:27 +0000602 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattner48b383b02003-11-25 01:02:51 +0000603 <dd>Global values with internal linkage are only directly accessible
604by objects in the current module. In particular, linking code into a
605module with an internal global value may cause the internal to be
606renamed as necessary to avoid collisions. Because the symbol is
607internal to the module, all references can be updated. This
608corresponds to the notion of the '<tt>static</tt>' keyword in C, or the
609idea of "anonymous namespaces" in C++.
610 <p> </p>
611 </dd>
Misha Brukmanc501f552004-03-01 17:47:27 +0000612 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattner48b383b02003-11-25 01:02:51 +0000613 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt>
614linkage, with the twist that linking together two modules defining the
615same <tt>linkonce</tt> globals will cause one of the globals to be
616discarded. This is typically used to implement inline functions.
617Unreferenced <tt>linkonce</tt> globals are allowed to be discarded.
618 <p> </p>
619 </dd>
Misha Brukmanc501f552004-03-01 17:47:27 +0000620 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattner48b383b02003-11-25 01:02:51 +0000621 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt>
622linkage, except that unreferenced <tt>weak</tt> globals may not be
623discarded. This is used to implement constructs in C such as "<tt>int
624X;</tt>" at global scope.
625 <p> </p>
626 </dd>
Misha Brukmanc501f552004-03-01 17:47:27 +0000627 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattner48b383b02003-11-25 01:02:51 +0000628 <dd>"<tt>appending</tt>" linkage may only be applied to global
629variables of pointer to array type. When two global variables with
630appending linkage are linked together, the two global arrays are
631appended together. This is the LLVM, typesafe, equivalent of having
632the system linker append together "sections" with identical names when
633.o files are linked.
634 <p> </p>
635 </dd>
Misha Brukmanc501f552004-03-01 17:47:27 +0000636 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattner48b383b02003-11-25 01:02:51 +0000637 <dd>If none of the above identifiers are used, the global is
638externally visible, meaning that it participates in linkage and can be
639used to resolve external symbol references.
640 <p> </p>
641 </dd>
Chris Lattner48b383b02003-11-25 01:02:51 +0000642</dl>
643<p> </p>
644<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
645variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
646variable and was linked with this one, one of the two would be renamed,
647preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
648external (i.e., lacking any linkage declarations), they are accessible
649outside of the current module. It is illegal for a function <i>declaration</i>
650to have any linkage type other than "externally visible".</a></p>
Misha Brukman76307852003-11-08 01:05:38 +0000651</div>
Chris Lattnerb1652612004-03-08 16:49:10 +0000652
Chris Lattner2f7c9632001-06-06 20:29:01 +0000653<!-- ======================================================================= -->
Chris Lattnerb1652612004-03-08 16:49:10 +0000654<div class="doc_subsection">
655 <a name="globalvars">Global Variables</a>
656</div>
657
Misha Brukman76307852003-11-08 01:05:38 +0000658<div class="doc_text">
Chris Lattnerb1652612004-03-08 16:49:10 +0000659
Chris Lattner48b383b02003-11-25 01:02:51 +0000660<p>Global variables define regions of memory allocated at compilation
661time instead of run-time. Global variables may optionally be
662initialized. A variable may be defined as a global "constant", which
663indicates that the contents of the variable will never be modified
Chris Lattnerb1652612004-03-08 16:49:10 +0000664(opening options for optimization).</p>
665
Chris Lattner48b383b02003-11-25 01:02:51 +0000666<p>As SSA values, global variables define pointer values that are in
667scope (i.e. they dominate) for all basic blocks in the program. Global
668variables always define a pointer to their "content" type because they
669describe a region of memory, and all memory objects in LLVM are
670accessed through pointers.</p>
Chris Lattnerb1652612004-03-08 16:49:10 +0000671
Misha Brukman76307852003-11-08 01:05:38 +0000672</div>
Chris Lattnerb1652612004-03-08 16:49:10 +0000673
674
Chris Lattner095735d2002-05-06 03:03:22 +0000675<!-- ======================================================================= -->
Chris Lattnerb1652612004-03-08 16:49:10 +0000676<div class="doc_subsection">
677 <a name="functionstructure">Functions</a>
Misha Brukman76307852003-11-08 01:05:38 +0000678</div>
Chris Lattnerb1652612004-03-08 16:49:10 +0000679
680<div class="doc_text">
681
682<p>LLVM function definitions are composed of a (possibly empty) argument list,
683an opening curly brace, a list of basic blocks, and a closing curly brace. LLVM
684function declarations are defined with the "<tt>declare</tt>" keyword, a
685function name, and a function signature.</p>
686
687<p>A function definition contains a list of basic blocks, forming the CFG for
688the function. Each basic block may optionally start with a label (giving the
689basic block a symbol table entry), contains a list of instructions, and ends
690with a <a href="#terminators">terminator</a> instruction (such as a branch or
691function return).</p>
692
693<p>The first basic block in program is special in two ways: it is immediately
694executed on entrance to the function, and it is not allowed to have predecessor
695basic blocks (i.e. there can not be any branches to the entry block of a
696function). Because the block can have no predecessors, it also cannot have any
697<a href="#i_phi">PHI nodes</a>.</p>
698
699<p>LLVM functions are identified by their name and type signature. Hence, two
700functions with the same name but different parameter lists or return values are
701considered different functions, and LLVM will resolves references to each
702appropriately.</p>
703
704</div>
705
706
Chris Lattner2f7c9632001-06-06 20:29:01 +0000707<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000708<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
709<!-- *********************************************************************** -->
Misha Brukman76307852003-11-08 01:05:38 +0000710<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000711<p>The LLVM instruction set consists of several different
712classifications of instructions: <a href="#terminators">terminator
713instructions</a>, <a href="#binaryops">binary instructions</a>, <a
714 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
715instructions</a>.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000716</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000717<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000718<div class="doc_subsection"> <a name="terminators">Terminator
719Instructions</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000720<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000721<p>As mentioned <a href="#functionstructure">previously</a>, every
722basic block in a program ends with a "Terminator" instruction, which
723indicates which block should be executed after the current block is
724finished. These terminator instructions typically yield a '<tt>void</tt>'
725value: they produce control flow, not values (the one exception being
726the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
Misha Brukman76307852003-11-08 01:05:38 +0000727<p>There are five different terminator instructions: the '<a
Chris Lattner48b383b02003-11-25 01:02:51 +0000728 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
729instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
Chris Lattner08b7d5b2004-10-16 18:04:13 +0000730the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
731 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
732 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000733</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000734<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000735<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
736Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000737<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000738<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000739<pre> ret &lt;type&gt; &lt;value&gt; <i>; Return a value from a non-void function</i>
Chris Lattner590645f2002-04-14 06:13:44 +0000740 ret void <i>; Return from void function</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000741</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000742<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000743<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
744value) from a function, back to the caller.</p>
John Criswell417228d2004-04-09 16:48:45 +0000745<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner48b383b02003-11-25 01:02:51 +0000746returns a value and then causes control flow, and one that just causes
747control flow to occur.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000748<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000749<p>The '<tt>ret</tt>' instruction may return any '<a
750 href="#t_firstclass">first class</a>' type. Notice that a function is
751not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
752instruction inside of the function that returns a value that does not
753match the return type of the function.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000754<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000755<p>When the '<tt>ret</tt>' instruction is executed, control flow
756returns back to the calling function's context. If the caller is a "<a
John Criswell40db33f2004-06-25 15:16:57 +0000757 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner48b383b02003-11-25 01:02:51 +0000758the instruction after the call. If the caller was an "<a
759 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
760at the beginning "normal" of the destination block. If the instruction
761returns a value, that value shall set the call or invoke instruction's
762return value.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000763<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000764<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner590645f2002-04-14 06:13:44 +0000765 ret void <i>; Return from a void function</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000766</pre>
Misha Brukman76307852003-11-08 01:05:38 +0000767</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000768<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000769<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000770<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000771<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000772<pre> br bool &lt;cond&gt;, label &lt;iftrue&gt;, label &lt;iffalse&gt;<br> br label &lt;dest&gt; <i>; Unconditional branch</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000773</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000774<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000775<p>The '<tt>br</tt>' instruction is used to cause control flow to
776transfer to a different basic block in the current function. There are
777two forms of this instruction, corresponding to a conditional branch
778and an unconditional branch.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000779<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000780<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
781single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
782unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
783value as a target.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000784<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000785<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
786argument is evaluated. If the value is <tt>true</tt>, control flows
787to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
788control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000789<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000790<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
791 href="#i_ret">ret</a> int 1<br>IfUnequal:<br> <a href="#i_ret">ret</a> int 0<br></pre>
Misha Brukman76307852003-11-08 01:05:38 +0000792</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000793<!-- _______________________________________________________________________ -->
Chris Lattnercf96c6c2004-02-24 04:54:45 +0000794<div class="doc_subsubsection">
795 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
796</div>
797
Misha Brukman76307852003-11-08 01:05:38 +0000798<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000799<h5>Syntax:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +0000800
801<pre>
802 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
803</pre>
804
Chris Lattner2f7c9632001-06-06 20:29:01 +0000805<h5>Overview:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +0000806
807<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
808several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman76307852003-11-08 01:05:38 +0000809instruction, allowing a branch to occur to one of many possible
810destinations.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +0000811
812
Chris Lattner2f7c9632001-06-06 20:29:01 +0000813<h5>Arguments:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +0000814
815<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
816comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
817an array of pairs of comparison value constants and '<tt>label</tt>'s. The
818table is not allowed to contain duplicate constant entries.</p>
819
Chris Lattner2f7c9632001-06-06 20:29:01 +0000820<h5>Semantics:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +0000821
Chris Lattner48b383b02003-11-25 01:02:51 +0000822<p>The <tt>switch</tt> instruction specifies a table of values and
823destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswellbcbb18c2004-06-25 16:05:06 +0000824table is searched for the given value. If the value is found, control flow is
825transfered to the corresponding destination; otherwise, control flow is
826transfered to the default destination.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000827
Chris Lattnercf96c6c2004-02-24 04:54:45 +0000828<h5>Implementation:</h5>
829
830<p>Depending on properties of the target machine and the particular
831<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswellbcbb18c2004-06-25 16:05:06 +0000832ways. For example, it could be generated as a series of chained conditional
833branches or with a lookup table.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +0000834
835<h5>Example:</h5>
836
837<pre>
838 <i>; Emulate a conditional br instruction</i>
839 %Val = <a href="#i_cast">cast</a> bool %value to int
840 switch int %Val, label %truedest [int 0, label %falsedest ]
841
842 <i>; Emulate an unconditional br instruction</i>
843 switch uint 0, label %dest [ ]
844
845 <i>; Implement a jump table:</i>
846 switch uint %val, label %otherwise [ uint 0, label %onzero
847 uint 1, label %onone
848 uint 2, label %ontwo ]
Chris Lattner2f7c9632001-06-06 20:29:01 +0000849</pre>
Misha Brukman76307852003-11-08 01:05:38 +0000850</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000851<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000852<div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>'
853Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000854<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000855<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000856<pre> &lt;result&gt; = invoke &lt;ptr to function ty&gt; %&lt;function ptr val&gt;(&lt;function args&gt;)<br> to label &lt;normal label&gt; except label &lt;exception label&gt;<br></pre>
Chris Lattnera8292f32002-05-06 22:08:29 +0000857<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000858<p>The '<tt>invoke</tt>' instruction causes control to transfer to a
859specified function, with the possibility of control flow transfer to
860either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>.
861If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>"
862instruction, control flow will return to the "normal" label. If the
863callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
864instruction, control is interrupted, and continued at the dynamically
865nearest "except" label.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000866<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +0000867<p>This instruction requires several arguments:</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000868<ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000869 <li>'<tt>ptr to function ty</tt>': shall be the signature of the
870pointer to function value being invoked. In most cases, this is a
871direct function invocation, but indirect <tt>invoke</tt>s are just as
872possible, branching off an arbitrary pointer to function value. </li>
873 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer
874to a function to be invoked. </li>
875 <li>'<tt>function args</tt>': argument list whose types match the
876function signature argument types. If the function signature indicates
877the function accepts a variable number of arguments, the extra
878arguments can be specified. </li>
879 <li>'<tt>normal label</tt>': the label reached when the called
880function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
881 <li>'<tt>exception label</tt>': the label reached when a callee
882returns with the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000883</ol>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000884<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +0000885<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner48b383b02003-11-25 01:02:51 +0000886 href="#i_call">call</a></tt>' instruction in most regards. The
887primary difference is that it establishes an association with a label,
888which is used by the runtime library to unwind the stack.</p>
889<p>This instruction is used in languages with destructors to ensure
890that proper cleanup is performed in the case of either a <tt>longjmp</tt>
891or a thrown exception. Additionally, this is important for
892implementation of '<tt>catch</tt>' clauses in high-level languages that
893support them.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000894<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000895<pre> %retval = invoke int %Test(int 15)<br> to label %Continue<br> except label %TestCleanup <i>; {int}:retval set</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000896</pre>
Misha Brukman76307852003-11-08 01:05:38 +0000897</div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +0000898
899
Chris Lattner5ed60612003-09-03 00:41:47 +0000900<!-- _______________________________________________________________________ -->
Chris Lattner08b7d5b2004-10-16 18:04:13 +0000901
Chris Lattner48b383b02003-11-25 01:02:51 +0000902<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
903Instruction</a> </div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +0000904
Misha Brukman76307852003-11-08 01:05:38 +0000905<div class="doc_text">
Chris Lattner08b7d5b2004-10-16 18:04:13 +0000906
Chris Lattner5ed60612003-09-03 00:41:47 +0000907<h5>Syntax:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +0000908<pre>
909 unwind
910</pre>
911
Chris Lattner5ed60612003-09-03 00:41:47 +0000912<h5>Overview:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +0000913
914<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
915at the first callee in the dynamic call stack which used an <a
916href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
917primarily used to implement exception handling.</p>
918
Chris Lattner5ed60612003-09-03 00:41:47 +0000919<h5>Semantics:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +0000920
921<p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to
922immediately halt. The dynamic call stack is then searched for the first <a
923href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
924execution continues at the "exceptional" destination block specified by the
925<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
926dynamic call chain, undefined behavior results.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000927</div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +0000928
929<!-- _______________________________________________________________________ -->
930
931<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
932Instruction</a> </div>
933
934<div class="doc_text">
935
936<h5>Syntax:</h5>
937<pre>
938 unreachable
939</pre>
940
941<h5>Overview:</h5>
942
943<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
944instruction is used to inform the optimizer that a particular portion of the
945code is not reachable. This can be used to indicate that the code after a
946no-return function cannot be reached, and other facts.</p>
947
948<h5>Semantics:</h5>
949
950<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
951</div>
952
953
954
Chris Lattner2f7c9632001-06-06 20:29:01 +0000955<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000956<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000957<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000958<p>Binary operators are used to do most of the computation in a
959program. They require two operands, execute an operation on them, and
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000960produce a single value. Although, that single value might represent
961multiple data, as is the case with the <a href="#t_packed">packed</a> data type.
962The result value of a binary operator is not
Chris Lattner48b383b02003-11-25 01:02:51 +0000963necessarily the same type as its operands.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000964<p>There are several different binary operators:</p>
Misha Brukman76307852003-11-08 01:05:38 +0000965</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000966<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000967<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
968Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000969<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000970<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000971<pre> &lt;result&gt; = add &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000972</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000973<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +0000974<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000975<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +0000976<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000977 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
978 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
979Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000980<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +0000981<p>The value produced is the integer or floating point sum of the two
982operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000983<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000984<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000985</pre>
Misha Brukman76307852003-11-08 01:05:38 +0000986</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000987<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000988<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
989Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000990<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000991<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000992<pre> &lt;result&gt; = sub &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000993</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000994<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +0000995<p>The '<tt>sub</tt>' instruction returns the difference of its two
996operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +0000997<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
998instruction present in most other intermediate representations.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000999<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001000<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001001 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001002values.
1003This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1004Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001005<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001006<p>The value produced is the integer or floating point difference of
1007the two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001008<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001009<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001010 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
1011</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001012</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001013<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001014<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
1015Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001016<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001017<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001018<pre> &lt;result&gt; = mul &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001019</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001020<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001021<p>The '<tt>mul</tt>' instruction returns the product of its two
1022operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001023<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001024<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001025 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001026values.
1027This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1028Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001029<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001030<p>The value produced is the integer or floating point product of the
Misha Brukman76307852003-11-08 01:05:38 +00001031two operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001032<p>There is no signed vs unsigned multiplication. The appropriate
1033action is taken based on the type of the operand.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001034<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001035<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001036</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001037</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001038<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001039<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
1040Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001041<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001042<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001043<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1044</pre>
1045<h5>Overview:</h5>
1046<p>The '<tt>div</tt>' instruction returns the quotient of its two
1047operands.</p>
1048<h5>Arguments:</h5>
1049<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
1050 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001051values.
1052This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1053Both arguments must have identical types.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001054<h5>Semantics:</h5>
1055<p>The value produced is the integer or floating point quotient of the
1056two operands.</p>
1057<h5>Example:</h5>
1058<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
1059</pre>
1060</div>
1061<!-- _______________________________________________________________________ -->
1062<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
1063Instruction</a> </div>
1064<div class="doc_text">
1065<h5>Syntax:</h5>
1066<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1067</pre>
1068<h5>Overview:</h5>
1069<p>The '<tt>rem</tt>' instruction returns the remainder from the
1070division of its two operands.</p>
1071<h5>Arguments:</h5>
1072<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1073 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001074values.
1075This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1076Both arguments must have identical types.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001077<h5>Semantics:</h5>
1078<p>This returns the <i>remainder</i> of a division (where the result
1079has the same sign as the divisor), not the <i>modulus</i> (where the
1080result has the same sign as the dividend) of a value. For more
1081information about the difference, see: <a
1082 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1083Math Forum</a>.</p>
1084<h5>Example:</h5>
1085<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1086</pre>
1087</div>
1088<!-- _______________________________________________________________________ -->
1089<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1090Instructions</a> </div>
1091<div class="doc_text">
1092<h5>Syntax:</h5>
1093<pre> &lt;result&gt; = seteq &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001094 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1095 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1096 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1097 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1098 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1099</pre>
Chris Lattner48b383b02003-11-25 01:02:51 +00001100<h5>Overview:</h5>
1101<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1102value based on a comparison of their two operands.</p>
1103<h5>Arguments:</h5>
1104<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1105be of <a href="#t_firstclass">first class</a> type (it is not possible
1106to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1107or '<tt>void</tt>' values, etc...). Both arguments must have identical
1108types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001109<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001110<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1111value if both operands are equal.<br>
1112The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1113value if both operands are unequal.<br>
1114The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1115value if the first operand is less than the second operand.<br>
1116The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1117value if the first operand is greater than the second operand.<br>
1118The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1119value if the first operand is less than or equal to the second operand.<br>
1120The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1121value if the first operand is greater than or equal to the second
1122operand.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001123<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001124<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001125 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
1126 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1127 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1128 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1129 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1130</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001131</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001132<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001133<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1134Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001135<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +00001136<p>Bitwise binary operators are used to do various forms of
1137bit-twiddling in a program. They are generally very efficient
1138instructions, and can commonly be strength reduced from other
1139instructions. They require two operands, execute an operation on them,
1140and produce a single value. The resulting value of the bitwise binary
1141operators is always the same type as its first operand.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001142</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001143<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001144<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1145Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001146<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001147<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001148<pre> &lt;result&gt; = and &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001149</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001150<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001151<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1152its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001153<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001154<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001155 href="#t_integral">integral</a> values. Both arguments must have
1156identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001157<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001158<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001159<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00001160<div style="align: center">
Misha Brukman76307852003-11-08 01:05:38 +00001161<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +00001162 <tbody>
1163 <tr>
1164 <td>In0</td>
1165 <td>In1</td>
1166 <td>Out</td>
1167 </tr>
1168 <tr>
1169 <td>0</td>
1170 <td>0</td>
1171 <td>0</td>
1172 </tr>
1173 <tr>
1174 <td>0</td>
1175 <td>1</td>
1176 <td>0</td>
1177 </tr>
1178 <tr>
1179 <td>1</td>
1180 <td>0</td>
1181 <td>0</td>
1182 </tr>
1183 <tr>
1184 <td>1</td>
1185 <td>1</td>
1186 <td>1</td>
1187 </tr>
1188 </tbody>
1189</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001190</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001191<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001192<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001193 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1194 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1195</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001196</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001197<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001198<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001199<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001200<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001201<pre> &lt;result&gt; = or &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001202</pre>
Chris Lattner48b383b02003-11-25 01:02:51 +00001203<h5>Overview:</h5>
1204<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1205or of its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001206<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001207<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001208 href="#t_integral">integral</a> values. Both arguments must have
1209identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001210<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001211<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001212<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00001213<div style="align: center">
Chris Lattner48b383b02003-11-25 01:02:51 +00001214<table border="1" cellspacing="0" cellpadding="4">
1215 <tbody>
1216 <tr>
1217 <td>In0</td>
1218 <td>In1</td>
1219 <td>Out</td>
1220 </tr>
1221 <tr>
1222 <td>0</td>
1223 <td>0</td>
1224 <td>0</td>
1225 </tr>
1226 <tr>
1227 <td>0</td>
1228 <td>1</td>
1229 <td>1</td>
1230 </tr>
1231 <tr>
1232 <td>1</td>
1233 <td>0</td>
1234 <td>1</td>
1235 </tr>
1236 <tr>
1237 <td>1</td>
1238 <td>1</td>
1239 <td>1</td>
1240 </tr>
1241 </tbody>
1242</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001243</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001244<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001245<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001246 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1247 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1248</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001249</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001250<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001251<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1252Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001253<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001254<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001255<pre> &lt;result&gt; = xor &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001256</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001257<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001258<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1259or of its two operands. The <tt>xor</tt> is used to implement the
1260"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001261<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001262<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001263 href="#t_integral">integral</a> values. Both arguments must have
1264identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001265<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001266<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001267<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00001268<div style="align: center">
Chris Lattner48b383b02003-11-25 01:02:51 +00001269<table border="1" cellspacing="0" cellpadding="4">
1270 <tbody>
1271 <tr>
1272 <td>In0</td>
1273 <td>In1</td>
1274 <td>Out</td>
1275 </tr>
1276 <tr>
1277 <td>0</td>
1278 <td>0</td>
1279 <td>0</td>
1280 </tr>
1281 <tr>
1282 <td>0</td>
1283 <td>1</td>
1284 <td>1</td>
1285 </tr>
1286 <tr>
1287 <td>1</td>
1288 <td>0</td>
1289 <td>1</td>
1290 </tr>
1291 <tr>
1292 <td>1</td>
1293 <td>1</td>
1294 <td>0</td>
1295 </tr>
1296 </tbody>
1297</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001298</div>
Chris Lattner48b383b02003-11-25 01:02:51 +00001299<p> </p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001300<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001301<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001302 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1303 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner5ed60612003-09-03 00:41:47 +00001304 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001305</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001306</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001307<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001308<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1309Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001310<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001311<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001312<pre> &lt;result&gt; = shl &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001313</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001314<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001315<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1316the left a specified number of bits.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001317<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001318<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001319 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1320type.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001321<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001322<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001323<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001324<pre> &lt;result&gt; = shl int 4, ubyte %var <i>; yields {int}:result = 4 &lt;&lt; %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001325 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1326 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1327</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001328</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001329<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001330<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1331Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001332<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001333<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001334<pre> &lt;result&gt; = shr &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001335</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001336<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001337<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1338the right a specified number of bits.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001339<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001340<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001341 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1342type.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001343<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001344<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1345most significant bit is duplicated in the newly free'd bit positions.
1346If the first argument is unsigned, zero bits shall fill the empty
1347positions.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001348<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001349<pre> &lt;result&gt; = shr int 4, ubyte %var <i>; yields {int}:result = 4 &gt;&gt; %var</i>
Chris Lattner33426d92003-06-18 21:30:51 +00001350 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001351 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner33426d92003-06-18 21:30:51 +00001352 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1353 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001354</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001355</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001356<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001357<div class="doc_subsection"> <a name="memoryops">Memory Access
1358Operations</a></div>
Misha Brukman76307852003-11-08 01:05:38 +00001359<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +00001360<p>A key design point of an SSA-based representation is how it
1361represents memory. In LLVM, no memory locations are in SSA form, which
1362makes things very simple. This section describes how to read, write,
1363allocate and free memory in LLVM.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001364</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001365<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001366<div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>'
1367Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001368<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001369<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001370<pre> &lt;result&gt; = malloc &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001371 &lt;result&gt; = malloc &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001372</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001373<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001374<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1375heap and returns a pointer to it.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001376<h5>Arguments:</h5>
John Criswella92e5862004-02-24 16:13:56 +00001377<p>The '<tt>malloc</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1378bytes of memory from the operating system and returns a pointer of the
Chris Lattner48b383b02003-11-25 01:02:51 +00001379appropriate type to the program. The second form of the instruction is
1380a shorter version of the first instruction that defaults to allocating
1381one element.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001382<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001383<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001384<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1385a pointer is returned.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001386<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001387<pre> %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
Misha Brukman76307852003-11-08 01:05:38 +00001388
Chris Lattner48b383b02003-11-25 01:02:51 +00001389 %size = <a
1390 href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001391 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1392 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001393</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001394</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001395<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001396<div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>'
1397Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001398<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001399<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001400<pre> free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001401</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001402<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001403<p>The '<tt>free</tt>' instruction returns memory back to the unused
1404memory heap, to be reallocated in the future.</p>
1405<p> </p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001406<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001407<p>'<tt>value</tt>' shall be a pointer value that points to a value
1408that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1409instruction.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001410<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001411<p>Access to the memory pointed to by the pointer is not longer defined
1412after this instruction executes.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001413<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001414<pre> %array = <a href="#i_malloc">malloc</a> [4 x ubyte] <i>; yields {[4 x ubyte]*}:array</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001415 free [4 x ubyte]* %array
1416</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001417</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001418<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001419<div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>'
1420Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001421<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001422<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001423<pre> &lt;result&gt; = alloca &lt;type&gt;, uint &lt;NumElements&gt; <i>; yields {type*}:result</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001424 &lt;result&gt; = alloca &lt;type&gt; <i>; yields {type*}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001425</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001426<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001427<p>The '<tt>alloca</tt>' instruction allocates memory on the current
1428stack frame of the procedure that is live until the current function
1429returns to its caller.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001430<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001431<p>The the '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
1432bytes of memory on the runtime stack, returning a pointer of the
1433appropriate type to the program. The second form of the instruction is
1434a shorter version of the first that defaults to allocating one element.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001435<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001436<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001437<p>Memory is allocated, a pointer is returned. '<tt>alloca</tt>'d
1438memory is automatically released when the function returns. The '<tt>alloca</tt>'
1439instruction is commonly used to represent automatic variables that must
1440have an address available. When the function returns (either with the <tt><a
1441 href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt>
Misha Brukman76307852003-11-08 01:05:38 +00001442instructions), the memory is reclaimed.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001443<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001444<pre> %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001445 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001446</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001447</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001448<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001449<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
1450Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001451<div class="doc_text">
Chris Lattner095735d2002-05-06 03:03:22 +00001452<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001453<pre> &lt;result&gt; = load &lt;ty&gt;* &lt;pointer&gt;<br> &lt;result&gt; = volatile load &lt;ty&gt;* &lt;pointer&gt;<br></pre>
Chris Lattner095735d2002-05-06 03:03:22 +00001454<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001455<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00001456<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001457<p>The argument to the '<tt>load</tt>' instruction specifies the memory
1458address to load from. The pointer must point to a <a
Chris Lattner10ee9652004-06-03 22:57:15 +00001459 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
Chris Lattner48b383b02003-11-25 01:02:51 +00001460marked as <tt>volatile</tt> then the optimizer is not allowed to modify
1461the number or order of execution of this <tt>load</tt> with other
1462volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
1463instructions. </p>
Chris Lattner095735d2002-05-06 03:03:22 +00001464<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001465<p>The location of memory pointed to is loaded.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00001466<h5>Examples:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001467<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
1468 <a
1469 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner095735d2002-05-06 03:03:22 +00001470 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1471</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001472</div>
Chris Lattner095735d2002-05-06 03:03:22 +00001473<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001474<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
1475Instruction</a> </div>
Chris Lattner095735d2002-05-06 03:03:22 +00001476<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001477<pre> store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt; <i>; yields {void}</i>
Chris Lattner12d456c2003-09-08 18:27:49 +00001478 volatile store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt; <i>; yields {void}</i>
Chris Lattner095735d2002-05-06 03:03:22 +00001479</pre>
Chris Lattner095735d2002-05-06 03:03:22 +00001480<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001481<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00001482<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001483<p>There are two arguments to the '<tt>store</tt>' instruction: a value
1484to store and an address to store it into. The type of the '<tt>&lt;pointer&gt;</tt>'
1485operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
1486operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the
1487optimizer is not allowed to modify the number or order of execution of
1488this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
1489 href="#i_store">store</a></tt> instructions.</p>
1490<h5>Semantics:</h5>
1491<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
1492at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00001493<h5>Example:</h5>
Chris Lattner48b383b02003-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 Lattner095735d2002-05-06 03:03:22 +00001497 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
1498</pre>
Chris Lattner095735d2002-05-06 03:03:22 +00001499<!-- _______________________________________________________________________ -->
Chris Lattner33fd7022004-04-05 01:30:49 +00001500<div class="doc_subsubsection">
1501 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
1502</div>
1503
Misha Brukman76307852003-11-08 01:05:38 +00001504<div class="doc_text">
Chris Lattner590645f2002-04-14 06:13:44 +00001505<h5>Syntax:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00001506<pre>
1507 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
1508</pre>
1509
Chris Lattner590645f2002-04-14 06:13:44 +00001510<h5>Overview:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00001511
1512<p>
1513The '<tt>getelementptr</tt>' instruction is used to get the address of a
1514subelement of an aggregate data structure.</p>
1515
Chris Lattner590645f2002-04-14 06:13:44 +00001516<h5>Arguments:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00001517
1518<p>This instruction takes a list of integer constants that indicate what
1519elements of the aggregate object to index to. The actual types of the arguments
1520provided depend on the type of the first pointer argument. The
1521'<tt>getelementptr</tt>' instruction is used to index down through the type
1522levels of a structure. When indexing into a structure, only <tt>uint</tt>
1523integer constants are allowed. When indexing into an array or pointer
1524<tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
1525
Chris Lattner48b383b02003-11-25 01:02:51 +00001526<p>For example, let's consider a C code fragment and how it gets
1527compiled to LLVM:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00001528
1529<pre>
1530 struct RT {
1531 char A;
1532 int B[10][20];
1533 char C;
1534 };
1535 struct ST {
1536 int X;
1537 double Y;
1538 struct RT Z;
1539 };
1540
1541 int *foo(struct ST *s) {
1542 return &amp;s[1].Z.B[5][13];
1543 }
1544</pre>
1545
Misha Brukman76307852003-11-08 01:05:38 +00001546<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00001547
1548<pre>
1549 %RT = type { sbyte, [10 x [20 x int]], sbyte }
1550 %ST = type { int, double, %RT }
1551
Brian Gaeke317ef962004-07-02 21:08:14 +00001552 implementation
1553
1554 int* %foo(%ST* %s) {
1555 entry:
1556 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13
Chris Lattner33fd7022004-04-05 01:30:49 +00001557 ret int* %reg
1558 }
1559</pre>
1560
Chris Lattner590645f2002-04-14 06:13:44 +00001561<h5>Semantics:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00001562
1563<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
Chris Lattner10ee9652004-06-03 22:57:15 +00001564on the pointer type that is being index into. <a href="#t_pointer">Pointer</a>
1565and <a href="#t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
1566<tt>ulong</tt>, or <tt>long</tt> values, and <a href="#t_struct">structure</a>
Chris Lattner33fd7022004-04-05 01:30:49 +00001567types require <tt>uint</tt> <b>constants</b>.</p>
1568
Misha Brukman76307852003-11-08 01:05:38 +00001569<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattner33fd7022004-04-05 01:30:49 +00001570type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
1571}</tt>' type, a structure. The second index indexes into the third element of
1572the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
1573sbyte }</tt>' type, another structure. The third index indexes into the second
1574element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
1575array. The two dimensions of the array are subscripted into, yielding an
1576'<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction return a pointer
1577to this element, thus computing a value of '<tt>int*</tt>' type.</p>
1578
Chris Lattner48b383b02003-11-25 01:02:51 +00001579<p>Note that it is perfectly legal to index partially through a
1580structure, returning a pointer to an inner element. Because of this,
1581the LLVM code for the given testcase is equivalent to:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00001582
1583<pre>
1584 int* "foo"(%ST* %s) {
1585 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
1586 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
1587 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
1588 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
1589 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
1590 ret int* %t5
1591 }
Chris Lattnera8292f32002-05-06 22:08:29 +00001592</pre>
Chris Lattner590645f2002-04-14 06:13:44 +00001593<h5>Example:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00001594<pre>
1595 <i>; yields [12 x ubyte]*:aptr</i>
1596 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
1597</pre>
1598
1599</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001600<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001601<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001602<div class="doc_text">
John Criswell417228d2004-04-09 16:48:45 +00001603<p>The instructions in this category are the "miscellaneous"
Chris Lattner48b383b02003-11-25 01:02:51 +00001604instructions, which defy better classification.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001605</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001606<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001607<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
1608Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001609<div class="doc_text">
Chris Lattner70de6632001-07-09 00:26:23 +00001610<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001611<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner70de6632001-07-09 00:26:23 +00001612<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001613<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
1614the SSA graph representing the function.</p>
Chris Lattner70de6632001-07-09 00:26:23 +00001615<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001616<p>The type of the incoming values are specified with the first type
1617field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
1618as arguments, with one pair for each predecessor basic block of the
1619current block. Only values of <a href="#t_firstclass">first class</a>
1620type may be used as the value arguments to the PHI node. Only labels
1621may be used as the label arguments.</p>
1622<p>There must be no non-phi instructions between the start of a basic
1623block and the PHI instructions: i.e. PHI instructions must be first in
1624a basic block.</p>
Chris Lattner70de6632001-07-09 00:26:23 +00001625<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001626<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
1627value specified by the parameter, depending on which basic block we
1628came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattnera8292f32002-05-06 22:08:29 +00001629<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001630<pre>Loop: ; Infinite loop that counts from 0 on up...<br> %indvar = phi uint [ 0, %LoopHeader ], [ %nextindvar, %Loop ]<br> %nextindvar = add uint %indvar, 1<br> br label %Loop<br></pre>
Misha Brukman76307852003-11-08 01:05:38 +00001631</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001632
Chris Lattnera8292f32002-05-06 22:08:29 +00001633<!-- _______________________________________________________________________ -->
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001634<div class="doc_subsubsection">
1635 <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
1636</div>
1637
Misha Brukman76307852003-11-08 01:05:38 +00001638<div class="doc_text">
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001639
Chris Lattnera8292f32002-05-06 22:08:29 +00001640<h5>Syntax:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001641
1642<pre>
1643 &lt;result&gt; = cast &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Chris Lattnera8292f32002-05-06 22:08:29 +00001644</pre>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001645
Chris Lattnera8292f32002-05-06 22:08:29 +00001646<h5>Overview:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001647
1648<p>
1649The '<tt>cast</tt>' instruction is used as the primitive means to convert
1650integers to floating point, change data type sizes, and break type safety (by
1651casting pointers).
1652</p>
1653
1654
Chris Lattnera8292f32002-05-06 22:08:29 +00001655<h5>Arguments:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001656
1657<p>
1658The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
1659class value, and a type to cast it to, which must also be a <a
1660href="#t_firstclass">first class</a> type.
1661</p>
1662
Chris Lattnera8292f32002-05-06 22:08:29 +00001663<h5>Semantics:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001664
1665<p>
1666This instruction follows the C rules for explicit casts when determining how the
1667data being cast must change to fit in its new container.
1668</p>
1669
1670<p>
1671When casting to bool, any value that would be considered true in the context of
1672a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
1673all else are '<tt>false</tt>'.
1674</p>
1675
1676<p>
1677When extending an integral value from a type of one signness to another (for
1678example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
1679<b>source</b> value is signed, and zero-extended if the source value is
1680unsigned. <tt>bool</tt> values are always zero extended into either zero or
1681one.
1682</p>
1683
Chris Lattner70de6632001-07-09 00:26:23 +00001684<h5>Example:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001685
1686<pre>
1687 %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattnerd8f8ede2002-06-25 18:03:17 +00001688 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner70de6632001-07-09 00:26:23 +00001689</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001690</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00001691
1692<!-- _______________________________________________________________________ -->
1693<div class="doc_subsubsection">
1694 <a name="i_select">'<tt>select</tt>' Instruction</a>
1695</div>
1696
1697<div class="doc_text">
1698
1699<h5>Syntax:</h5>
1700
1701<pre>
1702 &lt;result&gt; = select bool &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
1703</pre>
1704
1705<h5>Overview:</h5>
1706
1707<p>
1708The '<tt>select</tt>' instruction is used to choose one value based on a
1709condition, without branching.
1710</p>
1711
1712
1713<h5>Arguments:</h5>
1714
1715<p>
1716The '<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.
1717</p>
1718
1719<h5>Semantics:</h5>
1720
1721<p>
1722If the boolean condition evaluates to true, the instruction returns the first
1723value argument, otherwise it returns the second value argument.
1724</p>
1725
1726<h5>Example:</h5>
1727
1728<pre>
1729 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
1730</pre>
1731</div>
1732
1733
1734
1735
1736
Chris Lattner70de6632001-07-09 00:26:23 +00001737<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001738<div class="doc_subsubsection"> <a name="i_call">'<tt>call</tt>'
1739Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001740<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001741<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001742<pre> &lt;result&gt; = call &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)<br></pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001743<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001744<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001745<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001746<p>This instruction requires several arguments:</p>
Chris Lattnera8292f32002-05-06 22:08:29 +00001747<ol>
Chris Lattner48b383b02003-11-25 01:02:51 +00001748 <li>
1749 <p>'<tt>ty</tt>': shall be the signature of the pointer to function
1750value being invoked. The argument types must match the types implied
1751by this signature.</p>
1752 </li>
1753 <li>
1754 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a
1755function to be invoked. In most cases, this is a direct function
1756invocation, but indirect <tt>call</tt>s are just as possible,
1757calling an arbitrary pointer to function values.</p>
1758 </li>
1759 <li>
1760 <p>'<tt>function args</tt>': argument list whose types match the
1761function signature argument types. If the function signature
1762indicates the function accepts a variable number of arguments, the
1763extra arguments can be specified.</p>
1764 </li>
Chris Lattnera8292f32002-05-06 22:08:29 +00001765</ol>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001766<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001767<p>The '<tt>call</tt>' instruction is used to cause control flow to
1768transfer to a specified function, with its incoming arguments bound to
1769the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
1770instruction in the called function, control flow continues with the
1771instruction after the function call, and the return value of the
1772function is bound to the result argument. This is a simpler case of
1773the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001774<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001775<pre> %retval = call int %test(int %argc)<br> call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42);<br></pre>
Misha Brukman76307852003-11-08 01:05:38 +00001776</div>
Chris Lattner6a4a0492004-09-27 21:51:25 +00001777
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001778<!-- _______________________________________________________________________ -->
Chris Lattner6a4a0492004-09-27 21:51:25 +00001779<div class="doc_subsubsection">
1780 <a name="i_vanext">'<tt>vanext</tt>' Instruction</a>
1781</div>
1782
Misha Brukman76307852003-11-08 01:05:38 +00001783<div class="doc_text">
Chris Lattner6a4a0492004-09-27 21:51:25 +00001784
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001785<h5>Syntax:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00001786
1787<pre>
1788 &lt;resultarglist&gt; = vanext &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;
1789</pre>
1790
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001791<h5>Overview:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00001792
Chris Lattner48b383b02003-11-25 01:02:51 +00001793<p>The '<tt>vanext</tt>' instruction is used to access arguments passed
1794through the "variable argument" area of a function call. It is used to
1795implement the <tt>va_arg</tt> macro in C.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00001796
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001797<h5>Arguments:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00001798
1799<p>This instruction takes a <tt>va_list</tt> value and the type of the
1800argument. It returns another <tt>va_list</tt>. The actual type of
1801<tt>va_list</tt> may be defined differently for different targets. Most targets
1802use a <tt>va_list</tt> type of <tt>sbyte*</tt> or some other pointer type.</p>
1803
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001804<h5>Semantics:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00001805
1806<p>The '<tt>vanext</tt>' instruction advances the specified <tt>va_list</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00001807past an argument of the specified type. In conjunction with the <a
1808 href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement
1809the <tt>va_arg</tt> macro available in C. For more information, see
1810the variable argument handling <a href="#int_varargs">Intrinsic
1811Functions</a>.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00001812
Chris Lattner48b383b02003-11-25 01:02:51 +00001813<p>It is legal for this instruction to be called in a function which
1814does not take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman76307852003-11-08 01:05:38 +00001815function.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00001816
Misha Brukman76307852003-11-08 01:05:38 +00001817<p><tt>vanext</tt> is an LLVM instruction instead of an <a
Chris Lattner6a4a0492004-09-27 21:51:25 +00001818href="#intrinsics">intrinsic function</a> because it takes a type as an
1819argument. The type refers to the current argument in the <tt>va_list</tt>, it
1820tells the compiler how far on the stack it needs to advance to find the next
1821argument</p>
1822
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001823<h5>Example:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00001824
Chris Lattner48b383b02003-11-25 01:02:51 +00001825<p>See the <a href="#int_varargs">variable argument processing</a>
1826section.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00001827
Misha Brukman76307852003-11-08 01:05:38 +00001828</div>
Chris Lattner6a4a0492004-09-27 21:51:25 +00001829
Chris Lattner26ca62e2003-10-18 05:51:36 +00001830<!-- _______________________________________________________________________ -->
Chris Lattner6a4a0492004-09-27 21:51:25 +00001831<div class="doc_subsubsection">
1832 <a name="i_vaarg">'<tt>vaarg</tt>' Instruction</a>
1833</div>
1834
Misha Brukman76307852003-11-08 01:05:38 +00001835<div class="doc_text">
Chris Lattner6a4a0492004-09-27 21:51:25 +00001836
Chris Lattner26ca62e2003-10-18 05:51:36 +00001837<h5>Syntax:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00001838
1839<pre>
1840 &lt;resultval&gt; = vaarg &lt;va_list&gt; &lt;arglist&gt;, &lt;argty&gt;
1841</pre>
1842
Chris Lattner26ca62e2003-10-18 05:51:36 +00001843<h5>Overview:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00001844
1845<p>The '<tt>vaarg</tt>' instruction is used to access arguments passed through
1846the "variable argument" area of a function call. It is used to implement the
1847<tt>va_arg</tt> macro in C.</p>
1848
Chris Lattner26ca62e2003-10-18 05:51:36 +00001849<h5>Arguments:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00001850
1851<p>This instruction takes a <tt>va_list</tt> value and the type of the
1852argument. It returns a value of the specified argument type. Again, the actual
1853type of <tt>va_list</tt> is target specific.</p>
1854
Chris Lattner26ca62e2003-10-18 05:51:36 +00001855<h5>Semantics:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00001856
1857<p>The '<tt>vaarg</tt>' instruction loads an argument of the specified type from
1858the specified <tt>va_list</tt>. In conjunction with the <a
1859href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to implement the
1860<tt>va_arg</tt> macro available in C. For more information, see the variable
1861argument handling <a href="#int_varargs">Intrinsic Functions</a>.</p>
1862
1863<p>It is legal for this instruction to be called in a function which does not
1864take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman76307852003-11-08 01:05:38 +00001865function.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00001866
Misha Brukman76307852003-11-08 01:05:38 +00001867<p><tt>vaarg</tt> is an LLVM instruction instead of an <a
Chris Lattner6a4a0492004-09-27 21:51:25 +00001868href="#intrinsics">intrinsic function</a> because it takes an type as an
1869argument.</p>
1870
Chris Lattner26ca62e2003-10-18 05:51:36 +00001871<h5>Example:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00001872
1873<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
1874
Misha Brukman76307852003-11-08 01:05:38 +00001875</div>
Chris Lattner941515c2004-01-06 05:31:32 +00001876
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001877<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001878<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
1879<!-- *********************************************************************** -->
Chris Lattner941515c2004-01-06 05:31:32 +00001880
Misha Brukman76307852003-11-08 01:05:38 +00001881<div class="doc_text">
Chris Lattnerfee11462004-02-12 17:01:32 +00001882
1883<p>LLVM supports the notion of an "intrinsic function". These functions have
1884well known names and semantics, and are required to follow certain
1885restrictions. Overall, these instructions represent an extension mechanism for
1886the LLVM language that does not require changing all of the transformations in
1887LLVM to add to the language (or the bytecode reader/writer, the parser,
1888etc...).</p>
1889
1890<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix, this
1891prefix is reserved in LLVM for intrinsic names, thus functions may not be named
1892this. Intrinsic functions must always be external functions: you cannot define
1893the body of intrinsic functions. Intrinsic functions may only be used in call
1894or invoke instructions: it is illegal to take the address of an intrinsic
1895function. Additionally, because intrinsic functions are part of the LLVM
1896language, it is required that they all be documented here if any are added.</p>
1897
1898
1899<p>
1900Adding an intrinsic to LLVM is straight-forward if it is possible to express the
1901concept in LLVM directly (ie, code generator support is not _required_). To do
1902this, extend the default implementation of the IntrinsicLowering class to handle
1903the intrinsic. Code generators use this class to lower intrinsics they do not
1904understand to raw LLVM instructions that they do.
1905</p>
1906
Misha Brukman76307852003-11-08 01:05:38 +00001907</div>
Chris Lattner941515c2004-01-06 05:31:32 +00001908
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001909<!-- ======================================================================= -->
Chris Lattner941515c2004-01-06 05:31:32 +00001910<div class="doc_subsection">
1911 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
1912</div>
1913
Misha Brukman76307852003-11-08 01:05:38 +00001914<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +00001915
Misha Brukman76307852003-11-08 01:05:38 +00001916<p>Variable argument support is defined in LLVM with the <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001917 href="#i_vanext"><tt>vanext</tt></a> instruction and these three
1918intrinsic functions. These functions are related to the similarly
1919named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00001920
Chris Lattner48b383b02003-11-25 01:02:51 +00001921<p>All of these functions operate on arguments that use a
1922target-specific value type "<tt>va_list</tt>". The LLVM assembly
1923language reference manual does not define what this type is, so all
1924transformations should be prepared to handle intrinsics with any type
1925used.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00001926
Misha Brukman76307852003-11-08 01:05:38 +00001927<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner48b383b02003-11-25 01:02:51 +00001928instruction and the variable argument handling intrinsic functions are
1929used.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00001930
Chris Lattnerfee11462004-02-12 17:01:32 +00001931<pre>
1932int %test(int %X, ...) {
1933 ; Initialize variable argument processing
1934 %ap = call sbyte* %<a href="#i_va_start">llvm.va_start</a>()
1935
1936 ; Read a single integer argument
1937 %tmp = vaarg sbyte* %ap, int
1938
1939 ; Advance to the next argument
1940 %ap2 = vanext sbyte* %ap, int
1941
1942 ; Demonstrate usage of llvm.va_copy and llvm.va_end
1943 %aq = call sbyte* %<a href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2)
1944 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %aq)
1945
1946 ; Stop processing of arguments.
1947 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %ap2)
1948 ret int %tmp
1949}
1950</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001951</div>
Chris Lattner941515c2004-01-06 05:31:32 +00001952
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001953<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00001954<div class="doc_subsubsection">
1955 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
1956</div>
1957
1958
Misha Brukman76307852003-11-08 01:05:38 +00001959<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001960<h5>Syntax:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00001961<pre> call &lt;va_list&gt; ()* %llvm.va_start()<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001962<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001963<p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt>&lt;arglist&gt;</tt>
1964for subsequent use by the variable argument intrinsics.</p>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001965<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001966<p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00001967macro available in C. In a target-dependent way, it initializes and
1968returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt>
1969will produce the first variable argument passed to the function. Unlike
1970the C <tt>va_start</tt> macro, this intrinsic does not need to know the
1971last argument of the function, the compiler can figure that out.</p>
1972<p>Note that this intrinsic function is only legal to be called from
1973within the body of a variable argument function.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001974</div>
Chris Lattner941515c2004-01-06 05:31:32 +00001975
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001976<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00001977<div class="doc_subsubsection">
1978 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
1979</div>
1980
Misha Brukman76307852003-11-08 01:05:38 +00001981<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001982<h5>Syntax:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00001983<pre> call void (&lt;va_list&gt;)* %llvm.va_end(&lt;va_list&gt; &lt;arglist&gt;)<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001984<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001985<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
1986which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
1987or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001988<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001989<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001990<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001991<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00001992macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
1993Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
1994 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
1995with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001996</div>
Chris Lattner941515c2004-01-06 05:31:32 +00001997
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00001998<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00001999<div class="doc_subsubsection">
2000 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
2001</div>
2002
Misha Brukman76307852003-11-08 01:05:38 +00002003<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +00002004
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002005<h5>Syntax:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002006
2007<pre>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002008 call &lt;va_list&gt; (&lt;va_list&gt;)* %llvm.va_copy(&lt;va_list&gt; &lt;destarglist&gt;)
Chris Lattner757528b0b2004-05-23 21:06:01 +00002009</pre>
2010
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002011<h5>Overview:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002012
2013<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position
2014from the source argument list to the destination argument list.</p>
2015
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002016<h5>Arguments:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002017
Misha Brukman76307852003-11-08 01:05:38 +00002018<p>The argument is the <tt>va_list</tt> to copy.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002019
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002020<h5>Semantics:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002021
Misha Brukman76307852003-11-08 01:05:38 +00002022<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002023macro available in C. In a target-dependent way, it copies the source
2024<tt>va_list</tt> element into the returned list. This intrinsic is necessary
Chris Lattner53e5e2a2004-06-21 22:52:48 +00002025because the <tt><a href="#i_va_start">llvm.va_start</a></tt> intrinsic may be
Chris Lattner757528b0b2004-05-23 21:06:01 +00002026arbitrarily complex and require memory allocation, for example.</p>
2027
Misha Brukman76307852003-11-08 01:05:38 +00002028</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002029
Chris Lattnerfee11462004-02-12 17:01:32 +00002030<!-- ======================================================================= -->
2031<div class="doc_subsection">
Chris Lattner757528b0b2004-05-23 21:06:01 +00002032 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
2033</div>
2034
2035<div class="doc_text">
2036
2037<p>
2038LLVM support for <a href="GarbageCollection.html">Accurate Garbage
2039Collection</a> requires the implementation and generation of these intrinsics.
2040These intrinsics allow identification of <a href="#i_gcroot">GC roots on the
2041stack</a>, as well as garbage collector implementations that require <a
2042href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers.
2043Front-ends for type-safe garbage collected languages should generate these
2044intrinsics to make use of the LLVM garbage collectors. For more details, see <a
2045href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
2046</p>
2047</div>
2048
2049<!-- _______________________________________________________________________ -->
2050<div class="doc_subsubsection">
2051 <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
2052</div>
2053
2054<div class="doc_text">
2055
2056<h5>Syntax:</h5>
2057
2058<pre>
2059 call void (&lt;ty&gt;**, &lt;ty2&gt;*)* %llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
2060</pre>
2061
2062<h5>Overview:</h5>
2063
2064<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existance of a GC root to
2065the code generator, and allows some metadata to be associated with it.</p>
2066
2067<h5>Arguments:</h5>
2068
2069<p>The first argument specifies the address of a stack object that contains the
2070root pointer. The second pointer (which must be either a constant or a global
2071value address) contains the meta-data to be associated with the root.</p>
2072
2073<h5>Semantics:</h5>
2074
2075<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
2076location. At compile-time, the code generator generates information to allow
2077the runtime to find the pointer at GC safe points.
2078</p>
2079
2080</div>
2081
2082
2083<!-- _______________________________________________________________________ -->
2084<div class="doc_subsubsection">
2085 <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
2086</div>
2087
2088<div class="doc_text">
2089
2090<h5>Syntax:</h5>
2091
2092<pre>
2093 call sbyte* (sbyte**)* %llvm.gcread(sbyte** %Ptr)
2094</pre>
2095
2096<h5>Overview:</h5>
2097
2098<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
2099locations, allowing garbage collector implementations that require read
2100barriers.</p>
2101
2102<h5>Arguments:</h5>
2103
2104<p>The argument is the address to read from, which should be an address
2105allocated from the garbage collector.</p>
2106
2107<h5>Semantics:</h5>
2108
2109<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
2110instruction, but may be replaced with substantially more complex code by the
2111garbage collector runtime, as needed.</p>
2112
2113</div>
2114
2115
2116<!-- _______________________________________________________________________ -->
2117<div class="doc_subsubsection">
2118 <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
2119</div>
2120
2121<div class="doc_text">
2122
2123<h5>Syntax:</h5>
2124
2125<pre>
2126 call void (sbyte*, sbyte**)* %llvm.gcwrite(sbyte* %P1, sbyte** %P2)
2127</pre>
2128
2129<h5>Overview:</h5>
2130
2131<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
2132locations, allowing garbage collector implementations that require write
2133barriers (such as generational or reference counting collectors).</p>
2134
2135<h5>Arguments:</h5>
2136
2137<p>The first argument is the reference to store, and the second is the heap
2138location to store to.</p>
2139
2140<h5>Semantics:</h5>
2141
2142<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
2143instruction, but may be replaced with substantially more complex code by the
2144garbage collector runtime, as needed.</p>
2145
2146</div>
2147
2148
2149
2150<!-- ======================================================================= -->
2151<div class="doc_subsection">
Chris Lattner3649c3a2004-02-14 04:08:35 +00002152 <a name="int_codegen">Code Generator Intrinsics</a>
2153</div>
2154
2155<div class="doc_text">
2156<p>
2157These intrinsics are provided by LLVM to expose special features that may only
2158be implemented with code generator support.
2159</p>
2160
2161</div>
2162
2163<!-- _______________________________________________________________________ -->
2164<div class="doc_subsubsection">
2165 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
2166</div>
2167
2168<div class="doc_text">
2169
2170<h5>Syntax:</h5>
2171<pre>
2172 call void* ()* %llvm.returnaddress(uint &lt;level&gt;)
2173</pre>
2174
2175<h5>Overview:</h5>
2176
2177<p>
2178The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
2179indicating the return address of the current function or one of its callers.
2180</p>
2181
2182<h5>Arguments:</h5>
2183
2184<p>
2185The argument to this intrinsic indicates which function to return the address
2186for. Zero indicates the calling function, one indicates its caller, etc. The
2187argument is <b>required</b> to be a constant integer value.
2188</p>
2189
2190<h5>Semantics:</h5>
2191
2192<p>
2193The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
2194the return address of the specified call frame, or zero if it cannot be
2195identified. The value returned by this intrinsic is likely to be incorrect or 0
2196for arguments other than zero, so it should only be used for debugging purposes.
2197</p>
2198
2199<p>
2200Note that calling this intrinsic does not prevent function inlining or other
2201aggressive transformations, so the value returned may not that of the obvious
2202source-language caller.
2203</p>
2204</div>
2205
2206
2207<!-- _______________________________________________________________________ -->
2208<div class="doc_subsubsection">
2209 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
2210</div>
2211
2212<div class="doc_text">
2213
2214<h5>Syntax:</h5>
2215<pre>
2216 call void* ()* %llvm.frameaddress(uint &lt;level&gt;)
2217</pre>
2218
2219<h5>Overview:</h5>
2220
2221<p>
2222The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
2223pointer value for the specified stack frame.
2224</p>
2225
2226<h5>Arguments:</h5>
2227
2228<p>
2229The argument to this intrinsic indicates which function to return the frame
2230pointer for. Zero indicates the calling function, one indicates its caller,
2231etc. The argument is <b>required</b> to be a constant integer value.
2232</p>
2233
2234<h5>Semantics:</h5>
2235
2236<p>
2237The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
2238the frame address of the specified call frame, or zero if it cannot be
2239identified. The value returned by this intrinsic is likely to be incorrect or 0
2240for arguments other than zero, so it should only be used for debugging purposes.
2241</p>
2242
2243<p>
2244Note that calling this intrinsic does not prevent function inlining or other
2245aggressive transformations, so the value returned may not that of the obvious
2246source-language caller.
2247</p>
2248</div>
2249
John Criswellaa1c3c12004-04-09 16:43:20 +00002250<!-- ======================================================================= -->
2251<div class="doc_subsection">
2252 <a name="int_os">Operating System Intrinsics</a>
2253</div>
2254
2255<div class="doc_text">
2256<p>
2257These intrinsics are provided by LLVM to support the implementation of
2258operating system level code.
2259</p>
2260
2261</div>
John Criswella4501222004-04-12 15:02:16 +00002262
John Criswell508b93c2004-04-09 15:23:37 +00002263<!-- _______________________________________________________________________ -->
2264<div class="doc_subsubsection">
2265 <a name="i_readport">'<tt>llvm.readport</tt>' Intrinsic</a>
2266</div>
2267
2268<div class="doc_text">
2269
2270<h5>Syntax:</h5>
2271<pre>
John Criswellaa1c3c12004-04-09 16:43:20 +00002272 call &lt;integer type&gt; (&lt;integer type&gt;)* %llvm.readport (&lt;integer type&gt; &lt;address&gt;)
John Criswell508b93c2004-04-09 15:23:37 +00002273</pre>
2274
2275<h5>Overview:</h5>
2276
2277<p>
John Criswellaa1c3c12004-04-09 16:43:20 +00002278The '<tt>llvm.readport</tt>' intrinsic reads data from the specified hardware
2279I/O port.
John Criswell508b93c2004-04-09 15:23:37 +00002280</p>
2281
2282<h5>Arguments:</h5>
2283
2284<p>
John Criswellaa1c3c12004-04-09 16:43:20 +00002285The argument to this intrinsic indicates the hardware I/O address from which
2286to read the data. The address is in the hardware I/O address namespace (as
2287opposed to being a memory location for memory mapped I/O).
John Criswell508b93c2004-04-09 15:23:37 +00002288</p>
2289
2290<h5>Semantics:</h5>
2291
2292<p>
John Criswellaa1c3c12004-04-09 16:43:20 +00002293The '<tt>llvm.readport</tt>' intrinsic reads data from the hardware I/O port
2294specified by <i>address</i> and returns the value. The address and return
2295value must be integers, but the size is dependent upon the platform upon which
2296the program is code generated. For example, on x86, the address must be an
2297unsigned 16 bit value, and the return value must be 8, 16, or 32 bits.
John Criswell508b93c2004-04-09 15:23:37 +00002298</p>
2299
2300</div>
2301
2302<!-- _______________________________________________________________________ -->
2303<div class="doc_subsubsection">
2304 <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a>
2305</div>
2306
2307<div class="doc_text">
2308
2309<h5>Syntax:</h5>
2310<pre>
John Criswellaa1c3c12004-04-09 16:43:20 +00002311 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 Criswell508b93c2004-04-09 15:23:37 +00002312</pre>
2313
2314<h5>Overview:</h5>
2315
2316<p>
John Criswellaa1c3c12004-04-09 16:43:20 +00002317The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified hardware
2318I/O port.
John Criswell508b93c2004-04-09 15:23:37 +00002319</p>
2320
2321<h5>Arguments:</h5>
2322
2323<p>
John Criswell7a576472004-04-12 16:33:19 +00002324The first argument is the value to write to the I/O port.
John Criswell508b93c2004-04-09 15:23:37 +00002325</p>
2326
2327<p>
John Criswell7a576472004-04-12 16:33:19 +00002328The second argument indicates the hardware I/O address to which data should be
2329written. The address is in the hardware I/O address namespace (as opposed to
2330being a memory location for memory mapped I/O).
John Criswell508b93c2004-04-09 15:23:37 +00002331</p>
2332
2333<h5>Semantics:</h5>
2334
2335<p>
2336The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port
2337specified by <i>address</i>. The address and value must be integers, but the
2338size is dependent upon the platform upon which the program is code generated.
John Criswellaa1c3c12004-04-09 16:43:20 +00002339For example, on x86, the address must be an unsigned 16 bit value, and the
2340value written must be 8, 16, or 32 bits in length.
John Criswell508b93c2004-04-09 15:23:37 +00002341</p>
2342
2343</div>
Chris Lattner3649c3a2004-02-14 04:08:35 +00002344
John Criswella4501222004-04-12 15:02:16 +00002345<!-- _______________________________________________________________________ -->
2346<div class="doc_subsubsection">
2347 <a name="i_readio">'<tt>llvm.readio</tt>' Intrinsic</a>
2348</div>
2349
2350<div class="doc_text">
2351
2352<h5>Syntax:</h5>
2353<pre>
John Criswell7a576472004-04-12 16:33:19 +00002354 call &lt;result&gt; (&lt;ty&gt;*)* %llvm.readio (&lt;ty&gt; * &lt;pointer&gt;)
John Criswella4501222004-04-12 15:02:16 +00002355</pre>
2356
2357<h5>Overview:</h5>
2358
2359<p>
2360The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
2361address.
2362</p>
2363
2364<h5>Arguments:</h5>
2365
2366<p>
John Criswell7a576472004-04-12 16:33:19 +00002367The argument to this intrinsic is a pointer indicating the memory address from
2368which to read the data. The data must be a
2369<a href="#t_firstclass">first class</a> type.
John Criswella4501222004-04-12 15:02:16 +00002370</p>
2371
2372<h5>Semantics:</h5>
2373
2374<p>
2375The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
John Criswell7a576472004-04-12 16:33:19 +00002376location specified by <i>pointer</i> and returns the value. The argument must
2377be a pointer, and the return value must be a
2378<a href="#t_firstclass">first class</a> type. However, certain architectures
2379may not support I/O on all first class types. For example, 32 bit processors
2380may only support I/O on data types that are 32 bits or less.
John Criswella4501222004-04-12 15:02:16 +00002381</p>
2382
2383<p>
John Criswell7a576472004-04-12 16:33:19 +00002384This intrinsic enforces an in-order memory model for llvm.readio and
2385llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2386scheduled processors may execute loads and stores out of order, re-ordering at
2387run time accesses to memory mapped I/O registers. Using these intrinsics
2388ensures that accesses to memory mapped I/O registers occur in program order.
John Criswella4501222004-04-12 15:02:16 +00002389</p>
2390
2391</div>
2392
2393<!-- _______________________________________________________________________ -->
2394<div class="doc_subsubsection">
2395 <a name="i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a>
2396</div>
2397
2398<div class="doc_text">
2399
2400<h5>Syntax:</h5>
2401<pre>
John Criswell7a576472004-04-12 16:33:19 +00002402 call void (&lt;ty1&gt;, &lt;ty2&gt;*)* %llvm.writeio (&lt;ty1&gt; &lt;value&gt;, &lt;ty2&gt; * &lt;pointer&gt;)
John Criswella4501222004-04-12 15:02:16 +00002403</pre>
2404
2405<h5>Overview:</h5>
2406
2407<p>
2408The '<tt>llvm.writeio</tt>' intrinsic writes data to the specified memory
2409mapped I/O address.
2410</p>
2411
2412<h5>Arguments:</h5>
2413
2414<p>
John Criswell7a576472004-04-12 16:33:19 +00002415The first argument is the value to write to the memory mapped I/O location.
2416The second argument is a pointer indicating the memory address to which the
2417data should be written.
John Criswella4501222004-04-12 15:02:16 +00002418</p>
2419
2420<h5>Semantics:</h5>
2421
2422<p>
2423The '<tt>llvm.writeio</tt>' intrinsic writes <i>value</i> to the memory mapped
John Criswell7a576472004-04-12 16:33:19 +00002424I/O address specified by <i>pointer</i>. The value must be a
2425<a href="#t_firstclass">first class</a> type. However, certain architectures
2426may not support I/O on all first class types. For example, 32 bit processors
2427may only support I/O on data types that are 32 bits or less.
John Criswella4501222004-04-12 15:02:16 +00002428</p>
2429
2430<p>
John Criswell7a576472004-04-12 16:33:19 +00002431This intrinsic enforces an in-order memory model for llvm.readio and
2432llvm.writeio calls on machines that use dynamic scheduling. Dynamically
2433scheduled processors may execute loads and stores out of order, re-ordering at
2434run time accesses to memory mapped I/O registers. Using these intrinsics
2435ensures that accesses to memory mapped I/O registers occur in program order.
John Criswella4501222004-04-12 15:02:16 +00002436</p>
2437
2438</div>
2439
Chris Lattner3649c3a2004-02-14 04:08:35 +00002440<!-- ======================================================================= -->
2441<div class="doc_subsection">
Chris Lattnerfee11462004-02-12 17:01:32 +00002442 <a name="int_libc">Standard C Library Intrinsics</a>
2443</div>
2444
2445<div class="doc_text">
2446<p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00002447LLVM provides intrinsics for a few important standard C library functions.
2448These intrinsics allow source-language front-ends to pass information about the
2449alignment of the pointer arguments to the code generator, providing opportunity
2450for more efficient code generation.
Chris Lattnerfee11462004-02-12 17:01:32 +00002451</p>
2452
2453</div>
2454
2455<!-- _______________________________________________________________________ -->
2456<div class="doc_subsubsection">
2457 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
2458</div>
2459
2460<div class="doc_text">
2461
2462<h5>Syntax:</h5>
2463<pre>
2464 call void (sbyte*, sbyte*, uint, uint)* %llvm.memcpy(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2465 uint &lt;len&gt;, uint &lt;align&gt;)
2466</pre>
2467
2468<h5>Overview:</h5>
2469
2470<p>
2471The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2472location to the destination location.
2473</p>
2474
2475<p>
2476Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic
2477does not return a value, and takes an extra alignment argument.
2478</p>
2479
2480<h5>Arguments:</h5>
2481
2482<p>
2483The first argument is a pointer to the destination, the second is a pointer to
2484the source. The third argument is an (arbitrarily sized) integer argument
2485specifying the number of bytes to copy, and the fourth argument is the alignment
2486of the source and destination locations.
2487</p>
2488
Chris Lattner4c67c482004-02-12 21:18:15 +00002489<p>
2490If the call to this intrinisic has an alignment value that is not 0 or 1, then
2491the caller guarantees that the size of the copy is a multiple of the alignment
2492and that both the source and destination pointers are aligned to that boundary.
2493</p>
2494
Chris Lattnerfee11462004-02-12 17:01:32 +00002495<h5>Semantics:</h5>
2496
2497<p>
2498The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source
2499location to the destination location, which are not allowed to overlap. It
2500copies "len" bytes of memory over. If the argument is known to be aligned to
2501some boundary, this can be specified as the fourth argument, otherwise it should
2502be set to 0 or 1.
2503</p>
2504</div>
2505
2506
Chris Lattnerf30152e2004-02-12 18:10:10 +00002507<!-- _______________________________________________________________________ -->
2508<div class="doc_subsubsection">
2509 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
2510</div>
2511
2512<div class="doc_text">
2513
2514<h5>Syntax:</h5>
2515<pre>
2516 call void (sbyte*, sbyte*, uint, uint)* %llvm.memmove(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
2517 uint &lt;len&gt;, uint &lt;align&gt;)
2518</pre>
2519
2520<h5>Overview:</h5>
2521
2522<p>
2523The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source
2524location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>'
2525intrinsic but allows the two memory locations to overlap.
2526</p>
2527
2528<p>
2529Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic
2530does not return a value, and takes an extra alignment argument.
2531</p>
2532
2533<h5>Arguments:</h5>
2534
2535<p>
2536The first argument is a pointer to the destination, the second is a pointer to
2537the source. The third argument is an (arbitrarily sized) integer argument
2538specifying the number of bytes to copy, and the fourth argument is the alignment
2539of the source and destination locations.
2540</p>
2541
Chris Lattner4c67c482004-02-12 21:18:15 +00002542<p>
2543If the call to this intrinisic has an alignment value that is not 0 or 1, then
2544the caller guarantees that the size of the copy is a multiple of the alignment
2545and that both the source and destination pointers are aligned to that boundary.
2546</p>
2547
Chris Lattnerf30152e2004-02-12 18:10:10 +00002548<h5>Semantics:</h5>
2549
2550<p>
2551The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source
2552location to the destination location, which may overlap. It
2553copies "len" bytes of memory over. If the argument is known to be aligned to
2554some boundary, this can be specified as the fourth argument, otherwise it should
2555be set to 0 or 1.
2556</p>
2557</div>
2558
Chris Lattner941515c2004-01-06 05:31:32 +00002559
Chris Lattner3649c3a2004-02-14 04:08:35 +00002560<!-- _______________________________________________________________________ -->
2561<div class="doc_subsubsection">
2562 <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a>
2563</div>
2564
2565<div class="doc_text">
2566
2567<h5>Syntax:</h5>
2568<pre>
2569 call void (sbyte*, ubyte, uint, uint)* %llvm.memset(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
2570 uint &lt;len&gt;, uint &lt;align&gt;)
2571</pre>
2572
2573<h5>Overview:</h5>
2574
2575<p>
2576The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular
2577byte value.
2578</p>
2579
2580<p>
2581Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
2582does not return a value, and takes an extra alignment argument.
2583</p>
2584
2585<h5>Arguments:</h5>
2586
2587<p>
2588The first argument is a pointer to the destination to fill, the second is the
2589byte value to fill it with, the third argument is an (arbitrarily sized) integer
2590argument specifying the number of bytes to fill, and the fourth argument is the
2591known alignment of destination location.
2592</p>
2593
2594<p>
2595If the call to this intrinisic has an alignment value that is not 0 or 1, then
2596the caller guarantees that the size of the copy is a multiple of the alignment
2597and that the destination pointer is aligned to that boundary.
2598</p>
2599
2600<h5>Semantics:</h5>
2601
2602<p>
2603The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the
2604destination location. If the argument is known to be aligned to some boundary,
2605this can be specified as the fourth argument, otherwise it should be set to 0 or
26061.
2607</p>
2608</div>
2609
2610
Chris Lattner3b4f4372004-06-11 02:28:03 +00002611<!-- _______________________________________________________________________ -->
2612<div class="doc_subsubsection">
Alkis Evlogimenos0fa39232004-06-13 01:16:15 +00002613 <a name="i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a>
2614</div>
2615
2616<div class="doc_text">
2617
2618<h5>Syntax:</h5>
2619<pre>
2620 call bool (&lt;float or double&gt;, &lt;float or double&gt;)* %llvm.isunordered(&lt;float or double&gt; Val1,
2621 &lt;float or double&gt; Val2)
2622</pre>
2623
2624<h5>Overview:</h5>
2625
2626<p>
2627The '<tt>llvm.isunordered</tt>' intrinsic returns true if either or both of the
2628specified floating point values is a NAN.
2629</p>
2630
2631<h5>Arguments:</h5>
2632
2633<p>
2634The arguments are floating point numbers of the same type.
2635</p>
2636
2637<h5>Semantics:</h5>
2638
2639<p>
2640If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise
2641false.
2642</p>
2643</div>
2644
2645
Chris Lattner3b4f4372004-06-11 02:28:03 +00002646
2647
Chris Lattner941515c2004-01-06 05:31:32 +00002648<!-- ======================================================================= -->
2649<div class="doc_subsection">
2650 <a name="int_debugger">Debugger Intrinsics</a>
2651</div>
2652
2653<div class="doc_text">
2654<p>
2655The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
2656are described in the <a
2657href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
2658Debugging</a> document.
2659</p>
2660</div>
2661
2662
Chris Lattner2f7c9632001-06-06 20:29:01 +00002663<!-- *********************************************************************** -->
Chris Lattner2f7c9632001-06-06 20:29:01 +00002664<hr>
Misha Brukmanc501f552004-03-01 17:47:27 +00002665<address>
2666 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
2667 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
2668 <a href="http://validator.w3.org/check/referer"><img
2669 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
2670
2671 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
2672 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
2673 Last modified: $Date$
2674</address>
Misha Brukman76307852003-11-08 01:05:38 +00002675</body>
2676</html>